import{j as t,b as c}from"./chunks/BlockEditorTranslator.js?ver=1.3.21";import{a as j}from"./chunks/index5.js?ver=1.3.21";import{S as w}from"./chunks/SelectProductModal.js?ver=1.3.21";import{E as k}from"./chunks/EditorPanel.js?ver=1.3.21";import{E as N}from"./chunks/EditorPanelRow.js?ver=1.3.21";import{E as b}from"./chunks/ErrorBoundary.js?ver=1.3.21";import{u as S}from"./chunks/SingleProductContext.js?ver=1.3.21";import{k as v}from"./chunks/Icons.js?ver=1.3.21";import{a as y}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:E}=wp.blockEditor,B=({attributes:n,setAttributes:l,selectedProduct:e,setSelectedProduct:p})=>t.jsx(E,{children:t.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-description",children:t.jsx("div",{className:"fct-inspector-control-group",children:t.jsx("div",{className:"fct-inspector-control-body",children:t.jsx(k,{title:c("Product"),children:t.jsxs(N,{className:"flex-col",children:[t.jsx(w,{onModalClosed:r=>{l({product_id:r!=null&&r.ID?String(r.ID):""}),p(r)},selectedProduct:e,setSelectedProduct:p,isMultiple:!1}),(e==null?void 0:e.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:e.post_title})})}),t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[c("Description"),":"]})," ",(()=>{if(!(e!=null&&e.post_content))return c("(empty)");const r=e.post_content.replace(/<[^>]*>/g,"");return r.length>120?r.substring(0,120)+"...":r})()]})]})]})})})})})}),{useBlockProps:D}=wp.blockEditor,{registerBlockType:I}=wp.blocks,{useEffect:F,useState:T}=wp.element,{useSelect:C}=wp.data,{store:M}=wp.blockEditor,a=window.fluent_cart_product_description_data,u=window.fluentCartRestVars.rest;I(a.slug+"/"+a.name,{apiVersion:3,title:a.title,description:a.description,icon:{src:v},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""}},edit:({attributes:n,setAttributes:l,clientId:e})=>{const p=D({className:"fct-product-block-editor-product-description"}),[r,s]=T({}),m=u.url+"/products/"+n.product_id,o=S(),d=C(i=>{const{getBlockParents:h,getBlockName:_}=i(M);return h(e).some(x=>{const g=_(x);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(g)})},[e]),f=()=>{j({path:y(m,{with:["detail"]}),headers:{"X-WP-Nonce":u.nonce}}).then(i=>{s((i==null?void 0:i.product)||{})}).catch(()=>{s({})})};return F(()=>{o!=null&&o.product?s(o.product):!d&&n.product_id?f():s({})},[n.product_id,o==null?void 0:o.product]),t.jsx("div",{...p,children:t.jsxs(b,{children:[d?"":t.jsx(B,{attributes:n,setAttributes:l,selectedProduct:r,setSelectedProduct:s}),t.jsx("div",{className:"fct-product-description-preview",children:r!=null&&r.post_content?t.jsx("div",{dangerouslySetInnerHTML:{__html:r.post_content}}):t.jsx("p",{className:"fct-product-description-placeholder",children:c("Product Description")})})]})})},save:()=>null,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}});
