@extends('layouts.app')

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

    <div class="mb-6 flex items-center justify-between">
        <h1 class="text-xl font-semibold text-gray-900">Tema Warna</h1>
        @can('create themes')
            <a href="{{ route('admin.themes.create') }}" class="rounded bg-gray-900 px-3 py-2 text-sm text-white hover:bg-gray-700">
                Tambah Tema
            </a>
        @endcan
    </div>
    <p class="mb-4 text-sm text-gray-500">Buat beberapa tema (mis. Default, Natal, Kemerdekaan), lalu klik "Aktifkan" salah satu untuk mengganti warna utama homepage saat ada event.</p>

    <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">Warna</th>
                    <th class="px-4 py-2">Logo</th>
                    <th class="px-4 py-2">Nama</th>
                    <th class="px-4 py-2">Status</th>
                    <th class="px-4 py-2">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @forelse ($themes as $theme)
                    <tr class="border-t border-gray-100">
                        <td class="px-4 py-2">
                            <span class="inline-block h-6 w-6 rounded-full border border-gray-200 align-middle" style="background-color: {{ $theme->primary_color }}"></span>
                            <span class="ml-2 align-middle text-xs text-gray-500">{{ $theme->primary_color }}</span>
                        </td>
                        <td class="px-4 py-2">
                            @if ($theme->logoUrl())
                                <img src="{{ $theme->logoUrl() }}" alt="Logo {{ $theme->name }}" class="h-8 w-auto rounded bg-slate-800 object-contain p-1">
                            @else
                                <span class="text-xs text-gray-400">-</span>
                            @endif
                        </td>
                        <td class="px-4 py-2 font-medium text-gray-900">{{ $theme->name }}</td>
                        <td class="px-4 py-2">
                            @if ($theme->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 themes')
                                    @unless ($theme->is_active)
                                        <form method="POST" action="{{ route('admin.themes.activate', $theme) }}">
                                            @csrf
                                            <button type="submit" class="text-green-600 hover:underline">Aktifkan</button>
                                        </form>
                                    @endunless
                                    <a href="{{ route('admin.themes.edit', $theme) }}" class="text-blue-600 hover:underline">Edit</a>
                                @endcan
                                @can('delete themes')
                                    <form method="POST" action="{{ route('admin.themes.destroy', $theme) }}"
                                          onsubmit="return confirm('Hapus tema ini?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="text-red-600 hover:underline">Hapus</button>
                                    </form>
                                @endcan
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" class="px-4 py-6 text-center text-gray-500">Belum ada tema.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
