<?php
include "db.php";

// ⚠️ Ye password change kar lein apni marzi ka
$RESET_PASSWORD = "TAM@2026";

$done = false;
$error = "";
$access_denied = false;

if (isset($_POST['do_reset'])) {
    $entered_password = isset($_POST['password']) ? $_POST['password'] : '';

    if ($entered_password !== $RESET_PASSWORD) {
        $error = "Ghalat password. Stock reset nahi hua.";
    } else {
        if ($conn->query("UPDATE products SET stock_quantity = 0")) {
            $done = true;
        } else {
            $error = $conn->error;
        }
    }
} else {
    // Kisi ne seedha ye page GET request se khola, button ke bagair
    $access_denied = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap" rel="stylesheet">
<style>
body{
    background:#F5F5F5;
    font-family:'Poppins',sans-serif;
    margin:0;
    display:flex;
    align-items:center;
    justify-content:center;
    min-height:100vh;
}
.card{
    background:#fff;
    border-radius:8px;
    box-shadow:0 4px 18px rgba(0,0,0,0.08);
    padding:30px;
    width:100%;
    max-width:420px;
    text-align:center;
}
.card h2{
    color:#0C1F3A;
    font-size:18px;
    margin-bottom:10px;
}
.card p{
    color:#555;
    font-size:13px;
    margin-bottom:20px;
    line-height:1.6;
}
.success{
    color:#28A745;
    font-weight:600;
    font-size:14px;
}
.error{
    color:#E53E3E;
    font-weight:600;
    font-size:14px;
}
.back-link{
    display:inline-block;
    margin-top:18px;
    font-size:12px;
    color:#0C1F3A;
    text-decoration:underline;
}
</style>
</head>
<body>

<div class="card">
    <?php if ($done): ?>
        <h2>✅ Stock Reset Ho Gaya</h2>
        <p class="success">Sabhi products ki Total Stock Available ab 0 units set ho chuki hai. Purani inventory log entries waisi ki waisi mojood hain.</p>
        <script>setTimeout(function(){ window.location.href='inventory_view.php'; }, 2000);</script>
        <a href="inventory_view.php" class="back-link">Inventory page par wapas jayein</a>
    <?php elseif ($access_denied): ?>
        <h2>🔒 Access Denied</h2>
        <p class="error">Ye page seedha nahi khola ja sakta. Inventory page se "Reset All Stock" button use karein.</p>
        <a href="inventory_view.php" class="back-link">Inventory page par jayein</a>
    <?php elseif ($error): ?>
        <h2>❌ Error</h2>
        <p class="error"><?= htmlspecialchars($error) ?></p>
        <a href="inventory_view.php" class="back-link">Inventory page par wapas jayein</a>
    <?php endif; ?>
</div>

</body>
</html>