@extends('frontend.layouts.app')

@section('content')

    @php 
        $isLogin = auth()->check(); 
        $prefix = $isLogin ? '/secure' : '';
        
    @endphp

    <div id="showM">
        <div class="overlap g8mmenu-close"></div>
        @include('frontend.partials.mobile.header')
        @include('frontend.partials.mobile.sidebar-menu')

        <div class="content">
            
            @include('frontend.partials.mobile.navbar')

            <div class="nav__title">Slots</div>
            
            <section class="box">
                <div class="box__detail s1">
                    
                    @php
                        if ($providersDB->isEmpty()) {
                            // JIKA DATABASE KOSONG -> PAKAI DUMMY ORIGINAL ANDA
                            $providers = [
                                ['url' => 'pm', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Pragmatic-mobile.webp', 'alt' => 'Pragmatic Play'],
                                ['url' => 'fp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Fat-Panda-mobile.webp', 'alt' => 'Fat Panda'],
                                ['url' => 'mgp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Microgaming-mobile.webp', 'alt' => 'Microgaming'],
                                ['url' => 's88', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-SLOT88-mobile.webp', 'alt' => 'Slot88'],
                                ['url' => 'pg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-PGSoft-mobile.webp', 'alt' => 'PGSoft'],
                                ['url' => 'sg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Spadegaming-mobile.webp', 'alt' => 'Spadegaming'],
                                ['url' => 'jl', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-JILI-mobile.webp', 'alt' => 'Jili'],
                                ['url' => 'vp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Vpower-mobile.webp', 'alt' => 'Vpower'],
                                ['url' => 'jk', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-JOKER-mobile.webp', 'alt' => 'Joker'],
                                ['url' => 'hb', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Habanero-mobile.webp', 'alt' => 'Habanero'],
                                ['url' => 'fs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-FASTSPIN-mobile.webp', 'alt' => 'Fastspin'],
                                ['url' => 'lv2', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Live22-mobile.webp', 'alt' => 'Live22'],
                                ['url' => 'cq9', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-CQ9-mobile.webp', 'alt' => 'CQ9'],
                                ['url' => 'ka', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-KAGaming-mobile.webp', 'alt' => 'KA Gaming'],
                                ['url' => 'gp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Gameplay-mobile.webp', 'alt' => 'Gameplay'],
                                ['url' => 'pt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Playtech-mobile.webp', 'alt' => 'Playtech'],
                                ['url' => 'ps', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Playstar-mobile.webp', 'alt' => 'Playstar'],
                                ['url' => 'nt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-NETENT-mobile.webp', 'alt' => 'Netent'],
                                ['url' => 'nc', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-NLC-mobile.webp', 'alt' => 'Nolimit City'],
                                ['url' => 'rt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-RED-TIGER-mobile.webp', 'alt' => 'Red Tiger'],
                                ['url' => 'jb', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-JDB-mobile.webp', 'alt' => 'JDB'],
                                ['url' => 'fc', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-FACHAI-mobile.webp', 'alt' => 'Fa Chai'],
                                ['url' => 'ap', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-AP-mobile.webp', 'alt' => 'AdvantPlay'],
                                ['url' => 'hs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-HACKSAW-mobile.webp', 'alt' => 'Hacksaw'],
                                ['url' => 'bng', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-BNG-mobile.webp', 'alt' => 'BNG'],
                                ['url' => 'png', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-PLAYNGO-mobile.webp', 'alt' => 'PlaynGo'],
                                ['url' => 'alz', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-ALIZE-mobile.webp', 'alt' => 'Alize'],
                                ['url' => 'ep', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-EVOPLAY-mobile.webp', 'alt' => 'Evoplay'],
                                ['url' => 'ebtg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-BTG-mobile.webp', 'alt' => 'BTG'],
                                ['url' => 'ibx', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-IBEX-mobile.webp', 'alt' => 'Ibex'],
                                ['url' => 'rlx', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-RELAX-mobile.webp', 'alt' => 'Relax Gaming'],
                                ['url' => 'emp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-IMPERIUM-mobile.webp', 'alt' => 'Imperium Games'],
                                ['url' => 'ns', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-NEXTSPIN-mobile.webp', 'alt' => 'NextSpin'],
                                ['url' => 'ss', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-SMARTSOFT-mobile.webp', 'alt' => 'Smartsoft'],
                                ['url' => '5g', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-5G-mobile.webp', 'alt' => '5G Games'],
                                ['url' => 'ng', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Naga-mobile.webp', 'alt' => 'Naga Games'],
                                ['url' => 'bs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-BETSOFT-mobile.webp', 'alt' => 'Betsoft'],
                                ['url' => 'ds', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-Dragoonsoft-mobile.webp', 'alt' => 'Dragoonsoft'],
                                ['url' => 'ai', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-AIGAMING-mobile.webp', 'alt' => 'AI Gaming'],
                                ['url' => 'lp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-LITEPLAY-mobile.webp', 'alt' => 'Liteplay'],
                                ['url' => 'km', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/KINGMAKER-mobile.webp', 'alt' => 'Kingmaker'],
                                ['url' => 'pgs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/PEGASUS-mobile.webp', 'alt' => 'Pegasus'],
                                ['url' => 'ggs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/slots-GGSOFT-mobile.webp', 'alt' => 'GGSoft'],
                                ['url' => 'ace', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/mobile-v2/ACE333-mobile.webp', 'alt' => 'ACE333'],
                            ];
                        } else {
                            // JIKA DATABASE TERISI -> PAKAI DATA DARI DATABASE
                            $providers = [];
                            foreach($providersDB as $db) {
                                $providers[] = [
                                    'url' => strtolower($db->provider_code), 
                                    // Anggap gambar disimpan di folder /uploads/providers/
                                    'img' => asset('uploads/'.$db->banner_mobile), 
                                    'alt' => $db->provider_name
                                ];
                            }
                        }
                    @endphp

                    @foreach($providers as $p)
                        <div class="box__detail-img">
                            <a href="{{ $prefix }}/slots?sg={{ $p['url'] }}">
                                <img src="{{ $p['img'] }}" alt="{{ $p['alt'] }}" loading="lazy">
                            </a>
                        </div>
                    @endforeach
                    
                </div>
            </section>
            
            <section class="seo"></section>
        </div>
        
        @include('frontend.partials.mobile.bottom-nav')
    </div>
    
    <div id="showD">
        @include('frontend.partials.desktop.header')

        <section class="slider">
            <section class="marquee">
                <div class="wrapper">
                    <div class="s-a">
                        <div class="marquee__bullhorn">
                            <i class="fas fa-bullhorn"></i>
                        </div>
                        <marquee scrolldelay="150" behavior="scroll" onmouseover="this.stop();" onmouseout="this.start();" direction="left">
                            <div style="width: 100000px; transform: translateX(0px);" class="js-marquee-wrapper">
                                <div class="js-marquee" style="margin-right: 0px; float: left;">{{ general()->title }}</div>
                            </div>
                        </marquee>
                    </div>
                </div>
            </section>
            <div class="swiper__img">
                <div style="padding-top: 37px;"></div>
            </div>
        </section>

        <section class="featured">
            <div class="wrapper">
                <div class="featured__detail">
                    <div class="featured__detail-content">

                        @php
                            if ($providersDB->isEmpty()) {
                                // JIKA DATABASE KOSONG -> PAKAI DUMMY ORIGINAL ANDA
                                $providersDesktop = [
                                    ['url' => 'pm', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Pragmatic-web.webp', 'title' => 'Pragmatic Play'],
                                    ['url' => 'fp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Fat-Panda-web.webp', 'title' => 'Fat Panda'],
                                    ['url' => 'mgp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Microgaming-web.webp', 'title' => 'Microgaming'],
                                    ['url' => 's88', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-SLOT88-web.webp', 'title' => 'Slot88'],
                                    ['url' => 'pg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-PGSoft-web.webp', 'title' => 'PGSoft'],
                                    ['url' => 'sg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Spadegaming-web.webp', 'title' => 'Spadegaming'],
                                    ['url' => 'jl', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-JILI-web.webp', 'title' => 'Jili'],
                                    ['url' => 'vp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Vpower-web.webp', 'title' => 'V Power'],
                                    ['url' => 'jk', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-JOKER-web.webp', 'title' => 'Joker'],
                                    ['url' => 'hb', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Habanero-web.webp', 'title' => 'Habanero'],
                                    ['url' => 'fs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-FASTSPIN-web.webp', 'title' => 'FastSpin'],
                                    ['url' => 'lv2', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Live22-web.webp', 'title' => 'Live22 Slot'],
                                    ['url' => 'cq9', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-CQ9-web.webp', 'title' => 'CQ9'],
                                    ['url' => 'ka', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-KAGaming-web.webp', 'title' => 'KA Gaming'],
                                    ['url' => 'gp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Gameplay-web.webp', 'title' => 'Gameplay'],
                                    ['url' => 'pt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Playtech-web.webp', 'title' => 'Playtech'],
                                    ['url' => 'ps', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Playstar-web.webp', 'title' => 'Playstar'],
                                    ['url' => 'nt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-NETENT-web.webp', 'title' => 'Netent'],
                                    ['url' => 'nc', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-NLC-web.webp', 'title' => 'NoLimit City'],
                                    ['url' => 'rt', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-RED-TIGER-web.webp', 'title' => 'Red Tiger'],
                                    ['url' => 'jb', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-JDB-web.webp', 'title' => 'JDB'],
                                    ['url' => 'fc', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-FACHAI-web.webp', 'title' => 'Fa Chai'],
                                    ['url' => 'ap', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-AP-web.webp', 'title' => 'AdvantPlay'],
                                    ['url' => 'hs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-HACKSAW-web.webp', 'title' => 'Hacksaw'],
                                    ['url' => 'bng', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-BNG-web.webp', 'title' => 'BNG'],
                                    ['url' => 'png', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-PLAYNGO-web.webp', 'title' => 'PlaynGo'],
                                    ['url' => 'alz', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-ALIZE-web.webp', 'title' => 'Alize'],
                                    ['url' => 'ep', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-EVOPLAY-web.webp', 'title' => 'Evoplay'],
                                    ['url' => 'ebtg', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-BTG-web.webp', 'title' => 'Big Time Game'],
                                    ['url' => 'ibx', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-IBEX-web.webp', 'title' => 'Ibex'],
                                    ['url' => 'rlx', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-RELAX-web.webp', 'title' => 'Relax Gaming'],
                                    ['url' => 'emp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-IMPERIUM-web.webp', 'title' => 'Imperium Games'],
                                    ['url' => 'ns', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-NEXTSPIN-web.webp', 'title' => 'NextSpin'],
                                    ['url' => 'ss', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-SMARTSOFT-web.webp', 'title' => 'Smartsoft'],
                                    ['url' => '5g', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-5G-web.webp', 'title' => '5G Games'],
                                    ['url' => 'ng', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Naga-web.webp', 'title' => 'Naga Games'],
                                    ['url' => 'bs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-BETSOFT-web.webp', 'title' => 'Betsoft'],
                                    ['url' => 'ds', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-Dragoonsoft-web.webp', 'title' => 'Dragoon Soft'],
                                    ['url' => 'ai', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-AIGAMING-web.webp', 'title' => 'AI Gaming'],
                                    ['url' => 'lp', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/slots-LITEPLAY-web.webp', 'title' => 'Liteplay'],
                                    ['url' => 'km', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/KINGMAKER-web.webp', 'title' => 'KingMidas'],
                                    ['url' => 'pgs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/PEGASUS-web.webp', 'title' => 'Pegasus'],
                                    ['url' => 'ggs', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/GGSOFT-web.webp', 'title' => 'GGsoft'],
                                    ['url' => 'ace', 'img' => 'https://d1bkaj2gcjb1cb.cloudfront.net/common/assets/images/banner/desktop-v2/ACE333-web.webp', 'title' => 'ACE333'],
                                ];
                            } else {
                                // JIKA DATABASE TERISI -> PAKAI DATA DARI DATABASE
                                $providersDesktop = [];
                                foreach($providersDB as $db) {
                                    $providersDesktop[] = [
                                        'url' => strtolower($db->provider_code), 
                                        'img' => asset('uploads/'.$db->banner_desktop), 
                                        'title' => $db->provider_name
                                    ];
                                }
                            }
                        @endphp

                        @foreach($providersDesktop as $p)
                            <div class="content-box">
                                <a href="{{ $prefix }}/slots?sg={{ $p['url'] }}"></a>
                                <div class="content-box__img has-shadow">
                                    <img src="{{ $p['img'] }}" alt="{{ $p['title'] }}" class="img-blur" loading="lazy">
                                    <div class="cta-play">
                                        <div class="button-play">Main Sekarang</div>
                                    </div>
                                </div>
                                <div class="content-box__text">
                                    <div class="content-box__text-title text-center">
                                        <strong>{{ $p['title'] }}</strong>
                                    </div>
                                </div>
                            </div>
                        @endforeach

                    </div>
                </div>
            </div>
        </section>

        <section class="sidebar s-sidebar"></section>
        
        @include('frontend.partials.desktop.footer')
    </div>
@endsection

@push('scripts')
<script type="text/javascript">
    window.loadMeIfReady = function() {
    };

    $(document).ready(function() {
        $(document).on('click', '.play-game-btn', function(e) {
            e.preventDefault();
            let url = $(this).attr('data-url');
            
            $(this).siblings('.content-box__img').find('.button-play').html('<i class="fa fa-spinner fa-spin"></i> Loading');
            window.location.href = url; 
        });

        $(document).on('click', '.s-check-login', function(e) {
            e.preventDefault();
            if (typeof jAlert === "function") {
                jAlert('Silahkan login atau mendaftar untuk masuk kedalam permainan.', 'Peringatan');
            } else {
                alert('Silahkan login atau mendaftar untuk masuk kedalam permainan.');
            }
        });
        
        $(document).on('click', '.s-maintenance', function(e) {
            e.preventDefault();
            // Menggunakan jAlert jika ada (plugin alert kustom), jika tidak pakai alert bawaan browser
            if (typeof jAlert === "function") {
                jAlert('Mohon maaf, game sedang maintenance!!', 'Peringatan');
            } else {
                alert('Mohon maaf, game sedang maintenance!!');
            }
        });
    });
</script>
@endpush