<?php
session_start();
require_once 'includes/auth.php';
require_once 'db/config.php';
require_once 'includes/i18n.php';
require_once 'includes/helpers.php';

if (!is_logged_in()) {
    header('Location: login.php');
    exit;
}

$order_id = isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0;

if ($order_id === 0) {
    header('Location: orders.php');
    exit;
}

$db = db();
$stmt = $db->prepare("SELECT * FROM orders WHERE id = ? AND user_id = ?");
$stmt->execute([$order_id, $_SESSION['user_id']]);
$order = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$order) {
    header('Location: orders.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="<?= get_lang() ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= t('order_confirmation') ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/custom.css" rel="stylesheet">
</head>
<body>
    <?php require_once 'includes/header.php'; ?>
    <div class="container mt-5">
        <div class="alert alert-success" role="alert">
            <h4 class="alert-heading"><?= t('thank_you_for_your_order') ?></h4>
            <p><?= t('your_order_number') ?> <strong>#<?php echo $order['id']; ?></strong> <?= t('has_been_placed_successfully') ?></p>
            <hr>
            <p class="mb-0"><?= t('order_details_will_be_sent') ?> <a href="orders.php"><?= t('orders') ?></a>.</p>
        </div>
        <a href="index.php" class="btn btn-primary"><?= t('continue_shopping') ?></a>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
