@extends('admin::layouts.master')

@section('title', 'Sections')

@section('content')
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-bold">Homepage Sections</h1>
        <a href="{{ route('admin.sections.create') }}" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">Add Section</a>
    </div>

    <div class="bg-white rounded-lg shadow overflow-hidden">
        <table class="w-full">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">ID</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Key</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Title</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sort Order</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Active</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-200">
                @forelse($sections as $section)
                    <tr class="hover:bg-gray-50">
                        <td class="px-6 py-4">{{ $section->id }}</td>
                        <td class="px-6 py-4">
                            <code class="bg-gray-100 px-2 py-1 rounded text-sm">{{ $section->key }}</code>
                        </td>
                        <td class="px-6 py-4">
                            <a href="{{ route('admin.sections.show', $section->id) }}" class="text-blue-600 hover:underline">{{ $section->title }}</a>
                        </td>
                        <td class="px-6 py-4">{{ $section->sort_order }}</td>
                        <td class="px-6 py-4">{{ $section->is_active ? 'Yes' : 'No' }}</td>
                        <td class="px-6 py-4 space-x-2">
                            <a href="{{ route('admin.sections.edit', $section->id) }}" class="text-blue-600 hover:underline">Edit</a>
                            <form action="{{ route('admin.sections.destroy', $section->id) }}" method="POST" class="inline" onsubmit="return confirm('Delete this section?')">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="text-red-600 hover:underline">Delete</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="px-6 py-4 text-center text-gray-500">No sections found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
@endsection
