OwlCyberSecurity - MANAGER
Edit File: product-button-frontend.js
(self.webpackChunkwebpackWcBlocksFrontendJsonp=self.webpackChunkwebpackWcBlocksFrontendJsonp||[]).push([[409],{6144:(e,t,r)=>{"use strict";r.r(t),r.d(t,{Block:()=>D,default:()=>F});var o=r(1609),n=r(851),s=r(7723),a=r(7277),c=r(6087),i=r(7143),l=r(7594),d=r(8537),u=r(458),p=r.n(u),m=r(3993),_=r(2516);const b=Object.entries(_.iI).reduce(((e,[t,r])=>(e[t]=Object.entries(r).reduce(((e,[t,r])=>(e[t]=(e=>{const t={};return void 0!==e.label&&(t.label=e.label),void 0!==e.required&&(t.required=e.required),void 0!==e.hidden&&(t.hidden=e.hidden),void 0===e.label||e.optionalLabel||(t.optionalLabel=(0,s.sprintf)(/* translators: %s Field label. */ /* translators: %s Field label. */ (0,s.__)("%s (optional)","woocommerce"),e.label)),e.index&&((0,m.isNumber)(e.index)&&(t.index=e.index),(0,m.isString)(e.index)&&(t.index=parseInt(e.index,10))),e.hidden&&(t.required=!1),t})(r),e)),{}),e)),{});r(3832);var g=r(5703);const v=e=>{const t=((e,t,r="")=>{const o=r&&void 0!==b[r]?b[r]:{};return e.map((e=>({key:e,...t[e]||{},...o[e]||{}}))).sort(((e,t)=>e.index-t.index))})(_.Hw,g.defaultFields,e.country),r=Object.assign({},e);return t.forEach((({key:t,hidden:o})=>{o&&((e,t)=>e in t)(t,e)&&(r[t]="")})),r},y=(0,c.createContext)({isEditor:!1,currentPostId:0,currentView:"",previewData:{},getPreviewData:()=>({})}),w=window.CustomEvent||null,h=(e,t,r=!1,o=!1)=>{if("function"!=typeof jQuery)return()=>{};const n=()=>{((e,{bubbles:t=!1,cancelable:r=!1,element:o,detail:n={}})=>{if(!w)return;o||(o=document.body);const s=new w(e,{bubbles:t,cancelable:r,detail:n});o.dispatchEvent(s)})(t,{bubbles:r,cancelable:o})};return jQuery(document).on(e,n),()=>jQuery(document).off(e,n)},f=e=>{const t=null==e?void 0:e.detail;t&&t.preserveCartData||(0,i.dispatch)(l.cartStore).invalidateResolutionForStore()},C=e=>{(null!=e&&e.persisted||"back_forward"===(window.performance&&window.performance.getEntriesByType("navigation").length?window.performance.getEntriesByType("navigation")[0].type:""))&&(0,i.dispatch)(l.cartStore).invalidateResolutionForStore()},S=()=>{1===window.wcBlocksStoreCartListeners.count&&window.wcBlocksStoreCartListeners.remove(),window.wcBlocksStoreCartListeners.count--},E={first_name:"",last_name:"",company:"",address_1:"",address_2:"",city:"",state:"",postcode:"",country:"",phone:""},k={...E,email:""},T={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:l.EMPTY_TAX_LINES,currency_code:"",currency_symbol:"",currency_minor_unit:2,currency_decimal_separator:"",currency_thousand_separator:"",currency_prefix:"",currency_suffix:""},N=e=>Object.fromEntries(Object.entries(e).map((([e,t])=>[e,(0,d.decodeEntities)(t)]))),R={cartCoupons:l.EMPTY_CART_COUPONS,cartItems:l.EMPTY_CART_ITEMS,cartFees:l.EMPTY_CART_FEES,cartItemsCount:0,cartItemsWeight:0,crossSellsProducts:l.EMPTY_CART_CROSS_SELLS,cartNeedsPayment:!0,cartNeedsShipping:!0,cartItemErrors:l.EMPTY_CART_ITEM_ERRORS,cartTotals:T,cartIsLoading:!0,cartErrors:l.EMPTY_CART_ERRORS,billingData:k,billingAddress:k,shippingAddress:E,shippingRates:l.EMPTY_SHIPPING_RATES,isLoadingRates:!1,cartHasCalculatedShipping:!1,paymentMethods:l.EMPTY_PAYMENT_METHODS,paymentRequirements:l.EMPTY_PAYMENT_REQUIREMENTS,receiveCart:()=>{},receiveCartContents:()=>{},extensions:l.EMPTY_EXTENSIONS},x=(e={shouldSelect:!0})=>{const{shouldSelect:t}=e,{isEditor:r,previewData:o}=(0,c.useContext)(y),n=null==o?void 0:o.previewCart,s=(0,c.useRef)(),a=(0,c.useRef)(k),d=(0,c.useRef)(E);(0,c.useEffect)((()=>((()=>{if(window.wcBlocksStoreCartListeners||(window.wcBlocksStoreCartListeners={count:0,remove:()=>{}}),(null===(e=window.wcBlocksStoreCartListeners)||void 0===e?void 0:e.count)>0)return void window.wcBlocksStoreCartListeners.count++;var e;document.body.addEventListener("wc-blocks_added_to_cart",f),document.body.addEventListener("wc-blocks_removed_from_cart",f),window.addEventListener("pageshow",C);const t=h("added_to_cart","wc-blocks_added_to_cart"),r=h("removed_from_cart","wc-blocks_removed_from_cart");window.wcBlocksStoreCartListeners.count=1,window.wcBlocksStoreCartListeners.remove=()=>{document.body.removeEventListener("wc-blocks_added_to_cart",f),document.body.removeEventListener("wc-blocks_removed_from_cart",f),window.removeEventListener("pageshow",C),t(),r()}})(),S)),[]);const u=(0,i.useSelect)(((e,{dispatch:o})=>{if(!t)return R;if(r)return{...R,cartCoupons:n.coupons,cartItems:n.items,crossSellsProducts:n.cross_sells,cartFees:n.fees,cartItemsCount:n.items_count,cartItemsWeight:n.items_weight,cartNeedsPayment:n.needs_payment,cartNeedsShipping:n.needs_shipping,cartTotals:n.totals,shippingRates:n.shipping_rates,cartHasCalculatedShipping:n.has_calculated_shipping,paymentMethods:n.payment_methods,paymentRequirements:n.payment_requirements,cartIsLoading:!1,receiveCart:"function"==typeof(null==n?void 0:n.receiveCart)?n.receiveCart:()=>{},receiveCartContents:"function"==typeof(null==n?void 0:n.receiveCartContents)?n.receiveCartContents:()=>{}};const s=e(l.cartStore),c=s.getCartData(),i=s.getCartErrors(),u=s.getCartTotals(),m=!s.hasFinishedResolution("getCartData"),_=s.isCustomerDataUpdating(),{receiveCart:b,receiveCartContents:g}=o(l.cartStore),y=c.fees.length>0?c.fees.map((e=>N(e))):l.EMPTY_CART_FEES,w=c.coupons.length>0?c.coupons.map((e=>({...e,label:e.code}))):l.EMPTY_CART_COUPONS,h=v(N(c.billingAddress)),f=c.needsShipping?v(N(c.shippingAddress)):h;return p()(h,a.current)||(a.current=h),p()(f,d.current)||(d.current=f),{cartCoupons:w,cartItems:c.items,crossSellsProducts:c.crossSells,cartFees:y,cartItemsCount:c.itemsCount,cartItemsWeight:c.itemsWeight,cartNeedsPayment:c.needsPayment,cartNeedsShipping:c.needsShipping,cartItemErrors:c.errors,cartTotals:u,cartIsLoading:m,cartErrors:i,billingData:a.current,billingAddress:a.current,shippingAddress:d.current,extensions:c.extensions,shippingRates:c.shippingRates,isLoadingRates:_,cartHasCalculatedShipping:c.hasCalculatedShipping,paymentRequirements:c.paymentRequirements,receiveCart:b,receiveCartContents:g}}),[t,r]);return s.current&&p()(s.current,u)||(s.current=u),s.current},L=(e,t)=>{const r=e.find((({id:e})=>e===t));return r?r.quantity:0};var P=r(4487),A=r(2796),I=r(1616);r(1546);const M=({product:e,className:t,style:r})=>{const{id:u,permalink:p,add_to_cart:m,has_options:b,is_purchasable:v,is_in_stock:y}=e,{dispatchStoreEvent:w}=(0,a.y)(),{cartQuantity:h,addingToCart:f,addToCart:C}=(e=>{const{addItemToCart:t}=(0,i.useDispatch)(l.cartStore),{cartItems:r,cartIsLoading:o}=x(),{createErrorNotice:n,removeNotice:s}=(0,i.useDispatch)("core/notices"),[a,u]=(0,c.useState)(!1),p=(0,c.useRef)(L(r,e));return(0,c.useEffect)((()=>{const t=L(r,e);t!==p.current&&(p.current=t)}),[r,e]),{cartQuantity:Number.isFinite(p.current)?p.current:0,addingToCart:a,cartIsLoading:o,addToCart:(r=1)=>(u(!0),t(e,r).then((()=>{s("add-to-cart")})).catch((e=>{n((0,d.decodeEntities)(e.message),{id:"add-to-cart",context:"wc/all-products",isDismissible:!0})})).finally((()=>{u(!1)})))}})(u),S=Number.isFinite(h)&&h>0,E=!b&&v&&y,k=(0,d.decodeEntities)((null==m?void 0:m.description)||""),T=S?(0,s.sprintf)(/* translators: %s number of products in cart. */ /* translators: %s number of products in cart. */ (0,s._n)("%d in cart","%d in cart",h,"woocommerce"),h):(0,d.decodeEntities)((null==m?void 0:m.text)||(0,s.__)("Add to cart","woocommerce")),N=E?"button":"a",R={};return E?R.onClick=async()=>{await C(),w("cart-add-item",{product:e});const{cartRedirectAfterAdd:t}=(0,g.getSetting)("productsSettings");t&&(window.location.href=_.Vo)}:(R.href=p,R.rel="nofollow",R.onClick=()=>{w("product-view-link",{product:e})}),(0,o.createElement)(N,{...R,"aria-label":k,disabled:f,className:(0,n.A)(t,"wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button",{loading:f,added:S}),style:r},T)},O=({className:e,style:t,isLoading:r})=>(0,o.createElement)("button",{className:(0,n.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":r},e),style:t,disabled:!0},(0,s.__)("Add to cart","woocommerce")),D=e=>{const{className:t,textAlign:r}=e,s=(0,P.p)(e),{parentClassName:a}=(0,A.useInnerBlockLayoutContext)(),{isLoading:c,product:i}=(0,A.useProductDataContext)();return(0,o.createElement)("div",{className:(0,n.A)(t,"wp-block-button","wc-block-components-product-button",{[`${a}__product-add-to-cart`]:a,[`align-${r}`]:r})},i.id?(0,o.createElement)(M,{product:i,style:s.style,className:s.className}):(0,o.createElement)(O,{style:s.style,className:s.className,isLoading:c}))},F=(0,I.withProductDataContext)(D)},4487:(e,t,r)=>{"use strict";r.d(t,{p:()=>l});var o=r(851),n=r(3993),s=r(1194),a=r(9786);function c(e={}){const t={};return(0,a.getCSSRules)(e,{selector:""}).forEach((e=>{t[e.key]=e.value})),t}function i(e,t){return e&&t?`has-${(0,s.c)(t)}-${e}`:""}const l=e=>{const t=(e=>{const t=(0,n.isObject)(e)?e:{style:{}};let r=t.style;return(0,n.isString)(r)&&(r=JSON.parse(r)||{}),(0,n.isObject)(r)||(r={}),{...t,style:r}})(e),r=function(e){var t,r,s,a,l,d;const{backgroundColor:u,textColor:p,gradient:m,style:_}=e,b=i("background-color",u),g=i("color",p),v=function(e){if(e)return`has-${e}-gradient-background`}(m),y=v||(null==_||null===(t=_.color)||void 0===t?void 0:t.gradient);return{className:(0,o.A)(g,v,{[b]:!y&&!!b,"has-text-color":p||(null==_||null===(r=_.color)||void 0===r?void 0:r.text),"has-background":u||(null==_||null===(s=_.color)||void 0===s?void 0:s.background)||m||(null==_||null===(a=_.color)||void 0===a?void 0:a.gradient),"has-link-color":(0,n.isObject)(null==_||null===(l=_.elements)||void 0===l?void 0:l.link)?null==_||null===(d=_.elements)||void 0===d||null===(d=d.link)||void 0===d?void 0:d.color:void 0}),style:c({color:(null==_?void 0:_.color)||{}})}}(t),s=function(e){var t;const r=(null===(t=e.style)||void 0===t?void 0:t.border)||{};return{className:function(e){var t;const{borderColor:r,style:n}=e,s=r?i("border-color",r):"";return(0,o.A)({"has-border-color":!!r||!(null==n||null===(t=n.border)||void 0===t||!t.color),[s]:!!s})}(e),style:c({border:r})}}(t),a=function(e){var t;return{className:void 0,style:c({spacing:(null===(t=e.style)||void 0===t?void 0:t.spacing)||{}})}}(t),l=(e=>{const t=(0,n.isObject)(e.style.typography)?e.style.typography:{},r=(0,n.isString)(t.fontFamily)?t.fontFamily:"";return{className:e.fontFamily?`has-${e.fontFamily}-font-family`:r,style:{fontSize:e.fontSize?`var(--wp--preset--font-size--${e.fontSize})`:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,textDecoration:t.textDecoration,textTransform:t.textTransform}}})(t);return{className:(0,o.A)(l.className,r.className,s.className,a.className),style:{...l.style,...r.style,...s.style,...a.style}}}},1546:()=>{}}]);