import{_ as v,a as h,R as S,h as k,$ as D,S as b,G as p,c as r,o as a,b as s,t as l,e as x,E as c,I as w,f as g,F as P,g as C,D as L}from"./Bgmy51Qv.js";import{_ as N}from"./vU4aS4uy.js";import{u as O}from"./7pZkuj9N.js";import{u as R}from"./BHvLfWtM.js";import{d as z}from"./B9SrJvRU.js";const E={setup(){const{getRequest:t}=O();return{getRequest:t}},name:"ProductSearch",data(){return{productPage:1,productData:null,autoSuggestionOpen:!1,searchedString:"",fetchingProductList:!0}},watch:{searchedString:z(function(){this.productPage=1,this.fetchingData()},700)},directives:{outsideClick:S},props:{},mixins:[R],components:{Spinner:h},computed:{productList(){var t;return((t=this.productData)==null?void 0:t.data)||[]},resultText(){var t,e,u,d;if(this.productData&&((t=this.productData)==null?void 0:t.total)>0)return this.$t("list.show",{from:(e=this.productData)==null?void 0:e.from,to:(u=this.productData)==null?void 0:u.to,total:(d=this.productData)==null?void 0:d.total})},totalPage(){var t;return(t=this.productData)==null?void 0:t.last_page},orderId(){var t,e;return(e=(t=this._.provides[D]||this.$route)==null?void 0:t.params)==null?void 0:e.id}},methods:{autoSuggestionClose(){this.autoSuggestionOpen=!1},async openSuggestions(){this.autoSuggestionOpen||(this.autoSuggestionOpen=!0),this.productList.length===0&&await this.fetchingData()},goNext(t){const e=this.productPage+t;e<=this.totalPage&&e>0&&(this.productPage=e,this.fetchingData())},async fetchingData(){this.fetchingProductList=!0;try{this.productData=await this.getRequest({params:{page:this.productPage,orderby:"created_at",type:"DESC",q:this.searchedString},api:"getProducts"})}catch(t){k({statusCode:400,message:t.message})}this.fetchingProductList=!1}}},I={class:"dropdown-wrapper input-wrapper product-search"},T={class:"pos-rel"},V=["placeholder"],q={key:0,class:"search-dropdown"},B={class:"suggestion-body"},$={key:0,class:"spinner-wrapper"},F={key:1,class:"sb sb-2"},M=["onClick"],U={class:"dply-felx j-left"},j={key:0},G={key:1},A={key:2,class:"p-15"},H={class:"mx-w-50"},J={class:"text-right dply-felx mlr--2-5"};function K(t,e,u,d,n,i){const m=h,f=N,_=b("outside-click");return p((a(),r("div",I,[s("label",null,l(t.$t("list.sp")),1),s("div",T,[p(s("input",{type:"text","onUpdate:modelValue":e[0]||(e[0]=o=>n.searchedString=o),onClick:e[1]||(e[1]=c((...o)=>i.openSuggestions&&i.openSuggestions(...o),["prevent"])),placeholder:t.$t("list.sh")},null,8,V),[[w,n.searchedString]]),n.autoSuggestionOpen?(a(),r("div",q,[s("div",B,[n.fetchingProductList?(a(),r("div",$,[g(m,{radius:60,color:"primary"})])):i.productList.length?(a(),r("ul",F,[(a(!0),r(P,null,C(i.productList,(o,y)=>(a(),r("li",{key:y},[s("a",{href:"#",class:"dply-felx",onClick:c(Q=>t.$emit("product-clicked",o),["prevent"])},[s("div",U,[g(f,{class:"mr-15 img-40x","lazy-src":t.getThumbImageURL(o.image),alt:o.title},null,8,["lazy-src","alt"]),o.title?(a(),r("h5",j,l(o.title),1)):(a(),r("h5",G,l(t.$t("list.nt")),1))]),e[4]||(e[4]=s("i",{class:"mn-w-24x icon plus"},null,-1))],8,M)]))),128))])):(a(),r("p",A,l(t.$t("list.noData",{data:t.$t("product.product")})),1))]),s("div",{class:L(["ptb-10 plr-15 dply-felx suggestion-footer",{"ignore-click disabled":n.fetchingProductList||!i.productList.length}])},[s("p",H,l(i.resultText),1),s("div",J,[s("button",{class:"btn outline-btn mlr-2-5 dply-felx",onClick:e[2]||(e[2]=c(o=>i.goNext(-1),["prevent"]))},e[5]||(e[5]=[s("i",{class:"icon arrow-left"},null,-1)])),s("button",{class:"btn outline-btn mlr-2-5 dply-felx",onClick:e[3]||(e[3]=c(o=>i.goNext(1),["prevent"]))},e[6]||(e[6]=[s("i",{class:"icon arrow-right"},null,-1)]))])],2)])):x("",!0)])])),[[_,i.autoSuggestionClose]])}const et=v(E,[["render",K]]);export{et as _};
