<?php
define('SECURE_ACCESS', true);

$pageTitle = "Terms of Service";
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/auth.php';

$page = null;
if ($pdo) {
    try {
        $stmt = $pdo->prepare("SELECT * FROM cms_pages WHERE slug = 'terms'");
        $stmt->execute();
        $page = $stmt->fetch();
    } catch (PDOException $e) {
        // Fallback to static
    }
}

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

<div class="container-fluid px-md-5 py-5">
    <div class="row justify-content-center">
        <div class="col-12 col-lg-10">
            <div class="card border-0 shadow-sm p-4 p-md-5 rounded-3 bg-white">
                <?php if ($page): ?>
                    <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-2 mb-3">
                        <h1 class="fw-bold text-dark mb-0"><i class="bi bi-file-earmark-text-fill text-primary me-2"></i><?php echo htmlspecialchars($page['title']); ?></h1>
                        <span class="text-secondary small font-monospace">Last updated: <?php echo date('F d, Y', strtotime($page['updated_at'])); ?></span>
                    </div>
                    <hr class="my-4">
                    <div class="cms-rendered-content text-secondary leading-relaxed" style="font-size: 0.95rem; line-height: 1.75;">
                        <?php echo $page['content']; ?>
                    </div>
                <?php else: ?>
                    <h1 class="fw-bold mb-4 text-dark"><i class="bi bi-file-earmark-text-fill text-primary me-2"></i>Terms of Service</h1>
                    <p class="text-muted small">Last updated: July 05, 2026</p>
                    <hr class="my-4">
                    
                    <section class="mb-4">
                        <h5 class="fw-bold text-dark mb-3">1. Agreement to Terms</h5>
                        <p class="text-secondary leading-relaxed">
                            Welcome to our platform. By accessing or using our website and services, you agree to comply with and be bound by these Terms of Service. If you do not agree, please do not use our services.
                        </p>
                    </section>

                    <section class="mb-4">
                        <h5 class="fw-bold text-dark mb-3">2. Employee Referral Network</h5>
                        <p class="text-secondary leading-relaxed">
                            Our platform integrates a Corporate Hierarchy structure. By sharing your Employee Referral Code, you acknowledge that hierarchy commissions, placement rules, and direct rewards are governed by active corporate policies and configurations set by the system administrator.
                        </p>
                    </section>

                    <section class="mb-4">
                        <h5 class="fw-bold text-dark mb-3">3. User Accounts</h5>
                        <p class="text-secondary leading-relaxed">
                            To access certain features including event creation, speaker onboarding, or sponsor payouts, you are required to register an account. You must safeguard your password and maintain accurate profile data (including KYC verification details).
                        </p>
                    </section>

                    <section class="mb-4">
                        <h5 class="fw-bold text-dark mb-3">4. Ticket Purchases & Refunds</h5>
                        <p class="text-secondary leading-relaxed">
                            Ticket purchases are processed securely. Level commissions are distributed immediately upon ticket sales. All refunds are subject to our standard event cancelation policies.
                        </p>
                    </section>
                    
                    <section class="mb-0">
                        <h5 class="fw-bold text-dark mb-3">5. Modifications of Service</h5>
                        <p class="text-secondary leading-relaxed mb-0">
                            We reserve the right to modify, suspend, or discontinue any aspect of our services or configurations at any time without prior notice.
                        </p>
                    </section>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

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