<?php
include "includes/databse.php";
include "header.php";

// ADMIN CHECK
if ($_SESSION['usertype'] != "ADMIN") {
    echo "<script>window.location.href='index.php';</script>";
    exit;
}

// GET CURRENT VALUES (any user se le rahe hain because same for all users)
$q = mysqli_query($conn, "SELECT pfee, pdffee, death_fee FROM usertable LIMIT 1");
$data = mysqli_fetch_assoc($q);

// UPDATE ALL USERS
if (isset($_POST['update'])) {

    $pfee      = $_POST['pfee'];
    $pdffee    = $_POST['pdffee'];
    $death_fee = $_POST['death_fee'];

    $sql = "UPDATE usertable SET 
            pfee='$pfee',
            pdffee='$pdffee',
            death_fee='$death_fee'";

    $update = mysqli_query($conn, $sql);

    if ($update) {
        echo "<script>
        Swal.fire('Success','All Users Price Updated','success');
        setTimeout(()=>{ window.location.href='dbprice.php'; }, 1200);
        </script>";
    } else {
        echo "<script>
        Swal.fire('Error','".mysqli_error($conn)."','error');
        </script>";
    }
}
?>

<!-- ====== PREMIUM UI ====== -->
<style>
body{
    background:#f4f6f9;
    font-family:Arial;
}

.box{
    max-width:600px;
    margin:60px auto;
    background:#fff;
    border-radius:18px;
    box-shadow:0 10px 30px rgba(0,0,0,.1);
    overflow:hidden;
}

.header{
    background:linear-gradient(135deg,#0d6efd,#6f42c1);
    color:#fff;
    padding:20px;
    text-align:center;
}

.header h2{
    margin:0;
    font-weight:700;
}

.form-body{
    padding:25px;
}

.form-control{
    height:45px;
    border-radius:10px;
}

.label{
    font-weight:600;
    margin-bottom:5px;
    display:block;
}

.btn-submit{
    width:100%;
    padding:12px;
    border:none;
    border-radius:10px;
    background:linear-gradient(135deg,#198754,#20c997);
    color:#fff;
    font-weight:600;
    cursor:pointer;
}

.btn-submit:hover{
    transform:scale(1.02);
}
</style>

<div class="container">

    <div class="box">

        <div class="header">
            <h2>💰 PRICE UPDATE PANEL</h2>
            <p>Update All Users Pricing</p>
        </div>

        <div class="form-body">

            <form method="POST">

                <label class="label">Dob Update Pirce</label>
                <input type="number" step="0.01" name="pfee"
                       class="form-control"
                       value="<?php echo $data['pfee'] ?? 0; ?>" required>

                <br>

                <label class="label">Name Update Price</label>
                <input type="number" step="0.01" name="pdffee"
                       class="form-control"
                       value="<?php echo $data['pdffee'] ?? 0; ?>" required>

                <br>

                <label class="label">Mobile No Link Price</label>
                <input type="number" step="0.01" name="death_fee"
                       class="form-control"
                       value="<?php echo $data['death_fee'] ?? 0; ?>" required>

                <br>

                <button type="submit" name="update" class="btn-submit">
                    🚀 UPDATE PRICE
                </button>

            </form>

        </div>

    </div>

</div>