????

Your IP : 3.16.44.178


Current Path : /home/webcloude/www/wp-content/plugins/woocommerce/assets/client/blocks/
Upload File :
Current File : /home/webcloude/www/wp-content/plugins/woocommerce/assets/client/blocks/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=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.priority&&((0,m.isNumber)(e.priority)&&(t.index=e.priority),(0,m.isString)(e.priority)&&(t.index=parseInt(e.priority,10))),e.hidden&&(t.required=!1),t},y=Object.entries(_.iI).map((([e,t])=>[e,Object.entries(t).map((([e,t])=>[e,b(t)])).reduce(((e,[t,r])=>(e[t]=r,e)),{})])).reduce(((e,[t,r])=>(e[t]=r,e)),{});r(3832);var v=r(5703);const g=e=>{const t=((e,t,r="")=>{const o=r&&void 0!==y[r]?y[r]:{};return e.map((e=>({key:e,...t[e]||{},...o[e]||{}}))).sort(((e,t)=>e.index-t.index))})(_.Hw,v.defaultFields,e.country),r=Object.assign({},e);return t.forEach((({key:t="",hidden:o=!1})=>{o&&((e,t)=>e in t)(t,e)&&(r[t]="")})),r},C=(0,c.createContext)({isEditor:!1,currentPostId:0,currentView:"",previewData:{},getPreviewData:()=>({})}),h=window.CustomEvent||null,w=(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(!h)return;o||(o=document.body);const s=new h(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.CART_STORE_KEY).invalidateResolutionForStore()},E=e=>{(null!=e&&e.persisted||"back_forward"===(window.performance&&window.performance.getEntriesByType("navigation").length?window.performance.getEntriesByType("navigation")[0].type:""))&&(0,i.dispatch)(l.CART_STORE_KEY).invalidateResolutionForStore()},S=()=>{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:""},k={...T,email:""},R={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)]))),A={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:R,cartIsLoading:!0,cartErrors:l.EMPTY_CART_ERRORS,billingData:k,billingAddress:k,shippingAddress:T,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)(C),n=null==o?void 0:o.previewCart,s=(0,c.useRef)(),a=(0,c.useRef)(k),d=(0,c.useRef)(T);(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",E);const t=w("added_to_cart","wc-blocks_added_to_cart"),r=w("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",E),t(),r()}})(),S)),[]);const u=(0,i.useSelect)(((e,{dispatch:o})=>{if(!t)return A;if(r)return{...A,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.CART_STORE_KEY),c=s.getCartData(),i=s.getCartErrors(),u=s.getCartTotals(),m=!s.hasFinishedResolution("getCartData"),_=s.isCustomerDataUpdating(),{receiveCart:b,receiveCartContents:y}=o(l.CART_STORE_KEY),v=c.fees.length>0?c.fees.map((e=>N(e))):l.EMPTY_CART_FEES,C=c.coupons.length>0?c.coupons.map((e=>({...e,label:e.code}))):l.EMPTY_CART_COUPONS,h=g(N(c.billingAddress)),w=c.needsShipping?g(N(c.shippingAddress)):h;return p()(h,a.current)||(a.current=h),p()(w,d.current)||(d.current=w),{cartCoupons:C,cartItems:c.items,crossSellsProducts:c.crossSells,cartFees:v,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:y}}),[t,r]);return s.current&&p()(s.current,u)||(s.current=u),s.current},P=(e,t)=>{const r=e.find((({id:e})=>e===t));return r?r.quantity:0};var I=r(4487),L=r(2796),O=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:y,is_in_stock:g}=e,{dispatchStoreEvent:C}=(0,a.y)(),{cartQuantity:h,addingToCart:w,addToCart:f}=(e=>{const{addItemToCart:t}=(0,i.useDispatch)(l.CART_STORE_KEY),{cartItems:r,cartIsLoading:o}=x(),{createErrorNotice:n,removeNotice:s}=(0,i.useDispatch)("core/notices"),[a,u]=(0,c.useState)(!1),p=(0,c.useRef)(P(r,e));return(0,c.useEffect)((()=>{const t=P(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),E=Number.isFinite(h)&&h>0,S=!b&&y&&g,T=(0,d.decodeEntities)((null==m?void 0:m.description)||""),k=E?(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")),R=S?"button":"a",N={};return S?N.onClick=async()=>{await f(),C("cart-add-item",{product:e});const{cartRedirectAfterAdd:t}=(0,v.getSetting)("productsSettings");t&&(window.location.href=_.Vo)}:(N.href=p,N.rel="nofollow",N.onClick=()=>{C("product-view-link",{product:e})}),(0,o.createElement)(R,{...N,"aria-label":T,disabled:w,className:(0,n.A)(t,"wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button",{loading:w,added:E}),style:r},k)},Y=({className:e,style:t})=>(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",e),style:t,disabled:!0}),D=e=>{const{className:t,textAlign:r}=e,s=(0,I.p)(e),{parentClassName:a}=(0,L.useInnerBlockLayoutContext)(),{product:c}=(0,L.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})},c.id?(0,o.createElement)(M,{product:c,style:s.style,className:s.className}):(0,o.createElement)(Y,{style:s.style,className:s.className}))},F=(0,O.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,u;const{backgroundColor:p,textColor:m,gradient:_,style:b}=e,y=i("background-color",p),v=i("color",m),g=function(e){if(e)return`has-${e}-gradient-background`}(_),C=g||(null==b||null===(t=b.color)||void 0===t?void 0:t.gradient);return{className:(0,o.A)(v,g,{[y]:!C&&!!y,"has-text-color":m||(null==b||null===(r=b.color)||void 0===r?void 0:r.text),"has-background":p||(null==b||null===(s=b.color)||void 0===s?void 0:s.background)||_||(null==b||null===(a=b.color)||void 0===a?void 0:a.gradient),"has-link-color":(0,n.isObject)(null==b||null===(l=b.elements)||void 0===l?void 0:l.link)?null==b||null===(d=b.elements)||void 0===d||null===(u=d.link)||void 0===u?void 0:u.color:void 0}),style:c({color:(null==b?void 0:b.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:()=>{}}]);