@extends('layouts.admin')

@section('title', 'Master Kategori')
@section('page-title', 'Kelola Kategori Produk')

@section('content')
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
            <h5 class="mb-0 fw-bold">Daftar Kategori</h5>
            <a href="{{ route('admin.kategori.create') }}" class="btn btn-primary btn-sm rounded-pill px-4">
                <i class="bi bi-plus-lg me-1"></i> Tambah Baru
            </a>
        </div>
        <div class="card-body">
            @if(session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    {{ session('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            @endif

            <div class="table-responsive">
                <table class="table table-hover align-middle">
                    <thead class="bg-light">
                        <tr>
                            <th width="5%">No</th>
                            <th>Ikon</th>
                            <th>Nama Kategori</th>
                            <th>Slug</th>
                            <th>Jumlah Produk</th>
                            <th width="15%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($kategoris as $index => $kat)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>
                                    @if($kat->ikon)
                                        <i class="{{ $kat->ikon }} fs-5 text-secondary"></i>
                                    @else
                                        <span class="text-muted">-</span>
                                    @endif
                                </td>
                                <td class="fw-bold">{{ $kat->nama_kategori }}</td>
                                <td><code class="text-primary">{{ $kat->slug }}</code></td>
                                <td>
                                    <span class="badge bg-info bg-opacity-10 text-info rounded-pill px-3">
                                        {{ $kat->produks_count }} Produk
                                    </span>
                                </td>
                                <td class="text-center">
                                    <a href="{{ route('admin.kategori.edit', $kat->id) }}" class="btn btn-sm btn-warning me-1">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <form action="{{ route('admin.kategori.destroy', $kat->id) }}" method="POST"
                                        class="d-inline"
                                        onsubmit="return confirm('Yakin hapus kategori ini? Produk terkait akan kehilangan kategorinya.')">
                                        @csrf @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-danger">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center py-5 text-muted">Belum ada kategori data.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection