<?php
session_start();
include "../../connect/db.php";

$code = $_POST['code'] ?? '';

if (empty($_SESSION['admin_otp']) || empty($_SESSION['admin_otp_email'])) {
    echo "expired";
    exit();
}

// Check 10-minute expiry
if (time() - $_SESSION['admin_otp_time'] > 600) {
    unset($_SESSION['admin_otp'], $_SESSION['admin_otp_email'], $_SESSION['admin_otp_time']);
    echo "expired";
    exit();
}

if ($code === $_SESSION['admin_otp']) {
    $_SESSION['chap'] = $_SESSION['admin_otp_email'];
    unset($_SESSION['admin_otp'], $_SESSION['admin_otp_email'], $_SESSION['admin_otp_time']);
    echo "success";
} else {
    echo "incorrect";
}
