<?php
include 'includes/header.php'; 
include 'includes/sidebar.php';

// GET CURRENT FEE
$res = mysqli_query($conn, "SELECT setting_value FROM system_settings WHERE setting_key='account_fee_btc'");
$currentFee = mysqli_fetch_assoc($res)['setting_value'];

$success = false;

if ($_POST) {
    mysqli_query($conn, "
        UPDATE system_settings 
        SET setting_value='{$_POST['fee']}'
        WHERE setting_key='account_fee_btc'
    ");
    $success = true;

    // Refresh value
    $currentFee = $_POST['fee'];
}
?>

<div class="container-fluid py-5">

    <div class="row">
        <div class="col-md-5 mx-auto">

            <!-- Success Alert -->
            <?php if($success): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    ✅ Fee updated successfully!
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <div class="card p-4">

                <h5 class="mb-3 text-primary">💰 Update BTC Fee</h5>

                <!-- Current Fee Display -->
                <div class="mb-4 p-3 rounded" style="background:#020617; border:1px solid #1e293b;">
                    <small class="text-secondary">Current Fee</small>
                    <h4 class="mb-0"><?php echo $currentFee; ?> BTC</h4>
                </div>

                <form method="POST">

                    <div class="mb-3">
                        <label class="form-label">New BTC Fee</label>
                        <input 
                            type="text" 
                            name="fee" 
                            class="form-control" 
                            placeholder="Enter new BTC fee"
                            required
                        >
                    </div>

                    <div class="d-grid">
                        <button class="btn btn-primary">
                            💾 Update Fee
                        </button>
                    </div>

                </form>

            </div>

        </div>
    </div>

</div>

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