import{j as t,b as r}from"./chunks/BlockEditorTranslator.js?ver=1.5.0";import{a as w}from"./chunks/index5.js?ver=1.5.0";import{S as B}from"./chunks/SelectVariationModal.js?ver=1.5.0";import{q as P,B as C}from"./chunks/Icons.js?ver=1.5.0";import{a as E}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:D}=wp.blockEditor,{PanelBody:I,CheckboxControl:F,Button:M,Card:N,CardBody:z,Flex:O,FlexItem:R,FlexBlock:T}=wp.components,{useState:W}=wp.element,q=({attributes:s,setAttributes:o,selectedVariant:e})=>{const[a,l]=W(!1),f=()=>e?t.jsx(N,{size:"small",style:{marginTop:"12px"},children:t.jsx(z,{children:t.jsxs(O,{align:"flex-start",gap:3,children:[t.jsxs(T,{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:[r("Price"),":",t.jsx("span",{style:{fontWeight:"600",color:"#000",marginLeft:"4px"},dangerouslySetInnerHTML:{__html:e==null?void 0:e.formatted_total}})]})]}),t.jsx(R,{children:t.jsx(M,{icon:P,label:r("Edit product selection"),isSmall:!0,onClick:()=>l(!0)})})]})})}):null;return t.jsx(D,{children:t.jsxs(I,{title:r("Product Settings"),initialOpen:!0,children:[t.jsx(F,{label:r("Enable Instant Modal Checkout"),checked:s.enable_modal_checkout||!1,onChange:i=>o({enable_modal_checkout:i}),help:r("Open checkout in a modal instead of navigating to the product page.")}),t.jsxs(t.Fragment,{children:[t.jsx("p",{children:r("Select a specific product variation for this button.","fluent-cart")}),(!e||a)&&t.jsx(B,{button:!0,isMultiple:!1,setAttributes:o,onModalClosed:i=>{let c={...i},u=Object.keys(c);o({variationsData:{...c}}),o({variant_ids:u}),l(!1)}}),e&&!a&&f()]})]})})},{useBlockProps:A,RichText:H}=wp.blockEditor,{registerBlockType:L}=wp.blocks,{useEffect:g,useState:Q}=wp.element,{useSelect:U,useDispatch:X}=wp.data,{store:x}=wp.blockEditor,p=window.fluent_cart_buy_now_button_data,y=window.fluentCartRestVars.rest,$=y.url+"/products/variants/";L(p.slug+"/"+p.name,{apiVersion:3,title:p.title,description:p.description,icon:{src:C},example:{attributes:{}},category:"fluent-cart",attributes:{variant_ids:[],variationsData:{type:[Array,Object],default:[]},query_type:{type:"string",default:"default"},enable_modal_checkout:{type:"boolean",default:!1},text:{type:"string",default:"Buy Now"},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:s=>{const{attributes:o,setAttributes:e,clientId:a}=s,{text:l,placeholder:f}=o,i=A(),c=["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"],u=U(n=>{const{getBlockParents:h,getBlockName:d}=n(x);return h(a).some(S=>c.includes(d(S)))},[a]),{removeBlock:b}=X(x);g(()=>{u&&b(a)},[u]);const[_,m]=Q({});let k=(Array.isArray(o.variationsData)?o.variationsData:[])[0]||null,v={variant_ids:o.variant_ids,with_product:!0,per_page:10,page:1,order_by:"ID",order_type:"DESC"};const j=()=>{var n;if(!((n=o.variant_ids)!=null&&n.length)){m([]),e({variationsData:[]});return}w({path:E($,{params:v}),headers:{"X-WP-Nonce":y.nonce}}).then(h=>{const d=h.variants||[];m(d),e({variationsData:d})}).finally(()=>{})};return g(()=>{j()},[o.variant_ids]),t.jsxs("div",{children:[t.jsx(q,{attributes:o,setAttributes:e,preSelectedVariations:_,selectedVariant:k}),t.jsx(H,{...s,...i,tagName:"a",className:"wp-block-button__link wp-element-button",value:l,onChange:n=>e({text:n}),placeholder:f||r("Add text…","fluent-cart"),allowedFormats:["core/bold","core/italic"]})]})},save:function(s){return null}});
