import{h as _,i as D,r as C,e as i,o as r,d as h,a as P,w as T,F as V,g as B,c as N,n as O,b as j,t as m,u as g,O as x,f as k,a2 as A}from"./chunks/vue.esm-bundler.js?ver=1.3.23";import{u as E}from"./chunks/useElementPlusComponents.js?ver=1.3.23";import{t as v}from"./chunks/Translator.js?ver=1.3.23";import{u as $}from"./chunks/useElementor.js?ver=1.3.23";import{R as F}from"./chunks/Rest.js?ver=1.3.23";import"./chunks/index.js?ver=1.3.23";import"./chunks/index2.js?ver=1.3.23";import"./chunks/index4.js?ver=1.3.23";import"./chunks/dayjs.min.js?ver=1.3.23";import"./chunks/index3.js?ver=1.3.23";import"./chunks/Arr.js?ver=1.3.23";function I(o,t=300){const e=_(null);return(...l)=>{e.value&&clearTimeout(e.value),e.value=setTimeout(()=>{o(...l)},t)}}const Q={class:"searchable-select-container"},R={key:0,class:"searchable-select-loading"},q={key:1,class:"no-results"},L={__name:"SearchableSelect",props:{value:{type:[String,Number],default:""},onChange:{type:Function,required:!0}},setup(o){const t=o,e=_(""),l=_({}),a=_(!1),b=async(u,s)=>{a.value=!0;try{const p={active_view:"publish",per_page:10,page:1,search:u,filter_type:"simple",sort_by:"ID",with:["detail","variants"]};s&&(p.include_ids=[s]),F.get("products",p).then(f=>{const n={};f.products.data.forEach(d=>{n[d.ID.toString()]={value:d.ID.toString(),label:d.post_title,product:d}}),l.value=n}).catch(f=>{console.log(f)}).finally(()=>{})}catch(p){console.error("Error loading products:",p)}finally{a.value=!1}},y=I(()=>{b(e.value)},500),S=u=>{e.value=u,y()},c=u=>{t.onChange(u)};return D(()=>{b("",t.value)}),(u,s)=>{const p=C("el-option"),f=C("el-select");return r(),i("div",null,[h("div",Q,[P(f,{modelValue:e.value,"onUpdate:modelValue":s[0]||(s[0]=n=>e.value=n),filterable:"",remote:"",placeholder:g(v)("Search for products..."),"remote-method":S,loading:a.value,onChange:s[1]||(s[1]=n=>{const d=Object.values(l.value).find(w=>w.label===n);d&&c(d)})},{empty:T(()=>[a.value?(r(),i("div",R,m(g(v)("Loading...")),1)):e.value?(r(),i("div",q,m(g(v)("No products found.")),1)):j("",!0)]),default:T(()=>[(r(!0),i(V,null,B(Object.values(l.value),n=>(r(),N(p,{key:n.value,label:n.label,value:n.label,class:O({"option-item-selected":o.value===n.value})},null,8,["label","value","class"]))),128))]),_:1},8,["modelValue","placeholder","loading"])])])}}},M={class:"fluent-cart-product-details-button"},z={class:"fluent-cart-product-details-title"},H={key:0,class:"fct-selected-product-contents"},U=["title"],G={class:"product-title"},J={class:"product-id"},K={key:1},W={__name:"App",props:{selectedProduct:{type:String,default:""},productTitle:{type:String,default:""}},setup(o){let t=null;const e=o,l=_(e.productTitle),a=_(e.selectedProduct),b=()=>{a.value="",l.value="",setTimeout(()=>{t.setSettings("selected_product","")},100)},y=c=>{a.value=c,setTimeout(()=>{t.setSettings("selected_product",a.value.toString())},500)},S=c=>{c.hasOwnProperty("product")?(y(c.product.ID.toString()),l.value=c.product.post_title):y("")};return x(()=>{t=$()}),(c,u)=>{const s=C("el-button");return r(),i("div",M,[h("h3",z,m(g(v)("Product Details Button")),1),a.value?(r(),i("div",H,[h("div",{class:"fct-selected-product-contents-inner",title:l.value},[h("div",G,[h("span",J,"#"+m(a.value),1),k(" "+m(l.value),1)])],8,U),P(s,{class:"product-clear-button",onClick:b},{default:T(()=>[k(m(g(v)("Reset")),1)]),_:1})])):(r(),i("div",K,[P(L,{value:a.value,onChange:S},null,8,["value"])]))])}}},X=o=>{const t=o.dataset.selectedProduct,e=o.dataset.productTitle,l=A(W,{selectedProduct:t,productTitle:e});E(l),l.mixin({methods:{$t:v}}).mount(o)};jQuery(document).ready(function(){elementor.hooks.addAction("panel/open_editor/widget/fluent_cart_product_details_button",function(o,t,e){t.get("settings")})});jQuery(window).on("elementor/frontend/init",function(){elementorFrontend.hooks.addAction("frontend/element_ready/fluent_cart_product_details_button.default",function(o){const t=jQuery(o[0]).find("[data-fluent-cart-product-details-button-app]")[0];X(t)})});
