<?php
/**
 * صفحة تثبيت المنشورات والاستوريز
 */

session_start();
require_once '../config/database.php';

if (!isset($_SESSION['admin_id'])) {
    header('Location: login.php');
    exit;
}

$database = new Database();
$conn = $database->getConnection();

// فحص حالة الأنظمة
$posts_installed = false;
$stories_installed = false;

try {
    $check = $conn->query("SHOW TABLES LIKE 'posts'");
    $posts_installed = $check->rowCount() > 0;
} catch (Exception $e) {}

try {
    $check = $conn->query("SHOW TABLES LIKE 'stories'");
    $stories_installed = $check->rowCount() > 0;
} catch (Exception $e) {}

include 'includes/header.php';
?>

<div class="content-wrapper">
    <div class="page-header">
        <h1>🚀 تثبيت الميزات الجديدة</h1>
        <a href="dashboard.php" class="btn btn-secondary">
            <i class="fas fa-arrow-right"></i> رجوع
        </a>
    </div>

    <div style="max-width: 1000px; margin: 0 auto;">
        
        <!-- مقدمة -->
        <div class="card" style="margin-bottom: 30px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
            <div style="padding: 40px; text-align: center;">
                <h2 style="font-size: 32px; margin-bottom: 15px;">✨ ميزات جديدة ومثيرة!</h2>
                <p style="font-size: 18px; opacity: 0.9;">قم بتثبيت المنشورات والاستوريز لتحسين تجربة متجرك</p>
            </div>
        </div>

        <!-- الميزات -->
        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(450px, 1fr)); gap: 30px; margin-bottom: 30px;">
            
            <!-- المنشورات -->
            <div class="card" style="position: relative; overflow: hidden;">
                <?php if ($posts_installed): ?>
                    <div style="position: absolute; top: 20px; left: 20px; background: #10b981; color: white; padding: 8px 20px; border-radius: 50px; font-weight: 600; font-size: 14px;">
                        ✅ مثبت
                    </div>
                <?php endif; ?>
                
                <div style="padding: 30px;">
                    <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); border-radius: 20px; display: flex; align-items: center; justify-content: center; margin-bottom: 20px;">
                        <i class="fas fa-newspaper" style="font-size: 40px; color: white;"></i>
                    </div>
                    
                    <h3 style="font-size: 24px; font-weight: 700; margin-bottom: 15px; color: #1f2937;">نظام المنشورات (المدونة)</h3>
                    
                    <p style="color: #6b7280; line-height: 1.8; margin-bottom: 20px;">
                        أنشئ مدونة احترافية لمتجرك مع نظام إدارة محتوى كامل. شارك الأخبار، النصائح، والعروض الخاصة مع عملائك.
                    </p>
                    
                    <div style="background: #f3f4f6; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                        <h4 style="font-weight: 600; margin-bottom: 10px; color: #374151;">المميزات:</h4>
                        <ul style="list-style: none; padding: 0; margin: 0;">
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                محرر نصوص متقدم
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                6 فئات جاهزة
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                صور مميزة ووسوم
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                تصميم متجاوب
                            </li>
                        </ul>
                    </div>
                    
                    <?php if ($posts_installed): ?>
                        <a href="posts/index.php" class="btn btn-primary" style="width: 100%; justify-content: center;">
                            <i class="fas fa-arrow-left"></i> فتح المنشورات
                        </a>
                    <?php else: ?>
                        <a href="../setup/create_posts_system.php" class="btn btn-primary" style="width: 100%; justify-content: center;">
                            <i class="fas fa-download"></i> تثبيت الآن
                        </a>
                    <?php endif; ?>
                </div>
            </div>

            <!-- الاستوريز -->
            <div class="card" style="position: relative; overflow: hidden;">
                <?php if ($stories_installed): ?>
                    <div style="position: absolute; top: 20px; left: 20px; background: #10b981; color: white; padding: 8px 20px; border-radius: 50px; font-weight: 600; font-size: 14px;">
                        ✅ مثبت
                    </div>
                <?php endif; ?>
                
                <div style="padding: 30px;">
                    <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%); border-radius: 20px; display: flex; align-items: center; justify-content: center; margin-bottom: 20px;">
                        <i class="fas fa-circle-notch" style="font-size: 40px; color: white;"></i>
                    </div>
                    
                    <h3 style="font-size: 24px; font-weight: 700; margin-bottom: 15px; color: #1f2937;">نظام الاستوريز</h3>
                    
                    <p style="color: #6b7280; line-height: 1.8; margin-bottom: 20px;">
                        شريط استوريز تفاعلي مثل Instagram تماماً. اعرض العروض والمنتجات الجديدة بطريقة جذابة وعصرية.
                    </p>
                    
                    <div style="background: #f3f4f6; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                        <h4 style="font-weight: 600; margin-bottom: 10px; color: #374151;">المميزات:</h4>
                        <ul style="list-style: none; padding: 0; margin: 0;">
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                تصميم Instagram
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                تشغيل تلقائي
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                تسجيل المشاهدات
                            </li>
                            <li style="padding: 8px 0; color: #6b7280;">
                                <i class="fas fa-check" style="color: #10b981; margin-left: 10px;"></i>
                                سهل الاستخدام
                            </li>
                        </ul>
                    </div>
                    
                    <?php if ($stories_installed): ?>
                        <a href="stories/index.php" class="btn btn-primary" style="width: 100%; justify-content: center;">
                            <i class="fas fa-arrow-left"></i> فتح الاستوريز
                        </a>
                    <?php else: ?>
                        <a href="../setup/create_stories_system.php" class="btn btn-primary" style="width: 100%; justify-content: center;">
                            <i class="fas fa-download"></i> تثبيت الآن
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- معلومات إضافية -->
        <div class="card" style="background: #fef3c7; border: 2px solid #fbbf24;">
            <div style="padding: 20px;">
                <h4 style="color: #92400e; margin-bottom: 10px; display: flex; align-items: center; gap: 10px;">
                    <i class="fas fa-info-circle"></i>
                    ملاحظات مهمة
                </h4>
                <ul style="color: #92400e; line-height: 1.8; margin: 0; padding-right: 20px;">
                    <li>التثبيت يستغرق بضع ثوانٍ فقط</li>
                    <li>سيتم إنشاء الجداول والبيانات التجريبية تلقائياً</li>
                    <li>يمكنك تثبيت كل ميزة على حدة</li>
                    <li>جميع الميزات مجانية ومفتوحة المصدر</li>
                </ul>
            </div>
        </div>

    </div>
</div>

<?php include 'includes/footer.php'; ?>
