<?php
session_start();

// Prevent caching so the back button doesn't show the page after logout
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$dataFile = __DIR__ . '/data.json';
$data = [];
if (file_exists($dataFile)) {
    $content = file_get_contents($dataFile);
    $parsed = json_decode($content, true);
    if (is_array($parsed)) {
        $data = $parsed;
    }
}
$defaults = [
    'name' => 'MADISON LIPPY',
    'link' => 'https://a.vlmjm1.com/e767cbd3-d250-4a23-9dd7-33edd1e1a5b0?aff_id=313078&aff_sub5=SF_006OG00000GOXb7&source=Miushja',
    'photos_count' => 917,
    'videos_count' => 367,
    'profile_image' => 'img/profile.jpeg',
    'gallery_images' => [
        'img/gallery1.jpeg',
        'img/gallery2.jpeg',
        'img/gallery3.jpeg',
        'img/gallery4.jpeg'
    ],
    'gallery_videos' => [
        'vid/vid1.mp4',
        'vid/vid2.mp4',
        'vid/vid3.mp4',
        'vid/vid4.mp4',
        'vid/vid5.mp4'
    ]
];
$data = array_replace_recursive($defaults, $data);
if (isset($parsed['gallery_images'])) {
    $data['gallery_images'] = $parsed['gallery_images'];
}
if (isset($parsed['gallery_videos'])) {
    $data['gallery_videos'] = $parsed['gallery_videos'];
}
$link = htmlspecialchars($data['link'], ENT_QUOTES, 'UTF-8');
$name = htmlspecialchars($data['name'], ENT_QUOTES, 'UTF-8');
$photosCount = (int) $data['photos_count'];
$videosCount = (int) $data['videos_count'];
$profileImage = htmlspecialchars($data['profile_image'], ENT_QUOTES, 'UTF-8');
$livestreamImage = !empty($data['livestream_image']) ? htmlspecialchars($data['livestream_image'], ENT_QUOTES, 'UTF-8') : $profileImage;
$galleryImages = array_map(function ($img) {
    return htmlspecialchars($img, ENT_QUOTES, 'UTF-8');
}, $data['gallery_images']);
$galleryVideos = array_map(function ($vid) {
    return htmlspecialchars($vid, ENT_QUOTES, 'UTF-8');
}, $data['gallery_videos']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Creator Profile</title>
    <link rel="icon" href="data:,">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
    <link rel="preload" as="image" href="<?= $profileImage ?>" fetchpriority="high">
    <link rel="preload" as="font" type="font/woff2" href="fonts/JTUSjIg69CK48gW7PXoo9WlhyyTh89Y.woff2" crossorigin>
    <link rel="preload" as="font" type="font/woff2" href="fonts/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7W0Q5nw.woff2" crossorigin>

    <style>
<?= file_get_contents(__DIR__ . '/fontfile.css') ?>
<?= file_get_contents(__DIR__ . '/bootstrap-manual.css') ?>
<?= file_get_contents(__DIR__ . '/style.css') ?>
        /* Prevent image saving & dragging */
        img, video {
            -webkit-user-drag: none;
            -khtml-user-drag: none;
            -moz-user-drag: none;
            -o-user-drag: none;
            user-drag: none;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            user-select: none;
            pointer-events: auto;
        }

        /* Custom Tabs */
        .custom-tabs-container { display: flex; gap: 0.5rem; margin-bottom: 1rem; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 10px; }
        .tab-btn {
            display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; font-size: 16px; font-weight: 500;
            border: none; border-bottom: 2px solid transparent; transition: all 0.2s; background: none; cursor: pointer; color: #999;
            text-transform: uppercase;
        }
        .tab-btn.active { border-bottom-color: #C61C74; color: #C61C74; font-weight: 700; }
        .tab-btn:hover:not(.active) { color: #fff; }
        .badge-live-tab {
            display: inline-flex; align-items: center; gap: 0.25rem; font-size: 10px; font-weight: 700; text-transform: uppercase;
            padding: 2px 6px; border-radius: 20px; background-color: rgba(198, 28, 116, 0.2); color: #C61C74; margin-left: 5px;
        }
        .dot-pulse { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background-color: #C61C74; animation: pulse 2s infinite; }
        @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
        
        /* Dynamic Grid */
        .media-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 2rem;}
        @media(min-width: 768px) { .media-grid { grid-template-columns: repeat(3, 1fr); gap: 20px;} }
        @media(min-width: 1024px) { .media-grid { grid-template-columns: repeat(4, 1fr); gap: 20px;} }
        .contents { display: contents; }
        .hidden { display: none !important; }
        .media-card { position: relative; height: 300px; border-radius: 12px; overflow: hidden; background-color: #12081f; cursor: pointer; border: 1px solid #2d2145; }
        .media-card-live { border-color: #C61C74; box-shadow: 0 0 10px rgba(198, 28, 116, 0.3); height: auto; aspect-ratio: 3/4; }
        .media-img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s; }
        .media-card:hover .media-img { transform: scale(1.05); }
        .live-badge {
            position: absolute; top: 10px; left: 10px; display: flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase;
            background-color: #C61C74; color: #fff; padding: 2px 8px; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        .live-ping { width: 6px; height: 6px; background-color: #fff; border-radius: 50%; animation: ping 1s infinite; }
        @keyframes ping { 75%, 100% { transform: scale(2); opacity: 0; } }
    </style>
</head>
<body>
    <div class="container-fluid py-3 py-md-5 px-3 px-md-5">
        <div class="row align-items-center">
            <!-- Left (Profile) -->
            <div class="col-lg-8">
                <div class="row align-items-center">
                    <div class="col-4 text-center">
                        <div class="profile-image">
                            <img src="<?= $profileImage ?>" class="img-fluid rounded-circle" fetchpriority="high">
                            <span class="online"></span>
                        </div>
                    </div>
                    <div class="col-8">
                        <h1 class="display-2 fw-bold creator-name">
                            <div class="provile_name"><?= $name ?></div>
                            <div class=""> <img src="img/assets/Country_icon.png"> <img src="img/assets/verify_icon.png"></div>
                        </h1>
                        <p class=" pro_sub">
                            Your favorite creator for exclusive content, live shows & more
                        </p>
                        <div class="row mt-4">
                            <div class="col-6">
                                <div class="set_icons border-r">
                                    <div class="icons_pro">
                                        <img src="img/assets/video_icon.png">
                                    </div>
                                    <div class="text_pro">
                                        <h3><?= $videosCount ?></h3>
                                        <p>VIDEOS</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="set_icons">
                                    <div class="icons_pro">
                                        <img src="img/assets/gallary_icon.png">
                                    </div>
                                    <div class="text_pro">
                                        <h3><?= $photosCount ?></h3>
                                        <p>PHOTOS</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- right (Side cards) -->
            <div class="col-lg-4 ">
                <div class="side-card set-tpos">
                    <a href="#" data-bs-toggle="modal" data-bs-target="#affiliateModal" class="stretched-link"></a>
                    <div class="side_main">
                        <div class="side_icon">
                            <img src="img/assets/fire_icon.png">
                        </div>
                        <div class="side_text">
                            <h3> WATCH ME NOW</h3>
                            <p class="mob_noie">Join my live show</p>
                        </div>
                    </div>
                    <div class="side_arrow">
                        <img src="img/assets/right_arrow.png">
                    </div>
                </div>

                <div class="side-card mt-4">
                    <div class="side_main">
                        <a href="#" data-bs-toggle="modal" data-bs-target="#affiliateModal" class="stretched-link"></a>
                        <div class="side_icon">
                            <img src="img/assets/ex_icon.png">
                        </div>
                        <div class="side_text">
                            <h3>EXCLUSIVE CONTENT</h3>
                            <p>View premium content</p>
                        </div>
                    </div>
                    <div class="side_arrow">
                        <img src="img/assets/right_arrow.png">
                    </div>
                </div>
            </div>
        </div>

        <div class="row mt-5">
            <div class="col-lg-8">
                <div class="card-dark gallery_div">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <div class="custom-tabs-container w-100">
                            <button id="tab-photos" onclick="setActiveTab('photos')" class="tab-btn active">
                                PHOTOS (<?= $photosCount ?>)
                            </button>
                            <button id="tab-live" onclick="setActiveTab('live')" class="tab-btn">
                                LIVE STREAMS
                            </button>
                        </div>
                    </div>

                    <!-- Dynamic Grid Content -->
                    <div class="media-grid">
                        <!-- Photos Content -->
                        <div id="content-photos" class="contents">
                            <?php 
                            $displayImages = array_slice($galleryImages, 0, 4);
                            foreach ($displayImages as $key => $galleryImage): 
                            ?>
                            <div class="media-card" data-bs-toggle="modal" data-bs-target="#affiliateModal">
                                <img src="<?= $galleryImage ?>" class="media-img">
                                <?php if (!isset($displayImages[$key + 1])): ?>
                                    <div class="gray_scale" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); border-radius: 12px; pointer-events: none;">
                                        <img src="img/assets/Private.png" style="width:50px; position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); z-index:10;">
                                    </div>
                                <?php endif; ?>
                            </div>
                            <?php endforeach; ?>
                        </div>

                        <!-- Live Streams Content -->
                        <div id="content-live" class="contents hidden">
                            <div class="media-card media-card-live position-relative" data-bs-toggle="modal" data-bs-target="#affiliateModal" style="margin-bottom: 15px; border-radius: 12px; overflow: hidden; grid-column: 1 / -1; justify-self: center; width: 100%; max-width: 100%; border: none; box-shadow: none;">
                                <img src="<?= $livestreamImage ?>" alt="Locked Video" class="media-img" style="filter: brightness(0.6) blur(5px); width: 100%; height: 100%; object-fit: cover; display: block; transform: scale(1.15);">

                                <!-- Time Badge (Top Left) -->
                                <div style="position: absolute; top: 10px; left: 10px; z-index: 10; pointer-events: none;">
                                    <span style="color: white; font-weight: bold; font-size: 1rem; letter-spacing: 1px; text-shadow: 1px 1px 2px rgba(0,0,0,0.8);">58:00</span>
                                </div>

                                <!-- Locked Icon (Center) -->
                                <div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 10; pointer-events: none;">
                                    <img src="img/assets/Private.png" style="width: 40px;">
                                </div>
                            </div>
                            <?php 
                            $displayVideos = array_slice($galleryVideos, 0, 5);
                            foreach ($displayVideos as $key => $galleryVideo): 
                            ?>
                            <div class="media-card media-card-live" data-bs-toggle="modal" data-bs-target="#affiliateModal">
                                <video src="<?= $galleryVideo ?>" class="media-img" style="filter: blur(10px); transform: scale(1.2);" autoplay loop muted playsinline></video>
                                <?php if (!isset($displayVideos[$key + 1])): ?>
                                    <div class="gray_scale" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); border-radius: 12px; pointer-events: none;">
                                        <img src="img/assets/Private.png" style="width:50px; position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); z-index:10;">
                                    </div>
                                <?php endif; ?>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                    <!-- View All Content Button -->
                    <div class="side-card mt-4 justify-content-center">
                        <a href="#" data-bs-toggle="modal" data-bs-target="#affiliateModal" class="stretched-link"></a>
                        <div class="side_main justify-content-center w-100">
                            <div class="side_text text-center w-100">
                                <h3 class="mb-0">VIEW MORE</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>


    </div>

    <footer class=" border-top-color mt-5 py-4">
        <div class="container-fluid px-3 px-md-5">
            <div class="footer_maind">
                <div class="footer-left">
                    <div class="footer_ter">
                        <div class="footer-logoimg me-4"><img src="img/assets/logo.png" onerror="this.style.display='none'"></div>
                        <a href="<?= $link ?>" class="text-secondary me-4">Privacy Policy</a>
                        <a href="<?= $link ?>" class="text-secondary me-4">Terms of Service</a>
                        <a href="mailto:dmca.team@proton.me" class="text-secondary me-4">DMCA</a>
                        <a href="<?= $link ?>" class="text-secondary"> 18 U.S.C. 2257</a>
                    </div>
                </div>
                <div class="footer-right text-md-end text-secondary">
                    © 2026 <?= $name ?>. All rights reserved
                </div>
            </div>
        </div>
    </footer>

    <!-- Affiliate Modal -->
    <div class="modal fade" id="affiliateModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered mx-auto" style="max-width: 360px;">
            <div class="modal-content text-center" style="background-color: var(--panel, #161a22); border: 1px solid var(--border, #2a2f3d); color: var(--text, #e8eaf0); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.8);">
                <div class="modal-header border-0 pb-0 position-relative">
                    <button type="button" class="border-0 position-absolute top-0 end-0 m-2 d-flex align-items-center justify-content-center" data-bs-dismiss="modal" aria-label="Close" style="background-color: var(--text, #e8eaf0); color: var(--panel, #161a22); border-radius: 50%; width: 28px; height: 28px; z-index: 9999; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.3); transition: all 0.2s ease;">
                        <span aria-hidden="true" style="font-size: 1.2rem; font-weight: bold; line-height: 1; margin-top: -2px;">&times;</span>
                    </button>
                </div>
                <div class="modal-body pt-0 px-4 pb-4">
                    <h2 class="fw-bold mb-3" style="color: var(--accent, #ff4d6d); font-family: 'Times New Roman', serif; font-size: 1.6rem; letter-spacing: 1px;"><?= mb_strtoupper($name, 'UTF-8') ?></h2>
                    
                    <p class="fw-bold small mb-2">Watch explicit content for FREE in "Jerkmate"</p>
                    <div class="small mb-3" style="line-height: 1.6; color: #8a90a3;">
                        1- Create a FREE Jerkmate Account<br>
                        2- Get the Free Lifetime Membership<br>
                        3- Enjoy thousands of models like me
                    </div>

                    <a href="<?= $link ?>" class="d-block position-relative mb-3 text-decoration-none" style="border-radius: 8px; overflow: hidden; background-color: #2a2f3d;">
                        <img src="popup.gif" alt="Exclusive Offer" style="width: 100%; height: auto; display: block;">
                    </a>

                    <a href="<?= $link ?>" class="btn rounded-pill w-100 fw-bold fs-5" style="background-color: #000; border: 1px solid #333; color: #ff4d6d; padding: 10px;">
                        Join for Free
                    </a>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        function setActiveTab(tabId) {
            document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
            document.getElementById('tab-' + tabId).classList.add('active');
            
            document.getElementById('content-photos').classList.add('hidden');
            document.getElementById('content-live').classList.add('hidden');
            document.getElementById('content-' + tabId).classList.remove('hidden');
        }

        document.addEventListener('contextmenu', function(e) {
            e.preventDefault();
        });
    </script>
</body>
</html>
