<?php
include '../config/koneksi.php';
include '../helpers/functions.php';

if (!isLogin() || !isClient()) redirect('../auth/login.php');

$id_user = $_SESSION['id'];
$user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM users WHERE id='$id_user'"));

$title = "Dashboard Client";
include '../layouts/header.php';
?>

<div class="container-fluid">
    <div id="overlay" class="overlay"></div>

    <div class="row">
        <div class="col-lg-2 p-0">
            <?php include '../layouts/sidebar.php'; ?>
        </div>

        <div class="col-lg-10 p-0">
            <?php include '../layouts/navbar.php'; ?>

            <div class="content-wrap">
                <?php showFlash(); ?>

                <div class="row g-4">
                    
                    <!-- CARD SALDO -->
                    <div class="col-md-12">
                        <div class="card card-stat p-4">
                            <div class="d-flex justify-content-between align-items-center flex-wrap gap-3">
                                <div>
                                    <h6 class="text-muted mb-2">Saldo Saat Ini</h6>
                                    <h2 class="text-success mb-0"><?= rupiah($user['saldo']); ?></h2>
                                </div>

                                <div class="saldo-icon-box">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="46" height="46" fill="none" viewBox="0 0 24 24" stroke="#198754" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M17 9V7a5 5 0 00-10 0v2M5 9h14l-1 10a2 2 0 01-2 2H8a2 2 0 01-2-2L5 9z"/>
                                    </svg>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- FORM SETORAN -->
                    <div class="col-md-6">
                        <div class="card p-4 h-100">
                            <div class="d-flex align-items-center gap-2 mb-3">
                                <div class="icon-box icon-setoran">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24" stroke="white" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 3v12m0 0l-4-4m4 4l4-4M5 21h14"/>
                                    </svg>
                                </div>
                                <h5 class="section-title mb-0">Ajukan Setoran</h5>
                            </div>

                            <form action="setoran_simpan.php" method="POST" enctype="multipart/form-data">
                                <div class="mb-3">
                                    <label class="form-label">Nominal</label>
                                    <input type="number" name="nominal" class="form-control" required min="1000" placeholder="Masukkan nominal setoran">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">Bukti Transfer</label>
                                    <input type="file" name="bukti" class="form-control" accept=".jpg,.jpeg,.png" required>
                                    <small class="text-muted">Format: JPG, JPEG, PNG</small>
                                </div>

                                <button type="submit" name="simpan" class="btn btn-primary w-100 rounded-3">
                                    Kirim Pengajuan Setoran
                                </button>
                            </form>
                        </div>
                    </div>

                    <!-- FORM PENARIKAN -->
                    <div class="col-md-6">
                        <div class="card p-4 h-100">
                            <div class="d-flex align-items-center gap-2 mb-3">
                                <div class="icon-box icon-penarikan">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24" stroke="white" stroke-width="2">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 21V9m0 0l4 4m-4-4l-4 4M5 3h14"/>
                                    </svg>
                                </div>
                                <h5 class="section-title mb-0">Ajukan Penarikan</h5>
                            </div>

                            <form action="withdrawal_simpan.php" method="POST">
                                <div class="mb-3">
                                    <label class="form-label">Nominal</label>
                                    <input type="number" name="nominal" class="form-control" required min="1000" placeholder="Masukkan nominal penarikan">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">Bank Tujuan</label>
                                    <input type="text" name="bank_tujuan" class="form-control" required placeholder="Contoh: DKI / DKI Syariah">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">No. Rekening</label>
                                    <input type="text" name="rekening_tujuan" class="form-control" required placeholder="Masukkan nomor rekening">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">Nama Rekening</label>
                                    <input type="text" name="nama_rekening" class="form-control" required placeholder="Nama pemilik rekening">
                                </div>

                                <button type="submit" name="simpan" class="btn btn-warning w-100 rounded-3 text-white">
                                    Kirim Pengajuan Penarikan
                                </button>
                            </form>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<style>
.card-stat {
    padding: 20px;
    border-radius: 20px;
    border: none;
    background: linear-gradient(135deg, #ffffff, #f8fbff);
    box-shadow: 0 10px 25px rgba(0,0,0,0.06);
}

.stat-icon {
    width: 45px;
    height: 45px;
    border-radius: 12px;
    background: #eef4ff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.card-stat h6 {
    color: #6c757d;
    font-size: 14px;
}

.card-stat h2, .card-stat h4 {
    font-weight: 700;
    margin: 0;
}
</style>

<?php include '../layouts/footer.php'; ?>