<?= $this->extend('layout/template') ?>

<?= $this->section('content') ?>

<div class="container-fluid">

    <div class="card shadow-sm">
        <div class="card-header bg-success text-white">
            <h4 class="mb-0">
                <i class="fas fa-user-cog"></i>
                Pengaturan Akun
            </h4>
        </div>
        <div class="card-body">

            <?php if (session()->getFlashdata('success')) : ?>
                <div class="alert alert-success">
                    <i class="fas fa-check"></i>
                    <?= session()->getFlashdata('success') ?>
                </div>
            <?php endif; ?>

            <?php if (session()->getFlashdata('error')) : ?>
                <div class="alert alert-danger">
                    <i class="fas fa-times"></i>
                    <?= session()->getFlashdata('error') ?>
                </div>
            <?php endif; ?>

            <!-- Form Profil -->
            <form action="<?= base_url('pengaturan/profil/update') ?>" method="post">
                <?= csrf_field() ?>
                <input type="hidden" name="id" value="<?= esc($user['id'] ?? '') ?>">

                <h5 class="mb-3"><i class="fas fa-id-card"></i> Profil Admin</h5>
                <hr>

                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Nama Lengkap</label>
                            <input type="text" name="nama" class="form-control" value="<?= esc($user['nama'] ?? '') ?>" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Username</label>
                            <input type="text" name="username" class="form-control" value="<?= esc($user['username'] ?? '') ?>" required>
                        </div>
                    </div>
                </div>

                <button type="submit" class="btn btn-success">
                    <i class="fas fa-save"></i> Simpan Profil
                </button>
            </form>

            <hr class="my-4">

            <!-- Form Ganti Password -->
            <form action="<?= base_url('pengaturan/password') ?>" method="post">
                <?= csrf_field() ?>

                <h5 class="mb-3"><i class="fas fa-key"></i> Ganti Password</h5>
                <hr>

                <div class="row">
                    <div class="col-md-4">
                        <div class="mb-3">
                            <label class="form-label">Password Lama</label>
                            <input type="password" name="password_lama" class="form-control" required>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="mb-3">
                            <label class="form-label">Password Baru</label>
                            <input type="password" name="password_baru" class="form-control" required>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="mb-3">
                            <label class="form-label">Konfirmasi Password Baru</label>
                            <input type="password" name="password_konfirmasi" class="form-control" required>
                        </div>
                    </div>
                </div>

                <button type="submit" class="btn btn-warning">
                    <i class="fas fa-key"></i> Ganti Password
                </button>
            </form>

            <div class="mt-3">
                <a href="<?= base_url('pengaturan') ?>" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> Kembali
                </a>
            </div>

        </div>
    </div>

</div>

<?= $this->endSection() ?>
