| 1 |
import{j as r}from"./chunks/jsx-runtime.js?ver=1.6.6";import{g as V}from"./chunks/Icons.js?ver=1.6.6";import{b as s}from"./chunks/BlockEditorTranslator.js?ver=1.6.6";import{a as $}from"./chunks/index5.js?ver=1.6.6";import{E as R}from"./chunks/EditorPanel.js?ver=1.6.6";import{E as m}from"./chunks/EditorPanelRow.js?ver=1.6.6";import{C as x}from"./chunks/CustomSelect.js?ver=1.6.6";import{S as q}from"./chunks/SelectProductModal.js?ver=1.6.6";import{E as B}from"./chunks/ErrorBoundary.js?ver=1.6.6";import{a as O}from"./chunks/add-query-args.js?ver=1.6.6";import"./chunks/index6.js?ver=1.6.6";import"./chunks/ProductListItem.js?ver=1.6.6";const{InspectorControls:D}=wp.blockEditor,{RangeControl:I}=wp.components,W=({attributes:a,setAttributes:c,selectedProduct:p,setSelectedProduct:e})=>r.jsx(D,{children:r.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card",children:r.jsx("div",{className:"fct-inspector-control-group",children:r.jsx("div",{className:"fct-inspector-control-body",children:r.jsxs(R,{title:s("Product"),children:[r.jsxs(m,{children:[r.jsx("span",{className:"fct-inspector-control-label",children:s("Query type")}),r.jsx("div",{className:"actions",children:r.jsx(x,{customKeys:{key:"value",label:"label"},defaultValue:a.query_type,options:[{label:s("Default"),value:"default"},{label:s("Custom"),value:"custom"}],onChange:function(t){c({query_type:t})}})})]}),a.query_type==="custom"&&r.jsxs(m,{className:"flex-col",children:[r.jsx(q,{selectedProduct:p,setSelectedProduct:e,onModalClosed:t=>{t&&(c({product_id:t.ID||""}),e(t))}}),p&&r.jsxs("div",{className:"fct-selected-variation-info w-full",children:[r.jsx("strong",{children:s("Selected product:")}),r.jsx("p",{children:p.post_title})]})]}),r.jsxs(m,{children:[r.jsx("span",{className:"fct-inspector-control-label",children:s("Price Format")}),r.jsx("div",{className:"actions",children:r.jsx(x,{customKeys:{key:"value",label:"label"},defaultValue:a.price_format,options:[{label:s("Starts From"),value:"starts_from"},{label:s("Range"),value:"range"}],onChange:function(t){c({price_format:t})}})})]}),r.jsxs(m,{className:"flex-col",children:[r.jsx("span",{className:"fct-inspector-control-label",children:s("Card Sizing")}),r.jsxs("div",{className:"actions",children:[r.jsx(x,{defaultValue:typeof a.card_width=="string"?"full":"custom",options:[{label:s("Full Width"),value:"full"},{label:s("Custom Width"),value:"custom"}],onChange:t=>{c(t==="full"?{card_width:"100%"}:{card_width:216})}}),a.card_width!=="100%"&&r.jsx(I,{value:a.card_width,onChange:t=>c({card_width:t}),min:216,max:1e3,step:10})]})]})]})})})})}),K=""+new URL("assets/ProductCard.png",import.meta.url).href,{useBlockProps:M}=wp.blockEditor,{registerBlockType:P}=wp.blocks,{useEffect:Q,useState:T}=wp.element,n=window.fluent_cart_product_card_data,N=window.fluentCartRestVars.rest,f=n.currency_sign,b=n.currency_position;P(n.slug+"/"+n.name,{apiVersion:3,title:n.title,description:n.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:K,alt:"Product Card Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:V},category:"fluent-cart",attributes:{product_id:{type:["string","number"],default:""},price_format:{type:"string",default:"starts_from"},card_width:{type:["string","number"],default:216},query_type:{type:"string",default:"default"}},edit:({attributes:a,setAttributes:c})=>{var j;const p=M(),[e,t]=T({}),C=N.url+"/products/"+a.product_id,k=()=>{a.product_id&&$({path:O(C,{with:["block_product_detail"]}),headers:{"X-WP-Nonce":N.nonce}}).then(l=>{t(l.product||{})}).finally(()=>{})},S=()=>{var l;return((l=e==null?void 0:e.detail)==null?void 0:l.variation_type)==="simple_variations"},E=((j=e==null?void 0:e.detail)==null?void 0:j.stock_availability)==="out-of-stock";return Q(()=>{k()},[a.product_id]),r.jsx("div",{...p,children:r.jsx(B,{children:r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsx(W,{attributes:a,setAttributes:c,selectedProduct:e,setSelectedProduct:t}),r.jsxs("div",{className:"fct-product-card",style:{width:a.card_width==="100%"?"100%":`${a.card_width}px`},children:[r.jsx("div",{className:"fct-product-card-head",style:{position:"relative"},children:r.jsx("img",{className:"fct-product-card-image",src:(e==null?void 0:e.thumbnail)??n.placeholder_image,alt:e==null?void 0:e.post_title})}),r.jsxs("div",{className:"fct-product-card-body",children:[r.jsx("h5",{className:"fct-product-card-title",children:(e==null?void 0:e.post_title)??s("Select a Product")}),r.jsx("div",{className:"fct-product-card-price-wrap",children:(()=>{var _,y,g,v;const l=a.price_format,F=((_=e==null?void 0:e.detail)==null?void 0:_.variation_type)==="simple";let o=(y=e==null?void 0:e.detail)==null?void 0:y.min_price,u=(g=e==null?void 0:e.detail)==null?void 0:g.max_price,h=0;if(F){const i=(v=e==null?void 0:e.variants)==null?void 0:v[0];i&&(o=i.item_price,i.compare_price>o&&(h=i.compare_price))}const d=i=>{if(!i&&i!==0)return b==="after"?`0${f}`:`${f}0`;const w=String(parseFloat((i/100).toFixed(2)));return b==="after"?`${w}${f}`:`${f}${w}`};return h?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"fc_compare_price",children:r.jsx("del",{children:d(h)})}),r.jsx("span",{className:"fct-item-price",children:d(o)})]}):u&&u>o?l==="range"?r.jsx(r.Fragment,{children:r.jsxs("span",{className:"fct-item-price",children:[d(o)," - ",d(u)]})}):r.jsx(r.Fragment,{children:r.jsxs("span",{className:"fct-item-price",children:["From ",d(o)]})}):r.jsx(r.Fragment,{children:r.jsx("span",{className:"fct-item-price",children:d(o)})})})()})]}),r.jsx("div",{className:"fct-product-card-footer",children:E?r.jsx("button",{className:"fluent-cart-shop-app-view-product-button",disabled:!0,style:{cursor:"not-allowed",pointerEvents:"none"},children:r.jsx("span",{children:s("Out of Stock")})}):r.jsx("button",{className:"fluent-cart-shop-app-view-product-button",children:r.jsx("span",{children:s(S()?"View Options":"Add To Cart")})})})]})]})})})},save:function(a){return null}}); |