import{j as t,b as i}from"./chunks/BlockEditorTranslator.js?ver=1.5.4";import{a as E}from"./chunks/index5.js?ver=1.5.4";import{S as C}from"./chunks/SelectProductModal.js?ver=1.5.4";import{E as B}from"./chunks/EditorPanel.js?ver=1.5.4";import{E as F}from"./chunks/EditorPanelRow.js?ver=1.5.4";import{u as I}from"./chunks/SingleProductContext.js?ver=1.5.4";import{w as L}from"./chunks/Icons.js?ver=1.5.4";import{a as D}from"./chunks/add-query-args.js?ver=1.5.4";import"./chunks/ProductListItem.js?ver=1.5.4";import"./chunks/index6.js?ver=1.5.4";const{InspectorControls:h}=wp.blockEditor,{PanelBody:M,ToggleControl:g}=wp.components,R=({attributes:r,setAttributes:c,selectedProduct:o,setSelectedProduct:p,isInsideProductInfo:n,isLink:a,linkTarget:f})=>t.jsxs(t.Fragment,{children:[!n&&t.jsx(h,{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(B,{title:i("Product"),children:t.jsxs(F,{className:"flex-col",children:[t.jsx(C,{onModalClosed:e=>{c({product_id:e!=null&&e.ID?String(e.ID):""}),p(e)},selectedProduct:o,setSelectedProduct:p,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: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:o.post_title})})}),t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[i("Title"),":"]})," ",o.post_title]})]})]})})})})})}),t.jsx(h,{children:t.jsxs(M,{title:i("Settings"),children:[t.jsx(g,{label:i("Make title a link"),checked:a,onChange:e=>c({isLink:e})}),a&&t.jsx(g,{label:i("Open in new tab"),checked:f==="_blank",onChange:e=>c({linkTarget:e?"_blank":"_self"})})]})})]}),{useBlockProps:W}=wp.blockEditor,{registerBlockType:q,createBlock:z}=wp.blocks,{useEffect:x,useState:H}=wp.element,{useSelect:U}=wp.data,{store:V}=wp.blockEditor,l=window.fluent_cart_product_title_data;l.placeholder_image;const k=window.fluentCartRestVars.rest;q(l.slug+"/"+l.name,{apiVersion:3,title:l.title,description:l.description,icon:{src:L},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"-"},isLink:{type:"boolean",default:!0},linkTarget:{type:"string",default:"_self"}},edit:({attributes:r,setAttributes:c,clientId:o})=>{const p=W(),[n,a]=H(null),f=k.url+"/products/"+r.product_id,e=(n==null?void 0:n.view_url)||"#",s=I(),u=U(d=>{const{getBlockParents:T,getBlockName:v}=d(V);return T(o).some(S=>{const N=v(S);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(N)})},[o]);x(()=>{c({inside_product_info:u?"yes":"no",...u?{}:{query_type:"custom"}})},[u]);const j=()=>{E({path:D(f,{with:["detail","variants"]}),headers:{"X-WP-Nonce":k.nonce}}).then(d=>{a(d.product||{})}).finally(()=>{})};x(()=>{s!=null&&s.product&&a(s.product),!u&&r.product_id&&j()},[r.product_id,s==null?void 0:s.product]);const y=(n==null?void 0:n.post_title)||i("Product Title"),{isLink:m,linkTarget:_}=r,w=m?"a":"h5",b=m?{href:e,target:_,rel:_==="_blank"?"noopener noreferrer":void 0,onClick:d=>d.preventDefault()}:{};return t.jsxs("div",{...p,children:[t.jsx(R,{attributes:r,setAttributes:c,selectedProduct:n,setSelectedProduct:a,isInsideProductInfo:u,isLink:m,linkTarget:_}),t.jsx(w,{...p,...b,children:y})]})},save:function(r){return null},transforms:{from:[{type:"block",blocks:["fluent-cart/shopapp-product-title"],transform:r=>z(l.slug+"/"+l.name,{isLink:r.isLink??!0,linkTarget:r.linkTarget??"_self"})}]},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}});
