@extends('layouts.app')

@section('content')
<div class="container mx-auto max-w-5xl px-4">
    @include('admin.panel._nav')

    <h1 class="mb-6 text-xl font-semibold text-gray-900">Konten Section Homepage</h1>

    <div class="overflow-x-auto rounded border border-gray-200">
        <table class="min-w-full text-sm">
            <thead class="bg-gray-50 text-left text-gray-600">
                <tr>
                    <th class="px-4 py-2">Section</th>
                    <th class="px-4 py-2">Judul</th>
                    <th class="px-4 py-2">Item</th>
                    <th class="px-4 py-2">Status</th>
                    <th class="px-4 py-2">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($sections as $section)
                    <tr class="border-t border-gray-100">
                        <td class="px-4 py-2 font-medium text-gray-900">{{ $section->name }}</td>
                        <td class="px-4 py-2">{{ $section->title ?: '-' }}</td>
                        <td class="px-4 py-2">{{ $section->items_count }}</td>
                        <td class="px-4 py-2">
                            @if ($section->is_active)
                                <span class="rounded bg-green-100 px-2 py-1 text-xs text-green-800">Aktif</span>
                            @else
                                <span class="rounded bg-gray-200 px-2 py-1 text-xs text-gray-700">Nonaktif</span>
                            @endif
                        </td>
                        <td class="px-4 py-2">
                            <div class="flex flex-wrap gap-2">
                                @can('edit sections')
                                    <a href="{{ route('admin.sections.edit', $section) }}" class="text-blue-600 hover:underline">Edit</a>
                                    <form method="POST" action="{{ route('admin.sections.toggle-status', $section) }}">
                                        @csrf
                                        @method('PATCH')
                                        <button type="submit" class="text-amber-600 hover:underline">
                                            {{ $section->is_active ? 'Nonaktifkan' : 'Aktifkan' }}
                                        </button>
                                    </form>
                                @endcan
                            </div>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection
