<?php

include('includes/session2.php');

error_reporting(0);

include('includes/dbconnection.php');

require_once 'includes/session_term_helper.php';
$stResult = resolveCurrentSessionTerm($con);
$currentSessionName = $stResult['session_name'];
$currentTermName = $stResult['term_name'];

$cls = 'Graduated student';

$st = 'Graduated student';

$std = 'Graduated student';

$query = "SELECT * FROM fees WHERE class ='$cls' AND stream ='$st' AND student_type = '$std' ";

$result = mysqli_query($con, $query);


?>



<!DOCTYPE html>

<html>

<?php @include("includes/head.php"); ?>





<body class="hold-transition sidebar-mini layout-fixed">

    <div class="wrapper">

        <?php @include("includes/headerentrance.php"); ?>

        <?php @include("includes/entrancesidebar.php"); ?>



        <div class="content-wrapper">

            <section class="content-header premium-header">

                <div class="container-fluid">

                    <div class="header-glass-card">

                        <div class="row align-items-center">

                            <div class="col-md-8">

                                <div class="title-section">

                                    <div class="icon-box bg-primary-gradient shadow-sm">

                                        <i class="fas fa-credit-card"></i>

                                    </div>

                                    <div>

                                        <h1 class="premium-title text-primary">

                                            Payment Management

                                            <span class="premium-subtitle text-secondary">Certificate Fee</span>

                                        </h1>

                                    <div class="mt-1">
                                      <?php if ($currentSessionName): ?>
                                        <span class="badge badge-primary mr-1">
                                          <i class="fas fa-calendar-alt"></i>
                                          <?= htmlspecialchars($currentSessionName) ?>
                                        </span>
                                      <?php endif; ?>
                                      <?php if ($currentTermName): ?>
                                        <span class="badge badge-success">
                                          <i class="fas fa-bookmark"></i>
                                          <?= htmlspecialchars($currentTermName) ?>
                                        </span>
                                      <?php else: ?>
                                        <span class="badge badge-warning">
                                          <i class="fas fa-exclamation-triangle"></i> No active term
                                        </span>
                                      <?php endif; ?>
                                    </div>

                                    </div>

                                </div>

                            </div>

                            <div class="col-md-4">

                                <nav aria-label="breadcrumb">

                                    <ol class="breadcrumb premium-breadcrumb">

                                        <li class="breadcrumb-item"><a href="entrancedashboard.php"
                                                class="text-primary">Home</a></li>

                                        <li class="breadcrumb-item active" aria-current="page">Certificate Fee</li>

                                    </ol>

                                </nav>

                            </div>

                        </div>

                    </div>

                </div>

            </section>



            <section class="content">

                <div class="container-fluid">

                    <div class="row">

                        <div class="col-md-12">

                            <div class="card card-primary">

                                <div class="card-header">

                                    <h5 class="card-title font-weight-bold">

                                        <i class="fas fa-certificate"></i> Certificate || Testimonial Fees Payment

                                    </h5>

                                </div>

                                <div class="card-body">

                                    <span style="color: brown">

                                        <h5>Select what you are paying for</h5>

                                        <br>

                                        <hr>

                                        <br>

                                        <div
                                            class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-4 gap-4 mb-10">

                                            <?php

                                            if (mysqli_num_rows($result) > 0) {

                                                while ($row = mysqli_fetch_assoc($result)) {

                                                    $feeType = htmlspecialchars($row['name'], ENT_QUOTES, 'UTF-8');

                                                    $amount = (float) $row['amount'];

                                                    $class = htmlspecialchars($row['class'], ENT_QUOTES, 'UTF-8');

                                                    $feeId = (int) $row['id'];



                                                    // Logic check for custom amount items
                                            
                                                    $isOfficialDoc = stripos($feeType, 'OFFICIAL DOCUMENT') !== false;



                                                    /* --- STYLE MAPPING --- */

                                                    if (stripos($feeType, 'JSS 1 - 3') !== false) {

                                                        $style = ["bg" => "bg-cyan-50", "text" => "text-cyan-600"];

                                                    } elseif (stripos($feeType, 'SS 1 - 3') !== false) {

                                                        $style = ["bg" => "bg-orange-50", "text" => "text-orange-600"];

                                                    } elseif (stripos($feeType, 'OFFICIAL DOCUMENT') !== false) {

                                                        $style = ["bg" => "bg-indigo-50", "text" => "text-indigo-600"];

                                                    } elseif (stripos($feeType, 'TRANSCRIPT') !== false) {

                                                        $style = ["bg" => "bg-purple-50", "text" => "text-purple-600"];

                                                    } else {

                                                        $style = ["bg" => "bg-emerald-50", "text" => "text-emerald-600"];

                                                    }

                                                    ?>

                                                    <div class="bento-card group">

                                                        <div class="flex justify-between items-start mb-4">

                                                            <div
                                                                class="w-10 h-10 <?php echo $style['bg']; ?> <?php echo $style['text']; ?> rounded-xl flex items-center justify-center transition-transform group-hover:scale-110">

                                                                <i
                                                                    class="fas <?php echo $isOfficialDoc ? 'fa-file-invoice' : 'fa-money-bill-wave'; ?>"></i>

                                                            </div>



                                                            <?php if (!$isOfficialDoc): ?>

                                                                <a href="confirmpayen2.php?fee_id=<?php echo $feeId; ?>&pay_amount=<?php echo $amount; ?>"
                                                                    class="text-[12px] font-black text-slate-400 group-hover:text-slate-900 transition-colors tracking-tighter">

                                                                    <i class="fas fa-arrow-right"></i> PAY HERE

                                                                </a>

                                                            <?php endif; ?>

                                                        </div>



                                                        <h5 class="text-[14px] font-bold text-slate-600 truncate">

                                                            <?php echo $class; ?>

                                                        </h5>



                                                        <p class="text-[11px] font-bold uppercase text-slate-400 truncate mb-2">

                                                            <?php echo $feeType; ?>

                                                        </p>



                                                        <?php if ($isOfficialDoc): ?>

                                                            <form action="confirmpayen2.php" method="GET" class="mt-3">

                                                                <input type="hidden" name="fee_id" value="<?php echo $feeId; ?>">

                                                                <input type="hidden" name="tab_id"
                                                                    value="<?php echo $tabSessionID; ?>">

                                                                <input type="number" name="custom_amount" min="10" required
                                                                    placeholder="Enter ₦"
                                                                    class="w-full bg-slate-50 border-0 text-[12px] rounded-lg px-2 py-1 focus:ring-2 focus:ring-indigo-400 outline-none">

                                                                <button type="submit"
                                                                    class="mt-2 w-full text-[10px] font-black py-2 rounded-lg bg-indigo-600 text-white uppercase tracking-widest hover:bg-indigo-700 transition-colors">

                                                                    <i class="fas fa-arrow-right"></i> Confirm & Pay

                                                                </button>

                                                            </form>

                                                        <?php else: ?>

                                                            <p
                                                                class="mt-2 text-[16px] font-extrabold <?php echo $style['text']; ?>">

                                                                ₦<?php echo number_format($amount, 2); ?>

                                                            </p>



                                                            <div class="mt-4 w-full h-1 bg-slate-100 rounded-full overflow-hidden">

                                                                <div
                                                                    class="h-full <?php echo str_replace('text-', 'bg-', $style['text']); ?> opacity-40 w-full transform -translate-x-1/2 group-hover:translate-x-0 transition-transform duration-1000">
                                                                </div>

                                                            </div>

                                                        <?php endif; ?>

                                                    </div>

                                                    <?php

                                                }

                                            } else {

                                                echo "<p class='text-slate-400 col-span-full text-center py-10'>No payment options available.</p>";

                                            }

                                            ?>

                                        </div>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>

        </div>



        <?php @include("includes/footer.php"); ?>

    </div>



    <?php @include("includes/foot.php"); ?>

</body>



</html>