<div x-data="{ showConfirmModal: @entangle('showConfirmModal') }">

    {{-- Header --}}
    <div class="mb-6">
        <h1 class="text-2xl font-bold text-slate-800">Maintenance</h1>
        <p class="text-sm text-slate-500 mt-0.5">Informasi sistem dan perawatan cache aplikasi.</p>
    </div>

    <div class="max-w-3xl space-y-5">

        {{-- Info Sistem --}}
        <div class="bg-white rounded-xl border border-slate-200 p-6">
            <h2 class="font-semibold text-slate-800 mb-4">Informasi Sistem</h2>

            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div class="flex items-center justify-between py-2 border-b border-slate-100">
                    <span class="text-sm text-slate-500">PHP Version</span>
                    <span class="text-sm font-medium text-slate-800 font-mono">{{ $info['php_version'] }}</span>
                </div>
                <div class="flex items-center justify-between py-2 border-b border-slate-100">
                    <span class="text-sm text-slate-500">Laravel Version</span>
                    <span class="text-sm font-medium text-slate-800 font-mono">{{ $info['laravel_version'] }}</span>
                </div>
                <div class="flex items-center justify-between py-2 border-b border-slate-100">
                    <span class="text-sm text-slate-500">Database</span>
                    <span class="inline-flex items-center gap-1.5 text-sm font-medium">
                        <span class="w-2 h-2 rounded-full {{ $info['db_status'] === 'Terhubung' ? 'bg-green-500' : 'bg-red-500' }}"></span>
                        <span class="text-slate-800">{{ ucfirst($info['db_driver']) }}</span>
                        <span class="text-xs text-slate-400">({{ $info['db_status'] }})</span>
                    </span>
                </div>
                <div class="flex items-center justify-between py-2 border-b border-slate-100">
                    <span class="text-sm text-slate-500">Storage</span>
                    <span class="inline-flex items-center gap-1.5 text-sm font-medium">
                        <span class="w-2 h-2 rounded-full {{ $info['storage_writable'] ? 'bg-green-500' : 'bg-red-500' }}"></span>
                        <span class="text-slate-800">{{ ucfirst($info['storage_disk']) }}</span>
                        <span class="text-xs text-slate-400">({{ $info['storage_writable'] ? 'Writable' : 'Tidak writable' }})</span>
                    </span>
                </div>
                <div class="flex items-center justify-between py-2 sm:border-b-0 border-b border-slate-100">
                    <span class="text-sm text-slate-500">Cache Status</span>
                    <span class="inline-flex items-center gap-1.5 text-sm font-medium">
                        <span class="w-2 h-2 rounded-full {{ $info['cache_status'] === 'Aktif' ? 'bg-green-500' : 'bg-red-500' }}"></span>
                        <span class="text-slate-800">{{ ucfirst($info['cache_driver']) }}</span>
                        <span class="text-xs text-slate-400">({{ $info['cache_status'] }})</span>
                    </span>
                </div>
            </div>
        </div>

        {{-- Perawatan Cache --}}
        <div class="bg-white rounded-xl border border-slate-200 p-6">
            <h2 class="font-semibold text-slate-800 mb-1">Perawatan Cache</h2>
            <p class="text-sm text-slate-500 mb-4">Bersihkan cache aplikasi jika terjadi masalah tampilan atau konfigurasi yang tidak ter-update.</p>

            <div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
                @foreach ($actionLabels as $key => $label)
                    <button type="button" wire:click="confirmAction('{{ $key }}')"
                        class="flex items-center justify-between px-4 py-3 border border-slate-200 rounded-lg hover:border-orange-300 hover:bg-orange-50 transition-colors text-left"
                        wire:loading.attr="disabled" wire:target="executeAction">
                        <div>
                            <p class="text-sm font-medium text-slate-800">{{ $label }}</p>
                            <p class="text-xs text-slate-400">
                                @if ($key === 'cache')
                                    Hapus seluruh cache aplikasi
                                @elseif ($key === 'view')
                                    Hapus compiled Blade view
                                @elseif ($key === 'config')
                                    Hapus cache konfigurasi
                                @else
                                    Hapus cache daftar route
                                @endif
                            </p>
                        </div>
                        <svg class="w-5 h-5 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"/>
                        </svg>
                    </button>
                @endforeach
            </div>

            <p class="mt-4 text-xs text-slate-400">
                Setelah menjalankan perintah, beberapa halaman mungkin perlu di-refresh manual untuk menampilkan perubahan terbaru.
            </p>
        </div>

    </div>

    {{-- ── Modal Konfirmasi ────────────────────────────────────────────── --}}
    <div x-show="showConfirmModal" x-cloak class="fixed inset-0 z-50 flex items-center justify-center p-4"
        x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100">
        <div class="absolute inset-0 bg-black/50" @click="$wire.set('showConfirmModal', false)"></div>
        <div class="relative bg-white rounded-2xl shadow-xl w-full max-w-sm" @click.stop>
            <div class="p-6 text-center">
                <div class="w-12 h-12 bg-orange-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <svg class="w-6 h-6 text-orange-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"/>
                    </svg>
                </div>
                <h3 class="text-lg font-semibold text-slate-800 mb-1">
                    Jalankan "{{ $actionLabels[$pendingAction] ?? '' }}"?
                </h3>
                <p class="text-sm text-slate-500 mb-6">
                    Tindakan ini akan mempengaruhi seluruh aplikasi. Pastikan Anda yakin sebelum melanjutkan.
                </p>
                <div class="flex gap-3">
                    <button type="button" wire:click="$set('showConfirmModal', false)"
                        class="flex-1 px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50">
                        Batal
                    </button>
                    <button type="button" wire:click="executeAction"
                        class="flex-1 px-4 py-2 text-sm font-medium text-white bg-orange-500 rounded-lg hover:bg-orange-600"
                        wire:loading.attr="disabled" wire:target="executeAction">
                        <span wire:loading.remove wire:target="executeAction">Ya, Jalankan</span>
                        <span wire:loading wire:target="executeAction">Memproses...</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <x-admin.toast />
</div>
