import{d as B,bO as S,a as F,r as i,e as f,s as L,c7 as T,f as s,x as n,h as m,v as r,g as o,z as j,aG as z,aJ as A,aI as E,F as _,y as I,o as a,bs as G,_ as J}from"./BxiWQxwE.js";const R={key:0},U={key:1,class:"options"},H=["autocomplete"],K={key:0,class:"not-found"},P=["onClick"],Q=["label"],W=["value"],X=B({__name:"select-search",props:{modelValue:{type:Object,required:!0},label:{type:String,required:!1,default:null},autocomplete:{type:String,required:!1,default:null}},emits:["update:model-value"],setup(c,{emit:w}){const x=c,{availableStores:y}=S(),{defaultStore:V,currentStore:k}=S(),{$messages:p}=F(),h=i(null),b=w,d=i(""),u=i(!1),N=i(null),q=f(()=>{const e=O.value;if(e!=null&&e.fullName)return e.fullName;if(V.value)return p("assortment.popup.selectStore.option.showMoreStores");if(k.value.fullName)return k.value.fullName});L(u,async()=>{await G(()=>{var e;u.value&&((e=h.value)==null||e.focus())})}),T(N,()=>u.value=!1);const D=()=>{u.value=!u.value},M=e=>{u.value=!1;const t={fullName:e.fullName,storeId:e.storeId,postalCode:e.postalCode,city:e.city};b("update:model-value",t)},g=f(()=>[...y.value].sort((e,t)=>e.fullName.localeCompare(t.fullName))),O=f(()=>g.value.find(e=>{var t;return e.storeId===((t=x.modelValue)==null?void 0:t.storeId)})),v=f(()=>g.value.filter(e=>{var t;return(t=e.fullName)==null?void 0:t.toLowerCase().includes(d.value.toLowerCase())})),$=e=>{const t=e.target,l=y.value.find(C=>C.storeId===parseInt(t.value));b("update:model-value",l)};return(e,t)=>(a(),s(_,null,[e.$device.isDesktopOrTablet?(a(),s("div",{key:0,ref_key:"div",ref:N,class:"select"},[c.label?(a(),s("label",R,r(c.label),1)):n("",!0),m("button",{onClick:j(D,["prevent"])},r(o(q)),1),o(u)?(a(),s("div",U,[z(m("input",{ref_key:"search",ref:h,"onUpdate:modelValue":t[0]||(t[0]=l=>E(d)?d.value=l:null),type:"text",autocomplete:c.autocomplete},null,8,H),[[A,o(d)]]),m("ul",null,[o(v).length===0?(a(),s("li",K,r(o(p)("assortment.popup.selectStore.option.noStoresFound")),1)):n("",!0),(a(!0),s(_,null,I(o(v),l=>(a(),s("li",{key:l.storeId,onClick:C=>M(l)},r(l.fullName),9,P))),128))])])):n("",!0)],512)):n("",!0),e.$device.isMobile?(a(),s("select",{key:1,class:"more-stores",onChange:$},[m("optgroup",{label:o(p)("assortment.popup.selectStore.option.allStores")},[(a(!0),s(_,null,I(o(v),l=>(a(),s("option",{key:l.storeId,value:l.storeId},r(l.fullName),9,W))),128))],8,Q)],32)):n("",!0)],64))}}),Z=J(X,[["__scopeId","data-v-1a36b854"]]);export{Z as default};
