import{h as m,i as D,r as C,e as i,o as r,d as f,a as P,w as T,F as V,g as B,c as N,n as O,b as j,t as p,u as h,O as x,f as k,a2 as A}from"./chunks/vue.esm-bundler.js?ver=1.5.2";import{u as $}from"./chunks/useElementPlusComponents.js?ver=1.5.2";import{t as _}from"./chunks/Translator.js?ver=1.5.2";import{u as E}from"./chunks/useElementor.js?ver=1.5.2";import{R as F}from"./chunks/Rest.js?ver=1.5.2";import"./chunks/index.js?ver=1.5.2";import"./chunks/index2.js?ver=1.5.2";import"./chunks/index4.js?ver=1.5.2";import"./chunks/dayjs.min.js?ver=1.5.2";import"./chunks/index3.js?ver=1.5.2";import"./chunks/Arr.js?ver=1.5.2";function I(o,t=300){const e=m(null);return(...a)=>{e.value&&clearTimeout(e.value),e.value=setTimeout(()=>{o(...a)},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=m(""),a=m({}),l=m(!1),g=async(u,n)=>{l.value=!0;try{const v={active_view:"publish",per_page:10,page:1,search:u,filter_type:"simple",sort_by:"ID",with:["detail","variants"]};n&&(v.include_ids=[n]),F.get("products",v).then(y=>{const s={};y.products.data.forEach(d=>{s[d.ID.toString()]={value:d.ID.toString(),label:d.post_title,product:d}}),a.value=s}).catch(y=>{}).finally(()=>{})}catch{}finally{l.value=!1}},b=I(()=>{g(e.value)},500),S=u=>{e.value=u,b()},c=u=>{t.onChange(u)};return D(()=>{g("",t.value)}),(u,n)=>{const v=C("el-option"),y=C("el-select");return r(),i("div",null,[f("div",Q,[P(y,{modelValue:e.value,"onUpdate:modelValue":n[0]||(n[0]=s=>e.value=s),filterable:"",remote:"",placeholder:h(_)("Search for products..."),"remote-method":S,loading:l.value,onChange:n[1]||(n[1]=s=>{const d=Object.values(a.value).find(w=>w.label===s);d&&c(d)})},{empty:T(()=>[l.value?(r(),i("div",R,p(h(_)("Loading...")),1)):e.value?(r(),i("div",q,p(h(_)("No products found.")),1)):j("",!0)]),default:T(()=>[(r(!0),i(V,null,B(Object.values(a.value),s=>(r(),N(v,{key:s.value,label:s.label,value:s.label,class:O({"option-item-selected":o.value===s.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,a=m(e.productTitle),l=m(e.selectedProduct),g=()=>{l.value="",a.value="",setTimeout(()=>{t.setSettings("selected_product","")},100)},b=c=>{l.value=c,setTimeout(()=>{t.setSettings("selected_product",l.value.toString())},500)},S=c=>{c.hasOwnProperty("product")?(b(c.product.ID.toString()),a.value=c.product.post_title):b("")};return x(()=>{t=E()}),(c,u)=>{const n=C("el-button");return r(),i("div",M,[f("h3",z,p(h(_)("Product Details Button")),1),l.value?(r(),i("div",H,[f("div",{class:"fct-selected-product-contents-inner",title:a.value},[f("div",G,[f("span",J,"#"+p(l.value),1),k(" "+p(a.value),1)])],8,U),P(n,{class:"product-clear-button",onClick:g},{default:T(()=>[k(p(h(_)("Reset")),1)]),_:1})])):(r(),i("div",K,[P(L,{value:l.value,onChange:S},null,8,["value"])]))])}}},X=o=>{const t=o.dataset.selectedProduct,e=o.dataset.productTitle,a=A(W,{selectedProduct:t,productTitle:e});$(a),a.mixin({methods:{$t:_}}).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)})});
