<?php
// templates/landing2.php
$site_settings = get_site_settings($pdo);
$landing_title = $site_settings['landing_title'] ?? 'UTAMU';
$favicon = $site_settings['site_favicon'] ?? 'assets/images/favicon.png';

if (!$featured && !empty($videos)) {
    $featured = $videos[0];
}
?>
<!DOCTYPE html>
<html lang="en">


<!-- Mirrored from kausha.tanzaniahub.click/ by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 18 Mar 2026 16:18:41 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($landing_title) ?> | Premium</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&amp;display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"><!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-WFSQPTZZLJ"></script>

    <style>
        :root {
            --primary: #00A8E1;
            /* Prime Blue */
            --bg: #0f171e;
            --card-bg: #1b2530;
            --text-main: #ffffff;
            --text-dim: #8197a4;
            --nav-bg: #1a242f;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Roboto', sans-serif;
            background: var(--bg);
            color: var(--text-main);
            line-height: 1.4;
        }

        /* --- Prime Solid Navbar --- */
        .navbar {
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 1000;
            padding: 0 4%;
            height: 70px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: var(--nav-bg);
        }

        .logo {
            font-size: 1.8rem;
            font-weight: 900;
            color: #fff;
            text-decoration: none;
            letter-spacing: -1px;
        }

        .logo span {
            color: var(--primary);
        }

        .nav-right {
            display: flex;
            align-items: center;
            gap: 25px;
            color: var(--text-dim);
            font-size: 1.1rem;
        }

        /* --- Prime Wide Hero --- */
        .hero {
            height: 75vh;
            position: relative;
            display: flex;
            align-items: center;
            padding: 0 4%;
            background: linear-gradient(to right, var(--bg) 0%, rgba(15, 23, 30, 0.4) 50%, transparent 100%),
                linear-gradient(to top, var(--bg) 0%, transparent 20%),
                url('assets/landing4.jpg') center/cover;
        }

        .hero-content {
            max-width: 500px;
            z-index: 2;
        }

        .hero-title {
            font-size: clamp(2rem, 5vw, 3.5rem);
            font-weight: 700;
            margin-bottom: 15px;
            line-height: 1.1;
        }

        .hero-desc {
            color: var(--text-dim);
            font-size: 1.1rem;
            margin-bottom: 25px;
        }

        .btn {
            padding: 14px 40px;
            border-radius: 4px;
            /* Sharper corners */
            font-weight: 700;
            border: none;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            transition: 0.2s;
            text-decoration: none;
            font-size: 1rem;
        }

        .btn-play {
            background: var(--primary);
            color: #fff;
        }

        .btn-play:hover {
            background: #008fbe;
        }

        /* --- Grid System (16:9 Aspect) --- */
        .section-container {
            padding: 40px 4%;
        }

        .row-header {
            margin-bottom: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .row-title {
            font-size: 1.3rem;
            font-weight: 700;
            color: #fff;
        }

        .movie-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 15px;
        }

        .movie-card {
            background: transparent;
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        .card-thumb {
            width: 100%;
            aspect-ratio: 16/9;
            position: relative;
            border-radius: 4px;
            overflow: hidden;
            background: #252e39;
        }

        .card-thumb img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: opacity 0.3s;
        }

        .movie-card:hover {
            transform: scale(1.05);
            z-index: 10;
        }

        .movie-card:hover .card-thumb {
            outline: 3px solid #fff;
            outline-offset: -3px;
        }

        .badge-premium {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(0, 168, 225, 0.9);
            color: white;
            padding: 4px 8px;
            font-size: 0.65rem;
            font-weight: 700;
            border-radius: 2px;
        }

        .card-info {
            padding: 10px 0;
        }

        .card-info h3 {
            font-size: 0.95rem;
            font-weight: 500;
            color: #fff;
            margin-bottom: 2px;
        }

        .card-info p {
            font-size: 0.8rem;
            color: var(--text-dim);
        }

        /* --- Prime Style Modal --- */
        .modal-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.85);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 2000;
        }

        .modal-content {
            background: var(--bg);
            width: 100%;
            max-width: 480px;
            border: 1px solid #303c4a;
            padding: 40px;
            position: relative;
        }

        .modal-header h2 {
            font-size: 1.8rem;
            margin-bottom: 10px;
        }

        .payment-method {
            border: 1px solid #303c4a;
            padding: 20px;
            margin: 20px 0;
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .payment-method.active {
            border-color: var(--primary);
            background: rgba(0, 168, 225, 0.05);
        }

        .input-group input {
            width: 100%;
            background: #fff;
            border: 1px solid #8197a4;
            padding: 14px;
            color: #000;
            font-size: 1rem;
            margin-top: 10px;
        }

        .btn-full {
            width: 100%;
            margin-top: 20px;
            background: var(--primary);
            color: white;
            justify-content: center;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        @media (max-width: 768px) {
            .movie-grid {
                grid-template-columns: repeat(1, 1fr);
            }

            .hero {
                height: 50vh;
            }

            .hero-title {
                font-size: 1.8rem;
            }
        }
    </style>
</head>

<body>

    <nav class="navbar">
        <a href="#" class="logo">UTAMU<span>+</span></a>
        <div class="nav-right">
            <i class="fas fa-search"></i>
            <i class="fas fa-user-circle"></i>
        </div>
    </nav>

        <?php if ($featured): ?>
    <header class="hero" style="background: linear-gradient(to right, var(--bg) 0%, rgba(15, 23, 30, 0.4) 50%, transparent 100%), linear-gradient(to top, var(--bg) 0%, transparent 20%), url('<?= htmlspecialchars($featured['thumbnail_url'] ?: SITE_URL.'/assets/landing4.jpg') ?>') center/cover;">
        <div class="hero-content">
            <h1 class="hero-title"><?= htmlspecialchars($featured['title']) ?></h1>
            <p class="hero-desc">Connections zote mpya hapa angalia</p>
        </div>
    </header>
    <?php else: ?>
    <header class="hero">
        <div class="hero-content">
            <h1 class="hero-title">Bongo Videos</h1>
            <p class="hero-desc">Connections zote mpya hapa angalia</p>
        </div>
    </header>
    <?php endif; ?>

    <main class="section-container">
        <div class="row-header">
            <h2 class="row-title">Included with UTAMU+</h2>
        </div>

        <div class="movie-grid">
            <?php foreach ($videos as $vid): ?>
            <div class="movie-card" onclick="openPaymentModal(null, '<?= (int)$vid['price'] ?>', '<?= htmlspecialchars($vid['id']) ?>')">
                <div class="card-thumb">
                    <img src="<?= htmlspecialchars($vid['thumbnail_url'] ?: SITE_URL.'/assets/placeholder.jpg') ?>" alt="">
                    <span class="badge-premium">PREMIUM</span>
                </div>
                <div class="card-info">
                    <h3><?= htmlspecialchars($vid['title']) ?></h3>
                    <p><?= number_format($vid['views'] ?? rand(50, 500)) ?> views • Just added</p>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </main>
<div class="modal-overlay" id="paymentModal">
        <div class="modal-content">
            <i class="fas fa-times"
                style="position: absolute; top: 20px; right: 20px; cursor: pointer; color: var(--text-dim);"
                onclick="closePaymentModal()"></i>

            <div class="modal-header">
                <h2>Rent this video</h2>
                <p style="color: var(--text-dim);">Ready to watch? Rent this video instantly with Mobile Money.</p>
            </div>

            <input type="hidden" id="videoID" value="">

            <div class="payment-method active">
                <i class="fas fa-mobile-alt" style="font-size: 1.5rem; color: var(--primary);"></i>
                <div>
                    <strong id="modalPrice">TSH 0</strong>
                    <p style="font-size: 0.8rem; color: var(--text-dim)">Mobile Money (M-Pesa, Tigo, Airtel)</p>
                </div>
            </div>
<script>
const SITE = '<?= SITE_URL ?>';
let paymentCheckInterval = null;
let customModalId = ''; 
window.currentCheckoutId = null;
window.currentCheckoutTitle = 'Customer';
window.currentCheckoutPrice = 0;
window.originalBtnHtml = '';

function openPaymentModal(event, price, id) {
    if (event && event.preventDefault) event.preventDefault();
    customModalId = 'paymentModal';
    document.getElementById(customModalId).style.display = 'flex';
    setupModalData(price, id, '');
}
function openPaymentSheet(price, id) {
    customModalId = 'paymentModal';
    document.getElementById(customModalId).classList.add('open');
    setupModalData(price, id, '');
}
function openCyberModal(price, id) {
    customModalId = 'paymentModal';
    document.getElementById(customModalId).style.display = 'grid';
    setupModalData(price, id, '');
}
function openSheet(price, id) {
    customModalId = 'sheet';
    document.getElementById(customModalId).classList.add('show');
    document.getElementById('overlay').style.display = 'block';
    setupModalData(price, id, '');
}
function handleVideoClick(el, isPaid, url) { 
    if(isPaid) { window.location.href = url; return; }
    customModalId = 'paymentModal';
    document.getElementById(customModalId).classList.add('active');
    setupModalData(el.getAttribute('data-price'), el.getAttribute('data-id'), el.getAttribute('data-title'));
}

function closeCyberModal() { closeModalUniversal(); }
function closeSheet() { closeModalUniversal(); }
function closePaymentModal() { closeModalUniversal(); }
function closeModal() { closeModalUniversal(); }

function closeModalUniversal() {
    if(!customModalId) customModalId = 'paymentModal';
    const m = document.getElementById(customModalId);
    if(m) {
        m.style.display = 'none';
        m.classList.remove('open', 'active', 'show');
    }
    const sheet = document.getElementById('sheet');
    if(sheet) Object.assign(sheet.style, {bottom: '-100%'}) || sheet.classList.remove('show');
    
    const overlay = document.getElementById('overlay');
    if(overlay) overlay.style.display = 'none';
    if(paymentCheckInterval) clearInterval(paymentCheckInterval);
    resetPayButtonUniversal();
}

function setupModalData(price, id, title) {
    const vidInput = document.getElementById('videoID');
    if(vidInput) vidInput.value = id;
    
    window.currentCheckoutId = id;
    window.currentCheckoutTitle = title || 'Customer';
    window.currentCheckoutPrice = price;

    const priceEl = document.getElementById('modalPrice') || document.querySelector('.price-amount');
    if(priceEl) {
        if (priceEl.innerText.includes('TSH')) {
            priceEl.innerText = 'TSH ' + parseInt(price).toLocaleString();
        } else {
            priceEl.innerText = parseInt(price).toLocaleString();
        }
    }
}

async function processPayment() { 
    const phoneInput = document.querySelector('input[type="tel"]') || document.getElementById('phoneInput') || document.getElementById('phoneNumber');
    let phone = phoneInput ? phoneInput.value.replace(/[\s-]/g, '') : '';
    
    if (phone.length === 9 && !phone.startsWith('0')) phone = '0' + phone; 

    if (!phone || phone.length < 10) {
        alert("Weka namba sahihi ya simu, ianzie na 0");
        return;
    }

    const amount = window.currentCheckoutPrice;
    const videoID = window.currentCheckoutId || (document.getElementById('videoID') ? document.getElementById('videoID').value : null);
    
    const payBtn = document.querySelector('.btn-full') || document.querySelector('.btn-neon') || document.querySelector('.pay-btn-final') || document.getElementById('payBtn') || document.querySelector('.pay-btn');
    
    if(!window.originalBtnHtml) window.originalBtnHtml = payBtn.innerHTML;
    payBtn.innerHTML = 'INACHAKATA...';
    payBtn.disabled = true;

    try {
        const response = await fetch(SITE.replace(/\/+$/, '') + '/api/pay.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
            body: JSON.stringify({
                phone: phone,
                amount: parseInt(amount),
                videoID: videoID,
                name: window.currentCheckoutTitle,
                token: <?= json_encode($store_api_key) ?> || ''
            })
        });

        const data = await response.json();
        if (data.success) {
            payBtn.innerHTML = 'ANGALIA SIMU YAKO...';
            pollStatus(data.transaction_id);
        } else {
            alert(data.message || 'Hitilafu imetokea.');
            resetPayButtonUniversal();
        }
    } catch (e) {
        alert('Kuna tatizo la mtandao.');
        resetPayButtonUniversal();
    }
}

function submitPayment() { processPayment(); } 

function pollStatus(transactionId) {
    if (paymentCheckInterval) clearInterval(paymentCheckInterval);
    const payBtn = document.querySelector('.btn-full') || document.querySelector('.btn-neon') || document.querySelector('.pay-btn-final') || document.getElementById('payBtn') || document.querySelector('.pay-btn');
    
    paymentCheckInterval = setInterval(async () => {
        try {
            const token = <?= json_encode($store_api_key) ?> || '';
            const query = new URLSearchParams({ tran_id: transactionId, token: token, _: new Date().getTime() }).toString();
            const res = await fetch(SITE.replace(/\/+$/, '') + '/api/check_status.php?' + query);
            const data = await res.json();
            
            const s = (data.status || '').toLowerCase();
            const rs = (data.raw_status || '').toLowerCase();

            if (s === 'success' || s === 'completed' || rs === 'success' || rs === 'completed') {
                clearInterval(paymentCheckInterval);
                payBtn.innerHTML = 'IMEKUBALIWA! INAFUNGUA...';
                setTimeout(() => {
                    window.location.href = <?= json_encode($store_redirect_url) ?>; 
                }, 1500);
            } else if (s === 'failed' || s === 'cancelled') {
                clearInterval(paymentCheckInterval);
                alert('Malipo yameshindwa (' + (data.raw_status || s) + ')');
                resetPayButtonUniversal();
            }
        } catch(e) {}
    }, 5000);
}

function resetPayButtonUniversal() {
    const payBtn = document.querySelector('.btn-full') || document.querySelector('.btn-neon') || document.querySelector('.pay-btn-final') || document.getElementById('payBtn') || document.querySelector('.pay-btn');
    if(payBtn && window.originalBtnHtml) {
        payBtn.innerHTML = window.originalBtnHtml;
        payBtn.disabled = false;
    }
}

document.querySelectorAll('.modal-close, .fa-times').forEach(el => {
    el.addEventListener('click', closeModalUniversal);
});
</script>
</body>
</html>