<?php

session_start();

require_once __DIR__ . '/../../library/config.php';

require_once __DIR__ . '/../../library/super_admin_auth.php';

// allow_super_admin();

$page_title = 'Subscription Plans';

require_once __DIR__ . '/../includes/header.php';

require_once __DIR__ . '/../includes/sidebar.php';

/*
|--------------------------------------------------------------------------
| FETCH PLANS
|--------------------------------------------------------------------------
*/

$stmt = $pdo->prepare("

    SELECT *

    FROM super_admin_subscription_plans

    ORDER BY id DESC

");

$stmt->execute();

$plans = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>

<!-- =========================================================
CONTENT WRAPPER
========================================================= -->

<!--<div class="content-wrapper">-->

    <!-- =====================================================
    PAGE HEADER
    ====================================================== -->

    <section class="content-header">

        <div class="container-fluid">

            <div class="row mb-3">

                <div class="col-sm-6">

                    <h1 class="font-weight-bold">

                        Subscription Plans

                    </h1>

                    <p class="text-muted mb-0">

                        Manage SaaS pricing plans and features

                    </p>

                </div>

                <div class="col-sm-6 text-right">

                    <a
                        href="create_plan.php"
                        class="btn btn-primary shadow-sm px-4"
                    >

                        <i class="fas fa-plus mr-1"></i>

                        Create Plan

                    </a>

                </div>

            </div>

        </div>

    </section>

    <!-- =====================================================
    MAIN CONTENT
    ====================================================== -->

    <section class="content">

        <div class="container-fluid">

            <?php if($plans): ?>

                <div class="row">

                    <?php foreach($plans as $plan): ?>

                        <div class="col-lg-3 col-md-6">

                            <div class="card plan-card shadow-sm border-0">

                                <div class="card-body">

                                    <!-- STATUS -->

                                    <div class="d-flex justify-content-between align-items-center mb-3">

                                        <h4 class="mb-0 font-weight-bold">

                                            <?= htmlspecialchars($plan['plan_name']) ?>

                                        </h4>

                                        <?php if($plan['status'] == 'Active'): ?>

                                            <span class="badge badge-success px-3 py-2">

                                                Active

                                            </span>

                                        <?php else: ?>

                                            <span class="badge badge-danger px-3 py-2">

                                                Inactive

                                            </span>

                                        <?php endif; ?>

                                    </div>

                                    <!-- PRICE -->

                                    <div class="mb-3">

                                        <h2 class="price-text mb-1">

                                            ₹<?= number_format($plan['price'], 0) ?>

                                        </h2>

                                        <small class="text-muted">

                                            <?= $plan['duration_months'] ?> Months

                                        </small>

                                    </div>

                                    <!-- DETAILS -->

                                    <div class="plan-details">

                                        <div class="detail-item">

                                            <i class="fas fa-users text-primary mr-2"></i>

                                            Max Students:
                                            <strong>

                                                <?= $plan['max_students'] ?>

                                            </strong>

                                        </div>

                                    </div>

                                    <!-- ACTIONS -->

                                    <div class="d-flex justify-content-between mt-4">

                                        <a
                                            href="edit_plan.php?id=<?= $plan['id'] ?>"
                                            class="btn btn-outline-info btn-sm px-3"
                                        >

                                            <i class="fas fa-edit mr-1"></i>

                                            Edit

                                        </a>

                                        <a
                                            href="manage_features.php?id=<?= $plan['id'] ?>"
                                            class="btn btn-warning btn-sm px-3"
                                        >

                                            <i class="fas fa-lock mr-1"></i>

                                            Features

                                        </a>

                                    </div>

                                </div>

                            </div>

                        </div>

                    <?php endforeach; ?>

                </div>

            <?php else: ?>

                <!-- EMPTY STATE -->

                <div class="card shadow-sm border-0">

                    <div class="card-body text-center py-5">

                        <i class="fas fa-box-open fa-4x text-muted mb-3"></i>

                        <h4>

                            No Subscription Plans Found

                        </h4>

                        <p class="text-muted">

                            Create your first SaaS subscription plan.

                        </p>

                        <a
                            href="create_plan.php"
                            class="btn btn-primary mt-2"
                        >

                            <i class="fas fa-plus mr-1"></i>

                            Create Plan

                        </a>

                    </div>

                </div>

            <?php endif; ?>

        </div>

    </section>

<!--</div>-->

<!-- =========================================================
CUSTOM CSS
========================================================= -->

<style>

.plan-card {

    border-radius: 18px;
    transition: all 0.3s ease;
    overflow: hidden;
    background: #ffffff;
}

.plan-card:hover {

    transform: translateY(-6px);
}

.price-text {

    font-size: 34px;
    font-weight: 700;
    color: #007bff;
}

.plan-details {

    margin-top: 15px;
}

.detail-item {

    margin-bottom: 12px;
    font-size: 15px;
    color: #444;
}

.badge {

    border-radius: 30px;
    font-size: 12px;
    font-weight: 600;
}

.btn {

    border-radius: 10px;
}

.card {

    border-radius: 18px;
}

.content-header h1 {

    font-size: 28px;
}

</style>

<?php require_once __DIR__ . '/../includes/footer.php'; ?>