<?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.');

$privacyStmt = $db->query("SELECT setting_value FROM website_settings WHERE setting_key = 'privacy_policy'");
$privacyContent = $privacyStmt->fetch();

$privacyHtml = '';
if ($privacyContent && !empty($privacyContent['setting_value'])) {
    $privacyHtml = $privacyContent['setting_value'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Privacy Policy | <?php echo $siteName; ?></title>
    <meta name="description" content="<?php echo $siteName; ?> Privacy Policy - Learn how we collect, use, and protect your personal information.">
    <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>Privacy Policy</h1>
        <div class="legal-meta">Last updated: January 1, 2026</div>

        <?php if (!empty($privacyHtml)): ?>
            <?php echo $privacyHtml; ?>
        <?php else: ?>
            <h2>1. Information We Collect</h2>
            <p>We collect information you provide directly to us when you use our platform, including:</p>
            <ul>
                <li><strong>Account Information:</strong> Name, email address, phone number, and password when you create an account.</li>
                <li><strong>Restaurant Information:</strong> Restaurant name, address, menu items, pricing, and operational details when you set up your restaurant profile.</li>
                <li><strong>Order Information:</strong> Customer names, phone numbers, order details, and delivery addresses when orders are placed through the platform.</li>
                <li><strong>Payment Information:</strong> Transaction details related to orders and subscriptions (payment processing is handled by secure third-party providers).</li>
                <li><strong>Communications:</strong> Messages you send us through contact forms, support channels, or email.</li>
                <li><strong>Usage Data:</strong> Browser type, device information, IP address, pages visited, and interaction patterns collected automatically through cookies and analytics tools.</li>
            </ul>

            <h2>2. How We Use Information</h2>
            <p>We use the information we collect to:</p>
            <ul>
                <li>Provide, operate, and maintain the Tap2Order platform.</li>
                <li>Process orders and facilitate communication between restaurants and customers.</li>
                <li>Send transactional notifications related to orders and account activity.</li>
                <li>Improve our platform, develop new features, and analyze usage trends.</li>
                <li>Send marketing communications (with your consent where required by law).</li>
                <li>Detect, prevent, and address technical issues and fraudulent activity.</li>
                <li>Comply with legal obligations and enforce our terms of service.</li>
            </ul>

            <h2>3. Data Security</h2>
            <p>We implement industry-standard security measures to protect your personal information, including:</p>
            <ul>
                <li>SSL/TLS encryption for all data transmitted between your device and our servers.</li>
                <li>Encrypted storage of passwords using bcrypt hashing.</li>
                <li>Regular security audits and vulnerability assessments.</li>
                <li>Access controls and authentication mechanisms to protect against unauthorized access.</li>
                <li>Automated backups and disaster recovery procedures.</li>
            </ul>
            <p>While we strive to protect your data, no method of electronic transmission or storage is 100% secure, and we cannot guarantee absolute security.</p>

            <h2>4. Cookie Policy</h2>
            <p>We use cookies and similar tracking technologies to enhance your experience on our platform:</p>
            <ul>
                <li><strong>Essential Cookies:</strong> Required for basic platform functionality, including session management and security.</li>
                <li><strong>Analytics Cookies:</strong> Help us understand how visitors interact with our platform, allowing us to improve performance and user experience.</li>
                <li><strong>Preference Cookies:</strong> Remember your settings and preferences to provide a personalized experience.</li>
            </ul>
            <p>You can control cookie preferences through your browser settings. Disabling certain cookies may affect platform functionality.</p>

            <h2>5. Third-Party Services</h2>
            <p>We may share information with third-party service providers who assist us in operating our platform, including:</p>
            <ul>
                <li>Cloud hosting and infrastructure providers.</li>
                <li>Payment processing services.</li>
                <li>Analytics and monitoring tools.</li>
                <li>Communication services (email, SMS, push notifications).</li>
            </ul>
            <p>These third parties are contractually obligated to protect your information and use it only for the purposes we specify.</p>

            <h2>6. User Rights</h2>
            <p>You have the right to:</p>
            <ul>
                <li><strong>Access:</strong> Request a copy of the personal data we hold about you.</li>
                <li><strong>Rectification:</strong> Request correction of inaccurate or incomplete data.</li>
                <li><strong>Deletion:</strong> Request deletion of your personal data, subject to legal retention requirements.</li>
                <li><strong>Portability:</strong> Request transfer of your data to another service provider in a structured, machine-readable format.</li>
                <li><strong>Objection:</strong> Object to the processing of your personal data for certain purposes.</li>
                <li><strong>Withdraw Consent:</strong> Withdraw previously given consent at any time.</li>
            </ul>
            <p>To exercise these rights, please contact us using the information provided below.</p>

            <h2>7. Data Retention</h2>
            <p>We retain your personal information only for as long as necessary to fulfill the purposes for which it was collected, or as required by applicable laws and regulations. When data is no longer needed, it is securely deleted or anonymized.</p>

            <h2>8. Changes to This Policy</h2>
            <p>We may update this Privacy Policy from time to time. We will notify you of any material changes by posting the updated policy on this page with a revised "Last updated" date. Your continued use of the platform after changes are posted constitutes acceptance of the updated policy.</p>

            <h2>9. Contact Us</h2>
            <p>If you have any questions or concerns about this Privacy Policy or our data practices, 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>
