import{j as t,b as i}from"./chunks/BlockEditorTranslator.js?ver=1.5.2";import{a as y}from"./chunks/index5.js?ver=1.5.2";import{S as k}from"./chunks/SelectProductModal.js?ver=1.5.2";import{E as w}from"./chunks/EditorPanel.js?ver=1.5.2";import{E as b}from"./chunks/EditorPanelRow.js?ver=1.5.2";import{u as E}from"./chunks/SingleProductContext.js?ver=1.5.2";import{j as N}from"./chunks/Icons.js?ver=1.5.2";import{a as S}from"./chunks/add-query-args.js?ver=1.5.2";import"./chunks/ProductListItem.js?ver=1.5.2";import"./chunks/index6.js?ver=1.5.2";const{InspectorControls:v}=wp.blockEditor,B=({attributes:c,setAttributes:p,selectedProduct:r,setSelectedProduct:a})=>t.jsx(v,{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(w,{title:i("Product"),children:t.jsxs(b,{className:"flex-col",children:[t.jsx(k,{onModalClosed:e=>{p({product_id:e!=null&&e.ID?String(e.ID):""}),a(e)},selectedProduct:r,setSelectedProduct:a,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:i("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})})}),t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[i("Excerpt"),":"]})," ",(r==null?void 0:r.post_excerpt)||i("(empty)")]})]})]})})})})})}),{useBlockProps:F}=wp.blockEditor,{registerBlockType:I,createBlock:C}=wp.blocks,{useEffect:d,useState:T}=wp.element,{useSelect:D}=wp.data,{store:M}=wp.blockEditor,s=window.fluent_cart_excerpt_data;s.placeholder_image;const f=window.fluentCartRestVars.rest;I(s.slug+"/"+s.name,{apiVersion:3,title:s.title,description:s.description,icon:{src:N},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"-"}},edit:({attributes:c,setAttributes:p,clientId:r})=>{const a=F({className:"fct-product-block-editor-product-card-excerpt"}),[e,l]=T({}),m=f.url+"/products/"+c.product_id,o=E(),n=D(u=>{const{getBlockParents:x,getBlockName:h}=u(M);return x(r).some(g=>{const j=h(g);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(j)})},[r]);d(()=>{p({inside_product_info:n?"yes":"no",...n?{}:{query_type:"custom"}})},[n]);const _=()=>{y({path:S(m,{with:["detail","variants"]}),headers:{"X-WP-Nonce":f.nonce}}).then(u=>{l(u.product||{})}).finally(()=>{})};return d(()=>{o!=null&&o.product&&l(o.product),!n&&c.product_id&&_()},[c.product_id,o==null?void 0:o.product]),t.jsxs("div",{...a,children:[n?"":t.jsx(B,{attributes:c,setAttributes:p,selectedProduct:e,setSelectedProduct:l}),t.jsx("div",{className:"fct-product-excerpt",children:(e==null?void 0:e.post_excerpt)||i("Excerpt")})]})},save:function(c){return null},transforms:{from:[{type:"block",blocks:["fluent-cart/shopapp-product-excerpt"],transform:()=>C(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}});
