<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
    header("Location: index.php");
    exit();
}

if (isset($_POST['submit'])) {
    $new_upi = htmlspecialchars($_POST['new_upi']);
    $new_tr = htmlspecialchars($_POST['new_tr']);
    $new_mc = htmlspecialchars($_POST['new_mc']);

    $data = "<?php\n\$upi = '$new_upi';\n\$transaction_id = '$new_tr';\n\$merchant_code = '$new_mc';\n?>";
    file_put_contents('../upi.php', $data);
    $success_message = "✅ UPI settings updated successfully!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UPI Panel</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: linear-gradient(135deg, #0f172a, #1e293b);
            color: #fff;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Inter', sans-serif;
        }
        #particles-js {
            position: absolute;
            width: 100%;
            height: 100%;
            z-index: -1;
        }
        .admin-container {
            background: rgba(30, 41, 59, 0.7);
            backdrop-filter: blur(15px);
            border-radius: 20px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
            padding: 3rem;
            max-width: 500px;
            width: 100%;
            text-align: center;
            z-index: 1;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        .input-field {
            background: rgba(15, 23, 42, 0.7);
            color: #e2e8f0;
            border: 2px solid rgba(255, 255, 255, 0.1);
            padding: 1rem;
            border-radius: 12px;
            width: 100%;
            margin-bottom: 1.5rem;
            transition: all 0.3s ease;
        }
        .input-field:focus {
            outline: none;
            border-color: #22d3ee;
            box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
        }
        .shiny-button {
            background: linear-gradient(135deg, #0ea5e9, #22d3ee);
            color: white;
            font-size: 1.1rem;
            font-weight: 600;
            padding: 1rem 2rem;
            border: none;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
            width: 100%;
        }
        .shiny-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
        }
        .success-message {
            background: rgba(16, 185, 129, 0.2);
            border: 1px solid rgba(16, 185, 129, 0.3);
            border-radius: 8px;
            padding: 10px;
            margin-bottom: 20px;
        }
        .label {
            display: block;
            text-align: left;
            margin-bottom: 8px;
            color: #94a3b8;
            font-size: 0.9rem;
        }
        .input-container {
            position: relative;
        }
        .input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #64748b;
        }
        .input-with-icon {
            padding-left: 45px;
        }
    </style>
</head>
<body>
    <div id="particles-js"></div>
    <div class="admin-container">
        <h2 class="text-3xl font-bold mb-6">
            <i class="fas fa-wallet text-cyan-400 mr-3"></i>
            UPI Settings
        </h2>
        
        <?php if (isset($success_message)): ?>
            <div class="success-message">
                <i class="fas fa-check-circle mr-2 text-emerald-400"></i>
                <?= $success_message ?>
            </div>
        <?php endif; ?>
        
        <form method="post">
            <div class="mb-5">
                <label class="label" for="new_upi">
                    <i class="fas fa-money-check-alt mr-2"></i>
                    UPI ID
                </label>
                <div class="input-container">
                    <i class="input-icon fas fa-qrcode"></i>
                    <input class="input-field input-with-icon" id="new_upi" name="new_upi" type="text" placeholder="Enter new UPI ID" required>
                </div>
            </div>
            
            <div class="mb-5">
                <label class="label" for="new_tr">
                    <i class="fas fa-exchange-alt mr-2"></i>
                    Transaction ID
                </label>
                <div class="input-container">
                    <i class="input-icon fas fa-hashtag"></i>
                    <input class="input-field input-with-icon" id="new_tr" name="new_tr" type="text" placeholder="Enter transaction ID" required>
                </div>
            </div>
            
            <div class="mb-6">
                <label class="label" for="new_mc">
                    <i class="fas fa-store mr-2"></i>
                    Merchant Code
                </label>
                <div class="input-container">
                    <i class="input-icon fas fa-barcode"></i>
                    <input class="input-field input-with-icon" id="new_mc" name="new_mc" type="text" placeholder="Enter merchant code" required>
                </div>
            </div>
            
            <button type="submit" name="submit" class="shiny-button">
                <i class="fas fa-save mr-2"></i> Update Settings
            </button>
        </form>
    </div>
    
    <script>
        particlesJS("particles-js", {
            "particles": {
                "number": {
                    "value": 80,
                    "density": {
                        "enable": true,
                        "value_area": 800
                    }
                },
                "color": {
                    "value": "#22d3ee"
                },
                "shape": {
                    "type": "circle",
                    "stroke": {
                        "width": 0,
                        "color": "#000000"
                    }
                },
                "opacity": {
                    "value": 0.3,
                    "random": true,
                    "anim": {
                        "enable": true,
                        "speed": 1,
                        "opacity_min": 0.1,
                        "sync": false
                    }
                },
                "size": {
                    "value": 3,
                    "random": true,
                    "anim": {
                        "enable": true,
                        "speed": 20,
                        "size_min": 0.1,
                        "sync": false
                    }
                },
                "line_linked": {
                    "enable": true,
                    "distance": 150,
                    "color": "#22d3ee",
                    "opacity": 0.2,
                    "width": 1
                },
                "move": {
                    "enable": true,
                    "speed": 4,
                    "direction": "none",
                    "random": false,
                    "straight": false,
                    "out_mode": "out",
                    "bounce": false
                }
            },
            "interactivity": {
                "detect_on": "canvas",
                "events": {
                    "onhover": {
                        "enable": true,
                        "mode": "repulse"
                    },
                    "onclick": {
                        "enable": true,
                        "mode": "push"
                    },
                    "resize": true
                }
            },
            "retina_detect": true
        });
    </script>
</body>
</html>