<?php
session_start();
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../config/config.php';

$db = Database::getInstance()->getConnection();

$settingsStmt = $db->query("SELECT setting_key, setting_value FROM website_settings");
$settings = [];
while ($row = $settingsStmt->fetch()) {
    $settings[$row['setting_key']] = $row['setting_value'];
}

$siteName = sanitize($settings['site_name'] ?? 'Tap2Order');
$contactPhone = sanitize($settings['contact_phone'] ?? '+1 (555) 123-4567');
$contactEmail = sanitize($settings['contact_email'] ?? 'support@tap2order.com');
$contactAddress = sanitize($settings['contact_address'] ?? '123 Business Ave, Tech City, TC 10001');
$copyrightText = sanitize($settings['copyright_text'] ?? '© 2026 Tap2Order. All rights reserved.');

$termsStmt = $db->query("SELECT setting_value FROM website_settings WHERE setting_key = 'terms_conditions'");
$termsContent = $termsStmt->fetch();

$termsHtml = '';
if ($termsContent && !empty($termsContent['setting_value'])) {
    $termsHtml = $termsContent['setting_value'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Terms &amp; Conditions | <?php echo $siteName; ?></title>
    <meta name="description" content="<?php echo $siteName; ?> Terms and Conditions - Read our terms of service and usage policies.">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../assets/css/public.css">
    <style>
        .legal-page { padding: 140px 0 80px; min-height: 100vh; }
        .legal-page .container { max-width: 860px; }
        .legal-page h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 8px; }
        .legal-page .legal-meta { color: var(--gray-500); font-size: 0.9rem; margin-bottom: 40px; }
        .legal-page h2 { font-size: 1.3rem; font-weight: 700; margin: 32px 0 14px; color: var(--gray-900); }
        .legal-page p, .legal-page li { color: var(--gray-700); font-size: 0.95rem; line-height: 1.8; margin-bottom: 14px; }
        .legal-page ul { padding-left: 20px; margin-bottom: 14px; }
        .legal-page li { margin-bottom: 8px; }
        .legal-page strong { color: var(--gray-800); }
    </style>
</head>
<body>

<nav class="navbar" id="navbar">
    <div class="container">
        <a href="index.php" class="navbar-brand">
            <i class="fas fa-mobile-screen-button"></i> Tap<span>2</span>Order
        </a>
        <ul class="navbar-nav" id="navMenu">
            <li><a href="index.php#home">Home</a></li>
            <li><a href="index.php#features">Features</a></li>
            <li><a href="index.php#pricing">Pricing</a></li>
            <li><a href="demo.php">Demo</a></li>
            <li><a href="index.php#contact">Contact</a></li>
        </ul>
        <div class="navbar-actions">
            <a href="../login.php" class="btn btn-sm btn-outline-dark">Restaurant Login</a>
            <a href="index.php#contact" class="btn btn-sm btn-primary">Get Started</a>
            <button class="nav-toggle" id="navToggle" aria-label="Toggle navigation">
                <i class="fas fa-bars"></i>
            </button>
        </div>
    </div>
</nav>

<div class="legal-page">
    <div class="container">
        <h1>Terms &amp; Conditions</h1>
        <div class="legal-meta">Last updated: January 1, 2026</div>

        <?php if (!empty($termsHtml)): ?>
            <?php echo $termsHtml; ?>
        <?php else: ?>
            <h2>1. Acceptance of Terms</h2>
            <p>By accessing and using the Tap2Order platform ("Service"), you agree to be bound by these Terms and Conditions. If you do not agree with any part of these terms, you may not access or use the Service. These terms apply to all users, including restaurant owners, staff members, and customers.</p>

            <h2>2. User Accounts</h2>
            <p>To access certain features of the Service, you must create an account. You agree to:</p>
            <ul>
                <li>Provide accurate, current, and complete information during registration.</li>
                <li>Maintain the security of your password and account credentials.</li>
                <li>Notify us immediately of any unauthorized use of your account.</li>
                <li>Accept responsibility for all activities that occur under your account.</li>
            </ul>
            <p>We reserve the right to suspend or terminate accounts that violate these terms or are found to contain inaccurate information.</p>

            <h2>3. Ordering and Transactions</h2>
            <p>When customers place orders through the Tap2Order platform:</p>
            <ul>
                <li>All orders are subject to availability and restaurant acceptance.</li>
                <li>Prices displayed are set by the restaurant and include applicable taxes unless stated otherwise.</li>
                <li>Tap2Order acts as a technology platform facilitating the order process and is not a party to the transaction between the restaurant and customer.</li>
                <li>Restaurants are solely responsible for order fulfillment, food quality, and accuracy.</li>
                <li>Order modifications or cancellations are subject to the restaurant's policies.</li>
            </ul>

            <h2>4. Payments</h2>
            <p>Payment terms for the Service:</p>
            <ul>
                <li>Subscription fees are billed in advance on a monthly or annual basis according to the selected plan.</li>
                <li>All fees are non-refundable unless otherwise specified in our refund policy.</li>
                <li>We reserve the right to modify subscription fees with 30 days' prior notice.</li>
                <li>Failure to pay fees may result in suspension or termination of your account.</li>
                <li>Customer payments for orders are processed according to the restaurant's accepted payment methods.</li>
            </ul>

            <h2>5. Cancellation and Termination</h2>
            <p>You may cancel your subscription at any time through your account dashboard:</p>
            <ul>
                <li>Cancellation takes effect at the end of the current billing period.</li>
                <li>No partial refunds are provided for unused portions of a billing period.</li>
                <li>Upon cancellation, your account data will be retained for 30 days, after which it may be permanently deleted.</li>
                <li>We reserve the right to terminate accounts that violate these terms without prior notice.</li>
            </ul>

            <h2>6. Limitation of Liability</h2>
            <p>To the maximum extent permitted by applicable law:</p>
            <ul>
                <li>Tap2Order shall not be liable for any indirect, incidental, special, consequential, or punitive damages.</li>
                <li>Our total liability shall not exceed the amount paid by you for the Service in the twelve (12) months preceding the claim.</li>
                <li>We do not guarantee uninterrupted or error-free operation of the Service.</li>
                <li>Restaurants are independently responsible for compliance with all applicable laws, including food safety regulations.</li>
            </ul>

            <h2>7. Intellectual Property</h2>
            <p>All content, trademarks, logos, and intellectual property associated with Tap2Order are owned by or licensed to us. You may not reproduce, distribute, or create derivative works without our prior written consent. Restaurants retain ownership of their menu content, images, and branding uploaded to the platform.</p>

            <h2>8. Privacy</h2>
            <p>Your use of the Service is also governed by our <a href="privacy.php" style="color:var(--primary);">Privacy Policy</a>, which describes how we collect, use, and protect your personal information. By using the Service, you consent to the data practices described in the Privacy Policy.</p>

            <h2>9. Modifications to Terms</h2>
            <p>We reserve the right to modify these Terms and Conditions at any time. Changes will be effective immediately upon posting on this page. Your continued use of the Service after changes are posted constitutes acceptance of the modified terms. We encourage you to review these terms periodically.</p>

            <h2>10. Contact Us</h2>
            <p>If you have any questions about these Terms and Conditions, please contact us:</p>
            <ul>
                <li><strong>Email:</strong> <?php echo $contactEmail; ?></li>
                <li><strong>Phone:</strong> <?php echo $contactPhone; ?></li>
                <li><strong>Address:</strong> <?php echo $contactAddress; ?></li>
            </ul>
        <?php endif; ?>
    </div>
</div>

<footer class="footer">
    <div class="container">
        <div class="footer-bottom">
            <span><?php echo $copyrightText; ?></span>
            <span>Powered by DigitalNext Gen</span>
            <div>
                <a href="privacy.php" style="color:rgba(255,255,255,0.5);margin-right:16px;">Privacy Policy</a>
                <a href="terms.php" style="color:rgba(255,255,255,0.5);">Terms & Conditions</a>
            </div>
        </div>
    </div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
(function() {
    var navbar = document.getElementById('navbar');
    var navToggle = document.getElementById('navToggle');
    var navMenu = document.getElementById('navMenu');

    window.addEventListener('scroll', function() {
        if (window.scrollY > 80) { navbar.classList.add('scrolled'); }
        else { navbar.classList.remove('scrolled'); }
    });

    navToggle.addEventListener('click', function() {
        navMenu.classList.toggle('show');
    });

    var navLinks = navMenu.querySelectorAll('a');
    for (var i = 0; i < navLinks.length; i++) {
        navLinks[i].addEventListener('click', function() {
            navMenu.classList.remove('show');
        });
    }
})();
</script>
</body>
</html>
