<!-- resources/views/admin/settings.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Settings</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link href="{{ asset('css/styles.css') }}" rel="stylesheet">
</head>
<body class="bg-light">
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-4">
        <div class="container">
            <a class="navbar-brand" href="{{ route('admin.dashboard') }}">
                <i class="bi bi-arrow-left me-2"></i>
                Kembali ke Dashboard
            </a>
        </div>
    </nav>

    <div class="container py-4">
        <div class="row justify-content-center g-4">
            <!-- Max Queue Settings Column -->
            <div class="col-md-6">
                <div class="card h-100 shadow-sm">
                    <div class="card-body p-4">
                        <h4 class="card-title mb-4">
                            <i class="bi bi-people me-2 text-primary"></i>
                            Pengaturan Antrian
                        </h4>
                        <form action="{{ route('admin.updateSettings') }}" method="POST">
                            @csrf
                            <div class="mb-4">
                                <label class="form-label fw-bold">Maksimal Antrian per Hari</label>
                                <input type="number" 
                                       name="max_daily_queue" 
                                       class="form-control form-control-lg @error('max_daily_queue') is-invalid @enderror"
                                       value="{{ $settings['max_daily_queue'] ?? '' }}"
                                       required>
                                @error('max_daily_queue')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Kuota 08:00</label>
                                <input type="number" 
                                       name="quota_08_00" 
                                       class="form-control form-control-lg @error('quota_08_00') is-invalid @enderror"
                                       value="{{ $settings['quota_08_00'] ?? '' }}"
                                       required>
                                @error('quota_08_00')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Kuota 09:00</label>
                                <input type="number" 
                                       name="quota_09_00" 
                                       class="form-control form-control-lg @error('quota_09_00') is-invalid @enderror"
                                       value="{{ $settings['quota_09_00'] ?? '' }}"
                                       required>
                                @error('quota_09_00')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Kuota 10:00</label>
                                <input type="number" 
                                       name="quota_10_00" 
                                       class="form-control form-control-lg @error('quota_10_00') is-invalid @enderror"
                                       value="{{ $settings['quota_10_00'] ?? '' }}"
                                       required>
                                @error('quota_10_00')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Kuota 11:00</label>
                                <input type="number" 
                                       name="quota_11_00" 
                                       class="form-control form-control-lg @error('quota_11_00') is-invalid @enderror"
                                       value="{{ $settings['quota_11_00'] ?? '' }}"
                                       required>
                                @error('quota_11_00')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="d-grid">
                                <button type="submit" class="btn btn-primary btn-lg">
                                    <i class="bi bi-save me-2"></i>
                                    Simpan Pengaturan
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- Password Settings Column -->
            <div class="col-md-6">
                <div class="card h-100 shadow-sm">
                    <div class="card-body p-4">
                        <h4 class="card-title mb-4">
                            <i class="bi bi-shield-lock me-2 text-primary"></i>
                            Ganti Password
                        </h4>
                        <form action="{{ route('admin.updateSettings') }}" method="POST">
                            @csrf
                            <input type="hidden" name="max_daily_queue" value="{{ $settings['max_daily_queue'] ?? '' }}">
                            <div class="mb-4">
                                <label class="form-label fw-bold">Password Lama</label>
                                <input type="password" 
                                       name="old_password" 
                                       class="form-control form-control-lg @error('old_password') is-invalid @enderror">
                                @error('old_password')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Password Baru</label>
                                <input type="password" 
                                       name="new_password" 
                                       class="form-control form-control-lg @error('new_password') is-invalid @enderror">
                                @error('new_password')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="mb-4">
                                <label class="form-label fw-bold">Konfirmasi Password Baru</label>
                                <input type="password" 
                                       name="new_password_confirmation" 
                                       class="form-control form-control-lg">
                            </div>
                            <div class="d-grid">
                                <button type="submit" class="btn btn-primary btn-lg">
                                    <i class="bi bi-key me-2"></i>
                                    Ganti Password
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- Holiday Settings Two Columns Width -->
            <div class="col-12 mt-4">
                <div class="card shadow-sm">
                    <div class="card-body p-4">
                        <h4 class="card-title mb-4">
                            <i class="bi bi-calendar-event me-2 text-primary"></i>
                            Pengaturan Hari Libur
                        </h4>
                        <div class="row">
                            <!-- Holiday Input Form -->
                            <div class="col-md-6">
                                <form action="{{ route('admin.holiday.store') }}" method="POST">
                                    @csrf
                                    <div class="mb-4">
                                        <label class="form-label fw-bold">Tanggal Libur</label>
                                        <input type="date" 
                                               name="date" 
                                               class="form-control form-control-lg @error('date') is-invalid @enderror"
                                               min="{{ date('Y-m-d') }}"
                                               required>
                                        @error('date')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>
                                    <div class="mb-4">
                                        <label class="form-label fw-bold">Keterangan</label>
                                        <input type="text" 
                                               name="description" 
                                               class="form-control form-control-lg @error('description') is-invalid @enderror"
                                               placeholder="Contoh: Hari Raya Idul Fitri"
                                               required>
                                        @error('description')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>
                                    <div class="d-grid">
                                        <button type="submit" class="btn btn-primary btn-lg">
                                            <i class="bi bi-plus-circle me-2"></i>
                                            Tambah Hari Libur
                                        </button>
                                    </div>
                                </form>
                            </div>

                            <!-- Holiday List Table -->
                            <div class="col-md-6">
                                <div class="table-responsive">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Tanggal</th>
                                                <th>Keterangan</th>
                                                <th>Aksi</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @forelse($holidays as $holiday)
                                            <tr>
                                                <td>{{ \Carbon\Carbon::parse($holiday->date)->format('d/m/Y') }}</td>
                                                <td>{{ $holiday->description }}</td>
                                                <td>
                                                    <form action="{{ route('admin.holiday.delete', $holiday->id) }}" 
                                                          method="POST" 
                                                          class="d-inline"
                                                          onsubmit="return confirm('Yakin ingin menghapus hari libur ini?')">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="btn btn-danger btn-sm">
                                                            <i class="bi bi-trash"></i>
                                                        </button>
                                                    </form>
                                                </td>
                                            </tr>
                                            @empty
                                            <tr>
                                                <td colspan="3" class="text-center">Belum ada hari libur</td>
                                            </tr>
                                            @endforelse
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>