<!-- Page Title -->
<div class="d-flex justify-content-between align-items-center mb-4">
    <h3 class="mb-0" style="color: var(--sidebar-bg);">
        <i class="bi bi-pencil me-2"></i>Edit Admin
    </h3>
    <a href="<?php echo base_url('admin/admins'); ?>" class="btn btn-secondary">
        <i class="bi bi-arrow-left me-2"></i>Kembali
    </a>
</div>

<!-- Edit Form -->
<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">Form Edit Admin</h5>
            </div>
            <div class="card-body">
                <form action="<?php echo base_url('admin/proses_edit_admin/' . $admin->id); ?>" method="POST">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="username" class="form-label">Username *</label>
                            <input type="text" class="form-control" id="username" name="username" required
                                maxlength="50" value="<?php echo set_value('username', $admin->username); ?>">
                            <?php echo form_error('username', '<small class="text-danger">', '</small>'); ?>
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="password" class="form-label">Password</label>
                            <input type="password" class="form-control" id="password" name="password" minlength="6">
                            <small class="text-muted">Kosongkan jika tidak ingin mengganti password</small>
                            <?php echo form_error('password', '<small class="text-danger">', '</small>'); ?>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="nama_lengkap" class="form-label">Nama Lengkap *</label>
                        <input type="text" class="form-control" id="nama_lengkap" name="nama_lengkap" required
                            maxlength="100" value="<?php echo set_value('nama_lengkap', $admin->nama_lengkap); ?>">
                        <?php echo form_error('nama_lengkap', '<small class="text-danger">', '</small>'); ?>
                    </div>

                    <div class="mb-3">
                        <label for="email" class="form-label">Email *</label>
                        <input type="email" class="form-control" id="email" name="email" required maxlength="100"
                            value="<?php echo set_value('email', $admin->email); ?>">
                        <?php echo form_error('email', '<small class="text-danger">', '</small>'); ?>
                    </div>

                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="level" class="form-label">Level *</label>
                            <select class="form-select" id="level" name="level" required>
                                <option value="admin"
                                    <?php echo set_select('level', 'admin', $admin->level == 'admin'); ?>>Administrator
                                </option>
                                <option value="operator"
                                    <?php echo set_select('level', 'operator', $admin->level == 'operator'); ?>>Operator
                                </option>
                            </select>
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="is_active" class="form-label">Status *</label>
                            <select class="form-select" id="is_active" name="is_active" required>
                                <option value="1" <?php echo set_select('is_active', '1', $admin->is_active == 1); ?>>
                                    Aktif</option>
                                <option value="0" <?php echo set_select('is_active', '0', $admin->is_active == 0); ?>>
                                    Nonaktif</option>
                            </select>
                        </div>
                    </div>

                    <div class="d-flex justify-content-between mt-4">
                        <a href="<?php echo base_url('admin/admins'); ?>" class="btn btn-secondary">
                            <i class="bi bi-x-circle me-2"></i>Batal
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save me-2"></i>Update Admin
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <!-- Admin Info -->
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-person-circle me-2"></i>Informasi Admin</h5>
            </div>
            <div class="card-body">
                <table class="table table-borderless">
                    <tr>
                        <th>ID Admin</th>
                        <td>: <?php echo $admin->id; ?></td>
                    </tr>
                    <tr>
                        <th>Terdaftar</th>
                        <td>: <?php echo date('d/m/Y', strtotime($admin->created_at)); ?></td>
                    </tr>
                    <tr>
                        <th>Update Terakhir</th>
                        <td>: <?php echo date('d/m/Y H:i', strtotime($admin->updated_at)); ?></td>
                    </tr>
                    <tr>
                        <th>Last Login</th>
                        <td>:
                            <?php if ($admin->last_login): ?>
                                <?php echo date('d/m/Y H:i', strtotime($admin->last_login)); ?>
                            <?php else: ?>
                                Belum pernah login
                            <?php endif; ?>
                        </td>
                    </tr>
                </table>

                <hr>

                <div class="alert alert-info">
                    <h6><i class="bi bi-exclamation-circle me-2"></i>Perhatian:</h6>
                    <ul class="mb-0 small">
                        <li>Pastikan username tetap unik</li>
                        <li>Jika mengganti password, beritahu admin yang bersangkutan</li>
                        <li>Nonaktifkan akun jika admin sudah tidak bertugas</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>