| 1 |
import{j as e,b as s}from"./chunks/BlockEditorTranslator.js?ver=1.6.0";import{h as O}from"./chunks/Icons.js?ver=1.6.0";import{a as U}from"./chunks/index5.js?ver=1.6.0";import{E as k}from"./chunks/EditorPanel.js?ver=1.6.0";import{E as p}from"./chunks/EditorPanelRow.js?ver=1.6.0";import"./chunks/CustomSelect.js?ver=1.6.0";import{S as V}from"./chunks/SelectProductModal.js?ver=1.6.0";import"./chunks/SingleProductContext.js?ver=1.6.0";import{P as H}from"./chunks/ProductContext.js?ver=1.6.0";import{a as Q}from"./chunks/add-query-args.js?ver=1.6.0";import"./chunks/index6.js?ver=1.6.0";import"./chunks/ProductListItem.js?ver=1.6.0";const{InspectorControls:W}=wp.blockEditor,{CheckboxControl:X}=wp.components,{RangeControl:I}=wp.components,{SelectControl:N,ToggleControl:E}=wp.components,$=({attributes:a,setAttributes:c,selectedProduct:d,setSelectedProduct:g,isInsideProductInfo:i})=>{const{carousel_settings:t}=a,{useEffect:y,useState:M}=wp.element;return y(()=>{},[a,d]),e.jsx(W,{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.jsxs("div",{className:"fct-inspector-control-body",children:[e.jsx(k,{title:s("Product"),children:!i&&e.jsxs(p,{className:"flex-col",children:[e.jsx(V,{onModalClosed:o=>{const x=Array.isArray(o)?o.filter(r=>r==null?void 0:r.ID):[],v=x.map(r=>r.ID);c({product_ids:v}),g(x)},selectedProduct:d,setSelectedProduct:g,isMultiple:!0}),Array.isArray(a.product_ids)&&a.product_ids.length>0&&d&&d.length>0&&e.jsxs("div",{className:"fct-selected-products",children:[e.jsx("span",{className:"fct-selected-products__label",children:s("Selected products")}),e.jsx("div",{className:"fct-selected-products__list",children:d.map(o=>e.jsx("span",{className:"fct-product-chip",children:o.post_title},o.ID))})]})]})}),e.jsx(k,{title:s("Layout"),children:e.jsxs(p,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:s("Slides per view")}),e.jsx(I,{value:t.slidesToShow,onChange:o=>c({carousel_settings:{...t,slidesToShow:o}}),min:1,max:6})]})}),e.jsxs(k,{title:s("Behavior"),children:[e.jsx("p",{className:"fct-panel-subtitle",children:s("Carousel interaction & animation")}),e.jsx(p,{children:e.jsx(N,{label:s("Autoplay"),value:t.autoplay,options:[{label:s("Disabled"),value:"no"},{label:s("Always"),value:"yes"},{label:s("On Hover"),value:"hover"}],onChange:o=>{c({carousel_settings:{...t,autoplay:o}})}})}),["yes","hover"].includes(t.autoplay)&&e.jsx(p,{className:"fct-nested-control",children:e.jsx(I,{label:"Autoplay Delay (ms)",help:s("Time between slides in milliseconds"),value:t.autoplayDelay||3e3,min:300,max:1e4,step:100,onChange:o=>c({carousel_settings:{...t,autoplayDelay:o}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(p,{children:e.jsx(E,{label:s("Show arrows"),checked:t.arrows==="yes",onChange:o=>c({carousel_settings:{...t,arrows:o?"yes":"no"}})})}),t.arrows==="yes"&&e.jsx(p,{className:"fct-nested-control",children:e.jsx(N,{label:s("Arrow Size"),value:t.arrowsSize,options:[{label:s("Small"),value:"sm"},{label:s("Medium"),value:"md"},{label:s("Large"),value:"lg"}],onChange:o=>c({carousel_settings:{...t,arrowsSize:o}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(p,{children:e.jsx(E,{label:s("Show Pagination"),checked:t.pagination==="yes",onChange:o=>c({carousel_settings:{...t,pagination:o?"yes":"no"}})})}),t.pagination==="yes"&&e.jsx(p,{className:"fct-nested-control",children:e.jsx(N,{label:s("Pagination Type"),value:t.paginationType,options:[{label:s("Bullets"),value:"bullets"},{label:s("Fraction"),value:"fraction"},{label:s("Progress Bar"),value:"progress"},{label:s("Segmented (Modern)"),value:"segmented"}],onChange:o=>c({carousel_settings:{...t,paginationType:o}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(p,{children:e.jsx(X,{label:s("Infinite loop"),checked:t.infinite==="yes",onChange:o=>c({carousel_settings:{...t,infinite:o?"yes":"no"}})})})]})]})})})})},q=""+new URL("assets/ProductGallery.png",import.meta.url).href,{InnerBlocks:T,useBlockProps:D,useInnerBlocksProps:he,__experimentalUseBlockPreview:fe,BlockContextProvider:ge}=wp.blockEditor,{registerBlockType:J}=wp.blocks,{useEffect:h,useState:f,useRef:K}=wp.element,{useSelect:b}=wp.data,{store:Y}=wp.blockEditor,j=window.fluent_cart_product_carousel_block_editor_data,A=window.fluentCartRestVars.rest,Z=[["fluent-cart/product-carousel-loop",{className:"fluent-cart-product-carousel-loop",layout:{type:"constrained"},metadata:{name:"Product Carousel Loop"}},[["fluent-cart/product-image"],["fluent-cart/product-title"],["fluent-cart/excerpt"],["fluent-cart/price-range"],["fluent-cart/shopapp-product-buttons"]]],["fluent-cart/product-carousel-controls"],["fluent-cart/product-carousel-pagination"]];J(j.slug+"/"+j.name,{apiVersion:3,title:j.title,description:j.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:q,alt:"Product Carousel Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:O},category:"fluent-cart",supports:{html:!1,reusable:!1,innerBlocks:!0},attributes:{product_ids:{type:"array",default:[]},inside_product_info:{type:"string",default:"-"},carousel_settings:{type:"object",default:{slidesToShow:3,autoplay:"yes",autoplayDelay:3e3,arrows:"yes",arrowsSize:"md",pagination:"yes",paginationType:"bullets",infinite:"no"}},has_controls:{type:"string",default:"yes"},has_pagination:{type:"string",default:"yes"}},provides_context:{"fluent-cart/carousel_settings":"carousel_settings","fluent-cart/product_ids":"product_ids","fluent-cart/has_controls":"has_controls","fluent-cart/has_pagination":"has_pagination"},edit:({attributes:a,setAttributes:c,clientId:d})=>{const g=D({className:"fluent-cart-product-carousel-block"}),[i,t]=f([]),y=K(!1),[M,o]=f([]),[x,v]=f(!1),r=Math.max(1,Number(a.carousel_settings.slidesToShow||4)),L=a.carousel_settings.infinite==="yes",{has_controls:_,has_pagination:w}=b(l=>{const u=l("core/block-editor").getBlocks(d);return{has_controls:u.some(m=>m.name==="fluent-cart/product-carousel-controls"),has_pagination:u.some(m=>m.name==="fluent-cart/product-carousel-pagination")}},[d]);h(()=>{if(!y.current){if(!_&&!w)return;y.current=!0}c({has_controls:_?"yes":"no",has_pagination:w?"yes":"no"})},[_,w]);const P=b(l=>{const{getBlockParents:u,getBlockName:m}=l(Y);return u(d).some(n=>m(n)==="fluent-cart/product-info")},[d]);h(()=>{const l=P?"yes":"no";a.inside_product_info!==l&&c({inside_product_info:l})},[P]);const R=()=>{if(!(Array.isArray(a.product_ids)&&a.product_ids.length>0))return;v(!0);const u=A.url+"/products/fetchProductsByIds",m={productIds:a.product_ids,with:["detail","variants"]};U({path:Q(u,m),headers:{"X-WP-Nonce":A.nonce}}).then(n=>{var B;const G=Array.isArray((B=n==null?void 0:n.products)==null?void 0:B.data)?n.products.data:Array.isArray(n==null?void 0:n.products)?n.products:Array.isArray(n)?n:[];t(G),console.log("api response",i)}).finally(()=>{v(!1)})};h(()=>{R()},[a.product_ids]),h(()=>{},[i]);const z=(()=>{if(!i.length)return Array.from({length:r}).map((m,n)=>({ID:`placeholder-${n}`,isPlaceholder:!0}));if(!L||i.length>=r)return i.slice(0,r);const l=[...i];let u=0;for(;l.length<r;)l.push(i[u%i.length]),u++;return l.slice(0,r)})();Math.ceil((i.length||r)/r);const C=b(l=>l("core/block-editor").getBlock(d),[d]),[S,F]=f(1);h(()=>{if(S>1){new Date().toISOString();return}F(S+1)},[C]),C.innerBlocks;const[ee,se]=f();return e.jsxs("div",{...g,children:[e.jsx($,{attributes:a,setAttributes:c,selectedProduct:i,setSelectedProduct:t}),e.jsx("div",{className:"fct-product-gallery-wrapper is-editor-preview",children:e.jsx("div",{className:"fct-product-gallery-carousel editor-carousel-preview",style:{display:"grid",gap:"16px"},children:x||!i.length?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"fluent-cart-empty",children:[e.jsxs("div",{className:"fct-loading-header",children:[e.jsx("div",{className:"fct-loading-spinner"}),e.jsx("span",{children:s("Loading products...")})]}),e.jsx("div",{className:"dummy-grid",style:{"--fct-slides-per-view":r},children:Array.from({length:r}).map((l,u)=>e.jsxs("div",{className:"dummy-card",style:{"--card-index":u},children:[e.jsx("div",{className:"dummy-image skeleton"}),e.jsxs("div",{className:"dummy-content",children:[e.jsx("div",{className:"dummy-title skeleton"}),e.jsx("div",{className:"dummy-excerpt skeleton"}),e.jsx("div",{className:"dummy-price skeleton"})]}),e.jsx("div",{className:"dummy-btn-wrap",children:e.jsx("div",{className:"dummy-btn"})})]},u))})]})}):e.jsx(H,{value:{products:z},children:e.jsx(T,{template:Z})})})})]})},save:()=>{const a=D.save({className:"fluent-cart-product-carousel-block"});return e.jsx("div",{...a,children:e.jsx(T.Content,{})})}}); |