@if(!empty($splashAd))
@include('partials.splash-ad-styles')
<div id="dqSplashAd" class="dq-splash" role="dialog" aria-modal="true" aria-label="إعلان">
    <button type="button" class="dq-splash__close" aria-label="إغلاق">&times;</button>
    <div class="dq-splash__media">
        @if($splashAd->isVideo())
            <video id="dqSplashVideo"
                   src="{{ asset('storage/'.$splashAd->video_path) }}"
                   autoplay muted playsinline loop controls
                   controlslist="nodownload noplaybackrate"></video>
        @elseif($splashAd->image)
            <img src="{{ asset('storage/'.$splashAd->image) }}"
                 alt="{{ $splashAd->title_ar ?? $splashAd->title }}">
        @endif
    </div>
    @if($splashAd->link_url)
        <a href="{{ $splashAd->link_url }}" target="_blank" rel="noopener noreferrer" class="dq-splash__link">
            {{ $splashAd->link_text ?: 'اعرف المزيد' }}
        </a>
    @endif
</div>
<script>
(function(){
    var root=document.getElementById('dqSplashAd');
    if(!root) return;
    var v=document.getElementById('dqSplashVideo');
    function closeSplash(){
        root.remove();
        var st=document.getElementById('dq-splash-styles');
        if(st) st.remove();
        if(v){
            try{ v.pause(); }catch(e){}
            v.removeAttribute('src');
            v.load();
        }
    }
    var btn=root.querySelector('.dq-splash__close');
    if(btn) btn.addEventListener('click', closeSplash);
})();
</script>
@endif
