"use strict";exports.id=4365,exports.ids=[4365],exports.modules={4365:(e,t,r)=>{r.r(t),r.d(t,{default:()=>search});var a=r(43412),o=r.n(a);let getBaseDomain=e=>{if(e[0]===e[1])return`.${new URL(o().storeUrl).hostname}`;let t=e.map(e=>{try{let t=new URL(e).hostname,r=o().api.subDomainPrefix||[],a=RegExp(`^(${["www",...r].join("|")})\\.`);return t.replace(a,"")}catch{return""}}),r=t.map(e=>e.split(".").reverse()),a=Math.min(...r.map(e=>e.length)),s=[];for(let e=0;e<a;e++){let t=new Set(r.map(t=>t[e]));if(1===t.size)s.push(r[0][e]);else break}if(s.length<2){let t=`No common domain found for URLs: ${e.join(", ")}`;return console.warn(`${t}. Please check the Production URLs in the discovery.config file.`),""}return"."+s.reverse().join(".")};var s=r(26725);function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){var a;a=r[t],t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}let randomUUID=()=>"function"==typeof crypto.randomUUID?crypto.randomUUID().replaceAll("-",""):(1e6*Math.random()).toFixed(0),createOrRefreshCookie=(e,t)=>{let r=o().secureSubdomain?getBaseDomain([o().storeUrl,o().secureSubdomain]):`.${new URL(o().storeUrl).hostname}`;return()=>{let a=(0,s.ej)(e),o=void 0===a;return o&&(a=randomUUID()),document.cookie=`${e}=${a}; max-age=${t}; domain=${r}; path=/;`,a}},n={anonymous:createOrRefreshCookie("vtex-search-anonymous",31536e3),session:createOrRefreshCookie("vtex-search-session",1800)},sendEvent=e=>fetch(`https://sp.vtex.com/event-api/v1/${o().api.storeId}/event`,{method:"POST",body:JSON.stringify(_objectSpread(_objectSpread({},e),{},{userAgent:navigator.userAgent,anonymous:n.anonymous(),session:n.session()})),headers:{"content-type":"application/json"}}),isFullTextSearch=e=>"string"==typeof e.searchParams.get("q")&&/^\/s(\/)?$/g.test(e.pathname);setInterval(()=>sendEvent({type:"session.ping"}),6e4);let search=e=>{switch(e.name){case"search_select_item":{let t=new URL(e.params.url);if(!isFullTextSearch(t))return;for(let r of e.params.items??[]){let e=r.item_id??r.item_variant,a=r.index;e&&a&&sendEvent({type:"search.click",productId:e,position:a,url:t.href,text:t.searchParams.get("q")??"<empty>"})}break}case"intelligent_search_query":sendEvent({type:"search.query",url:e.params.url,text:e.params.term,misspelled:e.params.isTermMisspelled,match:e.params.totalCount,operator:e.params.logicalOperator,locale:e.params.locale});break;case"intelligent_search_autocomplete_query":sendEvent({type:"search.autocomplete.query",url:e.params.url,text:e.params.term,misspelled:e.params.isTermMisspelled,match:e.params.totalCount,operator:e.params.logicalOperator,locale:e.params.locale});break;case"intelligent_search_autocomplete_click":sendEvent(_objectSpread(_objectSpread({text:e.params.term,url:e.params.url??"",productId:e.params.productId??""},e.params.position&&{position:e.params.position}),{},{type:"search.autocomplete.click"}))}}},26725:(e,t,r)=>{function getCookie(e){let t=decodeURIComponent(document.cookie),r=t.split(";");for(let t of r){let[r,a]=t.trim().split("=");if(r===e)return a}}function parseJwt(e){return e?JSON.parse(Buffer.from(e.split(".")[1],"base64").toString()):null}r.d(t,{aj:()=>parseJwt,ej:()=>getCookie}),r(84802)}};