import{j as t,b as o}from"./BlockEditorTranslator-Do4trUgb.js";import{h as g}from"./Icons-DvCYCYqp.js";import{C as j,a as v}from"./index-C7Ob1qfg.js";import{S as P}from"./SelectProductModal-DVcPjGk4.js";import{E as b}from"./EditorPanel-CY23VFza.js";import{E as d}from"./EditorPanelRow-4NClJhlp.js";import{S as w}from"./SingleProductContext-BzN8-5Wa.js";import{a as k}from"./add-query-args-COp5A_Oq.js";import"./index-CGoo2crO.js";import"./ProductListItem-DCmiyLoH.js";const{InspectorControls:_}=wp.blockEditor,N=({attributes:e,setAttributes:s,selectedProduct:l,setSelectedProduct:h})=>t.jsx(_,{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:o("Product"),children:[t.jsxs(d,{children:[t.jsx("span",{className:"fct-inspector-control-label",children:o("Query type")}),t.jsx("div",{className:"actions",children:t.jsx(j,{customKeys:{key:"value",label:"label"},defaultValue:e.query_type,options:[{label:o("Default"),value:"default"},{label:o("Custom"),value:"custom"}],onChange:function(r){s({query_type:r})}})})]}),e.query_type==="custom"&&t.jsxs(d,{className:"flex-col",children:[t.jsx(P,{onModalClosed:r=>{console.log(r," selectedProduct"),s({product_id:String(r.ID)||""})}}),l&&t.jsxs("div",{className:"fct-selected-variation-info w-full",children:[t.jsx("strong",{children:o("Selected Product:")}),t.jsx("p",{children:l.post_title})]})]})]})})})})}),S=""+new URL("assets/ProductInfo-Cy9l_GKj.png",import.meta.url).href,{useBlockProps:p,InnerBlocks:u}=wp.blockEditor,{registerBlockType:E}=wp.blocks,{useEffect:C,useState:f}=wp.element,c=window.fluent_cart_product_info_data;c.placeholder_image;const m=window.fluentCartRestVars.rest,I=[["core/columns",{},[["core/column",{},[["fluent-cart/product-gallery",{}]]],["core/column",{},[["fluent-cart/shopapp-product-title",{}],["fluent-cart/stock",{}],["fluent-cart/shopapp-product-price",{}],["fluent-cart/buy-section",{}]]]]]];E(c.slug+"/"+c.name,{title:c.title,description:c.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:S,alt:"Product Info Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:g},category:"fluent-cart",supports:{html:!1,reusable:!1,innerBlocks:!0},attributes:{product_id:{type:"string",default:""},variant_id:{type:"string",default:""},query_type:{type:"string",default:"default"}},edit:({attributes:e,setAttributes:s})=>{const l=p({className:"my-plugin-product-card"}),[h,r]=f({}),[a,n]=f({}),x=m.url+"/products/"+e.product_id,y=()=>{v({path:k(x,{with:["detail","variants"]}),headers:{"X-WP-Nonce":m.nonce}}).then(i=>{console.log(i.product," response"),n(i.product||{})}).finally(()=>{})};return C(()=>{y()},[e.product_id]),t.jsxs("div",{...l,children:[t.jsx(N,{attributes:e,setAttributes:s,selectedProduct:a,setSelectedProduct:n}),t.jsx("div",{className:"product-card-inner",style:{border:"1px solid #eee",padding:"16px",borderRadius:"8px"},children:t.jsx(w,{value:{product:a},children:t.jsx(u,{template:I,templateLock:!1,allowedBlocks:["core/heading","fluent-cart/buy-section","fluent-cart/product-gallery","fluent-cart/stock","core/columns","core/paragraph","core/title","fluent-cart/shopapp-product-title","fluent-cart/shopapp-product-price"]})})})]})},save:()=>{const e=p.save({className:"my-plugin-product-card"});return t.jsx("div",{...e,children:t.jsx("div",{className:"product-card-inner",children:t.jsx(u.Content,{})})})}});
