<?php
session_start();
require_once __DIR__ . '/config.php';

$order_no = isset($_SESSION['last_order_no']) ? $_SESSION['last_order_no'] : '';
$order_name = isset($_SESSION['last_order_name']) ? $_SESSION['last_order_name'] : '';
$order_product = isset($_SESSION['last_order_product']) ? $_SESSION['last_order_product'] : '';
$order_price = isset($_SESSION['last_order_price']) ? $_SESSION['last_order_price'] : '0.00';
$order_payment = isset($_SESSION['last_order_payment']) ? $_SESSION['last_order_payment'] : '';

if (empty($order_no)) {
    header("Location: index.php");
    exit;
}

$pixel_scripts = '';
$pixels_head = '';
$pixels_body_top = '';
$pixels_body_bottom = '';
try {
    $tableExists = $pdo->query("SHOW TABLES LIKE 'ad_pixels'")->rowCount() > 0;
    if ($tableExists) {
        $stmt = $pdo->query("SELECT pixel_code, position FROM ad_pixels WHERE status = 1 AND (placement = 'all' OR placement = 'success') ORDER BY sort_order ASC, id ASC");
        $pixels = $stmt->fetchAll();
        foreach ($pixels as $p) {
            $pos = $p['position'] ?? 'head';
            if ($pos == 'head') {
                $pixels_head .= $p['pixel_code'] . "\n";
            } elseif ($pos == 'body-top') {
                $pixels_body_top .= $p['pixel_code'] . "\n";
            } else {
                $pixels_body_bottom .= $p['pixel_code'] . "\n";
            }
        }
    }
} catch(PDOException $e) {}
?>
<!DOCTYPE html>
<html lang="tr" dir="ltr">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Siparişiniz Alındı! - Powzzers Max Power</title>
<meta name="description" content="Siparişiniz başarıyla alındı.">

<link rel="stylesheet" href="assets/css/app0acb0acb.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.3.0/css/all.min.css" integrity="sha512-ApSLB1Pd3/bZN8fWB/RG9YhN/7bd9Hkf3AGaE2mPfebjrxagjuBtx2GcgdqIlJkUzwylBo61r9Xa9NmgBI0swA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;display=swap" rel="stylesheet">
<style>
* { font-family: 'Poppins', sans-serif; }
.container {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}
@media (min-width: 1024px) {
  .container { width: 50%; }
}
.success-circle {
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    box-shadow: 0 10px 40px rgba(16, 185, 129, 0.4);
    animation: pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}
.success-circle i {
    font-size: 60px;
    color: white;
    animation: checkmark 0.5s ease-in-out 0.3s both;
}
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    70% { box-shadow: 0 0 0 25px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
@keyframes checkmark {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.info-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 16px;
    padding: 24px;
    margin: 24px 0;
}
.order-no {
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 30px;
    display: inline-block;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 1px;
}
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}
.info-row:last-child { border-bottom: none; }
.info-label { opacity: 0.85; font-weight: 500; }
.info-value { font-weight: 700; text-align: right; }
.steps {
    display: flex;
    justify-content: space-between;
    margin: 30px 0;
    position: relative;
}

.step {
    text-align: center;
    position: relative;
    z-index: 1;
    flex: 1;
}
.step-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #10b981;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.step-icon.pending {
    background: #d1d5db;
    color: #6b7280;
    box-shadow: none;
}
.step-text {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 600;
}
.step-text.active { color: #10b981; }
.callout {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 16px;
    border-radius: 8px;
    margin: 24px 0;
}
.callout i { color: #f59e0b; margin-right: 8px; }
</style>
<?php echo $pixels_head; ?>
</head>

<body class="bg-gray-50 theme-ap7-first-tr no-webp ltr page-index no-mobile">
<?php echo $pixels_body_top; ?>
<div class="container mx-auto shadow-xl min-h-screen bg-white relative">
    <div class="bg-gray-700 relative">
        <img src="assets/images/bg/1.jpg" class="w-full h-auto select-none lazyload">
    </div>

    <div class="px-4 py-10 text-center">
        <div class="success-circle">
            <i class="fas fa-check"></i>
        </div>

        <h1 class="text-3xl font-extrabold text-gray-800 mb-3">
            🎉 Siparişiniz Alındı!
        </h1>
        <p class="text-gray-600 text-lg mb-2">
            Merhaba <strong class="text-gray-800"><?php echo htmlspecialchars($order_name); ?></strong>,
        </p>
        <p class="text-gray-600 mb-6">
            Siparişiniz başarıyla oluşturuldu. Siparişinizi teyit amaçlı en kısa sürede sizi arayacağız.
        </p>

        <div class="info-card">
            <div class="order-no mb-4">
                <i class="fas fa-receipt me-2"></i>
                SIPARIŞ NO: <?php echo $order_no; ?>
            </div>

            <div class="info-row">
                <span class="info-label">Ürün</span>
                <span class="info-value"><?php echo htmlspecialchars($order_product); ?></span>
            </div>
            <div class="info-row">
                <span class="info-label">Tutar</span>
                <span class="info-value"><?php echo number_format($order_price, 2, ',', '.'); ?> ₺</span>
            </div>
            <div class="info-row">
                <span class="info-label">Ödeme</span>
                <span class="info-value">
                    <?php echo getPaymentLabel($order_payment); ?>
                </span>
            </div>
            <div class="info-row">
                <span class="info-label">Durum</span>
                <span class="info-value">⏳ Onay Bekliyor</span>
            </div>
        </div>

        <h3 class="text-lg font-bold text-gray-800 mb-4 mt-8">
            Sipariş Süreci
        </h3>
        <div class="steps">
            <div class="step">
                <div class="step-icon"><i class="fas fa-check"></i></div>
                <div class="step-text active">Sipariş Alındı</div>
            </div>
            <div class="step">
                <div class="step-icon pending"><i class="fas fa-phone"></i></div>
                <div class="step-text">Teyit Araması</div>
            </div>
            <div class="step">
                <div class="step-icon pending"><i class="fas fa-truck"></i></div>
                <div class="step-text">Kargoya Verildi</div>
            </div>
            <div class="step">
                <div class="step-icon pending"><i class="fas fa-home"></i></div>
                <div class="step-text">Teslim Edildi</div>
            </div>
        </div>

        <div class="callout text-start">
            <p class="mb-0">
                <i class="fas fa-info-circle"></i>
                <strong>Bizi tercih ettiğiniz için teşekkürler!</strong><br>
                Mesai saatleri içinde (09:00 - 18:00) verdiğiniz siparişler aynı gün kargolanır. 
                Teyit amacılı telefon numaranızdan sizleri arayacağız. 
                Lütfen aramaları cevapladığınızdan emin olun. Aksi takdirde siparişiniz iptal edilebilir.
            </p>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-8">
            <a href="index.php" class="flex items-center justify-center bg-gray-800 hover:bg-gray-900 text-white text-lg font-bold p-4 rounded shadow w-full transition">
                <i class="fas fa-home me-2"></i>Ana Sayfaya Dön
            </a>
            <button onclick="window.print()" class="flex items-center justify-center bg-blue-600 hover:bg-blue-700 text-white text-lg font-bold p-4 rounded shadow w-full transition">
                <i class="fas fa-print me-2"></i>Yazdır
            </button>
        </div>
    </div>

    <footer class="mt-8">
        <div class="bg-gray-100 px-6 py-4">
            <img src="assets/images/bg/cargo-firms.png" class="w-full h-auto select-none lazyload" width="863" height="140" alt="cargo-firms">
        </div>
        <div class="bg-gray-800 text-gray-300">
            <div class="py-6 px-6 text-sm italic font-semibold text-center">
                Powzzers Max Power &copy; 2026
            </div>
        </div>
    </footer>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

<?php echo $pixels_body_bottom; ?>
</body>
</html>
