import{j as t,b as o}from"./chunks/BlockEditorTranslator.js?ver=1.5.3";import{E as u}from"./chunks/EditorPanel.js?ver=1.5.3";import{E as g}from"./chunks/EditorPanelRow.js?ver=1.5.3";import{u as m}from"./chunks/SingleProductContext.js?ver=1.5.3";import{m as x}from"./chunks/Icons.js?ver=1.5.3";import{E as h}from"./chunks/ErrorBoundary.js?ver=1.5.3";const{InspectorControls:_}=wp.blockEditor,{TextControl:y,SelectControl:b}=wp.components,j=({attributes:l,setAttributes:s,isOutOfStock:r})=>t.jsx(_,{children:t.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--sold-out-badge",children:t.jsx("div",{className:"fct-inspector-control-group",children:t.jsxs("div",{className:"fct-inspector-control-body",children:[t.jsx(u,{title:o("Badge Settings"),children:t.jsxs(g,{className:"flex-col",children:[t.jsx(y,{label:o("Badge Text"),value:l.badge_text,onChange:e=>s({badge_text:e}),help:o("Text displayed on the badge.")}),typeof r=="boolean"&&t.jsx("div",{className:`fct-sold-out-badge-status ${r?"fct-sold-out-badge-status--out-of-stock":"fct-sold-out-badge-status--in-stock"}`,children:r?o("Product is out of stock"):o("Product is in stock")})]})}),t.jsx(u,{title:o("Position & Style"),children:t.jsxs(g,{className:"flex-col",children:[t.jsx(b,{label:o("Badge Style"),value:l.badge_style,options:[{label:o("Badge"),value:"badge"},{label:o("Ribbon"),value:"ribbon"},{label:o("Tag"),value:"tag"}],onChange:e=>s({badge_style:e})}),t.jsx(b,{label:o("Position"),value:l.badge_position,options:[{label:o("Top Left"),value:"top-left"},{label:o("Top Right"),value:"top-right"},{label:o("Bottom Left"),value:"bottom-left"},{label:o("Bottom Right"),value:"bottom-right"}],onChange:e=>s({badge_position:e})})]})})]})})})}),{useBlockProps:v}=wp.blockEditor,{registerBlockType:k}=wp.blocks,{useEffect:S,useState:w,useMemo:B}=wp.element,n=window.fluent_cart_sold_out_badge_data;k(n.slug+"/"+n.name,{apiVersion:3,title:n.title,description:n.description,icon:{src:x},category:"fluent-cart",parent:["fluent-cart/products","fluent-cart/product-carousel","fluent-cart/product-image","fluent-cart/shopapp-product-image"],attributes:{badge_text:{type:"string",default:"Sold Out"},badge_style:{type:"string",default:"badge"},badge_position:{type:"string",default:"top-left"}},edit:({attributes:l,setAttributes:s})=>{const r=v(),[e,c]=w({}),a=m();S(()=>{a!=null&&a.product?c(a.product):c({})},[a==null?void 0:a.product]);const i=B(()=>{var p;return((p=e==null?void 0:e.detail)==null?void 0:p.stock_availability)==="out-of-stock"},[e]),f=["fct-sold-out-badge",`fct-sold-out-badge--${l.badge_style||"badge"}`,l.badge_position?`fct-sold-out-badge--${l.badge_position}`:""].filter(Boolean).join(" "),d=(e==null?void 0:e.ID)||(e==null?void 0:e.detail);return t.jsx("div",{...r,children:t.jsxs(h,{children:[t.jsx(j,{attributes:l,setAttributes:s,isOutOfStock:i}),t.jsx("span",{className:f,style:d&&!i?{opacity:.4}:{},children:l.badge_text||"Sold Out"}),d&&!i&&t.jsx("small",{style:{display:"block",color:"#999",fontSize:"11px",marginTop:"4px"},children:o("Product is in stock")})]})})},save:function(){return null},supports:{html:!1,align:["left","center","right"],color:{text:!0,background:!0,gradients:!0},typography:{fontSize:!0,__experimentalFontWeight:!0,__experimentalLetterSpacing:!0,__experimentalTextTransform:!0,__experimentalDefaultControls:{fontSize:!0}},spacing:{margin:!0,padding:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},shadow:!0}});
