@extends('layouts.app', [
    'pageTitle' => $title,
])

@section('content')
<div>
    <!-- Header -->
    <div class="mb-6 flex flex-wrap items-center justify-between gap-3">
        <div>
            <h2 class="text-xl font-semibold text-gray-800 dark:text-white/90">{{ $title }}</h2>
            <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Kelola kategori pengeluaran</p>
        </div>
        <a href="{{ route('expense-categories.create') }}"
           class="inline-flex items-center justify-center gap-2 rounded-lg bg-brand-500 px-4 py-2.5 text-sm font-medium text-white shadow-theme-xs hover:bg-brand-600">
            <svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
            </svg>
            Tambah Jenis
        </a>
    </div>

    @include('partials.alerts')

    <!-- Filters -->
    <div class="mb-6 rounded-xl border border-gray-200 bg-white p-4 dark:border-gray-800 dark:bg-white/[0.03]">
        <form action="{{ route('expense-categories.index') }}" method="GET" class="flex flex-wrap gap-4">
            <div class="w-full sm:flex-1">
                <x-form.input name="search" value="{{ request('search') }}" placeholder="Cari nama jenis..."/>
            </div>
            <div class="w-full sm:w-auto">
                <x-form.select name="status" placeholder="Semua Status">
                    <option value="active" {{ request('status') == 'active' ? 'selected' : '' }}>Aktif</option>
                    <option value="inactive" {{ request('status') == 'inactive' ? 'selected' : '' }}>Tidak Aktif</option>
                </x-form.select>
            </div>
            <button type="submit" class="rounded-lg bg-gray-100 px-4 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700">
                Cari
            </button>
        </form>
    </div>

    <!-- Table -->
    <div class="overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[0.03]">
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="border-b border-gray-100 dark:border-gray-800">
                    <tr class="text-left">
                        <th class="px-5 py-3 text-sm font-medium text-gray-500 dark:text-gray-400">Nama</th>
                        <th class="px-5 py-3 text-sm font-medium text-gray-500 dark:text-gray-400">Deskripsi</th>
                        <th class="px-5 py-3 text-sm font-medium text-gray-500 dark:text-gray-400">Jumlah Transaksi</th>
                        <th class="px-5 py-3 text-sm font-medium text-gray-500 dark:text-gray-400">Status</th>
                        <th class="px-5 py-3 text-sm font-medium text-gray-500 dark:text-gray-400"></th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100 dark:divide-gray-800">
                    @forelse($categories as $category)
                    <tr>
                        <td class="px-5 py-4 text-sm font-medium text-gray-800 dark:text-white/90">
                            {{ $category->name }}
                        </td>
                        <td class="px-5 py-4 text-sm text-gray-500 dark:text-gray-400">
                            {{ $category->description ?? '-' }}
                        </td>
                        <td class="px-5 py-4 text-sm text-gray-800 dark:text-white/90">
                            {{ $category->expenses_count }} transaksi
                        </td>
                        <td class="px-5 py-4">
                            <span class="inline-flex rounded-full px-2 py-1 text-xs font-medium {{ $category->is_active ? 'bg-success-100 text-success-700 dark:bg-success-500/15 dark:text-success-400' : 'bg-gray-100 text-gray-700 dark:bg-gray-500/15 dark:text-gray-400' }}">
                                {{ $category->is_active ? 'Aktif' : 'Tidak Aktif' }}
                            </span>
                        </td>
                        <td class="px-5 py-4">
                            <div class="flex items-center gap-2">
                                <a href="{{ route('expense-categories.edit', $category) }}" class="text-sm text-brand-500 hover:text-brand-600">Edit</a>
                                <button @click="$dispatch('open-delete-modal', { action: '{{ route('expense-categories.destroy', $category) }}', title: 'Hapus Jenis Pengeluaran?', description: 'Hapus jenis pengeluaran ini?' })" type="button" class="text-sm text-error-500 hover:text-error-600">Hapus</button>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="5" class="px-5 py-8 text-center text-sm text-gray-500 dark:text-gray-400">
                            Belum ada jenis pengeluaran
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

    @if($categories->hasPages())
    <div class="mt-4">
        {{ $categories->links() }}
    </div>
    @endif
</div>
    <x-ui.delete-confirm />
@endsection
