import{j as t,b as c}from"./chunks/BlockEditorTranslator.js?ver=1.3.21";import{n as y}from"./chunks/Icons.js?ver=1.3.21";import{a as _}from"./chunks/index5.js?ver=1.3.21";import{S as v}from"./chunks/SelectProductModal.js?ver=1.3.21";import{E as b}from"./chunks/EditorPanel.js?ver=1.3.21";import{E as u}from"./chunks/EditorPanelRow.js?ver=1.3.21";import{S as k}from"./chunks/SingleProductContext.js?ver=1.3.21";import{a as w}from"./chunks/add-query-args.js?ver=1.3.21";import"./chunks/ProductListItem.js?ver=1.3.21";import"./chunks/index6.js?ver=1.3.21";const{InspectorControls:N}=wp.blockEditor,{__experimentalToggleGroupControl:E,__experimentalToggleGroupControlOption:C}=wp.components,S=E,d=C,I=({attributes:e,setAttributes:l,selectedProduct:o,setSelectedProduct:n})=>t.jsx(N,{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.jsx("div",{className:"fct-inspector-control-body",children:t.jsxs(b,{title:c("Product"),children:[t.jsx(u,{children:t.jsxs(S,{isBlock:!0,label:c("Query type"),value:e.query_type,onChange:r=>{l({query_type:r})},children:[t.jsx(d,{value:"default",label:c("Default")}),t.jsx(d,{value:"custom",label:c("Custom")})]})}),e.query_type==="custom"&&t.jsxs(u,{className:"flex-col",children:[t.jsx(v,{onModalClosed:r=>{l({product_id:r!=null&&r.ID?String(r.ID):""}),n(r)},selectedProduct:o,setSelectedProduct:n,isMultiple:!1}),(o==null?void 0:o.post_title)&&t.jsxs("div",{className:"fct-selected-products",children:[t.jsx("span",{className:"fct-selected-products__label",children:c("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:o.post_title})})})]})]})]})})})})}),P=""+new URL("assets/ProductInfo.png",import.meta.url).href,{useBlockProps:f,InnerBlocks:m}=wp.blockEditor,{registerBlockType:B}=wp.blocks,{useEffect:T,useState:h}=wp.element,s=window.fluent_cart_product_info_data;s.placeholder_image;const g=window.fluentCartRestVars.rest,D=[["core/columns",{},[["core/column",{},[["fluent-cart/product-gallery",{}]]],["core/column",{},[["fluent-cart/product-title",{}],["fluent-cart/excerpt",{}],["fluent-cart/stock",{}],["fluent-cart/product-sku",{}],["fluent-cart/price-range",{}],["fluent-cart/buy-section",{}]]]]]];B(s.slug+"/"+s.name,{apiVersion:3,title:s.title,description:s.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:P,alt:"Product Info Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:y},category:"fluent-cart",supports:{html:!1,reusable:!1,innerBlocks:!0},attributes:{product_id:{type:["string","number"],default:""},variant_id:{type:"string",default:""},query_type:{type:"string",default:"default"}},edit:({attributes:e,setAttributes:l})=>{const o=f({className:"my-plugin-product-card"}),[n,r]=h({}),[i,a]=h(null),x=p=>{if(!p){a(null);return}_({path:w(g.url+"/products/"+p,{with:["detail","variants"]}),headers:{"X-WP-Nonce":g.nonce}}).then(j=>{a(j.product||null)})};return T(()=>{x(e.product_id)},[e.product_id]),t.jsxs("div",{...o,children:[t.jsx(I,{attributes:e,setAttributes:l,selectedProduct:i,setSelectedProduct:a}),t.jsx("div",{className:"product-card-inner",style:{border:"1px solid #eee",padding:"16px",borderRadius:"8px"},children:t.jsx(k,{value:{product:i},children:t.jsx(m,{template:D,templateLock:!1,allowedBlocks:["core/heading","fluent-cart/buy-section","fluent-cart/product-gallery","fluent-cart/stock","fluent-cart/product-sku","fluent-cart/price-range","core/columns","core/paragraph","core/title","fluent-cart/shopapp-product-title","fluent-cart/excerpt","fluent-cart/sale-badge"]})})})]})},save:()=>{const e=f.save({className:"my-plugin-product-card"});return t.jsx("div",{...e,children:t.jsx("div",{className:"product-card-inner",children:t.jsx(m.Content,{})})})}});
