import{b as i,j as t}from"./chunks/BlockEditorTranslator.js?ver=1.5.0";import{a as C}from"./chunks/index5.js?ver=1.5.0";import"./chunks/SingleProductContext.js?ver=1.5.0";import{p as D,q as E}from"./chunks/Icons.js?ver=1.5.0";import{S as I}from"./chunks/SelectVariationModal.js?ver=1.5.0";import{a as A}from"./chunks/add-query-args.js?ver=1.5.0";import"./chunks/ProductListItem.js?ver=1.5.0";import"./chunks/index6.js?ver=1.5.0";const{InspectorControls:F}=wp.blockEditor,{PanelBody:V,CheckboxControl:ot,Button:z,Card:M,CardBody:N,Flex:R,FlexItem:T,FlexBlock:W}=wp.components,{useBlockProps:q,RichText:O}=wp.blockEditor,{registerBlockType:H}=wp.blocks,{useEffect:h,useState:g}=wp.element,{useSelect:L,useDispatch:Q}=wp.data,{store:x}=wp.blockEditor,l=window.fluent_cart_add_to_cart_button_data,b=window.fluentCartRestVars.rest,U=b.url+"/products/variants/";H(l.slug+"/"+l.name,{apiVersion:3,title:l.title,description:l.description,icon:{src:D},category:"fluent-cart",attributes:{variant_ids:[],variationsData:{type:[Array,Object],default:[]},query_type:{type:"string",default:"default"},text:{type:"string",default:i("Add to Cart","fluent-cart")},placeholder:{type:"string"}},supports:{html:!1,align:["left","center","right"],alignWide:!1,typography:{fontSize:!0,lineHeight:!0},spacing:{margin:!0,padding:!0},color:{text:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},reusable:!1,shadow:!0},edit:c=>{const{attributes:a,setAttributes:o,clientId:d}=c,{text:y,placeholder:_}=a,v=q(),[X,p]=g({}),e=(Array.isArray(a.variationsData)?a.variationsData:[])[0]||null,[u,f]=g(!1),k=["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"],m=L(r=>{const{getBlockParents:s,getBlockName:n}=r(x);return s(d).some(B=>k.includes(n(B)))},[d]),{removeBlock:j}=Q(x);h(()=>{m&&j(d)},[m]);let S={variant_ids:a.variant_ids,with_product:!0,per_page:10,page:1,order_by:"ID",order_type:"DESC"};const w=()=>{var r;if(!((r=a.variant_ids)!=null&&r.length)){p([]),o({variationsData:[]});return}C({path:A(U,{params:S}),headers:{"X-WP-Nonce":b.nonce}}).then(s=>{const n=s.variants||[];p(n),o({variationsData:n})}).finally(()=>{})};h(()=>{w()},[a.variant_ids]);const P=()=>e?t.jsx(M,{size:"small",style:{marginTop:"12px"},children:t.jsx(N,{children:t.jsxs(R,{align:"flex-start",gap:3,children:[t.jsxs(W,{children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:"600",fontSize:"13px"},children:e==null?void 0:e.variation_title}),t.jsxs("div",{style:{fontSize:"13px",color:"#757575",marginBottom:"2px"},children:[i("Price"),":",t.jsx("span",{style:{fontWeight:"600",color:"#000",marginLeft:"4px"},dangerouslySetInnerHTML:{__html:e==null?void 0:e.formatted_total}})]})]}),t.jsx(T,{children:t.jsx(z,{icon:E,label:i("Edit product selection"),isSmall:!0,onClick:()=>f(!0)})})]})})}):null;return t.jsxs("div",{children:[t.jsx(F,{children:t.jsxs(V,{title:i("Product Settings"),initialOpen:!0,children:[t.jsx("p",{children:i("Select a specific product variation for this button.","fluent-cart")}),(!e||u)&&t.jsx(I,{not_subscribable:!0,button:!0,isMultiple:!1,setAttributes:o,onModalClosed:r=>{let s={...r},n=Object.keys(s);o({variationsData:{...s}}),o({variant_ids:n}),f(!1)}}),e&&!u&&P()]})}),t.jsx(O,{...c,...v,tagName:"div",className:"wp-block-button__link wp-element-button",value:y,onChange:r=>o({text:r}),placeholder:_||i("Add text…","fluent-cart"),allowedFormats:["core/bold","core/italic"]})]})},save:function(c){return null}});
