import{_ as Z}from"./Bq7L8Gqp.js";import{d as ee,e as te,w as se,Y as ae,am as oe,a0 as re,$ as ne,t as le,b as ie,c as ue,aO as ce,l as de,E as he}from"./BmsEUx_s.js";import{u as pe}from"./C0vPOvVt.js";import{a as y,l as S,k as me,b as M,E as ye,G as o,M as r,O as p,a1 as k,ac as ge,aw as be,u as t,z as fe,a2 as ve,P as F,a7 as V,V as m,X as P,H as q,I as A,Q as ke,a3 as D}from"./BO9AmBA3.js";import{u as we}from"./Caz6ZtR2.js";import{a as xe}from"./UWnfKqQJ.js";function Ce(){const w=y(""),c=pe({listingType:"productSearchListing"}),x=async(h={})=>{const n={query:w.value,...h};return c.search(n,{preventRouteChange:!0})},T=S(()=>{var h,n;return((n=(h=c.getAvailableFilters.value)==null?void 0:h.find(C=>C.name==="Item Type"))==null?void 0:n.options)??[]});return{searchTerm:w,loading:c.loading,search:x,loadMore:c.loadMore,getProducts:c.getElements,getTotal:c.getTotal,itemTypeFilterOptions:T}}const _e={class:"flex items-center"},Me=["placeholder","aria-label"],Se={key:0,class:"flex justify-between px-1 pt-2 pb-1 mx-2 mb-2 b-b-yt-gray-500 b-b-1"},Te={class:"para-5 text-yt-gray-500"},$e={key:0,class:"w-80 h-40 bg-brand-light blur-2xl fixed animate-spin"},Le={key:1},Pe={key:0},Ie={key:1,"data-testid":"layout-search-result-box-no-result"},Fe=me({__name:"LayoutStoreSearch",props:{displayTotal:{default:10},darkMode:{type:Boolean}},emits:["link-clicked"],setup(w){var E;const c=w,{searchTerm:x,search:T,getProducts:h,getTotal:n,loading:C,itemTypeFilterOptions:W}=Ce(),l=y(!1),_=y(null),g=y(),Q=ee(),{formatLink:$}=te(Q),{sessionContext:U}=se(),j=(E=U.value)==null?void 0:E.shippingLocation.country.iso;M(l,e=>{const{focused:s}=ae(g);s.value=e,!e&&g.value&&g.value.blur()});const d=y("");M(d,e=>{e.length>=3&&G(e)});const G=oe(async e=>{{const s=he();s==null||s.trackEvent({event:"search",label:"Site Search",category:"Engagement",region:j,search_term:e,value:e})}x.value=e,await T()},300),H=S(()=>d.value.length>=3&&l.value);re(_,()=>{l.value=!1});const{enter:K}=ne({target:g}),{push:X}=le();M(()=>ie().fullPath,e=>{e.includes("/search")||(d.value="",x.value="",l.value=!1)});const{closeAllLevels:I}=we(),Y=xe();M(K,e=>{e&&(I(),Y.close(),l.value=!1,X($(`/search?query=${d.value}`)))});const{t:B}=ue(),O=S(()=>B("form.searchPlaceholder")),R=y("auto"),N=()=>{setTimeout(()=>{if(!_.value)return;const e=_.value.getBoundingClientRect();R.value=`${document.body.clientWidth-e.left}px`},0)};ye(()=>{ce(document.querySelector("header"),N),N()});const J=new Map([["Clothing","Apparel"]]),z=S(()=>{const e=h.value.slice(0,c.displayTotal);return W.value.concat([{id:"other",name:B("product.productType.other")}]).map(i=>{const b=J.get(i.name);return{id:i.id,label:i.name,products:e.filter(u=>{var f,v,L;const a=(v=(f=u.extensions)==null?void 0:f.productType)==null?void 0:v.productType;return i.id==="other"?!a:(a==null?void 0:a.toLowerCase())===((L=i.name)==null?void 0:L.toLowerCase())||!!b&&(a==null?void 0:a.toLowerCase())===b.toLowerCase()})}}).filter(i=>i.products.length>0)});return(e,s)=>{const i=Z,b=de;return o(),r("div",{ref_key:"searchContainer",ref:_,class:k(["relative group p-2 rounded-sm pr-0 border-yt-black border-1 inline-block w-full",[t(l)?"shadow-lg":"shadow",e.darkMode?"bg-yt-black b-b-1 b-b-white":"bg-inherit"]])},[p("div",_e,[p("div",{class:k(["i-yt-search flex-none h-6 w-6 group-hover:text-brand-primary cursor-pointer",[e.darkMode?"text-white":"text-yt-black"]])},null,2),ge(p("input",{ref_key:"searchInput",ref:g,name:"searchInput","onUpdate:modelValue":s[0]||(s[0]=u=>fe(d)?d.value=u:null),"data-testid":"layout-search-input",type:"text",class:k(["sw-search-input px-2 ml-2 lg:ml-0 xl:ml-2 grow h-6 placeholder:font-bebasneuebook font-bebasneuebook text-xl transition duration-200 outline-none w-56 md:w-10/12",[e.darkMode?"placeholder:text-white text-white bg-yt-black focus:opacity-90":"placeholder:text-yt-black focus:opacity-50"]]),placeholder:t(O),onClick:s[1]||(s[1]=u=>l.value=!0),"aria-label":t(O)},null,10,Me),[[be,t(d)]])]),t(H)?(o(),r("div",{key:0,"data-testid":"layout-search-result-box",class:k(["absolute border-t-1 duration-300 left-0 mt-2 overflow-hidden right-0 bg-white rounded-b-md shadow-md transition-height md:w-[var(--result-box-w)] z-9",e.darkMode?"border-yt-gray-500":"border-gray-100"]),style:ve({"--result-box-w":t(R)})},[(o(!0),r(F,null,V(t(z),u=>(o(),r("div",{key:u.id},[t(z).length>1?(o(),r("div",Se,[p("span",Te,m(u.label),1)])):P("",!0),(o(!0),r(F,null,V(u.products,a=>{var f,v;return o(),q(b,{key:a.id,to:t($)(`/${(v=(f=a==null?void 0:a.seoUrls)==null?void 0:f[0])==null?void 0:v.seoPathInfo}`),"data-testid":"layout-search-suggest-link",onClick:s[2]||(s[2]=L=>[l.value=!1,e.$emit("link-clicked")])},{default:A(()=>[ke(i,{product:a},null,8,["product"])]),_:2},1032,["to"])}),128))]))),128)),p("div",{class:k(["h-11 text-sm rounded-b-md p-3 text-center transition",[t(C)?["bg-brand-primary"]:["bg-gray-100"]]]),style:{"clip-path":"inset(0% 0% 0% 0%)"}},[t(C)?(o(),r("div",$e)):(o(),r("div",Le,[t(n)>0?(o(),q(b,{key:0,"data-testid":"layout-search-result-box-more-link",to:t($)({path:"/search",query:{query:t(d)}}),onClick:s[3]||(s[3]=u=>[l.value=!1,e.$emit("link-clicked"),t(I)()])},{default:A(()=>[D(m(e.$t("search.see"))+" ",1),t(n)!==1?(o(),r("span",Pe,m(e.$t("search.all")),1)):P("",!0),D(" "+m(t(n))+" ",1),p("span",null,m(e.$t("search.result",t(n))),1)]),_:1},8,["to"])):(o(),r("div",Ie,m(e.$t("search.noResults")),1))]))],2)],6)):P("",!0)],2)}}});export{Fe as _};