<?php
session_start();
require_once 'db_connect.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$meter_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if (!$meter_id) {
    echo "❌ Invalid meter ID.";
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_delete'])) {
    // Hard delete
    $stmt = $conn_rbe->prepare("DELETE FROM flecto_meters WHERE id = ?");
    $stmt->execute([$meter_id]);
    header("Location: admin-dashboard.php");
    exit();
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Delete FLECTO Meter</title>
    <style>
        body {
            background: #0a1a2f;
            color: white;
            font-family: Arial, sans-serif;
            padding: 40px;
        }
        .card {
            background: #122c4c;
            padding: 25px;
            border-radius: 12px;
            max-width: 400px;
            margin: auto;
            text-align: center;
        }
        button {
            background: #ff6666;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 8px;
            font-weight: bold;
            margin: 10px;
            cursor: pointer;
        }
        a {
            color: #7ed957;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div class="card">
        <h2>Confirm Deletion</h2>
        <p>Are you sure you want to delete this <strong>FLECTO meter</strong>?</p>
        <form method="post">
            <input type="hidden" name="confirm_delete" value="1">
            <button type="submit">Yes, Delete</button>
            <a href="admin-dashboard.php">Cancel</a>
        </form>
    </div>
</body>
</html>
