(()=>{"use strict";var e={20:(e,t,n)=>{var s=n(609),r=Symbol.for("react.element"),i=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,c=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,n){var s,i={},l=null,u=null;for(s in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,s)&&!a.hasOwnProperty(s)&&(i[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===i[s]&&(i[s]=t[s]);return{$$typeof:r,type:e,key:l,ref:u,props:i,_owner:c.current}}t.Fragment=i,t.jsx=l,t.jsxs=l},338:(e,t,n)=>{var s=n(795);t.H=s.createRoot,s.hydrateRoot},609:e=>{e.exports=window.React},795:e=>{e.exports=window.ReactDOM},848:(e,t,n)=>{e.exports=n(20)}},t={};function n(s){var r=t[s];if(void 0!==r)return r.exports;var i=t[s]={exports:{}};return e[s](i,i.exports,n),i.exports}var s=n(338);const r=window.wp.plugins,i=window.wc.blocksCheckout,o=window.wp.i18n,c=window.wc.priceFormat,a=window.wc.wcSettings;function l(e){return{day:(0,o._nx)("day","days",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),week:(0,o._nx)("week","weeks",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),month:(0,o._nx)("month","months",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),year:(0,o._nx)("year","years",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions")}}function u({billing_interval:e,billing_period:t},n,s){const r=l(e)[t];return n=n.trim(),1===e?`${s} ${n} ${r}`:(0,o.sprintf)(
/*
       * translators: %1$s is the price of the product. %2$s is the separator used e.g "every" or "/",
       * %3$d is the length, %4$s is week, month, year
       */
/*
       * translators: %1$s is the price of the product. %2$s is the separator used e.g "every" or "/",
       * %3$d is the length, %4$s is week, month, year
       */
(0,o.__)("%1$s %2$s %3$d %4$s","woocommerce-subscriptions"),s,n,e,r)}function p({subscriptionLength:e,billingInterval:t}){return e===t}var d=n(848);const m=(0,a.getSetting)("displayCartPricesIncludingTax",!1),g=({currency:e,values:t})=>{const{total_discount:n,total_discount_tax:s}=t,r=parseInt(n,10);if(!r)return null;const c=parseInt(s,10),a=m?r+c:r;return(0,d.jsx)(i.TotalsItem,{className:"wc-block-components-totals-discount",currency:e,label:(0,o.__)("Discount","woocommerce-subscriptions"),value:-1*a})},_=({values:e,currency:t,selectedRate:n,needsShipping:s,calculatedShipping:r})=>{if(!s||!r)return null;const c=m?parseInt(e.total_shipping,10)+parseInt(e.total_shipping_tax,10):parseInt(e.total_shipping,10),l=0===c&&(0,a.isWcVersion)("9.0",">=")?(0,d.jsx)("strong",{children:(0,o.__)("Free","woocommerce-subscriptions")}):c;return(0,d.jsx)(i.TotalsItem,{value:l,label:(0,o.__)("Shipping","woocommerce-subscriptions"),currency:t,description:!!n&&(0,o.sprintf)(
// translators: %s selected shipping rate (ex: flat rate)
// translators: %s selected shipping rate (ex: flat rate)
(0,o.__)("via %s","woocommerce-subscriptions"),n)})},b=({nextPaymentDate:e,subscriptionLength:t,billingPeriod:n,billingInterval:s})=>{const r=function({subscriptionLength:e,billingPeriod:t}){const n=l(e);return(0,o.sprintf)("For %1$d %2$s",e,n[t],"woocommerce-subscriptions")}({subscriptionLength:t,billingPeriod:n}),i=p({subscriptionLength:t,billingInterval:s})?(0,o.sprintf)(/* Translators: %1$s is a date. */ /* Translators: %1$s is a date. */
(0,o.__)("Due: %1$s","woocommerce-subscriptions"),e):(0,o.sprintf)(/* Translators: %1$s is a date. */ /* Translators: %1$s is a date. */
(0,o.__)("Starting: %1$s","woocommerce-subscriptions"),e);return(0,d.jsxs)("span",{children:[!!e&&i," ",!!t&&t>=s&&(0,d.jsx)("span",{className:"wcs-recurring-totals__subscription-length",children:r})]})},w=({currency:e,billingInterval:t,billingPeriod:n,nextPaymentDate:s,subscriptionLength:r,totals:c})=>{const a=p({billingInterval:t,subscriptionLength:r})?(0,o.__)("Total","woocommerce-subscriptions"):function({billingInterval:e,billingPeriod:t}){switch(e){case 1:if("day"===t)return(0,o.__)("Daily recurring total","woocommerce-subscriptions");if("week"===t)return(0,o.__)("Weekly recurring total","woocommerce-subscriptions");if("month"===t)return(0,o.__)("Monthly recurring total","woocommerce-subscriptions");if("year"===t)return(0,o.__)("Yearly recurring total","woocommerce-subscriptions");break;case 2:return(0,o.sprintf)(/* translators: %1$s is week, month, year */ /* translators: %1$s is week, month, year */
(0,o.__)("Recurring total every 2nd %1$s","woocommerce-subscriptions"),t);case 3:return(0,o.sprintf)(/* Translators: %1$s is week, month, year */ /* Translators: %1$s is week, month, year */
(0,o.__)("Recurring total every 3rd %1$s","woocommerce-subscriptions"),t);default:return(0,o.sprintf)(/* Translators: %1$d is number of weeks, months, days, years. %2$s is week, month, year */ /* Translators: %1$d is number of weeks, months, days, years. %2$s is week, month, year */
(0,o.__)("Recurring total every %1$dth %2$s","woocommerce-subscriptions"),e,t)}}({billingInterval:t,billingPeriod:n});return(0,d.jsx)(i.TotalsItem,{className:"wcs-recurring-totals-panel__title",currency:e,label:a,value:c,description:(0,d.jsx)(b,{nextPaymentDate:s,subscriptionLength:r,billingInterval:t,billingPeriod:n})})},h=({subscription:e,needsShipping:t,calculatedShipping:n})=>{const{totals:s,billing_interval:r,billing_period:a,next_payment_date:l,subscription_length:u,shipping_rates:p}=e;if(!l)return null;const b=p?.[0]?.shipping_rates?.find((({selected:e})=>e))?.name,h=(0,c.getCurrencyFromPriceResponse)(s);return(0,d.jsxs)("div",{className:"wcs-recurring-totals-panel",children:[(0,d.jsx)(w,{billingInterval:r,billingPeriod:a,nextPaymentDate:l,subscriptionLength:u,totals:parseInt(s.total_price,10),currency:h}),(0,d.jsxs)(i.Panel,{className:"wcs-recurring-totals-panel__details",initialOpen:!1,title:(0,o.__)("Details","woocommerce-subscriptions"),children:[(0,d.jsxs)(i.TotalsWrapper,{children:[(0,d.jsx)(i.Subtotal,{currency:h,values:s}),(0,d.jsx)(g,{currency:h,values:s})]}),(0,d.jsx)(i.TotalsWrapper,{className:"wc-block-components-totals-shipping",children:(0,d.jsx)(_,{currency:h,needsShipping:t,calculatedShipping:n,values:s,selectedRate:b})}),!m&&(0,d.jsx)(i.TotalsWrapper,{children:(0,d.jsx)(i.TotalsTaxes,{currency:h,values:s})}),(0,d.jsx)(i.TotalsWrapper,{children:(0,d.jsx)(i.TotalsItem,{className:"wcs-recurring-totals-panel__details-total",currency:h,label:(0,o.__)("Total","woocommerce-subscriptions"),value:parseInt(s.total_price,10)})})]})]})},f=({extensions:e,cart:t})=>{const{subscriptions:n}=e,{cartNeedsShipping:s,cartHasCalculatedShipping:r}=t;return n&&0!==n.length?n.map((({key:e,...t})=>(0,d.jsx)(h,{subscription:t,needsShipping:s,calculatedShipping:r},e))):null},x=window.wp.element,v=({extensions:e,collapsible:t,collapse:n,showItems:s,noResultsMessage:r,renderOption:i,components:o,context:c})=>{const{subscriptions:a=[]}=e,{ShippingRatesControlPackage:l}=o,u=(0,x.useMemo)((()=>Object.values(a).map((e=>e.shipping_rates)).filter(Boolean).flat()),[a]),p=(0,x.useMemo)((()=>u.length>1||n),[u.length,n]),m=(0,x.useMemo)((()=>u.length>1||s),[u.length,s]);return u.map((({package_id:e,...n})=>(0,d.jsx)(l,{packageId:e,packageData:n,collapsible:t,collapse:p,showItems:m,noResultsMessage:r,renderOption:i,highlightChecked:"woocommerce/checkout"===c},e)))};var y=n(609);const k=window.wp.components,j=window.wp.data,I=window.wp.url,S=({lineItem:e})=>{const[t,n]=(0,y.useState)(!1),[s,r]=(0,y.useState)(!1),[c,a]=(0,y.useState)(""),[l,u]=(0,y.useState)(!0),p="invalid-gifting-recipient",{setValidationErrors:m,clearValidationError:g}=(0,j.useDispatch)("wc/store/validation"),_=e?.querySelector(".wc-block-components-product-details__item-key .wc-block-components-product-details__value")?.textContent||"",b=(0,j.useSelect)((e=>{if(!_)return null;const t=e("wc/store/cart");if(!t)return null;try{const e=t.getCartData();return e?.items?.find((e=>e.key===_))||null}catch(e){return null}}),[_]),w=(0,y.useMemo)((()=>{if(!b?.item_data)return null;const e=b.item_data.find((e=>"gifting_to_hidden"===e.name));return e?.value||null}),[b]);(0,y.useEffect)((()=>{null!==w&&(a(w),n(!0))}),[w]),(0,y.useEffect)((()=>{if(!e)return;const t=e.querySelector(".wc-block-components-product-details__gifting-to-hidden");if(!t)return;const s=t.querySelector(".wc-block-components-product-details__value");a(s?s.textContent:""),n(!0)}),[e]);const h=e=>{if(!e&&!(0,I.isEmail)(c))return u(!1),void m({[p]:{message:(0,o.__)("Please enter a valid email address","woocommerce-subscriptions"),hidden:!1}});r(!1),u(!0),g(p),(0,i.extensionCartUpdate)({namespace:"wcsg-cart",data:{recipient:!0===e?"":c,itemKey:_}}).then((()=>{r(!1)})).catch((()=>{u(!1),r(!0),m({[p]:{message:(0,o.__)("Please enter a valid email address","woocommerce-subscriptions"),hidden:!1}})}))};return _?(0,d.jsxs)("div",{className:"wcsg-gifting-to-container",children:[(!t||s)&&(0,d.jsx)(k.CheckboxControl,{"aria-label":window.wcSettings.subscriptions_data.gifting_checkbox_text||(0,o.__)("This is a gift","woocommerce-subscriptions"),label:window.wcSettings.subscriptions_data.gifting_checkbox_text||(0,o.__)("This is a gift","woocommerce-subscriptions"),checked:t,onChange:e=>{n(e),r(e)}}),t&&!s&&(0,d.jsxs)("div",{className:"wcsg-gifting-to-container-view",children:[(0,d.jsxs)("span",{title:(0,o.__)("Gifting to","woocommerce-subscriptions"),children:[(0,o.__)("Gifting to:","woocommerce-subscriptions")," ",!s&&c]}),(0,d.jsx)(k.Button,{variant:"link",onClick:()=>r(!0),children:(0,o.__)("Edit","woocommerce-subscriptions")}),(0,d.jsx)(k.Button,{variant:"link","aria-label":(0,o.__)("Remove gift recipient","woocommerce-subscriptions"),onClick:()=>(n(!1),a(""),void h(!0)),children:(0,o.__)("Remove","woocommerce-subscriptions")})]}),s&&(0,d.jsxs)("div",{className:"wcsg-gifting-to-container-editing",children:[(0,d.jsx)(k.TextControl,{type:"email",className:"wc-block-components-text-input "+(l?"":"has-error"),value:c,onChange:e=>a(e),onFocus:()=>u(!0),"aria-label":(0,o.__)("Gifting recipient","woocommerce-subscriptions"),role:"textbox"}),(0,d.jsx)("button",{className:"wc-block-components-button wp-element-button gifting-update-button",onClick:()=>h(!1),name:"Update",children:(0,o.__)("Update","woocommerce-subscriptions")})]}),s&&!l&&(0,d.jsx)(i.ValidationInputError,{elementId:p,propertyName:p})]}):null};(0,r.registerPlugin)("woocommerce-subscriptions",{render:()=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.ExperimentalOrderShippingPackages,{children:(0,d.jsx)(v,{})}),(0,d.jsx)(i.ExperimentalOrderMeta,{children:(0,d.jsx)(f,{})})]}),scope:"woocommerce-checkout"}),(0,i.registerCheckoutFilters)("woocommerce-subscriptions",{totalLabel:(e,{subscriptions:t})=>t?.length>0?(0,o.__)("Total due today","woocommerce-subscriptions"):e,subtotalPriceFormat:(e,{subscriptions:t})=>{if(t?.billing_period&&t?.billing_interval){const{billing_interval:n,subscription_length:s}=t;return p({subscriptionLength:s,billingInterval:n})?u(t,1===s?
// translators: the word used to describe billing frequency, e.g. "for" 1 day or "for" 1 month.
// translators: the word used to describe billing frequency, e.g. "for" 1 day or "for" 1 month.
(0,o.__)("for 1","woocommerce-subscriptions"):
// translators: the word used to describe billing frequency, e.g. "for" 6 days or "for" 2 weeks.
// translators: the word used to describe billing frequency, e.g. "for" 6 days or "for" 2 weeks.
(0,o.__)("for","woocommerce-subscriptions"),e):u(t,
// translators: the word used to describe billing frequency, e.g. "every" 6 days or "every" 2 weeks.
// translators: the word used to describe billing frequency, e.g. "every" 6 days or "every" 2 weeks.
(0,o.__)("every","woocommerce-subscriptions"),e)}return e},saleBadgePriceFormat:(e,{subscriptions:t})=>t?.billing_period&&t?.billing_interval?u(t,"/",e):e,itemName:(e,{subscriptions:t})=>t?.is_resubscribe?(0,o.sprintf)(
// translators: %s Product name.
// translators: %s Product name.
(0,o.__)("%s (resubscription)","woocommerce-subscriptions"),e):t?.switch_type?(0,o.sprintf)(
// translators: %1$s Product name, %2$s Switch type (upgraded, downgraded, or crossgraded).
// translators: %1$s Product name, %2$s Switch type (upgraded, downgraded, or crossgraded).
(0,o.__)("%1$s (%2$s)","woocommerce-subscriptions"),e,function(e){switch(e){case"upgraded":return(0,o.__)("Upgrade","woocommerce-subscriptions");case"downgraded":return(0,o.__)("Downgrade","woocommerce-subscriptions");case"crossgraded":return(0,o.__)("Crossgrade","woocommerce-subscriptions");default:return""}}(t.switch_type)):e,cartItemPrice:(e,{subscriptions:t},{context:n})=>t?.sign_up_fees?"cart"===n?(0,o.sprintf)(/* translators: %s is the subscription price to pay immediately (ie: $10). */ /* translators: %s is the subscription price to pay immediately (ie: $10). */
(0,o.__)("Due today %s","woocommerce-subscriptions"),e):(0,o.sprintf)(/* translators: %s is the subscription price to pay immediately (ie: $10). */ /* translators: %s is the subscription price to pay immediately (ie: $10). */
(0,o.__)("%s due today","woocommerce-subscriptions"),e):e,placeOrderButtonLabel:e=>{const t=(0,a.getSetting)("subscriptions_data");return t?.place_order_override?t?.place_order_override:e}}),function(){const e=new MutationObserver(t);function t(){if(document.body.classList.contains("woocommerce-checkout"))return;const t=document.querySelectorAll(".wc-block-components-product-metadata");t.length&&e&&e.disconnect(),t.forEach((function(e,t){const n="my-custom-message-"+t;if(!document.getElementById(n)){const t=document.createElement("div");t.className="wcsg-block-recipient-container",t.id=n,e.parentNode.insertBefore(t,e)}(0,s.H)(document.getElementById(n)).render((0,d.jsx)(S,{lineItem:e}))}))}t(),e.observe(document.body,{childList:!0,subtree:!0})}()})();