import{i as _,j as D,a as C,c as i,o as r,f as h,d as P,w as T,F as V,h as N,b as j,n as B,e as x,t as m,u as g,N as A,g as k,a2 as E}from"./vue.esm-bundler-DZdE0M9V.js";import{u as O}from"./useElementPlusComponents-B_fOPHjO.js";import{t as v}from"./Translator-Bios5QX5.js";import{u as $}from"./useElementor-CLTCC9L5.js";import{R as F}from"./Rest-DEQMhckH.js";import"./index-D0R5Hqh1.js";import"./index-I6zcAgit.js";import"./index-Db9JpFxU.js";import"./dayjs.min-2rai63wT.js";import"./Arr-MwYQQ3qa.js";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)):x("",!0)]),default:T(()=>[(r(!0),i(V,null,N(Object.values(l.value),n=>(r(),j(p,{key:n.value,label:n.label,value:n.label,class:B({"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 A(()=>{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=E(W,{selectedProduct:t,productTitle:e});O(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)})});
