import{al as settingsStore,av as smarticoStore,aw as openExternalUrl,ax as normalizeSportsbookLink,ac as useRouter,ay as shouldSkipSportsNavigation,az as scrollSportsPageToTop,d as defineComponent,at as useCloudflareImage,a0 as toRef,Z as ref,Q as computed,am as onMounted,ao as onBeforeUnmount,J as watch,m as createElementBlock,ag as createCommentVNode,b as createBaseVNode,F as Fragment,f as createVNode,aA as Transition,w as withCtx,ad as withModifiers,ah as VIcon,t as toDisplayString,ab as unref,p as VBtn,ai as api,aB as writeSessionCache,aC as SESSION_CACHE_KEYS,aD as readSessionCache,a9 as t,h as createTextVNode,q as interfaceStore,aE as openRegisterModal,o as openBlock,aj as _export_sfc}from"./index-BTTFajzp.js";function useSettingsMenuLink(){const router=useRouter(),settings=settingsStore();async function navigateFromMenuLink(link){if(!link)return;const trimmed=link.trim();if(!trimmed)return;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)){await openExternalUrl(trimmed);return}if(/^[a-z][a-z\d+\-.]*:/i.test(trimmed)){window.location.assign(trimmed);return}const providerType=settings.business.sport_sportbook_type,normalizedLink=normalizeSportsbookLink(trimmed,providerType),currentPath=router.currentRoute?.value?.path??"/";if(!shouldSkipSportsNavigation(currentPath,normalizedLink,providerType))try{await router.push(normalizedLink),scrollSportsPageToTop(normalizedLink)}catch(e){console.error("settings menu router navigation failed:",e),window.location.assign(normalizedLink)}}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"},_hoisted_8={key:2,class:"bg-brand-card flex aspect-[884/327] w-full flex-col items-center justify-center gap-3 rounded-md px-4 text-center"},_hoisted_9={class:"text-sm text-gray-300"},ALT_MAX=125,AFFILIATE_COOKIE="cg-affiliate-code",AFFILIATE_MAX_AGE_SEC=3600*24*7;function firstArray(e,n){for(const o of n){const a=e[o];if(Array.isArray(a))return a;if(a&&typeof a=="object"){const r=firstArray(a,["data","banners","items"]);if(r.length>0)return r}}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 o of n)if(typeof o=="string"&&o.trim())return trimAlt(o);return""}function firstString(e,n){for(const o of n){const a=e[o];if(typeof a=="string"&&a.trim())return a.trim()}return""}function normalizeCarouselItem(e,n){const o=e,a=firstString(o,["image","desktop_image","desktopImage","image_url","image_cf","src"]),r=firstString(o,["image_mobile","imageMobile","mobile_image","mobileImage"])||a;if(!a&&!r)return null;const m=a||r,g=r||m,i=pickAccessibleText(e)||trimAlt(`Conteúdo em destaque da ${n}`);return{url:typeof e.url=="string"?e.url:"",image:m,imageMobile:g,accessibleLabel:i}}function normalizeCarouselList(e,n){const o=[];for(const a of e){const r=normalizeCarouselItem(a,n);r&&o.push(r)}return o}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 o=new URL(n,typeof window<"u"?window.location.href:"https://local.invalid"),a=o.pathname,r=a.indexOf("dp:");if(r>=0)return a.slice(r)+o.search}catch{}return null}function persistAffiliateCode(e){if(typeof document>"u")return;const n=window.location.protocol==="https:",o=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",a=o?"Lax":"None",r=n&&!o?"; Secure":"";document.cookie=`${AFFILIATE_COOKIE}=${encodeURIComponent(e)}; Path=/; Max-Age=${AFFILIATE_MAX_AGE_SEC}; SameSite=${a}${r}`}const _sfc_main=defineComponent({__name:"Index",props:{enabled:{type:Boolean,default:!0}},setup(e){const n=e,{getCloudflareImage:o}=useCloudflareImage(),{navigateFromMenuLink:a}=useSettingsMenuLink(),r=toRef(n,"enabled"),m=ref(!1),g=ref(!1),i=ref([]),u=ref(0),b=ref(!1),A=computed(()=>i.value.length>0),f=computed(()=>i.value[u.value]??null);function k(c){if(i.value.length===0)return;const s=(c%i.value.length+i.value.length)%i.value.length;u.value=s}function y(c,s){const l=s&&c.imageMobile||c.image;return o(l,void 0,s?"banMobile":"banDesktop")}async function w(c=!1){if(!(b.value&&!c)){c&&(b.value=!1),m.value=!0,g.value=!1;try{const{data:s}=await api.get("/api/banners"),l=parseBannersBody(s),p=settingsStore().business,d=typeof p.general_site_title=="string"&&p.general_site_title.trim()?p.general_site_title.trim():"marca";i.value=normalizeCarouselList(l,d),i.value.length>0&&writeSessionCache(SESSION_CACHE_KEYS.banners,i.value),u.value>=i.value.length&&(u.value=0)}catch(s){console.error("/api/banners request failed:",s);const l=readSessionCache(SESSION_CACHE_KEYS.banners);l?.length?(i.value=l,u.value>=i.value.length&&(u.value=0)):(i.value=[],g.value=!0)}finally{m.value=!1,b.value=!0}}}const L="Banners promocionais",C=computed(()=>m.value?"A carregar banners":"Sem banners"),B="Voltar banner",I="Avançar banner";let v=null;const E=4e3;function _(){v&&(clearInterval(v),v=null)}function h(){_(),!(!r.value||i.value.length<2)&&(v=setInterval(()=>{k(u.value+1)},E))}function M(){_()}onMounted(()=>{w(),h()}),onBeforeUnmount(()=>_()),watch(()=>[i.value.length,r.value],()=>{if(!r.value){_();return}h()});function N(){k(u.value+1),h()}function V(){k(u.value-1),h()}function T(){interfaceStore().setModal({name:"login"})}function z(){openRegisterModal()}async function F(c){const s=f.value;if(!s?.url)return;const l=s.url.trim();if(!l)return;c.preventDefault();const p=parseSmarticoDeepLink(l);if(p){await a(p);return}try{const d=new URL(l,window.location.origin);if(d.origin===window.location.origin){const S=d.searchParams.get("login");if(S==="1"){T();return}if(S==="0"){z();return}const x=d.searchParams.get("code");x&&persistAffiliateCode(x),await a(`${d.pathname}${d.search}${d.hash}`);return}}catch{}await a(l)}return(c,s)=>r.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:M,onMouseleave:h},[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:u.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:F},[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":B,onClick:withModifiers(V,["stop"])},[createVNode(VIcon,{icon:"fa6-solid: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":I,onClick:withModifiers(N,["stop"])},[createVNode(VIcon,{icon:"fa6-solid:chevron-right","aria-hidden":"true"})])],64)):m.value?(openBlock(),createElementBlock("div",_hoisted_6,[createBaseVNode("span",_hoisted_7,toDisplayString(C.value),1),s[1]||(s[1]=createBaseVNode("div",{class:"aspect-[884/327] w-full"},null,-1))])):g.value?(openBlock(),createElementBlock("div",_hoisted_8,[createBaseVNode("p",_hoisted_9,toDisplayString(unref(t)("common.load-failed")),1),createVNode(VBtn,{size:"small",variant:"text",color:"primary",onClick:s[0]||(s[0]=l=>w(!0))},{default:withCtx(()=>[createTextVNode(toDisplayString(unref(t)("common.retry")),1)]),_:1})])):createCommentVNode("",!0)])],32)):createCommentVNode("",!0)}}),__unplugin_components_0=_export_sfc(_sfc_main,[["__scopeId","data-v-4d346fb1"]]);export{__unplugin_components_0 as _,useSettingsMenuLink as u};