import{d as defineComponent,ai as useCloudflareImage,K as computed,a2 as t,h as createElementBlock,ab as createCommentVNode,b as createVNode,w as withCtx,a as createBaseVNode,x as normalizeStyle,i as VBtn,e as createTextVNode,t as toDisplayString,aj as resolveComponent,o as openBlock,S as ref,ae as api,ad as useRouter,aq as smarticoStore,U as toRef,a4 as onMounted,a6 as onBeforeUnmount,C as watch,F as Fragment,ar as Transition,a8 as withModifiers,ac as VIcon,a3 as settingsStore,j as interfaceStore,af as _export_sfc}from"./index-Cj-040Sc.js";const _hoisted_1$1=["aria-label"],_hoisted_2$1={key:1,class:"bg-brand-card group relative flex aspect-[18/10] w-full flex-col rounded-md"},_hoisted_3$1={class:"absolute left-0 top-0 z-10 flex h-full w-full cursor-pointer items-center justify-center rounded-md bg-black/40 opacity-0 transition-all group-hover:opacity-100"};function firstArray$1(e,n){for(const a of n){const r=e[a];if(Array.isArray(r))return r;if(r&&typeof r=="object"){const o=firstArray$1(r,["data","providers","items"]);if(o.length>0)return o}}return[]}function parseProvidersBody(e){return Array.isArray(e)?e:!e||typeof e!="object"?[]:firstArray$1(e,["data","providers","items","result"])}function firstString$1(e,n){for(const a of n){const r=e[a];if(typeof r=="string"&&r.trim())return r.trim()}return""}function normalizeProviderList(e){const n=[];for(const a of e){if(!a||typeof a!="object")continue;const r=a,o=firstString$1(r,["slug","provider_slug"]);o&&n.push({id:typeof r.id=="string"||typeof r.id=="number"?r.id:void 0,slug:o,name:firstString$1(r,["name","title"])||o,aggregator:firstString$1(r,["aggregator","provider_aggregator"])||void 0,image:firstString$1(r,["image","image_url","logo"])||void 0,image_cf:firstString$1(r,["image_cf","imageCf","logo_cf"])||void 0,custom_image:firstString$1(r,["custom_image","customImage"])||void 0,degrade_image:firstString$1(r,["degrade_image","degradeImage"])||void 0})}return n}function getProviderImageUrl(e,n){if(!e.image&&!e.image_cf){const r=String(e.name||"").trim();return`url('https://via.placeholder.com/500x300?text=${encodeURIComponent(r||"Provedor")}')`}return`url(${n(e.image_cf,e.image,"desktop")})`}const _sfc_main$1=defineComponent({__name:"Index",props:{provider:{},shimmer:{type:Boolean,default:!1},loadingAriaLabel:{}},setup(e){const n=e,{getCloudflareImage:a}=useCloudflareImage(),r=computed(()=>t("providers.view-games")),o=computed(()=>{const i=t("providers.view-games-aria");if(!n.provider)return i;const s=String(n.provider.name||"").trim();return s?`${i} ${s}`:i}),d=computed(()=>n.provider?getProviderImageUrl(n.provider,a):"");return(i,s)=>{const v=resolveComponent("router-link");return e.shimmer?(openBlock(),createElementBlock("div",{key:0,class:"bg-brand-card flex aspect-[18/10] w-full animate-pulse rounded-md",role:"status","aria-label":e.loadingAriaLabel},null,8,_hoisted_1$1)):e.provider?(openBlock(),createElementBlock("div",_hoisted_2$1,[createVNode(v,{to:`/providers/${e.provider.slug}`,class:"h-full w-full cursor-pointer","aria-label":o.value,title:o.value},{default:withCtx(()=>[createBaseVNode("div",{style:normalizeStyle({backgroundImage:d.value}),class:"h-full rounded-md bg-contain bg-no-repeat bg-blend-darken"},null,4),createBaseVNode("div",_hoisted_3$1,[createVNode(VBtn,{color:"primary",size:"x-small",class:"pointer-events-none font-bold","aria-label":o.value,title:o.value},{default:withCtx(()=>[createTextVNode(toDisplayString(r.value),1)]),_:1},8,["aria-label","title"])])]),_:1},8,["to","aria-label","title"])])):createCommentVNode("",!0)}}}),isLoading=ref(!1),providers=ref([]),error=ref(null),hasFetched=ref(!1);let fetchPromise=null;async function executeFetch(){isLoading.value=!0,error.value=null;try{const{data:e}=await api.get("/api/casino-games/providers"),n=parseProvidersBody(e);providers.value=normalizeProviderList(n)}catch(e){console.error("/api/casino-games/providers request failed:",e),error.value=e,providers.value=[]}finally{isLoading.value=!1,hasFetched.value=!0,fetchPromise=null}}function useProviders(){async function e(){if(!hasFetched.value){if(fetchPromise){await fetchPromise;return}fetchPromise=executeFetch(),await fetchPromise}}return{isLoading,providers,error,hasFetched,fetchProviders:e}}function useSettingsMenuLink(){const router=useRouter();async function navigateFromMenuLink(link){if(!link)return;const trimmed=link.trim();if(trimmed){if(trimmed.includes("dp:")){await smarticoStore().openDeepLink(trimmed);return}if(/^javascript:/i.test(trimmed)){try{eval(trimmed)}catch(e){console.error("settings menu javascript: link failed:",e)}return}if(/^https?:\/\//i.test(trimmed)){window.open(trimmed,"_blank","noopener,noreferrer");return}if(/^[a-z][a-z\d+\-.]*:/i.test(trimmed)){window.location.assign(trimmed);return}try{await router.push(trimmed)}catch(e){console.error("settings menu router navigation failed:",e),window.location.assign(trimmed)}}}return{navigateFromMenuLink}}const _hoisted_1={class:"relative w-full md:overflow-hidden md:rounded-md"},_hoisted_2={class:"relative aspect-[884/327] w-full overflow-hidden"},_hoisted_3=["href","aria-label"],_hoisted_4=["srcset"],_hoisted_5=["src","alt"],_hoisted_6={key:1,class:"bg-brand-card h-auto w-full animate-pulse",role:"status","aria-live":"polite"},_hoisted_7={class:"sr-only"},ALT_MAX=125,AFFILIATE_COOKIE="cg-affiliate-code",AFFILIATE_MAX_AGE_SEC=3600*24*7;function firstArray(e,n){for(const a of n){const r=e[a];if(Array.isArray(r))return r;if(r&&typeof r=="object"){const o=firstArray(r,["data","banners","items"]);if(o.length>0)return o}}return[]}function parseBannersBody(e){return Array.isArray(e)?e:!e||typeof e!="object"?[]:firstArray(e,["data","banners","items","result"])}function trimAlt(e){const n=e.trim();return n?n.length>ALT_MAX?n.slice(0,ALT_MAX):n:""}function pickAccessibleText(e){const n=[e.alt_text,e.alt,e.title,e.name,e.description];for(const a of n)if(typeof a=="string"&&a.trim())return trimAlt(a);return""}function firstString(e,n){for(const a of n){const r=e[a];if(typeof r=="string"&&r.trim())return r.trim()}return""}function normalizeCarouselItem(e,n){const a=e,r=firstString(a,["image","desktop_image","desktopImage","image_url","image_cf","src"]),o=firstString(a,["image_mobile","imageMobile","mobile_image","mobileImage"])||r;if(!r&&!o)return null;const d=r||o,i=o||d,s=pickAccessibleText(e)||trimAlt(`Conteúdo em destaque da ${n}`);return{url:typeof e.url=="string"?e.url:"",image:d,imageMobile:i,accessibleLabel:s}}function normalizeCarouselList(e,n){const a=[];for(const r of e){const o=normalizeCarouselItem(r,n);o&&a.push(o)}return a}function parseSmarticoDeepLink(e){const n=e.trim();if(n.slice(0,3)==="dp:")return n;if(n.slice(0,4)==="/dp:")return n.replace(/^\/+/,"");try{const a=new URL(n,typeof window<"u"?window.location.href:"https://local.invalid"),r=a.pathname,o=r.indexOf("dp:");if(o>=0)return r.slice(o)+a.search}catch{}return null}function persistAffiliateCode(e){if(typeof document>"u")return;const n=window.location.protocol==="https:",a=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",r=a?"Lax":"None",o=n&&!a?"; Secure":"";document.cookie=`${AFFILIATE_COOKIE}=${encodeURIComponent(e)}; Path=/; Max-Age=${AFFILIATE_MAX_AGE_SEC}; SameSite=${r}${o}`}const _sfc_main=defineComponent({__name:"Index",props:{enabled:{type:Boolean,default:!0}},setup(e){const n=e,{getCloudflareImage:a}=useCloudflareImage(),{navigateFromMenuLink:r}=useSettingsMenuLink(),o=toRef(n,"enabled"),d=ref(!1),i=ref([]),s=ref(0),v=ref(!1),A=computed(()=>i.value.length>0),f=computed(()=>i.value[s.value]??null);function _(l){if(i.value.length===0)return;const c=(l%i.value.length+i.value.length)%i.value.length;s.value=c}function y(l,c){const u=c&&l.imageMobile||l.image;return a(u,void 0,c?"banMobile":"banDesktop")}async function x(){if(!v.value){d.value=!0;try{const{data:l}=await api.get("/api/banners"),c=parseBannersBody(l),u=settingsStore().business,p=typeof u.general_site_title=="string"&&u.general_site_title.trim()?u.general_site_title.trim():"marca";i.value=normalizeCarouselList(c,p),s.value>=i.value.length&&(s.value=0)}catch(l){console.error("/api/banners request failed:",l),i.value=[]}finally{d.value=!1,v.value=!0}}}const L="Banners promocionais",B=computed(()=>d.value?"A carregar banners":"Sem banners"),S="Voltar banner",C="Avançar banner";let h=null;const I=4e3;function b(){h&&(clearInterval(h),h=null)}function g(){b(),!(!o.value||i.value.length<2)&&(h=setInterval(()=>{_(s.value+1)},I))}function $(){b()}onMounted(()=>{x(),g()}),onBeforeUnmount(()=>b()),watch(()=>[i.value.length,o.value],()=>{if(!o.value){b();return}g()});function V(){_(s.value+1),g()}function M(){_(s.value-1),g()}function N(){interfaceStore().setModal({name:"login"})}function F(){interfaceStore().setModal({name:"register"})}async function P(l){const c=f.value;if(!c?.url)return;const u=c.url.trim();if(!u)return;l.preventDefault();const p=parseSmarticoDeepLink(u);if(p){await r(p);return}try{const m=new URL(u,window.location.origin);if(m.origin===window.location.origin){const k=m.searchParams.get("login");if(k==="1"){N();return}if(k==="0"){F();return}const w=m.searchParams.get("code");w&&persistAffiliateCode(w),await r(`${m.pathname}${m.search}${m.hash}`);return}}catch{}await r(u)}return(l,c)=>o.value?(openBlock(),createElementBlock("section",{key:0,class:"group -mx-4 w-[calc(100%+2rem)] md:mx-0 md:w-full","aria-roledescription":"carousel",role:"region","aria-label":L,onMouseenter:$,onMouseleave:g},[createBaseVNode("div",_hoisted_1,[A.value?(openBlock(),createElementBlock(Fragment,{key:0},[createBaseVNode("div",_hoisted_2,[createVNode(Transition,{name:"banner-slide"},{default:withCtx(()=>[f.value?(openBlock(),createElementBlock("a",{key:s.value,href:f.value.url||"#",class:"absolute inset-0 block focus:outline-none focus-visible:ring-2 focus-visible:ring-white/80","aria-label":f.value.accessibleLabel,onClick:P},[createBaseVNode("picture",null,[createBaseVNode("source",{srcset:y(f.value,!0),media:"(max-width: 767px)"},null,8,_hoisted_4),createBaseVNode("img",{class:"block h-full w-full",src:y(f.value,!1),alt:f.value.accessibleLabel??"",width:"884",height:"327",decoding:"async",fetchpriority:"high"},null,8,_hoisted_5)])],8,_hoisted_3)):createCommentVNode("",!0)]),_:1})]),createBaseVNode("button",{type:"button",class:"absolute left-2 top-1/2 z-20 inline-flex h-9 w-9 -translate-y-1/2 items-center justify-center rounded-full bg-transparent text-white transition-[opacity,background-color] duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/85 md:left-3.5 md:h-[42px] md:w-[42px] md:bg-black/35 md:opacity-0 md:backdrop-blur-sm md:hover:bg-black/60 md:group-hover:opacity-100","aria-label":S,onClick:withModifiers(M,["stop"])},[createVNode(VIcon,{icon:"fa-sharp fa-light fa-chevron-left","aria-hidden":"true"})]),createBaseVNode("button",{type:"button",class:"absolute right-2 top-1/2 z-20 inline-flex h-9 w-9 -translate-y-1/2 items-center justify-center rounded-full bg-transparent text-white transition-[opacity,background-color] duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/85 md:right-3.5 md:h-[42px] md:w-[42px] md:bg-black/35 md:opacity-0 md:backdrop-blur-sm md:hover:bg-black/60 md:group-hover:opacity-100","aria-label":C,onClick:withModifiers(V,["stop"])},[createVNode(VIcon,{icon:"fa-sharp fa-light fa-chevron-right","aria-hidden":"true"})])],64)):(openBlock(),createElementBlock("div",_hoisted_6,[createBaseVNode("span",_hoisted_7,toDisplayString(B.value),1),c[0]||(c[0]=createBaseVNode("div",{class:"aspect-[884/327] w-full"},null,-1))]))])],32)):createCommentVNode("",!0)}}),__unplugin_components_0=_export_sfc(_sfc_main,[["__scopeId","data-v-10d2e895"]]);export{_sfc_main$1 as _,useSettingsMenuLink as a,__unplugin_components_0 as b,useProviders as u};