import{j as t,b as s}from"./BlockEditorTranslator-Do4trUgb.js";import{j as g}from"./Icons-DvCYCYqp.js";import{S as v}from"./SelectProductModal-DVcPjGk4.js";import{E as w}from"./EditorPanel-CY23VFza.js";import{E as f}from"./EditorPanelRow-4NClJhlp.js";import{C as S,a as P}from"./index-C7Ob1qfg.js";import{u as b}from"./SingleProductContext-BzN8-5Wa.js";import{a as E}from"./add-query-args-COp5A_Oq.js";import"./ProductListItem-DCmiyLoH.js";import"./index-CGoo2crO.js";const{InspectorControls:N}=wp.blockEditor,C=({attributes:o,setAttributes:r,selectedProduct:c,setSelectedProduct:i})=>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(w,{title:s("Product"),children:[t.jsxs(f,{children:[t.jsx("span",{className:"fct-inspector-control-label",children:s("Query type")}),t.jsx("div",{className:"actions",children:t.jsx(S,{customKeys:{key:"value",label:"label"},defaultValue:o.query_type,options:[{label:s("Default"),value:"default"},{label:s("Custom"),value:"custom"}],onChange:function(e){r({query_type:e})}})})]}),o.query_type==="custom"&&t.jsxs(f,{className:"flex-col",children:[t.jsx(v,{onModalClosed:e=>{r({product_id:String(e.ID)||""})}}),c&&t.jsxs("div",{className:"fct-selected-variation-info w-full",children:[t.jsx("strong",{children:s("Selected Product:")}),t.jsx("p",{children:c.post_title})]})]})]})})})})}),{useBlockProps:I}=wp.blockEditor,{registerBlockType:q}=wp.blocks,{useEffect:B,useState:D}=wp.element,{useSelect:R}=wp.data,{store:M}=wp.blockEditor,m=window.fluentCartRestVars.rest,n=window.fluent_cart_stock_data;q(n.slug+"/"+n.name,{title:n.title,description:n.description,icon:{src:g},supports:n.supports||[],category:"fluent-cart",attributes:{product_id:{type:"string",default:""},variant_id:{type:"string",default:""},query_type:{type:"string",default:"default"}},edit:({attributes:o,setAttributes:r,clientId:c})=>{var p,u;const i=I(),e=b(),a=R(l=>{const{getBlockParents:x,getBlockName:k}=l(M);return x(c).some(_=>k(_)==="fluent-cart/product-info")},[c]);r({inside_product_info:a?"yes":"no"});const[h,d]=D({}),y=m.url+"/products/"+o.product_id,j=()=>{P({path:E(y,{with:["detail","variants"]}),headers:{"X-WP-Nonce":m.nonce}}).then(l=>{console.log(l.product," response"),d(l.product||{})}).finally(()=>{})};return a||B(()=>{j()},[o.product_id]),t.jsxs("div",{...i,children:[a?"":t.jsx(C,{attributes:o,setAttributes:r,selectedProduct:h,setSelectedProduct:d}),(u=(p=e==null?void 0:e.product)==null?void 0:p.detail)!=null&&u.stock_availability?t.jsx("div",{children:s("In Stock")}):s("Out of Stock")]})},save:function(o){return null}});
