<x-filament-panels::page>
    <x-filament::section heading="主题列表">
        <div class="grid gap-5 sm:grid-cols-2 lg:grid-cols-3">
            @forelse($this->themes as $theme)
                <div class="flex flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-white/10 dark:bg-white/5">
                    {{-- 主题预览图 --}}
                    <div class="relative aspect-[4/3] overflow-hidden bg-gray-100 dark:bg-white/5">
                        @if($theme['screenshot'])
                            <img src="{{ theme('asset', $theme['screenshot'], $theme['name']) }}"
                                 alt="{{ $theme['title'] }} 预览"
                                 class="h-full w-full object-cover object-top transition-transform duration-300 hover:scale-105">
                        @else
                            <div class="flex h-full items-center justify-center text-gray-400">
                                <x-filament::icon icon="heroicon-o-photo" class="h-10 w-10" />
                            </div>
                        @endif
                        @if($theme['active'])
                            <div class="absolute left-3 top-3">
                                <x-filament::badge color="success">使用中</x-filament::badge>
                            </div>
                        @endif
                    </div>

                    <div class="flex flex-1 flex-col p-5">
                        <div class="flex items-center justify-between">
                            <h3 class="font-semibold">{{ $theme['title'] }}</h3>
                            <span class="text-xs text-gray-400">v{{ $theme['version'] }}</span>
                        </div>
                        <p class="mt-1 flex-1 text-sm text-gray-500 dark:text-gray-400">{{ $theme['description'] }}</p>
                        <p class="mt-1 text-xs text-gray-400">{{ $theme['author'] }}</p>

                        @if($theme['inject_points'])
                            <div class="mt-3 flex flex-wrap gap-1">
                                @foreach($theme['inject_points'] as $point)
                                    <x-filament::badge color="gray" size="xs">{{ $point }}</x-filament::badge>
                                @endforeach
                            </div>
                        @endif

                        <div class="mt-4 flex gap-2">
                            @if(! $theme['active'])
                                <x-filament::button size="sm" color="primary" wire:click="activateTheme('{{ $theme['name'] }}')">启用</x-filament::button>
                                <x-filament::button size="sm" color="danger" wire:click="uninstallTheme('{{ $theme['name'] }}')" wire:confirm="确定删除该主题？">删除</x-filament::button>
                            @endif
                        </div>
                    </div>
                </div>
            @empty
                <p class="text-sm text-gray-500">暂无主题</p>
            @endforelse
        </div>
    </x-filament::section>

    <x-filament::section heading="安装主题（ZIP）">
        <form wire:submit="uploadThemeZip" class="flex items-end gap-3">
            <div class="flex-1">
                <x-filament::input.wrapper>
                    <x-filament::input type="file" wire:model="zip" accept=".zip" />
                </x-filament::input.wrapper>
                @error('zip') <p class="mt-1 text-sm text-danger-600">{{ $message }}</p> @enderror
            </div>
            <x-filament::button type="submit" color="primary">安装</x-filament::button>
        </form>
    </x-filament::section>
</x-filament-panels::page>
