<x-app-layout>
    <x-slot name="header">
        <div class="d-flex justify-content-between align-items-center">
            <h2 class="h4 mb-0">Kelola Desa: {{ $desa->nama }}</h2>
            <div>
                @if ($desa->status !== 'published')
                    <form action="{{ route('super-admin.desa.publish', $desa) }}" method="POST" class="d-inline">
                        @csrf
                        <button class="btn btn-success btn-sm">Publikasikan</button>
                    </form>
                @else
                    <form action="{{ route('super-admin.desa.suspend', $desa) }}" method="POST" class="d-inline">
                        @csrf
                        <button class="btn btn-warning btn-sm">Suspend</button>
                    </form>
                @endif
            </div>
        </div>
    </x-slot>

    <div class="row g-3">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">Data Desa</div>
                <div class="card-body">
                    <form action="{{ route('super-admin.desa.update', $desa) }}" method="POST" enctype="multipart/form-data">
                        @csrf @method('PUT')
                        @include('pilkades::super-admin.desa.form', ['desa' => $desa])
                        <button class="btn btn-primary">Simpan Perubahan</button>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card mb-3">
                <div class="card-header">Admin Desa</div>
                <div class="card-body">
                    @forelse ($desa->admins as $admin)
                        <div class="d-flex justify-content-between align-items-center border-bottom py-2">
                            <div>
                                <div class="fw-semibold">{{ $admin->user->name }}</div>
                                <div class="small text-muted">{{ $admin->user->email }}</div>
                            </div>
                            <form action="{{ route('super-admin.admin-desa.reset-password', $admin->user) }}" method="POST">
                                @csrf
                                <button class="btn btn-sm btn-outline-secondary">Reset Password</button>
                            </form>
                        </div>
                    @empty
                        <p class="text-muted small mb-0">Belum ada Admin Desa untuk desa ini.</p>
                    @endforelse
                </div>
            </div>

            <div class="card">
                <div class="card-header">Tambah Admin Desa</div>
                <div class="card-body">
                    <form action="{{ route('super-admin.admin-desa.store', $desa) }}" method="POST">
                        @csrf
                        <div class="mb-3">
                            <x-input-label for="name" value="Nama" />
                            <x-text-input id="name" name="name" required />
                        </div>
                        <div class="mb-3">
                            <x-input-label for="email" value="Email" />
                            <x-text-input id="email" name="email" type="email" required />
                        </div>
                        <div class="mb-3">
                            <x-input-label for="jabatan" value="Jabatan (opsional)" />
                            <x-text-input id="jabatan" name="jabatan" />
                        </div>
                        <button class="btn btn-primary btn-sm">Buat Akun Admin Desa</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
