import{j as e,b as c}from"./BlockEditorTranslator-Do4trUgb.js";import{i as N}from"./Icons-DvCYCYqp.js";import"./SelectVariationModal-BnB_afqi.js";import{C as k,a as E}from"./index-C7Ob1qfg.js";import{E as C}from"./EditorPanel-CY23VFza.js";import{E as m}from"./EditorPanelRow-4NClJhlp.js";import{S}from"./SelectProductModal-DVcPjGk4.js";import{u as I}from"./SingleProductContext-BzN8-5Wa.js";import{a as P}from"./add-query-args-COp5A_Oq.js";import"./ProductListItem-DCmiyLoH.js";import"./index-CGoo2crO.js";const{InspectorControls:B}=wp.blockEditor,{CheckboxControl:q}=wp.components,D=({attributes:s,setAttributes:a,selectedProduct:n,setSelectedProduct:d,isInsideProductInfo:t})=>e.jsx(B,{children:e.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card",children:e.jsx("div",{className:"fct-inspector-control-group",children:e.jsx("div",{className:"fct-inspector-control-body",children:e.jsxs(C,{title:c("Product"),children:[!t&&e.jsxs(e.Fragment,{children:[e.jsxs(m,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:c("Query type")}),e.jsx("div",{className:"actions",children:e.jsx(k,{customKeys:{key:"value",label:"label"},defaultValue:s.query_type,options:[{label:c("Default"),value:"default"},{label:c("Custom"),value:"custom"}],onChange:function(o){a({query_type:o})}})})]}),s.query_type==="custom"&&e.jsxs(m,{className:"flex-col",children:[e.jsx(S,{onModalClosed:o=>{a({product_id:o.ID||""}),d(o)}}),n&&e.jsxs("div",{className:"fct-selected-variation-info w-full",children:[e.jsx("strong",{children:c("Selected product:")}),e.jsx("p",{children:n.post_title})]})]})]}),e.jsxs(m,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:c("Enable image zoom")}),e.jsx("div",{className:"actions",children:e.jsx(q,{checked:s.enableImageZoom==="yes",onChange:o=>{a({enableImageZoom:o?"yes":"no"})}})})]})]})})})})}),G=""+new URL("assets/ProductGallery-Dr4b0DP7.png",import.meta.url).href,{useBlockProps:R}=wp.blockEditor,{registerBlockType:Z}=wp.blocks,{useEffect:x,useState:F}=wp.element,i=window.fluent_cart_product_gallery_data,g=i.placeholder_image,j=window.fluentCartRestVars.rest,{useSelect:M}=wp.data,{store:Q}=wp.blockEditor;Z(i.slug+"/"+i.name,{title:i.title,description:i.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:G,alt:"Product Gallery Preview",style:{width:"100%",height:"auto"}}}]},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:"-"},enableImageZoom:{type:"string",default:"yes"}},edit:({attributes:s,setAttributes:a,clientId:n})=>{var f,h,y;const d=R(),[t,o]=F({}),b=j.url+"/products/"+s.product_id,u=M(r=>{const{getBlockParents:p,getBlockName:w}=r(Q);return p(n).some(_=>w(_)==="fluent-cart/product-info")},[n]);a({inside_product_info:u?"yes":"no"});const l=I(),v=()=>{E({path:P(b,{with:["variants"]}),headers:{"X-WP-Nonce":j.nonce}}).then(r=>{console.log(r," response"),o(r.product||{})}).finally(()=>{})};return x(()=>{v()},[]),x(()=>{l!=null&&l.product&&o(l.product)},[l==null?void 0:l.product]),e.jsxs("div",{...d,children:[e.jsx(D,{attributes:s,setAttributes:a,selectedProduct:t,setSelectedProduct:o,isInsideProductInfo:u}),t!=null&&t.ID?e.jsxs("div",{className:"fct-product-gallery-wrapper",children:[e.jsx("div",{className:"fct-product-gallery-thumb",children:e.jsx("img",{src:((h=(f=t==null?void 0:t.detail)==null?void 0:f.featured_media)==null?void 0:h.url)??g,alt:""})}),e.jsx("div",{className:"fct-gallery-thumb-controls",children:(y=t==null?void 0:t.variants)==null?void 0:y.map((r,p)=>e.jsx("div",{className:"fct-gallery-thumb-control-button",children:e.jsx("img",{src:r.thumbnail??g,alt:r.variation_title??""})},r.id||p))})]}):e.jsx("div",{className:"fluent-cart-empty",children:e.jsx("div",{className:"fluent-cart-empty-message",children:c("No product gallery")})})]})},save:function(s){return null}});
