<?php
session_start();

// التحقق من تسجيل الدخول
if (!isset($_SESSION['user_id'])) {
    header("Location: index.php");
    exit();
}

// جلب اسم المستخدم الحالي
$user_name = $_SESSION['user_name'] ?? 'مستخدم غير محدد';
?>

<!DOCTYPE html>
<html lang="ar">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Astra - الفواتير المعلقة</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
            direction: rtl;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #2ECC71, #3498DB, #E74C3C);
            overflow-x: hidden;
            animation: gradientShift 10s ease infinite;
            background-size: 400% 400%;
        }

        @keyframes gradientShift {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .container-fluid {
            padding: 20px;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            padding: 20px;
            margin-bottom: 20px;
            animation: fadeIn 1s ease-in-out;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        h2 {
            color: #2ECC71;
            font-weight: bold;
            text-align: center;
            margin-bottom: 20px;
            text-shadow: 0 0 5px rgba(46, 204, 113, 0.5);
        }

        .pending-invoice-btn {
            background: linear-gradient(45deg, #9B59B6, #8E44AD);
            border: none;
            color: #fff;
            padding: 10px 20px;
            border-radius: 10px;
            margin: 10px 0;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.4s ease;
            display: block;
            width: 100%;
            text-align: center;
        }

        .pending-invoice-btn:hover {
            background: linear-gradient(45deg, #8E44AD, #7D3C98);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(155, 89, 182, 0.5);
        }

        .btn-back {
            background: linear-gradient(45deg, #E74C3C, #C0392B);
            border: none;
            color: #fff;
            padding: 10px 20px;
            border-radius: 10px;
            margin: 10px 0;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.4s ease;
            display: inline-block;
        }

        .btn-back:hover {
            background: linear-gradient(45deg, #C0392B, #A93226);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(231, 76, 60, 0.5);
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="card">
            <h2><i class="fas fa-pause-circle me-2"></i> الفواتير المعلقة</h2>
            <div>
                <?php if (!empty($_SESSION['pending_invoices'])): ?>
                    <?php foreach ($_SESSION['pending_invoices'] as $invoice_num => $invoice): ?>
                        <button class="pending-invoice-btn" onclick="window.location.href='sales_invoice.php?restore_invoice=<?php echo $invoice_num; ?>'">
                            فاتورة معلقة #<?php echo $invoice_num; ?> - العميل: <?php echo htmlspecialchars($invoice['client_id']); ?> - التاريخ: <?php echo $invoice['date']; ?>
                        </button>
                    <?php endforeach; ?>
                <?php else: ?>
                    <p style="color: #9B59B6; font-size: 1rem; text-align: center;">لا توجد فواتير معلقة حاليًا.</p>
                <?php endif; ?>
            </div>
            <button class="btn-back" onclick="window.location.href='dashboard.php'"><i class="fas fa-arrow-right me-2"></i> العودة إلى لوحة التحكم</button>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>