File: /home/shrsglobal/www/wp-content/plugins/woocommerce/assets/client/blocks/product-button-frontend.js
(globalThis.webpackChunkwebpackWcBlocksFrontendJsonp=globalThis.webpackChunkwebpackWcBlocksFrontendJsonp||[]).push([[409],{3867:(t,e,r)=>{"use strict";r.r(e),r.d(e,{Block:()=>M,default:()=>Y});var o=r(6087),s=r(4921),n=r(7723),c=r(1509),i=r(7143),a=r(7594),d=r(8537),l=r(1824),u=r.n(l),p=r(8331),m=r(3993);const _=Object.entries(p.iI).reduce(((t,[e,r])=>(t[e]=Object.entries(r).reduce(((t,[e,r])=>(t[e]=(t=>{const e={};return void 0!==t.label&&(e.label=t.label),void 0!==t.required&&(e.required=t.required),void 0!==t.hidden&&(e.hidden=t.hidden),void 0===t.label||t.optionalLabel||(e.optionalLabel=(0,n.sprintf)(/* translators: %s Field label. */ /* translators: %s Field label. */
(0,n.__)("%s (optional)","woocommerce"),t.label)),void 0!==t.optionalLabel&&(e.optionalLabel=t.optionalLabel),t.index&&((0,m.isNumber)(t.index)&&(e.index=t.index),(0,m.isString)(t.index)&&(e.index=parseInt(t.index,10))),t.hidden&&(e.required=!1),e})(r),t)),{}),t)),{});var g=r(5703);const b=window.CustomEvent||null,y=(t,e,r=!1,o=!1)=>{if("function"!=typeof jQuery)return()=>{};const s=()=>{((t,{bubbles:e=!1,cancelable:r=!1,element:o,detail:s={}})=>{if(!b)return;o||(o=document.body);const n=new b(t,{bubbles:e,cancelable:r,detail:s});o.dispatchEvent(n)})(e,{bubbles:r,cancelable:o})};return jQuery(document).on(t,s),()=>jQuery(document).off(t,s)},h=t=>{const e=t?.detail;e&&e.preserveCartData||(0,i.dispatch)(a.cartStore).invalidateResolutionForStore()},w=t=>{(t?.persisted||"back_forward"===(window.performance&&window.performance.getEntriesByType("navigation").length?window.performance.getEntriesByType("navigation")[0].type:""))&&(0,i.dispatch)(a.cartStore).invalidateResolutionForStore()},f=()=>{1===window.wcBlocksStoreCartListeners.count&&window.wcBlocksStoreCartListeners.remove(),window.wcBlocksStoreCartListeners.count--},T={first_name:"",last_name:"",company:"",address_1:"",address_2:"",city:"",state:"",postcode:"",country:"",phone:""},C={...T,email:""},S={total_items:"",total_items_tax:"",total_fees:"",total_fees_tax:"",total_discount:"",total_discount_tax:"",total_shipping:"",total_shipping_tax:"",total_price:"",total_tax:"",tax_lines:a.EMPTY_TAX_LINES,currency_code:"",currency_symbol:"",currency_minor_unit:2,currency_decimal_separator:"",currency_thousand_separator:"",currency_prefix:"",currency_suffix:""},E=t=>Object.fromEntries(Object.entries(t).map((([t,e])=>[t,(0,d.decodeEntities)(e)]))),k=(t,e)=>{const r=(t=>{const e=((t,e,r="")=>{const o=r&&void 0!==_[r]?_[r]:{};return t.map((t=>({key:t,...e&&t in e?e[t]:{},...o&&t in o?o[t]:{}}))).sort(((t,e)=>t.index-e.index))})(p.Hw,g.defaultFields,t.country),r=Object.assign({},t);return e.forEach((({key:e,hidden:o})=>{!0===o&&((t,e)=>t in e)(e,t)&&(r[e]="")})),r})(E(t));return u()(e.current,r)||(e.current=r),e.current},x={billingAddress:C,billingData:C,cartCoupons:a.EMPTY_CART_COUPONS,cartErrors:a.EMPTY_CART_ERRORS,cartFees:a.EMPTY_CART_FEES,cartHasCalculatedShipping:!1,cartIsLoading:!0,cartItemErrors:a.EMPTY_CART_ITEM_ERRORS,cartItems:a.EMPTY_CART_ITEMS,cartItemsCount:0,cartItemsWeight:0,cartNeedsPayment:!0,cartNeedsShipping:!0,cartTotals:S,crossSellsProducts:a.EMPTY_CART_CROSS_SELLS,extensions:a.EMPTY_EXTENSIONS,hasPendingItemsOperations:!1,isLoadingRates:!1,paymentMethods:a.EMPTY_PAYMENT_METHODS,paymentRequirements:a.EMPTY_PAYMENT_REQUIREMENTS,receiveCart:()=>{},receiveCartContents:()=>{},shippingAddress:T,shippingRates:a.EMPTY_SHIPPING_RATES},v=(t={shouldSelect:!0})=>{const{shouldSelect:e}=t,r=(0,o.useRef)(),s=(0,o.useRef)(C),n=(0,o.useRef)(T);(0,o.useEffect)((()=>((()=>{if(window.wcBlocksStoreCartListeners||(window.wcBlocksStoreCartListeners={count:0,remove:()=>{}}),window.wcBlocksStoreCartListeners?.count>0)return void window.wcBlocksStoreCartListeners.count++;document.body.addEventListener("wc-blocks_added_to_cart",h),document.body.addEventListener("wc-blocks_removed_from_cart",h),window.addEventListener("pageshow",w);const t=y("added_to_cart","wc-blocks_added_to_cart"),e=y("removed_from_cart","wc-blocks_removed_from_cart");window.wcBlocksStoreCartListeners.count=1,window.wcBlocksStoreCartListeners.remove=()=>{document.body.removeEventListener("wc-blocks_added_to_cart",h),document.body.removeEventListener("wc-blocks_removed_from_cart",h),window.removeEventListener("pageshow",w),t(),e()}})(),f)),[]);const{receiveCart:c,receiveCartContents:l}=(0,i.useDispatch)(a.cartStore),{cartData:p,cartErrors:m,cartTotals:_,cartIsLoading:g,isLoadingRates:b,hasPendingItemsOperations:S}=(0,i.useSelect)((t=>{const e=t(a.cartStore),r=!e.hasFinishedResolution("getCartData",[]);return{cartData:e.getCartData(),cartErrors:e.getCartErrors(),cartTotals:e.getCartTotals(),cartIsLoading:r,isLoadingRates:e.isAddressFieldsForShippingRatesUpdating(),hasPendingItemsOperations:e.hasPendingItemsOperations()}}),[]);if(!e)return x;const v=k(p.billingAddress,s),L=p.needsShipping?k(p.shippingAddress,n):v,A={billingAddress:v,billingData:v,cartCoupons:(O=p.coupons,O.length>0?O.map((t=>({...t,label:(0,d.decodeEntities)(t.code)}))):a.EMPTY_CART_COUPONS),cartErrors:m,cartFees:(N=p.fees,N.length>0?N.map((t=>E(t))):a.EMPTY_CART_FEES),cartHasCalculatedShipping:p.hasCalculatedShipping,cartIsLoading:g,cartItemErrors:p.errors,cartItems:p.items,cartItemsCount:p.itemsCount,cartItemsWeight:p.itemsWeight,cartNeedsPayment:p.needsPayment,cartNeedsShipping:p.needsShipping,cartTotals:_,crossSellsProducts:p.crossSells,extensions:p.extensions,hasPendingItemsOperations:S,isLoadingRates:b,paymentMethods:p.paymentMethods,paymentRequirements:p.paymentRequirements,receiveCart:c,receiveCartContents:l,shippingAddress:L,shippingRates:(R=p.shippingRates,R.length>0?R.map((t=>({...t,shipping_rates:t.shipping_rates.length>0?t.shipping_rates.map((t=>E(t))):[]}))):[])};var R,N,O;return r.current&&u()(r.current,A)||(r.current=A),r.current},L=(t,e)=>{const r=t.find((({id:t})=>t===e));return r?r.quantity:0};var A=r(41),R=r(2796),N=r(1616),O=(r(7316),r(4179)),P=r(790);const I=({product:t,isDescendantOfAddToCartWithOptions:e,collection:r})=>{const o="woocommerce/product-collection/cart-contents"===r,c="external"===t.type,i=c?t.button_text:t.add_to_cart?.single_text;let a;return a=o?(0,n.__)("Finish checkout","woocommerce"):e?i:t.add_to_cart?.text,(0,P.jsx)("button",{disabled:!1,className:(0,s.A)("wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button"),style:{},children:c?t.button_text:a||(0,n.__)("Add to cart","woocommerce")})},D=({product:t,isDescendantOfAddToCartWithOptions:e,className:r,style:l,collection:u})=>{const{id:m,permalink:_,add_to_cart:b,has_options:y,is_purchasable:h,is_in_stock:w}=t,{dispatchStoreEvent:f}=(0,c.y)(),{cartQuantity:T,addingToCart:C,addToCart:S}=(t=>{const{addItemToCart:e}=(0,i.useDispatch)(a.cartStore),{cartItems:r,cartIsLoading:s}=v(),{createErrorNotice:n,removeNotice:c}=(0,i.useDispatch)("core/notices"),[l,u]=(0,o.useState)(!1),p=(0,o.useRef)(L(r,t));return(0,o.useEffect)((()=>{const e=L(r,t);e!==p.current&&(p.current=e)}),[r,t]),{cartQuantity:Number.isFinite(p.current)?p.current:0,addingToCart:l,cartIsLoading:s,addToCart:(r=1)=>(u(!0),e(t,r).then((()=>{c("add-to-cart")})).catch((t=>{n((0,d.decodeEntities)(t.message),{id:"add-to-cart",context:"wc/all-products",isDismissible:!0})})).finally((()=>{u(!1)})))}})(m),E=Number.isFinite(T)&&T>0,k="woocommerce/product-collection/cart-contents"===u,x=!y&&h&&w,A=(0,d.decodeEntities)(b?.description||""),R=k?(0,n.__)("Finish checkout","woocommerce"):(({cartQuantity:t,productCartDetails:e,isDescendantOfAddToCartWithOptions:r})=>Number.isFinite(t)&&t>0?(0,n.sprintf)(/* translators: %s number of products in cart. */ /* translators: %s number of products in cart. */
(0,n._n)("%d in cart","%d in cart",t,"woocommerce"),t):r&&e?.single_text?e?.single_text:e?.text||(0,n.__)("Add to cart","woocommerce"))({cartQuantity:T,productCartDetails:b,isDescendantOfAddToCartWithOptions:e}),N=x&&!k?"button":"a",O={};return k?(O.href=p.Vo,O.rel="nofollow",O.onClick=()=>{f("cart-view-link",{product:t})}):x?O.onClick=async()=>{await S(),f("cart-add-item",{product:t});const{cartRedirectAfterAdd:e}=(0,g.getSetting)("productsSettings");e&&(window.location.href=p.Vo)}:(O.href=_,O.rel="nofollow",O.onClick=()=>{f("product-view-link",{product:t})}),(0,P.jsx)(N,{...O,"aria-label":A,disabled:C,className:(0,s.A)(r,"wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button",{loading:C,added:E}),style:l,children:R})},j=({className:t,style:e})=>(0,P.jsx)("button",{className:(0,s.A)("wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button","wc-block-components-product-button__button--placeholder",t),style:e,disabled:!0,children:(0,n.__)("Add to cart","woocommerce")}),F=({className:t,style:e,blockClientId:r,collection:c})=>{const{current:i,registerListener:a,unregisterListener:d}=(0,O.A)();let l;return(0,o.useEffect)((()=>{if(r)return a(r),()=>{d(r)}}),[r,a,d]),l="woocommerce/product-collection/cart-contents"===c?(0,n.__)("Finish checkout","woocommerce"):"external"===i?.slug?(0,n.__)("Buy product","woocommerce"):(0,n.__)("Add to cart","woocommerce"),(0,P.jsx)("button",{className:(0,s.A)("wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button",t),style:e,disabled:!0,children:l})},M=t=>{const{className:e,textAlign:r,blockClientId:o,collection:n}=t,c=(0,A.p)(t),{parentClassName:i}=(0,R.useInnerBlockLayoutContext)(),{product:a,isLoading:d}=(0,R.useProductDataContext)({product:t.product,isAdmin:t.isAdmin}),l=a?.id&&t.isAdmin&&(0,p.Sc)();return(0,P.jsx)("div",{className:(0,s.A)(e,"wp-block-button","wc-block-components-product-button",{[`${i}__product-add-to-cart`]:i,[`align-${r}`]:r}),children:d?(0,P.jsx)(j,{className:c.className,style:c.style}):(0,P.jsxs)(P.Fragment,{children:[l&&(0,P.jsx)(I,{product:a,isDescendantOfAddToCartWithOptions:t["woocommerce/isDescendantOfAddToCartWithOptions"],collection:n}),!l&&(a&&a?.id?(0,P.jsx)(D,{product:a,style:c.style,className:c.className,isAdmin:t.isAdmin,isDescendantOfAddToCartWithOptions:t["woocommerce/isDescendantOfAddToCartWithOptions"],productEntity:t.product,collection:n}):(0,P.jsx)(F,{style:c.style,className:c.className,isLoading:null!=d&&d,blockClientId:o,collection:n}))]})})},Y=(0,N.withProductDataContext)(M)},41:(t,e,r)=>{"use strict";r.d(e,{p:()=>d});var o=r(4921),s=r(3993),n=r(7356),c=r(9786);function i(t={}){const e={};return(0,c.getCSSRules)(t,{selector:""}).forEach((t=>{e[t.key]=t.value})),e}function a(t,e){return t&&e?`has-${(0,n.c)(e)}-${t}`:""}const d=t=>{const e=(t=>{const e=(0,s.isObject)(t)?t:{style:{}};let r=e.style;return(0,s.isString)(r)&&(r=JSON.parse(r)||{}),(0,s.isObject)(r)||(r={}),{...e,style:r}})(t),r=function(t){const{backgroundColor:e,textColor:r,gradient:n,style:c}=t,d=a("background-color",e),l=a("color",r),u=function(t){if(t)return`has-${t}-gradient-background`}(n),p=u||c?.color?.gradient;return{className:(0,o.A)(l,u,{[d]:!p&&!!d,"has-text-color":r||c?.color?.text,"has-background":e||c?.color?.background||n||c?.color?.gradient,"has-link-color":(0,s.isObject)(c?.elements?.link)?c?.elements?.link?.color:void 0}),style:i({color:c?.color||{}})}}(e),n=function(t){const e=t.style?.border||{};return{className:function(t){const{borderColor:e,style:r}=t,s=e?a("border-color",e):"";return(0,o.A)({"has-border-color":!!e||!!r?.border?.color,[s]:!!s})}(t),style:i({border:e})}}(e),c=function(t){return{className:void 0,style:i({spacing:t.style?.spacing||{}})}}(e),d=(t=>{const e=(0,s.isObject)(t.style.typography)?t.style.typography:{},r=(0,s.isString)(e.fontFamily)?e.fontFamily:"";return{className:t.fontFamily?`has-${t.fontFamily}-font-family`:r,style:{fontSize:t.fontSize?`var(--wp--preset--font-size--${t.fontSize})`:e.fontSize,fontStyle:e.fontStyle,fontWeight:e.fontWeight,letterSpacing:e.letterSpacing,lineHeight:e.lineHeight,textDecoration:e.textDecoration,textTransform:e.textTransform}}})(e);return{className:(0,o.A)(d.className,r.className,n.className,c.className),style:{...d.style,...r.style,...n.style,...c.style}}}},4179:(t,e,r)=>{"use strict";r.d(e,{A:()=>_});var o=r(7143);const s="woocommerce/product-type-template-state",n="SWITCH_PRODUCT_TYPE",c="SET_PRODUCT_TYPES",i="REGISTER_LISTENER",a="UNREGISTER_LISTENER",d=(0,r(5703).getSetting)("productTypes",{}),l=Object.keys(d).map((t=>({slug:t,label:d[t]}))),u={productTypes:{list:l,current:l[0]?.slug},listeners:[]},p={switchProductType:t=>({type:n,current:t}),setProductTypes:t=>({type:c,productTypes:t}),registerListener:t=>({type:i,listener:t}),unregisterListener:t=>({type:a,listener:t})},m=(0,o.createReduxStore)(s,{reducer:(t=u,e)=>{switch(e.type){case c:return{...t,productTypes:{...t.productTypes,list:e.productTypes||[]}};case n:return{...t,productTypes:{...t.productTypes,current:e.current}};case i:return{...t,listeners:[...t.listeners,e.listener||""]};case a:return{...t,listeners:t.listeners.filter((t=>t!==e.listener))};default:return t}},actions:p,selectors:{getProductTypes:t=>t.productTypes.list,getCurrentProductType:t=>t.productTypes.list.find((e=>e.slug===t.productTypes.current)),getRegisteredListeners:t=>t.listeners}});function _(){const{productTypes:t,current:e,registeredListeners:r}=(0,o.useSelect)((t=>{const{getProductTypes:e,getCurrentProductType:r,getRegisteredListeners:o}=t(m);return{productTypes:e(),current:r(),registeredListeners:o()}}),[]),{switchProductType:s,registerListener:n,unregisterListener:c}=(0,o.useDispatch)(m);return{productTypes:t,current:e,set:s,registeredListeners:r,registerListener:n,unregisterListener:c}}(0,o.select)(s)||(0,o.register)(m)},7316:()=>{}}]);