import{j as t,b as r}from"./chunks/BlockEditorTranslator.js?ver=1.3.21";import{o as g}from"./chunks/Icons.js?ver=1.3.21";import{S as j}from"./chunks/SelectProductModal.js?ver=1.3.21";import{E as S}from"./chunks/EditorPanel.js?ver=1.3.21";import{E as N}from"./chunks/EditorPanelRow.js?ver=1.3.21";import{a as E}from"./chunks/index5.js?ver=1.3.21";import{u as B}from"./chunks/SingleProductContext.js?ver=1.3.21";import{a as I}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:A}=wp.blockEditor,C=({attributes:a,setAttributes:p,selectedProduct:o,setSelectedProduct:d,isInsideProductInfo:c})=>{var n;return c?null:t.jsx(A,{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.jsx(S,{title:r("Product"),children:t.jsxs(N,{className:"flex-col",children:[t.jsx(j,{onModalClosed:s=>{p({product_id:s!=null&&s.ID?String(s.ID):""}),d(s)},selectedProduct:o,setSelectedProduct:d,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:r("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})})}),((n=o==null?void 0:o.detail)==null?void 0:n.stock_availability)&&t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[r("Stock"),":"]})," ",o.detail.stock_availability==="in-stock"&&r("In Stock"),o.detail.stock_availability==="out-of-stock"&&r("Out of Stock"),o.detail.stock_availability==="backorder"&&r("Available on Backorder"),o.detail.stock_availability==="low-stock"&&r("Low Stock")]})]})]})})})})})})},{useBlockProps:L}=wp.blockEditor,{registerBlockType:M}=wp.blocks,{useEffect:k,useState:R}=wp.element,{useSelect:q}=wp.data,{store:F}=wp.blockEditor,u=window.fluent_cart_stock_data,m=window.fluentCartRestVars.rest;M(u.slug+"/"+u.name,{apiVersion:3,title:u.title,description:u.description,icon:{src:g},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""},variant_id:{type:"string",default:""},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"-"}},edit:({attributes:a,setAttributes:p,clientId:o})=>{var f;const d=L(),[c,n]=R({}),s=m.url+"/products/"+a.product_id,i=B(),e=q(l=>{const{getBlockParents:v,getBlockName:y}=l(F);return v(o).some(w=>{const x=y(w);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(x)})},[o]);k(()=>{p({inside_product_info:e?"yes":"no",...e?{}:{query_type:"custom"}})},[e]);const _=l=>{switch(l){case"in-stock":return r("In Stock");case"out-of-stock":return r("Out of Stock");case"backorder":return r("Available on Backorder");case"low-stock":return r("Low Stock");default:return r("Stock Availability")}},h=()=>{E({path:I(s,{with:["detail","variants"]}),headers:{"X-WP-Nonce":m.nonce}}).then(l=>{n(l.product||{})}).finally(()=>{})};k(()=>{i!=null&&i.product&&n(i.product),!e&&a.product_id&&h()},[a.product_id,i==null?void 0:i.product]);const b=_((f=c==null?void 0:c.detail)==null?void 0:f.stock_availability)||r("Stock Availability");return t.jsxs("div",{...d,children:[e?"":t.jsx(C,{attributes:a,setAttributes:p,selectedProduct:c,setSelectedProduct:n}),t.jsx("div",{className:"fct-stock-status",children:b})]})},save:function(a){return null},supports:{html:!1,align:["left","center","right"],__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},spacing:{margin:!0,padding:!0},shadow:!0,__experimentalFilter:{duotone:!0}}});
