import{j as t,b as o}from"./chunks/BlockEditorTranslator.js?ver=1.3.25";import{a as k}from"./chunks/index5.js?ver=1.3.25";import{S as N}from"./chunks/SelectProductModal.js?ver=1.3.25";import{C as v}from"./chunks/CustomSelect.js?ver=1.3.25";import{E as d}from"./chunks/EditorPanel.js?ver=1.3.25";import{E as u}from"./chunks/EditorPanelRow.js?ver=1.3.25";import{u as w}from"./chunks/SingleProductContext.js?ver=1.3.25";import{l as b}from"./chunks/Icons.js?ver=1.3.25";import{a as E}from"./chunks/add-query-args.js?ver=1.3.25";import"./chunks/ProductListItem.js?ver=1.3.25";import"./chunks/index6.js?ver=1.3.25";const{InspectorControls:F}=wp.blockEditor,I=({attributes:n,setAttributes:i,selectedProduct:r,setSelectedProduct:l})=>t.jsx(F,{children:t.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card",children:t.jsx("div",{className:"fct-inspector-control-group",children:t.jsxs("div",{className:"fct-inspector-control-body",children:[t.jsx(d,{title:o("Product"),children:t.jsxs(u,{className:"flex-col",children:[t.jsx(N,{onModalClosed:e=>{i({product_id:e!=null&&e.ID?String(e.ID):""}),l(e)},selectedProduct:r,setSelectedProduct:l,isMultiple:!1}),(r==null?void 0:r.post_title)&&t.jsxs("div",{className:"fct-selected-products",children:[t.jsx("span",{className:"fct-selected-products__label",children:o("Selected Product")}),t.jsx("div",{className:"fct-selected-products__list",children:t.jsx("div",{className:"fct-product-chip-group",children:t.jsx("span",{className:"fct-product-chip fct-product-chip--parent",children:r.post_title})})}),(r==null?void 0:r.detail)&&t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[o("Price"),":"]})," ",t.jsx("span",{dangerouslySetInnerHTML:{__html:r.detail.formatted_min_price}}),r.detail.min_price!==r.detail.max_price&&t.jsxs(t.Fragment,{children:[" - ",t.jsx("span",{dangerouslySetInnerHTML:{__html:r.detail.formatted_max_price}})]})]})]})]})}),t.jsx(d,{title:o("Settings"),children:t.jsx(u,{children:t.jsx("div",{className:"fct-block-editor-control-item",children:t.jsxs("div",{className:"fct-inspector-control-row",children:[t.jsx("span",{className:"label",children:o("Price Format")}),t.jsx("div",{className:"actions",children:t.jsx(v,{customKeys:{key:"value",label:"label"},defaultValue:n.price_format,options:[{label:o("Starts From"),value:"starts_from"},{label:o("Range"),value:"range"}],onChange:function(e){i({price_format:e})}})})]})})})})]})})})}),{useBlockProps:T}=wp.blockEditor,{registerBlockType:C,createBlock:M}=wp.blocks,{useEffect:f,useState:B}=wp.element,{useSelect:H}=wp.data,{store:L}=wp.blockEditor,s=window.fluent_cart_price_range_data;s.placeholder_image;const _=window.fluentCartRestVars.rest;C(s.slug+"/"+s.name,{apiVersion:3,title:s.title,description:s.description,icon:{src:b},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"-"},price_format:{type:"string",default:"starts_from"}},edit:({attributes:n,setAttributes:i,clientId:r})=>{const l=T(),[e,p]=B({}),h=_.url+"/products/"+n.product_id,a=w(),c=H(m=>{const{getBlockParents:g,getBlockName:j}=m(L);return g(r).some(y=>{const S=j(y);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(S)})},[r]);f(()=>{i({inside_product_info:c?"yes":"no",...c?{}:{query_type:"custom"}})},[c]);const x=()=>{k({path:E(h,{with:["detail","variants"]}),headers:{"X-WP-Nonce":_.nonce}}).then(m=>{p(m.product||{})}).finally(()=>{})};return f(()=>{a!=null&&a.product&&p(a.product),!c&&n.product_id&&x()},[n.product_id,a==null?void 0:a.product]),t.jsxs("div",{...l,children:[c?"":t.jsx(I,{attributes:n,setAttributes:i,selectedProduct:e,setSelectedProduct:p}),e!=null&&e.detail?t.jsxs("div",{className:"fct-product-price-range",children:[t.jsx("span",{className:"price-min",dangerouslySetInnerHTML:{__html:e.detail.formatted_min_price}}),e.detail.min_price!==e.detail.max_price&&t.jsxs(t.Fragment,{children:[" - ",t.jsx("span",{className:"price-max",dangerouslySetInnerHTML:{__html:e.detail.formatted_max_price}})]})]}):"$0.00"]})},save:function(n){return null},transforms:{from:[{type:"block",blocks:["fluent-cart/shopapp-product-price"],transform:()=>M(s.slug+"/"+s.name)}]},supports:{html:!1,align:["left","center","right"],typography:{fontSize:!0,lineHeight:!0,__experimentalFontFamily:!0,__experimentalFontWeight:!0,__experimentalFontStyle:!0,__experimentalTextTransform:!0,__experimentalTextDecoration:!0,__experimentalLetterSpacing:!0,__experimentalDefaultControls:{fontSize:!0,lineHeight:!0,fontWeight:!0}},color:{text:!0,background:!0,link:!0,gradients:!0},spacing:{margin:!0,padding:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},shadow:!0}});
