<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta name="content-signal" content="search=yes,ai-train=no">
    @php
        $defaultTitle = config('app,name') . ' - Nonton Drama Episode Pendek Terbaik';
        $defaultDesc = 'Situs nonton drama pendek, film, dan serial TV terbaru dengan subtitle Indonesia. Gratis dan update setiap hari.';
        $defaultImage = config('app.og_image'); 
        $defaultUrl = request()->fullUrl();
        $defaultType = 'website';
        $defaultCanonical = request()->fullUrl();
    @endphp
    <title>@yield('title', $defaultTitle)</title>
    {{--Meta SEO--}}
    @if(config('app.google_webmaster'))
        <meta name="google-site-verification" content="{{config('app.google_webmaster')}}" />
    @endif
    @if(config('app.bing_webmaster'))
        <meta name="msvalidate.01" content="{{config('app.bing_webmaster')}}" />
    @endif
    @if(config('app.yandex_webmaster'))
        <meta name="yandex-verification" content="{{config('app.yandex_webmaster')}}" />
    @endif
    <meta name="description" content="@yield('description', $defaultDesc)">
    <meta property="og:title" content="@yield('title', $defaultTitle)">
    <meta property="og:description" content="@yield('description', $defaultDesc)">
    <meta property="og:image" content="@yield('image', $defaultImage)">
    <meta property="og:url" content="@yield('url', $defaultUrl)">
    <meta property="og:type" content="@yield('type', $defaultType)">
    <meta property="og:site_name" content="{{config('app.name')}}">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="@yield('title', $defaultTitle)">
    <meta name="twitter:description" content="@yield('description', $defaultDesc)">
    <meta name="twitter:image" content="@yield('image', $defaultImage)">
    <meta name="theme-color" content="{{ env('PWA_THEME_COLOR', '#000000') }}">
    <link rel="apple-touch-icon" href="{{ env('FAVICON_URL', '/images/logo-s.png') }}">
    <link rel="icon" href="{{config('app.favicon')}}" type="image/png">
    <link rel="canonical" href="@yield('canonical', $defaultCanonical)" />
    {{-- <meta name="twitter:site" content="@NamaTwitterAnda"> --}}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    <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=Lato:wght@100;200;300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="{{ asset('assets/css/style.min.css?ver=2.0.0') }}" rel="stylesheet">
    <link rel="preconnect" href="https://sres.dramaboxdb.com"/>
    <link rel="preconnect" href="https://placehold.co"/>
    <link rel="preconnect" href="https://thwztchapter.dramaboxdb.com"/>
    <style>
        .box-icon {
            display: none!important;
        }
        @if(isset($type) && $type == 'episode')
        .container {
            max-width: 1300px!important;
        }
        @media(max-width: 767.98px) {
            .footer-custom {
                display: none!important;
            }
        }
        @endif
        
        @if(isset($type) && $type == 'single')
        @media(max-width: 767.98px) {
            .footer-custom {
                display: none!important;
            }
        }
        @endif
        @media(min-width: 768px) {
            .mobile-footer-banner {
                max-width: 450px;
                margin: 0 auto;
            }
        }
    </style>
    @if(isset($ldJson))
    <script type="application/ld+json">
        @json($ldJson)
    </script>
    @endif
    @if(isset($ldBreadcrumb))
    <script type="application/ld+json">
        @json($ldBreadcrumb)
    </script>
    @endif

    @stack('styles')
    @if(!Route::is('episode'))
    <link rel="manifest" href="/manifest.json?v={{ time() }}">
    @endif
    {{--Google Analytics--}}
    @if(config('app.google_analytics'))
    <script async src="https://www.googletagmanager.com/gtag/js?id={{config('app.google_analytics')}}"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', '{{config("app.google_analytics")}}');
    </script>
    @endif
</head>
<body>
    @if(config('app.floating_ads') && !Route::is('episode'))
    <div class="floating-banner banner-kiri" id="banner-kiri-container">
        <span class="close-banner" onclick="hideBanner('banner-kiri-container')">CLOSE</span>
        <a href="{{config('app.ads_link_url_left')}}" target="_blank">
            <img src="{{config('app.ads_image_url_left')}}" alt="Iklan Kiri">
        </a>
    </div>
    
    <div class="floating-banner banner-kanan" id="banner-kanan-container">
        <span class="close-banner" onclick="hideBanner('banner-kanan-container')">CLOSE</span>
        <a href="{{config('app.ads_link_url_right')}}" target="_blank">
            <img src="{{config('app.ads_image_url_right')}}" alt="Iklan Kanan">
        </a>
    </div>
    @endif
    <x-header/>
    
    @yield('content')

    <x-footer/>
    
    @if (Route::is('home') && config('app.apk_banner') == true)
    <div class="mobile-footer-banner" id="mobileFooterBanner" style="display: none;">
        <button type="button" class="close-button" aria-label="Close" onclick="document.getElementById('mobileFooterBanner').style.display='none';">X</button>
        <div class="app-info">
            <img src="{{config('app.logo_sm')}}" alt="Logo" class="app-logo">
            <span class="app-text">{{config('app.text_banner')}}</span>
        </div>
        {{--<a href="{{url(config('app.link_banner'))}}" class="btn open-button">Open</a>--}}
        <a href="javascript:void(0)" id="pwa-install-btn" class="btn open-button" style="display: none;">Install</a>
    </div>
    @endif
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
    <script type="text/javascript" defer src="{{ asset('assets/js/script.min.js?ver=2.0.0') }}"></script>
    @if(Route::is('episode'))
    <script type="text/javascript" defer src="{{ asset('assets/js/episode.min.js?ver=2.0.0') }}"></script>
    @endif
    @stack('scripts')
    <script>
        (function() {
            'use strict';
            const checkDevTools = () => {
                const minElapsedTime = 100;
                const startTime = new Date();
                debugger;
                const elapsedTime = new Date() - startTime;
                if (elapsedTime > minElapsedTime) {
                    window.location.href = "{{config('app.url')}}";
                }
            };
            setInterval(checkDevTools, 1000);
        })();
    </script>
    @if(!Route::is('episode'))
    <script>
    // Registrasi Service Worker
    if ('serviceWorker' in navigator) {
        window.addEventListener('load', () => {
            navigator.serviceWorker.register('/sw.js')
                .then(reg => {
                    console.log('SW terdaftar dengan scope:', reg.scope);
                })
                .catch(err => {
                    console.error('SW gagal terdaftar:', err);
                });
        });
    }

    // Logika Tombol Instalasi Anda (Script yang sebelumnya Anda kirim)
    (function() {
        window.pwaPromptEvent = null;
        const installBtn = document.getElementById('pwa-install-btn');
        const bannerPwa = document.getElementById('mobileFooterBanner');

        if (installBtn && bannerPwa) {
            window.addEventListener('beforeinstallprompt', (e) => {
                e.preventDefault();
                window.pwaPromptEvent = e;
                installBtn.style.display = 'inline-block';
                bannerPwa.style.display = 'flex';
            });

            installBtn.addEventListener('click', async () => {
                if (window.pwaPromptEvent) {
                    window.pwaPromptEvent.prompt();
                    const { outcome } = await window.pwaPromptEvent.userChoice;
                    window.pwaPromptEvent = null;
                    bannerPwa.style.display = 'none';
                }
            });
        }
    })();
    </script>
    @endif
    
    {{--Histats--}}
    @if(config('app.histats_sid'))
        <script type="text/javascript">var _Hasync= _Hasync|| [];
        _Hasync.push(['Histats.start', '1,{{config("app.histats_sid")}},4,0,0,0,00010000']);
        _Hasync.push(['Histats.fasi', '1']);
        _Hasync.push(['Histats.track_hits', '']);
        (function() {
        var hs = document.createElement('script'); hs.type = 'text/javascript'; hs.async = true;
        hs.src = ('//s10.histats.com/js15_as.js');
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs);
        })();</script>
        <noscript><a href="/" target="_blank"><img  src="//sstatic1.histats.com/0.gif?{{config('app.histats_sid')}}&101" alt="site stats" border="0"></a></noscript>
    @endif
    @if(env('FOOTER_SCRIPT'))
        {!! base64_decode(env('FOOTER_SCRIPT')) !!}
    @endif
</body>
</html>
