{{-- Admin Loan Products Index --}}
<x-app-layout title="Loan Products">

    <x-module-hero title="Loan Products" description="Manage loan products and configurations" icon="fa-money-bill-wave">
        <x-slot name="tabs">
            @can('view loan products')
                <a href="{{ route('admin.loan-products.index') }}" class="module-hero-tab active-tab">
                    <i class="fas fa-box"></i> Products
                </a>
            @endcan
            @can('view loan applications')
                <a href="{{ route('admin.loan-applications.index') }}" class="module-hero-tab">
                    <i class="fas fa-file-alt"></i> Applications
                </a>
            @endcan
            @can('view loan applications')
                <a href="{{ route('admin.loans.active') }}" class="module-hero-tab">
                    <i class="fas fa-check-circle"></i> Active Loans
                </a>
            @endcan
            @can('view loan applications')
                <a href="{{ route('admin.loans.overdue') }}" class="module-hero-tab">
                    <i class="fas fa-exclamation-triangle"></i> Overdue
                </a>
            @endcan
            @can('view members')
                <a href="{{ route('admin.membership.dashboard') }}" class="module-hero-tab">
                    <i class="fas fa-id-card"></i> Membership
                </a>
            @endcan
        </x-slot>
        <x-slot name="actions">
            @can('create loan products')
                <a href="{{ route('admin.loan-products.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-white/20 hover:bg-white/30 text-white text-sm font-medium rounded transition">
                    <i class="fas fa-plus"></i> New Product
                </a>
            @endcan
        </x-slot>
    </x-module-hero>

    <div class="p-6">
        @if(session('success'))
            <div class="mb-6 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg flex items-center">
                <i class="fas fa-check-circle mr-3"></i> {{ session('success') }}
            </div>
        @endif
        @if(session('error'))
            <div class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg flex items-center">
                <i class="fas fa-exclamation-circle mr-3"></i> {{ session('error') }}
            </div>
        @endif

        @if($products->count() > 0)
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                @foreach($products as $product)
                    <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-shadow">
                        <div class="p-5 text-white relative" style="background-color: var(--theme-bg-sidebar);">
                            @if($product->is_featured)
                                <span class="absolute top-3 right-3 bg-yellow-400 text-yellow-900 text-xs px-2 py-0.5 rounded-full font-semibold">Featured</span>
                            @endif
                            <h3 class="text-lg font-bold mb-1">{{ $product->name }}</h3>
                            <p class="text-white/70 text-sm">{{ $product->interest_rate_display ?? $product->interest_rate . '% APR' }}</p>
                        </div>
                        <div class="p-5">
                            <p class="text-gray-600 text-sm mb-4 line-clamp-2">{{ $product->description ?? 'Configure loan terms and eligibility.' }}</p>
                            <div class="grid grid-cols-3 gap-2 mb-4 text-center">
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-lg font-bold text-gray-900">{{ $product->loan_applications_count ?? 0 }}</div>
                                    <div class="text-xs text-gray-500">Applications</div>
                                </div>
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-sm font-bold text-gray-900">{{ $product->min_term_months }}-{{ $product->max_term_months }}</div>
                                    <div class="text-xs text-gray-500">Months</div>
                                </div>
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-sm font-bold text-gray-900">{{ $product->currency }}</div>
                                    <div class="text-xs text-gray-500">Currency</div>
                                </div>
                            </div>
                            <div class="flex justify-between items-center mb-4">
                                <span class="text-xs text-gray-500">Status:</span>
                                <span class="px-2 py-0.5 rounded-full text-xs font-semibold {{ $product->is_active ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' }}">
                                    {{ $product->is_active ? 'Active' : 'Inactive' }}
                                </span>
                            </div>
                            <div class="flex gap-2">
                                <a href="{{ route('admin.loan-products.show', $product) }}" class="btn-action-view flex-1 justify-center">
                                    <i class="fas fa-eye"></i> View
                                </a>
                                @can('edit loan products')
                                    <a href="{{ route('admin.loan-products.edit', $product) }}" class="btn-action-edit flex-1 justify-center">
                                        <i class="fas fa-edit"></i> Edit
                                    </a>
                                @endcan
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
        @else
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-12 text-center">
                <i class="fas fa-box-open text-5xl text-gray-300 mb-4"></i>
                <h3 class="text-lg font-semibold text-gray-700 mb-2">No Loan Products</h3>
                <p class="text-gray-500 mb-6">Get started by creating your first loan product.</p>
                @can('create loan products')
                    <a href="{{ route('admin.loan-products.create') }}" class="inline-flex items-center px-6 py-2.5 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm font-medium">
                        <i class="fas fa-plus mr-2"></i> Create First Product
                    </a>
                @endcan
            </div>
        @endif
    </div>

</x-app-layout>
