<?php
/**
 * Madrasa Terms & Conditions View/Print Page
 * Refactored to Bootstrap 5.3 & Dynamic Data
 * Included via index.php context
 */

// $crud and constants are available via index.php context
$conf_res = $crud->getRecordSet("SELECT * FROM config LIMIT 1");
$conf = !empty($conf_res) ? $conf_res[0] : [];

// Fetch terms and conditions
$res = $crud->getRecordSet("SELECT * FROM rules_and_regulations WHERE sno = 1");
$content = !empty($res) ? $res[0]['contents_ur'] : '<p class="text-center py-5">قواعد و ضوابط دستیاب نہیں ہیں۔ براہ کرم سسٹم سیٹنگز میں جا کر درج کریں۔</p>';
?>
<style>
    @font-face {
        font-family: 'Jameel Noori Nastaleeq';
        src: url('fonts/JameelNooriNastaleeq.ttf');
        /* Fallback if local */
    }

    body {
        font-family: 'Jameel Noori Nastaleeq', 'Noto Sans Arabic', Arial, sans-serif;
        background-color: #f0f2f5;
        color: #333;
        line-height: 1.8;
    }

    .report-paper {
        background: white;
        padding: 50px;
        margin: 30px auto;
        width: 210mm;
        /* A4 width */
        min-height: 297mm;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
        border-radius: 4px;
        position: relative;
    }

    .report-header {
        border-bottom: 3px double #2c3e50;
        margin-bottom: 40px;
        padding-bottom: 20px;
    }

    .madrasa-name {
        font-size: 38px;
        font-weight: 800;
        color: #1a2a3a;
        margin-bottom: 10px;
    }

    .madrasa-meta {
        font-size: 18px;
        color: #555;
    }

    .report-title {
        background: #f8f9fa;
        border: 1px solid #dee2e6;
        display: inline-block;
        padding: 8px 40px;
        border-radius: 50px;
        font-weight: bold;
        margin: 20px 0;
        font-size: 24px;
    }

    .terms-content {
        font-size: 20px;
        text-align: justify;
    }

    /* TinyMCE output reset/styling */
    .terms-content p {
        margin-bottom: 15px;
    }

    .footer-sig {
        margin-top: 80px;
        padding-top: 20px;
    }

    .sig-box {
        border-top: 1px solid #999;
        width: 200px;
        display: inline-block;
        padding-top: 10px;
        margin: 0 50px;
    }

    @media print {
        body {
            background-color: white !important;
        }

        .report-paper {
            margin: 0 auto;
            box-shadow: none;
            padding: 20px;
            width: 100%;
        }

        .no-print {
            display: none !important;
        }

        .report-paper {
            border: none !important;
        }
    }

    .btn-floating {
        position: fixed;
        bottom: 30px;
        left: 30px;
        z-index: 1000;
    }
</style>
<div class="container no-print mt-4 text-center">
    <div class="d-flex justify-content-center gap-2">
        <button onclick="window.print()" class="btn btn-primary rounded-pill px-4 shadow-sm">
            <i class="bi bi-printer me-2"></i>پرنٹ کریں (Print)
        </button>
        <a href="index.php?page=settings" class="btn btn-dark rounded-pill px-4 shadow-sm">
            <i class="bi bi-gear me-2"></i>سیٹنگز (Settings)
        </a>
        <a href="index.php" class="btn btn-outline-secondary rounded-pill px-4 shadow-sm">
            <i class="bi bi-house me-2"></i>ہوم پیج
        </a>
    </div>
</div>

<div class="report-paper">
    <div class="report-header text-center">
        <h1 class="madrasa-name">
            <?php echo $conf['M_Name'] ?? 'مدرسہ کا نام'; ?>
        </h1>
        <p class="madrasa-meta mb-2">
            <?php echo $conf['M_Address'] ?? 'پتہ درج نہیں ہے'; ?>
        </p>
        <div class="d-flex justify-content-center gap-4 madrasa-meta">
            <span><i class="bi bi-telephone-fill me-1"></i> فون:
                <?php echo $conf['P_Number'] ?? '-'; ?>
            </span>
            <?php if (!empty($conf['Reg_Number'])) { ?>
                <span><i class="bi bi-patch-check-fill me-1"></i> الحاق نمبر:
                    <?php echo $conf['Reg_Number']; ?>
                </span>
            <?php } ?>
        </div>

        <div class="report-title">
            قواعد و ضوابط (Rules & Regulations)
        </div>
    </div>

    <div class="terms-content">
        <?php echo $content; ?>
    </div>

    <div class="footer-sig text-center mt-auto">
        <div class="sig-box">
            دستخط امیدوار / سرپرست
        </div>
        <div class="sig-box">
            مہتمم / ناظم مدرسہ
        </div>
    </div>
</div>