@lockerverse/react 0.2.168-dev.1 → 0.2.169-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MIGRATIONS.md CHANGED
@@ -36,6 +36,21 @@ If it cannot be found, report that limit and use the baseline review below. Do n
36
36
  claim that every historical migration was applied. Read this file even if the
37
37
  version already matches: a previous upgrade may have missed host adoption steps.
38
38
 
39
+ ## 0.2.169-dev.1 — six-month payment widgets
40
+
41
+ Affected: @lockerverse/sdk checkout and @lockerverse/react payment widgets.
42
+
43
+ - **Required:** upgrade both packages together before offering Products whose
44
+ `paymentOption` is `every-six-months`. This option requires a backend that
45
+ supports a Stripe month interval with an interval count of 6.
46
+ - **Automatic:** catalog validation, recurring selection, Stripe subscription
47
+ mode, checkout summaries, and payment buttons recognize the new option.
48
+ - **Recommended:** custom host price labels should show “Every 6 months”. Fixed
49
+ hosted product URLs must omit `amount` and `paymentOption` overrides.
50
+ - **Unchanged:** one-time, monthly, and annual Products retain their behavior.
51
+ - **Check:** load a six-month Product and confirm its amount and cadence before
52
+ submission. Do not submit a live payment for an integration check.
53
+
39
54
  ## 0.2.168-dev.1 — bank authorization terms
40
55
 
41
56
  - **Affected:** React payment widgets with ACH enabled.
package/README.md CHANGED
@@ -187,7 +187,7 @@ requires the current authoritative quote.
187
187
  This small example shows fixed-price Products. For a custom-price Product, ask
188
188
  for the amount in the host UI and pass `amountCents` with `productSlug`.
189
189
 
190
- For a monthly or annual Product, omit quantity. The component shows the
190
+ For a monthly, six-month, or annual Product, omit quantity. The component shows the
191
191
  cadence and configures Stripe Elements for a subscription:
192
192
 
193
193
  ```tsx
@@ -238,7 +238,7 @@ closes. Closing a dialog does not complete or cancel a payment.
238
238
  React dialog. The launcher selects its controls from each Product's existing
239
239
  capabilities. Visitors can set quantities for fixed one-time Products and add
240
240
  an inline amount for custom one-time Products. The launcher combines these
241
- one-time choices in one checkout. Monthly and annual Products are exclusive:
241
+ one-time choices in one checkout. Monthly, six-month, and annual Products are exclusive:
242
242
  the visitor selects one tier before the same `LockerversePayment` form opens in
243
243
  subscription mode.
244
244
 
@@ -1 +1 @@
1
- {"version":3,"file":"lockerverse-donate-launcher.d.ts","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"mappings":";;iBAwjBgB,4BACd,aACA,UACA,WACG,gBACF,iDAA8B,IAAA"}
1
+ {"version":3,"file":"lockerverse-donate-launcher.d.ts","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"mappings":";;iBA2jBgB,4BACd,aACA,UACA,WACG,gBACF,iDAA8B,IAAA"}
@@ -1,2 +1,2 @@
1
- import{n as e,t}from"./accent-contrast.js";import{n,t as r}from"./lockerverse-payment.js";import{createElement as i,useState as a}from"react";import{Fragment as o,jsx as s,jsxs as c}from"react/jsx-runtime";import{Dialog as l}from"@base-ui/react/dialog";import{getLockerverseMinimumCustomAmountCents as u}from"@lockerverse/sdk/checkout";const d=new Intl.NumberFormat(`en-US`,{currency:`USD`,style:`currency`}),f=/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,p=[1e3,2500,5e3,1e4];function m(e){if(!f.test(e))return null;let t=Math.round(Number(e)*100);return Number.isSafeInteger(t)&&t>0?t:null}function h(e,t){let n=``;return t===`monthly`&&(n=`/month`),t===`annually`&&(n=`/year`),`${d.format(e/100)}${n}`}function g({customAmounts:e,product:t,quantities:n,recurringProductId:r,setCustomAmounts:i,setQuantities:a,setRecurringProductId:o}){let l=n[t.id]??0;if(t.pricingMode===`fixed`&&t.paymentOption===`one-time`){let e=t.minimumQuantity??1,n=Math.min(t.maximumQuantity??1/0,t.inventoryQuantity??1/0);return c(`span`,{className:`lockerverse-launcher__quantity`,children:[s(`button`,{"aria-label":`Decrease ${t.name} quantity`,disabled:l===0,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r<=e?0:r-1}})},type:`button`,children:`−`}),s(`output`,{"aria-label":`${t.name} quantity`,children:l}),s(`button`,{"aria-label":`Increase ${t.name} quantity`,disabled:n<e||l>=n,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r===0?e:r+1}})},type:`button`,children:`+`})]})}return t.pricingMode===`custom`&&t.paymentOption===`one-time`?c(`span`,{className:`lockerverse-launcher__custom-amount`,children:[s(`span`,{"aria-hidden":`true`,children:`$`}),s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>{o(null),i(n=>({...n,[t.id]:e.target.value}))},placeholder:`0.00`,step:`0.01`,type:`number`,value:e[t.id]??``}),t.minimumAmountCents===null?null:c(`small`,{children:[`Minimum `,d.format(t.minimumAmountCents/100)]})]}):s(`button`,{"aria-label":`Select ${t.name}`,"aria-pressed":r===t.id,className:`lockerverse-launcher__select`,onClick:()=>{a({}),i({}),o(e=>e===t.id?null:t.id)},type:`button`,children:`Select`})}function _({variant:e=`default`,...t}){let{customAmounts:n,product:r,quantities:i,recurringProductId:a}=t,o=m(n[r.id]??``),l=a===r.id||r.paymentOption===`one-time`&&(r.pricingMode===`fixed`&&(i[r.id]??0)>0||r.pricingMode===`custom`&&o!==null&&o>=u(r));return c(`article`,{className:`lockerverse-launcher__product lockerverse-launcher__product--${e}`,"data-selected":l||void 0,children:[c(`span`,{className:`lockerverse-launcher__product-copy`,children:[s(`strong`,{className:`lockerverse-launcher__product-name`,children:r.name}),r.description?s(`small`,{children:r.description}):null,r.amountCents===null?null:s(`span`,{className:`lockerverse-launcher__product-price`,children:h(r.amountCents,r.paymentOption)})]}),s(g,{...t})]})}function v({customAmounts:e,product:t,setCustomAmounts:n,setRecurringProductId:r}){let i=e[t.id]??``,a=m(i),o=p.filter(e=>e>=u(t)),l=o.includes(a??0),f=e=>{r(null),n(n=>({...n,[t.id]:e}))};return s(`div`,{className:`lockerverse-launcher__donation-option`,children:c(`fieldset`,{className:`lockerverse-launcher__donation-choices`,children:[c(`legend`,{className:`lockerverse-launcher__sr-only`,children:[t.name,` amount`]}),s(`button`,{"aria-pressed":i===``,onClick:()=>f(``),type:`button`,children:`No thanks`}),o.map(e=>s(`button`,{"aria-pressed":a===e,onClick:()=>f(String(e/100)),type:`button`,children:d.format(e/100).replace(`.00`,``)},e)),s(`label`,{className:`lockerverse-launcher__donation-other`,"data-selected":i!==``&&!l||void 0,children:s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>f(e.target.value),placeholder:`Other $`,step:`0.01`,type:`number`,value:l?``:i})})]})})}function y({products:e,variant:t=`default`,...n}){return s(`div`,{className:`lockerverse-launcher__product-list`,children:e.map(e=>t===`donation`?i(v,{...n,key:e.id,product:e}):i(_,{...n,key:e.id,product:e,variant:t}))})}function b(e,t){let n=0,r=0;for(let i of t){let t=e.products.find(e=>e.slug===i.productSlug);if(t){if(`quantity`in i){n+=i.quantity,r+=(t.amountCents??0)*i.quantity;continue}n+=1,r+=`amountCents`in i?i.amountCents:t.amountCents??0}}return{amountCents:r,itemCount:n}}function x(){return s(`div`,{"aria-label":`Loading donation options`,className:`lockerverse-launcher__loading`,role:`status`,children:[0,1,2].map(e=>s(`span`,{"aria-hidden":`true`,className:`lockerverse-launcher__loading-row`},e))})}function S(e,t,n,r){if(r){let t=e.products.find(e=>e.id===r&&e.paymentOption!==`one-time`);return t?[{productSlug:t.slug}]:[]}return e.products.flatMap(e=>{let r=t[e.id]??0;if(e.pricingMode===`fixed`&&e.paymentOption===`one-time`&&r>0)return[{productSlug:e.slug,quantity:r}];let i=m(n[e.id]??``);return e.pricingMode===`custom`&&e.paymentOption===`one-time`&&i!==null&&i>=u(e)?[{amountCents:i,productSlug:e.slug}]:[]})}function C({catalog:e,onContinue:t,...n}){let r=S(e,n.quantities,n.customAmounts,n.recurringProductId),i=b(e,r),a=e.products.filter(e=>e.paymentOption===`one-time`&&e.pricingMode===`custom`),o=e.products.filter(e=>!a.includes(e));return c(`form`,{className:`lockerverse-launcher__products`,onSubmit:e=>{e.preventDefault(),r.length>0&&t(r)},children:[o.length>0?s(`section`,{className:`lockerverse-launcher__section`,children:s(y,{...n,products:o})}):null,a.length>0?c(`section`,{className:`lockerverse-launcher__donation`,children:[c(`header`,{className:`lockerverse-launcher__section-header`,children:[s(`h3`,{children:`Add a donation`}),s(`p`,{children:`Choose an amount to add to this order.`})]}),s(y,{...n,products:a,variant:`donation`})]}):null,e.products.length>0?c(`footer`,{className:`lockerverse-launcher__footer`,children:[c(`p`,{"aria-live":`polite`,className:`lockerverse-launcher__summary`,children:[s(`span`,{children:i.itemCount===0?`No items selected`:`${i.itemCount} ${i.itemCount===1?`item`:`items`} selected`}),i.itemCount===0?null:s(`strong`,{children:d.format(i.amountCents/100)})]}),s(`button`,{className:`lockerverse-launcher__continue`,disabled:r.length===0,type:`submit`,children:`Continue`})]}):null]})}function w({onEdit:e,paymentProps:t,selection:n,style:i,widget:a}){return c(`div`,{className:`lockerverse-launcher__checkout`,children:[s(`header`,{className:`lockerverse-launcher__checkout-toolbar`,children:s(`button`,{className:`lockerverse-launcher__back`,onClick:e,type:`button`,children:`Edit order`})}),s(r,{...t,selection:n,style:i,widget:a})]})}function T({catalog:e,checkout:t}){return t?c(o,{children:[s(l.Title,{className:`lockerverse-launcher__sr-only`,children:`Checkout`}),s(l.Description,{className:`lockerverse-launcher__sr-only`,children:`Review the order and complete payment.`})]}):e?c(`header`,{className:`lockerverse-launcher__header`,children:[e.community?c(`div`,{className:`lockerverse-launcher__brand`,children:[e.community.imageUrl?s(`img`,{alt:`${e.community.name} logo`,height:`28`,src:e.community.imageUrl,width:`28`}):null,s(`span`,{children:e.community.name})]}):null,s(l.Title,{className:`lockerverse-launcher__title`,children:e.widget.title??e.widget.name}),s(l.Description,{className:`lockerverse-launcher__description`,children:e.widget.description??`Choose your options, then continue to checkout.`})]}):c(`header`,{className:`lockerverse-launcher__header`,children:[s(l.Title,{className:`lockerverse-launcher__title`,children:`Donate`}),s(l.Description,{className:`lockerverse-launcher__description`,children:`Choose your options, then continue to checkout.`})]})}function E({buttonLabel:r=`Donate`,position:i=`inline`,widget:o,...u}){let[d,f]=a(null),[p,m]=a({}),[h,g]=a({}),[_,v]=a(null),{catalog:y,error:b,loading:S}=o,E=e(u.style?.[`--lockerverse-accent`]??y?.community?.accentColor??`#38d77a`),D=t(E),O={...u.style};(u.style?.[`--lockerverse-accent`]!==void 0||y?.community?.accentColor)&&(O[`--lockerverse-accent`]=E),D&&u.style?.[`--lockerverse-accent-contrast`]===void 0&&(O[`--lockerverse-accent-contrast`]=D);let k;return k=S?s(x,{}):b?c(`div`,{role:`alert`,children:[s(`p`,{children:`Unable to load donation options.`}),s(`button`,{onClick:o.refresh,type:`button`,children:`Retry`})]}):y?s(C,{catalog:y,customAmounts:p,onContinue:f,quantities:h,recurringProductId:_,setCustomAmounts:m,setQuantities:g,setRecurringProductId:v}):s(x,{}),!(S||b)&&d&&y&&(k=s(w,{onEdit:()=>f(null),paymentProps:u,selection:d,style:O,widget:o})),c(l.Root,{onOpenChange:e=>{e&&y&&u.stripeLoader===void 0&&requestAnimationFrame(()=>{n(y)})},children:[s(l.Trigger,{className:`lockerverse-launcher lockerverse-launcher--${i}`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:r}),c(l.Portal,{children:[s(l.Backdrop,{className:`lockerverse-launcher__backdrop`}),s(l.Viewport,{className:`lockerverse-launcher__viewport`,children:c(l.Popup,{className:`lockerverse-launcher__dialog`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:[s(T,{catalog:y,checkout:d!==null}),s(l.Close,{"aria-label":`Close donation dialog`,className:`lockerverse-launcher__close`,children:s(`span`,{"aria-hidden":`true`,children:`×`})}),k]})})]})]})}export{E as t};
1
+ import{n as e,t}from"./accent-contrast.js";import{n,t as r}from"./lockerverse-payment.js";import{createElement as i,useState as a}from"react";import{Fragment as o,jsx as s,jsxs as c}from"react/jsx-runtime";import{Dialog as l}from"@base-ui/react/dialog";import{getLockerverseMinimumCustomAmountCents as u}from"@lockerverse/sdk/checkout";const d=new Intl.NumberFormat(`en-US`,{currency:`USD`,style:`currency`}),f=/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,p=[1e3,2500,5e3,1e4];function m(e){if(!f.test(e))return null;let t=Math.round(Number(e)*100);return Number.isSafeInteger(t)&&t>0?t:null}function h(e,t){let n=``;return t===`monthly`&&(n=`/month`),t===`annually`&&(n=`/year`),t===`every-six-months`&&(n=` every 6 months`),`${d.format(e/100)}${n}`}function g({customAmounts:e,product:t,quantities:n,recurringProductId:r,setCustomAmounts:i,setQuantities:a,setRecurringProductId:o}){let l=n[t.id]??0;if(t.pricingMode===`fixed`&&t.paymentOption===`one-time`){let e=t.minimumQuantity??1,n=Math.min(t.maximumQuantity??1/0,t.inventoryQuantity??1/0);return c(`span`,{className:`lockerverse-launcher__quantity`,children:[s(`button`,{"aria-label":`Decrease ${t.name} quantity`,disabled:l===0,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r<=e?0:r-1}})},type:`button`,children:`−`}),s(`output`,{"aria-label":`${t.name} quantity`,children:l}),s(`button`,{"aria-label":`Increase ${t.name} quantity`,disabled:n<e||l>=n,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r===0?e:r+1}})},type:`button`,children:`+`})]})}return t.pricingMode===`custom`&&t.paymentOption===`one-time`?c(`span`,{className:`lockerverse-launcher__custom-amount`,children:[s(`span`,{"aria-hidden":`true`,children:`$`}),s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>{o(null),i(n=>({...n,[t.id]:e.target.value}))},placeholder:`0.00`,step:`0.01`,type:`number`,value:e[t.id]??``}),t.minimumAmountCents===null?null:c(`small`,{children:[`Minimum `,d.format(t.minimumAmountCents/100)]})]}):s(`button`,{"aria-label":`Select ${t.name}`,"aria-pressed":r===t.id,className:`lockerverse-launcher__select`,onClick:()=>{a({}),i({}),o(e=>e===t.id?null:t.id)},type:`button`,children:`Select`})}function _({variant:e=`default`,...t}){let{customAmounts:n,product:r,quantities:i,recurringProductId:a}=t,o=m(n[r.id]??``),l=a===r.id||r.paymentOption===`one-time`&&(r.pricingMode===`fixed`&&(i[r.id]??0)>0||r.pricingMode===`custom`&&o!==null&&o>=u(r));return c(`article`,{className:`lockerverse-launcher__product lockerverse-launcher__product--${e}`,"data-selected":l||void 0,children:[c(`span`,{className:`lockerverse-launcher__product-copy`,children:[s(`strong`,{className:`lockerverse-launcher__product-name`,children:r.name}),r.description?s(`small`,{children:r.description}):null,r.amountCents===null?null:s(`span`,{className:`lockerverse-launcher__product-price`,children:h(r.amountCents,r.paymentOption)})]}),s(g,{...t})]})}function v({customAmounts:e,product:t,setCustomAmounts:n,setRecurringProductId:r}){let i=e[t.id]??``,a=m(i),o=p.filter(e=>e>=u(t)),l=o.includes(a??0),f=e=>{r(null),n(n=>({...n,[t.id]:e}))};return s(`div`,{className:`lockerverse-launcher__donation-option`,children:c(`fieldset`,{className:`lockerverse-launcher__donation-choices`,children:[c(`legend`,{className:`lockerverse-launcher__sr-only`,children:[t.name,` amount`]}),s(`button`,{"aria-pressed":i===``,onClick:()=>f(``),type:`button`,children:`No thanks`}),o.map(e=>s(`button`,{"aria-pressed":a===e,onClick:()=>f(String(e/100)),type:`button`,children:d.format(e/100).replace(`.00`,``)},e)),s(`label`,{className:`lockerverse-launcher__donation-other`,"data-selected":i!==``&&!l||void 0,children:s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>f(e.target.value),placeholder:`Other $`,step:`0.01`,type:`number`,value:l?``:i})})]})})}function y({products:e,variant:t=`default`,...n}){return s(`div`,{className:`lockerverse-launcher__product-list`,children:e.map(e=>t===`donation`?i(v,{...n,key:e.id,product:e}):i(_,{...n,key:e.id,product:e,variant:t}))})}function b(e,t){let n=0,r=0;for(let i of t){let t=e.products.find(e=>e.slug===i.productSlug);if(t){if(`quantity`in i){n+=i.quantity,r+=(t.amountCents??0)*i.quantity;continue}n+=1,r+=`amountCents`in i?i.amountCents:t.amountCents??0}}return{amountCents:r,itemCount:n}}function x(){return s(`div`,{"aria-label":`Loading donation options`,className:`lockerverse-launcher__loading`,role:`status`,children:[0,1,2].map(e=>s(`span`,{"aria-hidden":`true`,className:`lockerverse-launcher__loading-row`},e))})}function S(e,t,n,r){if(r){let t=e.products.find(e=>e.id===r&&e.paymentOption!==`one-time`);return t?[{productSlug:t.slug}]:[]}return e.products.flatMap(e=>{let r=t[e.id]??0;if(e.pricingMode===`fixed`&&e.paymentOption===`one-time`&&r>0)return[{productSlug:e.slug,quantity:r}];let i=m(n[e.id]??``);return e.pricingMode===`custom`&&e.paymentOption===`one-time`&&i!==null&&i>=u(e)?[{amountCents:i,productSlug:e.slug}]:[]})}function C({catalog:e,onContinue:t,...n}){let r=S(e,n.quantities,n.customAmounts,n.recurringProductId),i=b(e,r),a=e.products.filter(e=>e.paymentOption===`one-time`&&e.pricingMode===`custom`),o=e.products.filter(e=>!a.includes(e));return c(`form`,{className:`lockerverse-launcher__products`,onSubmit:e=>{e.preventDefault(),r.length>0&&t(r)},children:[o.length>0?s(`section`,{className:`lockerverse-launcher__section`,children:s(y,{...n,products:o})}):null,a.length>0?c(`section`,{className:`lockerverse-launcher__donation`,children:[c(`header`,{className:`lockerverse-launcher__section-header`,children:[s(`h3`,{children:`Add a donation`}),s(`p`,{children:`Choose an amount to add to this order.`})]}),s(y,{...n,products:a,variant:`donation`})]}):null,e.products.length>0?c(`footer`,{className:`lockerverse-launcher__footer`,children:[c(`p`,{"aria-live":`polite`,className:`lockerverse-launcher__summary`,children:[s(`span`,{children:i.itemCount===0?`No items selected`:`${i.itemCount} ${i.itemCount===1?`item`:`items`} selected`}),i.itemCount===0?null:s(`strong`,{children:d.format(i.amountCents/100)})]}),s(`button`,{className:`lockerverse-launcher__continue`,disabled:r.length===0,type:`submit`,children:`Continue`})]}):null]})}function w({onEdit:e,paymentProps:t,selection:n,style:i,widget:a}){return c(`div`,{className:`lockerverse-launcher__checkout`,children:[s(`header`,{className:`lockerverse-launcher__checkout-toolbar`,children:s(`button`,{className:`lockerverse-launcher__back`,onClick:e,type:`button`,children:`Edit order`})}),s(r,{...t,selection:n,style:i,widget:a})]})}function T({catalog:e,checkout:t}){return t?c(o,{children:[s(l.Title,{className:`lockerverse-launcher__sr-only`,children:`Checkout`}),s(l.Description,{className:`lockerverse-launcher__sr-only`,children:`Review the order and complete payment.`})]}):e?c(`header`,{className:`lockerverse-launcher__header`,children:[e.community?c(`div`,{className:`lockerverse-launcher__brand`,children:[e.community.imageUrl?s(`img`,{alt:`${e.community.name} logo`,height:`28`,src:e.community.imageUrl,width:`28`}):null,s(`span`,{children:e.community.name})]}):null,s(l.Title,{className:`lockerverse-launcher__title`,children:e.widget.title??e.widget.name}),s(l.Description,{className:`lockerverse-launcher__description`,children:e.widget.description??`Choose your options, then continue to checkout.`})]}):c(`header`,{className:`lockerverse-launcher__header`,children:[s(l.Title,{className:`lockerverse-launcher__title`,children:`Donate`}),s(l.Description,{className:`lockerverse-launcher__description`,children:`Choose your options, then continue to checkout.`})]})}function E({buttonLabel:r=`Donate`,position:i=`inline`,widget:o,...u}){let[d,f]=a(null),[p,m]=a({}),[h,g]=a({}),[_,v]=a(null),{catalog:y,error:b,loading:S}=o,E=e(u.style?.[`--lockerverse-accent`]??y?.community?.accentColor??`#38d77a`),D=t(E),O={...u.style};(u.style?.[`--lockerverse-accent`]!==void 0||y?.community?.accentColor)&&(O[`--lockerverse-accent`]=E),D&&u.style?.[`--lockerverse-accent-contrast`]===void 0&&(O[`--lockerverse-accent-contrast`]=D);let k;return k=S?s(x,{}):b?c(`div`,{role:`alert`,children:[s(`p`,{children:`Unable to load donation options.`}),s(`button`,{onClick:o.refresh,type:`button`,children:`Retry`})]}):y?s(C,{catalog:y,customAmounts:p,onContinue:f,quantities:h,recurringProductId:_,setCustomAmounts:m,setQuantities:g,setRecurringProductId:v}):s(x,{}),!(S||b)&&d&&y&&(k=s(w,{onEdit:()=>f(null),paymentProps:u,selection:d,style:O,widget:o})),c(l.Root,{onOpenChange:e=>{e&&y&&u.stripeLoader===void 0&&requestAnimationFrame(()=>{n(y)})},children:[s(l.Trigger,{className:`lockerverse-launcher lockerverse-launcher--${i}`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:r}),c(l.Portal,{children:[s(l.Backdrop,{className:`lockerverse-launcher__backdrop`}),s(l.Viewport,{className:`lockerverse-launcher__viewport`,children:c(l.Popup,{className:`lockerverse-launcher__dialog`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:[s(T,{catalog:y,checkout:d!==null}),s(l.Close,{"aria-label":`Close donation dialog`,className:`lockerverse-launcher__close`,children:s(`span`,{"aria-hidden":`true`,children:`×`})}),k]})})]})]})}export{E as t};
2
2
  //# sourceMappingURL=lockerverse-donate-launcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lockerverse-donate-launcher.js","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"sourcesContent":["import { Dialog } from \"@base-ui/react/dialog\";\nimport {\n getLockerverseMinimumCustomAmountCents,\n type LockerverseCatalog,\n type LockerverseProduct,\n} from \"@lockerverse/sdk/checkout\";\nimport {\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n useState,\n} from \"react\";\nimport { getAccentContrast, normalizeAccentColor } from \"./accent-contrast.ts\";\nimport { LockerversePayment } from \"./lockerverse-payment.tsx\";\nimport { preloadLockerversePayment } from \"./payment-form.tsx\";\nimport type {\n LockerverseDonateLauncherProps,\n LockerversePaymentProps,\n LockerversePaymentSelectionItem,\n LockerversePaymentStyle,\n} from \"./types.ts\";\nimport type { UseLockerverseWidgetResult } from \"./use-lockerverse-widget.ts\";\n\nconst usd = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\nconst decimalAmountPattern = /^(?:0|[1-9]\\d*)(?:\\.\\d{1,2})?$/;\nconst suggestedDonationAmountsCents = [1000, 2500, 5000, 10_000];\n\nfunction parseAmountCents(value: string) {\n if (!decimalAmountPattern.test(value)) {\n return null;\n }\n const amountCents = Math.round(Number(value) * 100);\n return Number.isSafeInteger(amountCents) && amountCents > 0\n ? amountCents\n : null;\n}\n\nfunction formatProductPrice(\n amountCents: number,\n paymentOption: \"one-time\" | \"monthly\" | \"annually\"\n) {\n let cadence = \"\";\n if (paymentOption === \"monthly\") {\n cadence = \"/month\";\n }\n if (paymentOption === \"annually\") {\n cadence = \"/year\";\n }\n return `${usd.format(amountCents / 100)}${cadence}`;\n}\n\ntype LauncherProductControlProps = {\n customAmounts: Record<string, string>;\n product: LockerverseProduct;\n quantities: Record<string, number>;\n recurringProductId: string | null;\n setCustomAmounts: Dispatch<SetStateAction<Record<string, string>>>;\n setQuantities: Dispatch<SetStateAction<Record<string, number>>>;\n setRecurringProductId: Dispatch<SetStateAction<string | null>>;\n};\n\nfunction LauncherProductControl({\n customAmounts,\n product,\n quantities,\n recurringProductId,\n setCustomAmounts,\n setQuantities,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const quantity = quantities[product.id] ?? 0;\n if (product.pricingMode === \"fixed\" && product.paymentOption === \"one-time\") {\n const minimum = product.minimumQuantity ?? 1;\n const maximum = Math.min(\n product.maximumQuantity ?? Number.POSITIVE_INFINITY,\n product.inventoryQuantity ?? Number.POSITIVE_INFINITY\n );\n return (\n <span className=\"lockerverse-launcher__quantity\">\n <button\n aria-label={`Decrease ${product.name} quantity`}\n disabled={quantity === 0}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity <= minimum ? 0 : currentQuantity - 1,\n };\n });\n }}\n type=\"button\"\n >\n −\n </button>\n <output aria-label={`${product.name} quantity`}>{quantity}</output>\n <button\n aria-label={`Increase ${product.name} quantity`}\n disabled={maximum < minimum || quantity >= maximum}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity === 0 ? minimum : currentQuantity + 1,\n };\n });\n }}\n type=\"button\"\n >\n +\n </button>\n </span>\n );\n }\n\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\"\n ) {\n return (\n <span className=\"lockerverse-launcher__custom-amount\">\n <span aria-hidden=\"true\">$</span>\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: event.target.value,\n }));\n }}\n placeholder=\"0.00\"\n step=\"0.01\"\n type=\"number\"\n value={customAmounts[product.id] ?? \"\"}\n />\n {product.minimumAmountCents === null ? null : (\n <small>Minimum {usd.format(product.minimumAmountCents / 100)}</small>\n )}\n </span>\n );\n }\n\n return (\n <button\n aria-label={`Select ${product.name}`}\n aria-pressed={recurringProductId === product.id}\n className=\"lockerverse-launcher__select\"\n onClick={() => {\n setQuantities({});\n setCustomAmounts({});\n setRecurringProductId((current) =>\n current === product.id ? null : product.id\n );\n }}\n type=\"button\"\n >\n Select\n </button>\n );\n}\n\ntype LauncherProductOptionProps = LauncherProductControlProps & {\n variant?: \"default\" | \"donation\";\n};\n\nfunction LauncherProductOption({\n variant = \"default\",\n ...props\n}: LauncherProductOptionProps) {\n const { customAmounts, product, quantities, recurringProductId } = props;\n const customAmount = parseAmountCents(customAmounts[product.id] ?? \"\");\n const isSelected =\n recurringProductId === product.id ||\n (product.paymentOption === \"one-time\" &&\n ((product.pricingMode === \"fixed\" && (quantities[product.id] ?? 0) > 0) ||\n (product.pricingMode === \"custom\" &&\n customAmount !== null &&\n customAmount >= getLockerverseMinimumCustomAmountCents(product))));\n return (\n <article\n className={`lockerverse-launcher__product lockerverse-launcher__product--${variant}`}\n data-selected={isSelected || undefined}\n >\n <span className=\"lockerverse-launcher__product-copy\">\n <strong className=\"lockerverse-launcher__product-name\">\n {product.name}\n </strong>\n {product.description ? <small>{product.description}</small> : null}\n {product.amountCents === null ? null : (\n <span className=\"lockerverse-launcher__product-price\">\n {formatProductPrice(product.amountCents, product.paymentOption)}\n </span>\n )}\n </span>\n <LauncherProductControl {...props} />\n </article>\n );\n}\n\nfunction LauncherDonationOption({\n customAmounts,\n product,\n setCustomAmounts,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const amount = customAmounts[product.id] ?? \"\";\n const amountCents = parseAmountCents(amount);\n const suggestions = suggestedDonationAmountsCents.filter(\n (suggestion) =>\n suggestion >= getLockerverseMinimumCustomAmountCents(product)\n );\n const isSuggestedAmount = suggestions.includes(amountCents ?? 0);\n const setAmount = (value: string) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: value,\n }));\n };\n\n return (\n <div className=\"lockerverse-launcher__donation-option\">\n <fieldset className=\"lockerverse-launcher__donation-choices\">\n <legend className=\"lockerverse-launcher__sr-only\">\n {product.name} amount\n </legend>\n <button\n aria-pressed={amount === \"\"}\n onClick={() => setAmount(\"\")}\n type=\"button\"\n >\n No thanks\n </button>\n {suggestions.map((suggestion) => (\n <button\n aria-pressed={amountCents === suggestion}\n key={suggestion}\n onClick={() => setAmount(String(suggestion / 100))}\n type=\"button\"\n >\n {usd.format(suggestion / 100).replace(\".00\", \"\")}\n </button>\n ))}\n <label\n className=\"lockerverse-launcher__donation-other\"\n data-selected={amount !== \"\" && !isSuggestedAmount ? true : undefined}\n >\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => setAmount(event.target.value)}\n placeholder=\"Other $\"\n step=\"0.01\"\n type=\"number\"\n value={isSuggestedAmount ? \"\" : amount}\n />\n </label>\n </fieldset>\n </div>\n );\n}\n\ntype LauncherProductListProps = Omit<LauncherProductControlProps, \"product\"> & {\n products: LockerverseProduct[];\n variant?: LauncherProductOptionProps[\"variant\"];\n};\n\nfunction LauncherProductList({\n products,\n variant = \"default\",\n ...controlProps\n}: LauncherProductListProps) {\n return (\n <div className=\"lockerverse-launcher__product-list\">\n {products.map((product) =>\n variant === \"donation\" ? (\n <LauncherDonationOption\n {...controlProps}\n key={product.id}\n product={product}\n />\n ) : (\n <LauncherProductOption\n {...controlProps}\n key={product.id}\n product={product}\n variant={variant}\n />\n )\n )}\n </div>\n );\n}\n\nfunction getSelectionSummary(\n catalog: LockerverseCatalog,\n selection: LockerversePaymentSelectionItem[]\n) {\n let itemCount = 0;\n let amountCents = 0;\n for (const item of selection) {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n continue;\n }\n if (\"quantity\" in item) {\n itemCount += item.quantity;\n amountCents += (product.amountCents ?? 0) * item.quantity;\n continue;\n }\n itemCount += 1;\n amountCents +=\n \"amountCents\" in item ? item.amountCents : (product.amountCents ?? 0);\n }\n return { amountCents, itemCount };\n}\n\nfunction LauncherLoading() {\n return (\n <div\n aria-label=\"Loading donation options\"\n className=\"lockerverse-launcher__loading\"\n role=\"status\"\n >\n {[0, 1, 2].map((item) => (\n <span\n aria-hidden=\"true\"\n className=\"lockerverse-launcher__loading-row\"\n key={item}\n />\n ))}\n </div>\n );\n}\n\nfunction createLauncherSelection(\n catalog: LockerverseCatalog,\n quantities: Record<string, number>,\n customAmounts: Record<string, string>,\n recurringProductId: string | null\n): LockerversePaymentSelectionItem[] {\n if (recurringProductId) {\n const product = catalog.products.find(\n (candidate) =>\n candidate.id === recurringProductId &&\n candidate.paymentOption !== \"one-time\"\n );\n return product ? [{ productSlug: product.slug }] : [];\n }\n\n return catalog.products.flatMap(\n (product): LockerversePaymentSelectionItem[] => {\n const quantity = quantities[product.id] ?? 0;\n if (\n product.pricingMode === \"fixed\" &&\n product.paymentOption === \"one-time\" &&\n quantity > 0\n ) {\n return [{ productSlug: product.slug, quantity }];\n }\n const amountCents = parseAmountCents(customAmounts[product.id] ?? \"\");\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\" &&\n amountCents !== null &&\n amountCents >= getLockerverseMinimumCustomAmountCents(product)\n ) {\n return [{ amountCents, productSlug: product.slug }];\n }\n return [];\n }\n );\n}\n\ntype LauncherSelectionStateProps = Omit<LauncherProductControlProps, \"product\">;\n\ntype LauncherCatalogProps = LauncherSelectionStateProps & {\n catalog: LockerverseCatalog;\n onContinue: (selection: LockerversePaymentSelectionItem[]) => void;\n};\n\nfunction LauncherCatalog({\n catalog,\n onContinue,\n ...selectionState\n}: LauncherCatalogProps) {\n const draftSelection = createLauncherSelection(\n catalog,\n selectionState.quantities,\n selectionState.customAmounts,\n selectionState.recurringProductId\n );\n const summary = getSelectionSummary(catalog, draftSelection);\n const donationProducts = catalog.products.filter(\n (product) =>\n product.paymentOption === \"one-time\" && product.pricingMode === \"custom\"\n );\n const orderProducts = catalog.products.filter(\n (product) => !donationProducts.includes(product)\n );\n\n return (\n <form\n className=\"lockerverse-launcher__products\"\n onSubmit={(event) => {\n event.preventDefault();\n if (draftSelection.length > 0) {\n onContinue(draftSelection);\n }\n }}\n >\n {orderProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__section\">\n <LauncherProductList {...selectionState} products={orderProducts} />\n </section>\n ) : null}\n {donationProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__donation\">\n <header className=\"lockerverse-launcher__section-header\">\n <h3>Add a donation</h3>\n <p>Choose an amount to add to this order.</p>\n </header>\n <LauncherProductList\n {...selectionState}\n products={donationProducts}\n variant=\"donation\"\n />\n </section>\n ) : null}\n {catalog.products.length > 0 ? (\n <footer className=\"lockerverse-launcher__footer\">\n <p aria-live=\"polite\" className=\"lockerverse-launcher__summary\">\n <span>\n {summary.itemCount === 0\n ? \"No items selected\"\n : `${summary.itemCount} ${summary.itemCount === 1 ? \"item\" : \"items\"} selected`}\n </span>\n {summary.itemCount === 0 ? null : (\n <strong>{usd.format(summary.amountCents / 100)}</strong>\n )}\n </p>\n <button\n className=\"lockerverse-launcher__continue\"\n disabled={draftSelection.length === 0}\n type=\"submit\"\n >\n Continue\n </button>\n </footer>\n ) : null}\n </form>\n );\n}\n\ntype LauncherPaymentProps = Omit<\n LockerversePaymentProps,\n \"selection\" | \"widget\"\n>;\n\ntype LauncherCheckoutProps = {\n onEdit: () => void;\n paymentProps: LauncherPaymentProps;\n selection: LockerversePaymentSelectionItem[];\n style: LockerversePaymentStyle;\n widget: UseLockerverseWidgetResult;\n};\n\nfunction LauncherCheckout({\n onEdit,\n paymentProps,\n selection,\n style,\n widget,\n}: LauncherCheckoutProps) {\n return (\n <div className=\"lockerverse-launcher__checkout\">\n <header className=\"lockerverse-launcher__checkout-toolbar\">\n <button\n className=\"lockerverse-launcher__back\"\n onClick={onEdit}\n type=\"button\"\n >\n Edit order\n </button>\n </header>\n <LockerversePayment\n {...paymentProps}\n selection={selection}\n style={style}\n widget={widget}\n />\n </div>\n );\n}\n\nfunction LauncherDialogHeading({\n catalog,\n checkout,\n}: {\n catalog: LockerverseCatalog | null;\n checkout: boolean;\n}) {\n if (checkout) {\n return (\n <>\n <Dialog.Title className=\"lockerverse-launcher__sr-only\">\n Checkout\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__sr-only\">\n Review the order and complete payment.\n </Dialog.Description>\n </>\n );\n }\n\n if (!catalog) {\n return (\n <header className=\"lockerverse-launcher__header\">\n <Dialog.Title className=\"lockerverse-launcher__title\">\n Donate\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n Choose your options, then continue to checkout.\n </Dialog.Description>\n </header>\n );\n }\n\n return (\n <header className=\"lockerverse-launcher__header\">\n {catalog.community ? (\n <div className=\"lockerverse-launcher__brand\">\n {catalog.community.imageUrl ? (\n <img\n alt={`${catalog.community.name} logo`}\n height=\"28\"\n src={catalog.community.imageUrl}\n width=\"28\"\n />\n ) : null}\n <span>{catalog.community.name}</span>\n </div>\n ) : null}\n <Dialog.Title className=\"lockerverse-launcher__title\">\n {catalog.widget.title ?? catalog.widget.name}\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n {catalog.widget.description ??\n \"Choose your options, then continue to checkout.\"}\n </Dialog.Description>\n </header>\n );\n}\n\nexport function LockerverseDonateLauncher({\n buttonLabel = \"Donate\",\n position = \"inline\",\n widget,\n ...paymentProps\n}: LockerverseDonateLauncherProps) {\n const [selection, setSelection] = useState<\n LockerversePaymentSelectionItem[] | null\n >(null);\n const [customAmounts, setCustomAmounts] = useState<Record<string, string>>(\n {}\n );\n const [quantities, setQuantities] = useState<Record<string, number>>({});\n const [recurringProductId, setRecurringProductId] = useState<string | null>(\n null\n );\n const { catalog, error, loading } = widget;\n const accent = normalizeAccentColor(\n paymentProps.style?.[\"--lockerverse-accent\"] ??\n catalog?.community?.accentColor ??\n \"#38d77a\"\n );\n const accentContrast = getAccentContrast(accent);\n const launcherStyle: LockerversePaymentStyle = { ...paymentProps.style };\n if (\n paymentProps.style?.[\"--lockerverse-accent\"] !== undefined ||\n catalog?.community?.accentColor\n ) {\n launcherStyle[\"--lockerverse-accent\"] = accent;\n }\n if (\n accentContrast &&\n paymentProps.style?.[\"--lockerverse-accent-contrast\"] === undefined\n ) {\n launcherStyle[\"--lockerverse-accent-contrast\"] = accentContrast;\n }\n\n let content: ReactNode;\n if (loading) {\n content = <LauncherLoading />;\n } else if (error) {\n content = (\n <div role=\"alert\">\n <p>Unable to load donation options.</p>\n <button onClick={widget.refresh} type=\"button\">\n Retry\n </button>\n </div>\n );\n } else if (catalog) {\n content = (\n <LauncherCatalog\n catalog={catalog}\n customAmounts={customAmounts}\n onContinue={setSelection}\n quantities={quantities}\n recurringProductId={recurringProductId}\n setCustomAmounts={setCustomAmounts}\n setQuantities={setQuantities}\n setRecurringProductId={setRecurringProductId}\n />\n );\n } else {\n content = <LauncherLoading />;\n }\n if (!(loading || error) && selection && catalog) {\n content = (\n <LauncherCheckout\n onEdit={() => setSelection(null)}\n paymentProps={paymentProps}\n selection={selection}\n style={launcherStyle}\n widget={widget}\n />\n );\n }\n\n return (\n <Dialog.Root\n onOpenChange={(open) => {\n if (open && catalog && paymentProps.stripeLoader === undefined) {\n requestAnimationFrame(() => {\n preloadLockerversePayment(catalog);\n });\n }\n }}\n >\n <Dialog.Trigger\n className={`lockerverse-launcher lockerverse-launcher--${position}`}\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n {buttonLabel}\n </Dialog.Trigger>\n <Dialog.Portal>\n <Dialog.Backdrop className=\"lockerverse-launcher__backdrop\" />\n <Dialog.Viewport className=\"lockerverse-launcher__viewport\">\n <Dialog.Popup\n className=\"lockerverse-launcher__dialog\"\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n <LauncherDialogHeading\n catalog={catalog}\n checkout={selection !== null}\n />\n <Dialog.Close\n aria-label=\"Close donation dialog\"\n className=\"lockerverse-launcher__close\"\n >\n <span aria-hidden=\"true\">×</span>\n </Dialog.Close>\n {content}\n </Dialog.Popup>\n </Dialog.Viewport>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}\n"],"mappings":"gVAuBA,MAAM,EAAM,IAAI,KAAK,aAAa,QAAS,CACzC,SAAU,MACV,MAAO,UACT,CAAC,EACK,EAAuB,iCACvB,EAAgC,CAAC,IAAM,KAAM,IAAM,GAAM,EAE/D,SAAS,EAAiB,EAAe,CACvC,GAAI,CAAC,EAAqB,KAAK,CAAK,EAClC,OAAO,KAET,IAAM,EAAc,KAAK,MAAM,OAAO,CAAK,EAAI,GAAG,EAClD,OAAO,OAAO,cAAc,CAAW,GAAK,EAAc,EACtD,EACA,IACN,CAEA,SAAS,EACP,EACA,EACA,CACA,IAAI,EAAU,GAOd,OANI,IAAkB,YACpB,EAAU,UAER,IAAkB,aACpB,EAAU,SAEL,GAAG,EAAI,OAAO,EAAc,GAAG,IAAI,GAC5C,CAYA,SAAS,EAAuB,CAC9B,gBACA,UACA,aACA,qBACA,mBACA,gBACA,yBAC8B,CAC9B,IAAM,EAAW,EAAW,EAAQ,KAAO,EAC3C,GAAI,EAAQ,cAAgB,SAAW,EAAQ,gBAAkB,WAAY,CA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EAAC,EAAO,QAAR,CACE,UAAW,8CAA8C,IACzD,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAEN,SAAA,CACa,CAAA,EAChB,EAAC,EAAO,OAAR,CAAA,SAAA,CACE,EAAC,EAAO,SAAR,CAAiB,UAAU,gCAAkC,CAAA,EAC7D,EAAC,EAAO,SAAR,CAAiB,UAAU,iCACzB,SAAA,EAAC,EAAO,MAAR,CACE,UAAU,+BACV,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAHT,SAAA,CAKE,EAAC,EAAD,CACW,UACT,SAAU,IAAc,IACzB,CAAA,EACD,EAAC,EAAO,MAAR,CACE,aAAW,wBACX,UAAU,8BAEV,SAAA,EAAC,OAAD,CAAM,cAAY,OAAO,SAAA,GAAO,CAAA,CACpB,CAAA,EACb,CACW,GACC,CAAA,CACJ,CAAA,CAAA,CACJ,GAEjB"}
1
+ {"version":3,"file":"lockerverse-donate-launcher.js","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"sourcesContent":["import { Dialog } from \"@base-ui/react/dialog\";\nimport {\n getLockerverseMinimumCustomAmountCents,\n type LockerverseCatalog,\n type LockerverseProduct,\n} from \"@lockerverse/sdk/checkout\";\nimport {\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n useState,\n} from \"react\";\nimport { getAccentContrast, normalizeAccentColor } from \"./accent-contrast.ts\";\nimport { LockerversePayment } from \"./lockerverse-payment.tsx\";\nimport { preloadLockerversePayment } from \"./payment-form.tsx\";\nimport type {\n LockerverseDonateLauncherProps,\n LockerversePaymentProps,\n LockerversePaymentSelectionItem,\n LockerversePaymentStyle,\n} from \"./types.ts\";\nimport type { UseLockerverseWidgetResult } from \"./use-lockerverse-widget.ts\";\n\nconst usd = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\nconst decimalAmountPattern = /^(?:0|[1-9]\\d*)(?:\\.\\d{1,2})?$/;\nconst suggestedDonationAmountsCents = [1000, 2500, 5000, 10_000];\n\nfunction parseAmountCents(value: string) {\n if (!decimalAmountPattern.test(value)) {\n return null;\n }\n const amountCents = Math.round(Number(value) * 100);\n return Number.isSafeInteger(amountCents) && amountCents > 0\n ? amountCents\n : null;\n}\n\nfunction formatProductPrice(\n amountCents: number,\n paymentOption: \"one-time\" | \"monthly\" | \"annually\" | \"every-six-months\"\n) {\n let cadence = \"\";\n if (paymentOption === \"monthly\") {\n cadence = \"/month\";\n }\n if (paymentOption === \"annually\") {\n cadence = \"/year\";\n }\n if (paymentOption === \"every-six-months\") {\n cadence = \" every 6 months\";\n }\n return `${usd.format(amountCents / 100)}${cadence}`;\n}\n\ntype LauncherProductControlProps = {\n customAmounts: Record<string, string>;\n product: LockerverseProduct;\n quantities: Record<string, number>;\n recurringProductId: string | null;\n setCustomAmounts: Dispatch<SetStateAction<Record<string, string>>>;\n setQuantities: Dispatch<SetStateAction<Record<string, number>>>;\n setRecurringProductId: Dispatch<SetStateAction<string | null>>;\n};\n\nfunction LauncherProductControl({\n customAmounts,\n product,\n quantities,\n recurringProductId,\n setCustomAmounts,\n setQuantities,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const quantity = quantities[product.id] ?? 0;\n if (product.pricingMode === \"fixed\" && product.paymentOption === \"one-time\") {\n const minimum = product.minimumQuantity ?? 1;\n const maximum = Math.min(\n product.maximumQuantity ?? Number.POSITIVE_INFINITY,\n product.inventoryQuantity ?? Number.POSITIVE_INFINITY\n );\n return (\n <span className=\"lockerverse-launcher__quantity\">\n <button\n aria-label={`Decrease ${product.name} quantity`}\n disabled={quantity === 0}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity <= minimum ? 0 : currentQuantity - 1,\n };\n });\n }}\n type=\"button\"\n >\n −\n </button>\n <output aria-label={`${product.name} quantity`}>{quantity}</output>\n <button\n aria-label={`Increase ${product.name} quantity`}\n disabled={maximum < minimum || quantity >= maximum}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity === 0 ? minimum : currentQuantity + 1,\n };\n });\n }}\n type=\"button\"\n >\n +\n </button>\n </span>\n );\n }\n\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\"\n ) {\n return (\n <span className=\"lockerverse-launcher__custom-amount\">\n <span aria-hidden=\"true\">$</span>\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: event.target.value,\n }));\n }}\n placeholder=\"0.00\"\n step=\"0.01\"\n type=\"number\"\n value={customAmounts[product.id] ?? \"\"}\n />\n {product.minimumAmountCents === null ? null : (\n <small>Minimum {usd.format(product.minimumAmountCents / 100)}</small>\n )}\n </span>\n );\n }\n\n return (\n <button\n aria-label={`Select ${product.name}`}\n aria-pressed={recurringProductId === product.id}\n className=\"lockerverse-launcher__select\"\n onClick={() => {\n setQuantities({});\n setCustomAmounts({});\n setRecurringProductId((current) =>\n current === product.id ? null : product.id\n );\n }}\n type=\"button\"\n >\n Select\n </button>\n );\n}\n\ntype LauncherProductOptionProps = LauncherProductControlProps & {\n variant?: \"default\" | \"donation\";\n};\n\nfunction LauncherProductOption({\n variant = \"default\",\n ...props\n}: LauncherProductOptionProps) {\n const { customAmounts, product, quantities, recurringProductId } = props;\n const customAmount = parseAmountCents(customAmounts[product.id] ?? \"\");\n const isSelected =\n recurringProductId === product.id ||\n (product.paymentOption === \"one-time\" &&\n ((product.pricingMode === \"fixed\" && (quantities[product.id] ?? 0) > 0) ||\n (product.pricingMode === \"custom\" &&\n customAmount !== null &&\n customAmount >= getLockerverseMinimumCustomAmountCents(product))));\n return (\n <article\n className={`lockerverse-launcher__product lockerverse-launcher__product--${variant}`}\n data-selected={isSelected || undefined}\n >\n <span className=\"lockerverse-launcher__product-copy\">\n <strong className=\"lockerverse-launcher__product-name\">\n {product.name}\n </strong>\n {product.description ? <small>{product.description}</small> : null}\n {product.amountCents === null ? null : (\n <span className=\"lockerverse-launcher__product-price\">\n {formatProductPrice(product.amountCents, product.paymentOption)}\n </span>\n )}\n </span>\n <LauncherProductControl {...props} />\n </article>\n );\n}\n\nfunction LauncherDonationOption({\n customAmounts,\n product,\n setCustomAmounts,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const amount = customAmounts[product.id] ?? \"\";\n const amountCents = parseAmountCents(amount);\n const suggestions = suggestedDonationAmountsCents.filter(\n (suggestion) =>\n suggestion >= getLockerverseMinimumCustomAmountCents(product)\n );\n const isSuggestedAmount = suggestions.includes(amountCents ?? 0);\n const setAmount = (value: string) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: value,\n }));\n };\n\n return (\n <div className=\"lockerverse-launcher__donation-option\">\n <fieldset className=\"lockerverse-launcher__donation-choices\">\n <legend className=\"lockerverse-launcher__sr-only\">\n {product.name} amount\n </legend>\n <button\n aria-pressed={amount === \"\"}\n onClick={() => setAmount(\"\")}\n type=\"button\"\n >\n No thanks\n </button>\n {suggestions.map((suggestion) => (\n <button\n aria-pressed={amountCents === suggestion}\n key={suggestion}\n onClick={() => setAmount(String(suggestion / 100))}\n type=\"button\"\n >\n {usd.format(suggestion / 100).replace(\".00\", \"\")}\n </button>\n ))}\n <label\n className=\"lockerverse-launcher__donation-other\"\n data-selected={amount !== \"\" && !isSuggestedAmount ? true : undefined}\n >\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => setAmount(event.target.value)}\n placeholder=\"Other $\"\n step=\"0.01\"\n type=\"number\"\n value={isSuggestedAmount ? \"\" : amount}\n />\n </label>\n </fieldset>\n </div>\n );\n}\n\ntype LauncherProductListProps = Omit<LauncherProductControlProps, \"product\"> & {\n products: LockerverseProduct[];\n variant?: LauncherProductOptionProps[\"variant\"];\n};\n\nfunction LauncherProductList({\n products,\n variant = \"default\",\n ...controlProps\n}: LauncherProductListProps) {\n return (\n <div className=\"lockerverse-launcher__product-list\">\n {products.map((product) =>\n variant === \"donation\" ? (\n <LauncherDonationOption\n {...controlProps}\n key={product.id}\n product={product}\n />\n ) : (\n <LauncherProductOption\n {...controlProps}\n key={product.id}\n product={product}\n variant={variant}\n />\n )\n )}\n </div>\n );\n}\n\nfunction getSelectionSummary(\n catalog: LockerverseCatalog,\n selection: LockerversePaymentSelectionItem[]\n) {\n let itemCount = 0;\n let amountCents = 0;\n for (const item of selection) {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n continue;\n }\n if (\"quantity\" in item) {\n itemCount += item.quantity;\n amountCents += (product.amountCents ?? 0) * item.quantity;\n continue;\n }\n itemCount += 1;\n amountCents +=\n \"amountCents\" in item ? item.amountCents : (product.amountCents ?? 0);\n }\n return { amountCents, itemCount };\n}\n\nfunction LauncherLoading() {\n return (\n <div\n aria-label=\"Loading donation options\"\n className=\"lockerverse-launcher__loading\"\n role=\"status\"\n >\n {[0, 1, 2].map((item) => (\n <span\n aria-hidden=\"true\"\n className=\"lockerverse-launcher__loading-row\"\n key={item}\n />\n ))}\n </div>\n );\n}\n\nfunction createLauncherSelection(\n catalog: LockerverseCatalog,\n quantities: Record<string, number>,\n customAmounts: Record<string, string>,\n recurringProductId: string | null\n): LockerversePaymentSelectionItem[] {\n if (recurringProductId) {\n const product = catalog.products.find(\n (candidate) =>\n candidate.id === recurringProductId &&\n candidate.paymentOption !== \"one-time\"\n );\n return product ? [{ productSlug: product.slug }] : [];\n }\n\n return catalog.products.flatMap(\n (product): LockerversePaymentSelectionItem[] => {\n const quantity = quantities[product.id] ?? 0;\n if (\n product.pricingMode === \"fixed\" &&\n product.paymentOption === \"one-time\" &&\n quantity > 0\n ) {\n return [{ productSlug: product.slug, quantity }];\n }\n const amountCents = parseAmountCents(customAmounts[product.id] ?? \"\");\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\" &&\n amountCents !== null &&\n amountCents >= getLockerverseMinimumCustomAmountCents(product)\n ) {\n return [{ amountCents, productSlug: product.slug }];\n }\n return [];\n }\n );\n}\n\ntype LauncherSelectionStateProps = Omit<LauncherProductControlProps, \"product\">;\n\ntype LauncherCatalogProps = LauncherSelectionStateProps & {\n catalog: LockerverseCatalog;\n onContinue: (selection: LockerversePaymentSelectionItem[]) => void;\n};\n\nfunction LauncherCatalog({\n catalog,\n onContinue,\n ...selectionState\n}: LauncherCatalogProps) {\n const draftSelection = createLauncherSelection(\n catalog,\n selectionState.quantities,\n selectionState.customAmounts,\n selectionState.recurringProductId\n );\n const summary = getSelectionSummary(catalog, draftSelection);\n const donationProducts = catalog.products.filter(\n (product) =>\n product.paymentOption === \"one-time\" && product.pricingMode === \"custom\"\n );\n const orderProducts = catalog.products.filter(\n (product) => !donationProducts.includes(product)\n );\n\n return (\n <form\n className=\"lockerverse-launcher__products\"\n onSubmit={(event) => {\n event.preventDefault();\n if (draftSelection.length > 0) {\n onContinue(draftSelection);\n }\n }}\n >\n {orderProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__section\">\n <LauncherProductList {...selectionState} products={orderProducts} />\n </section>\n ) : null}\n {donationProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__donation\">\n <header className=\"lockerverse-launcher__section-header\">\n <h3>Add a donation</h3>\n <p>Choose an amount to add to this order.</p>\n </header>\n <LauncherProductList\n {...selectionState}\n products={donationProducts}\n variant=\"donation\"\n />\n </section>\n ) : null}\n {catalog.products.length > 0 ? (\n <footer className=\"lockerverse-launcher__footer\">\n <p aria-live=\"polite\" className=\"lockerverse-launcher__summary\">\n <span>\n {summary.itemCount === 0\n ? \"No items selected\"\n : `${summary.itemCount} ${summary.itemCount === 1 ? \"item\" : \"items\"} selected`}\n </span>\n {summary.itemCount === 0 ? null : (\n <strong>{usd.format(summary.amountCents / 100)}</strong>\n )}\n </p>\n <button\n className=\"lockerverse-launcher__continue\"\n disabled={draftSelection.length === 0}\n type=\"submit\"\n >\n Continue\n </button>\n </footer>\n ) : null}\n </form>\n );\n}\n\ntype LauncherPaymentProps = Omit<\n LockerversePaymentProps,\n \"selection\" | \"widget\"\n>;\n\ntype LauncherCheckoutProps = {\n onEdit: () => void;\n paymentProps: LauncherPaymentProps;\n selection: LockerversePaymentSelectionItem[];\n style: LockerversePaymentStyle;\n widget: UseLockerverseWidgetResult;\n};\n\nfunction LauncherCheckout({\n onEdit,\n paymentProps,\n selection,\n style,\n widget,\n}: LauncherCheckoutProps) {\n return (\n <div className=\"lockerverse-launcher__checkout\">\n <header className=\"lockerverse-launcher__checkout-toolbar\">\n <button\n className=\"lockerverse-launcher__back\"\n onClick={onEdit}\n type=\"button\"\n >\n Edit order\n </button>\n </header>\n <LockerversePayment\n {...paymentProps}\n selection={selection}\n style={style}\n widget={widget}\n />\n </div>\n );\n}\n\nfunction LauncherDialogHeading({\n catalog,\n checkout,\n}: {\n catalog: LockerverseCatalog | null;\n checkout: boolean;\n}) {\n if (checkout) {\n return (\n <>\n <Dialog.Title className=\"lockerverse-launcher__sr-only\">\n Checkout\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__sr-only\">\n Review the order and complete payment.\n </Dialog.Description>\n </>\n );\n }\n\n if (!catalog) {\n return (\n <header className=\"lockerverse-launcher__header\">\n <Dialog.Title className=\"lockerverse-launcher__title\">\n Donate\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n Choose your options, then continue to checkout.\n </Dialog.Description>\n </header>\n );\n }\n\n return (\n <header className=\"lockerverse-launcher__header\">\n {catalog.community ? (\n <div className=\"lockerverse-launcher__brand\">\n {catalog.community.imageUrl ? (\n <img\n alt={`${catalog.community.name} logo`}\n height=\"28\"\n src={catalog.community.imageUrl}\n width=\"28\"\n />\n ) : null}\n <span>{catalog.community.name}</span>\n </div>\n ) : null}\n <Dialog.Title className=\"lockerverse-launcher__title\">\n {catalog.widget.title ?? catalog.widget.name}\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n {catalog.widget.description ??\n \"Choose your options, then continue to checkout.\"}\n </Dialog.Description>\n </header>\n );\n}\n\nexport function LockerverseDonateLauncher({\n buttonLabel = \"Donate\",\n position = \"inline\",\n widget,\n ...paymentProps\n}: LockerverseDonateLauncherProps) {\n const [selection, setSelection] = useState<\n LockerversePaymentSelectionItem[] | null\n >(null);\n const [customAmounts, setCustomAmounts] = useState<Record<string, string>>(\n {}\n );\n const [quantities, setQuantities] = useState<Record<string, number>>({});\n const [recurringProductId, setRecurringProductId] = useState<string | null>(\n null\n );\n const { catalog, error, loading } = widget;\n const accent = normalizeAccentColor(\n paymentProps.style?.[\"--lockerverse-accent\"] ??\n catalog?.community?.accentColor ??\n \"#38d77a\"\n );\n const accentContrast = getAccentContrast(accent);\n const launcherStyle: LockerversePaymentStyle = { ...paymentProps.style };\n if (\n paymentProps.style?.[\"--lockerverse-accent\"] !== undefined ||\n catalog?.community?.accentColor\n ) {\n launcherStyle[\"--lockerverse-accent\"] = accent;\n }\n if (\n accentContrast &&\n paymentProps.style?.[\"--lockerverse-accent-contrast\"] === undefined\n ) {\n launcherStyle[\"--lockerverse-accent-contrast\"] = accentContrast;\n }\n\n let content: ReactNode;\n if (loading) {\n content = <LauncherLoading />;\n } else if (error) {\n content = (\n <div role=\"alert\">\n <p>Unable to load donation options.</p>\n <button onClick={widget.refresh} type=\"button\">\n Retry\n </button>\n </div>\n );\n } else if (catalog) {\n content = (\n <LauncherCatalog\n catalog={catalog}\n customAmounts={customAmounts}\n onContinue={setSelection}\n quantities={quantities}\n recurringProductId={recurringProductId}\n setCustomAmounts={setCustomAmounts}\n setQuantities={setQuantities}\n setRecurringProductId={setRecurringProductId}\n />\n );\n } else {\n content = <LauncherLoading />;\n }\n if (!(loading || error) && selection && catalog) {\n content = (\n <LauncherCheckout\n onEdit={() => setSelection(null)}\n paymentProps={paymentProps}\n selection={selection}\n style={launcherStyle}\n widget={widget}\n />\n );\n }\n\n return (\n <Dialog.Root\n onOpenChange={(open) => {\n if (open && catalog && paymentProps.stripeLoader === undefined) {\n requestAnimationFrame(() => {\n preloadLockerversePayment(catalog);\n });\n }\n }}\n >\n <Dialog.Trigger\n className={`lockerverse-launcher lockerverse-launcher--${position}`}\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n {buttonLabel}\n </Dialog.Trigger>\n <Dialog.Portal>\n <Dialog.Backdrop className=\"lockerverse-launcher__backdrop\" />\n <Dialog.Viewport className=\"lockerverse-launcher__viewport\">\n <Dialog.Popup\n className=\"lockerverse-launcher__dialog\"\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n <LauncherDialogHeading\n catalog={catalog}\n checkout={selection !== null}\n />\n <Dialog.Close\n aria-label=\"Close donation dialog\"\n className=\"lockerverse-launcher__close\"\n >\n <span aria-hidden=\"true\">×</span>\n </Dialog.Close>\n {content}\n </Dialog.Popup>\n </Dialog.Viewport>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}\n"],"mappings":"gVAuBA,MAAM,EAAM,IAAI,KAAK,aAAa,QAAS,CACzC,SAAU,MACV,MAAO,UACT,CAAC,EACK,EAAuB,iCACvB,EAAgC,CAAC,IAAM,KAAM,IAAM,GAAM,EAE/D,SAAS,EAAiB,EAAe,CACvC,GAAI,CAAC,EAAqB,KAAK,CAAK,EAClC,OAAO,KAET,IAAM,EAAc,KAAK,MAAM,OAAO,CAAK,EAAI,GAAG,EAClD,OAAO,OAAO,cAAc,CAAW,GAAK,EAAc,EACtD,EACA,IACN,CAEA,SAAS,EACP,EACA,EACA,CACA,IAAI,EAAU,GAUd,OATI,IAAkB,YACpB,EAAU,UAER,IAAkB,aACpB,EAAU,SAER,IAAkB,qBACpB,EAAU,mBAEL,GAAG,EAAI,OAAO,EAAc,GAAG,IAAI,GAC5C,CAYA,SAAS,EAAuB,CAC9B,gBAC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AO,KAAR,CACE,aAAe,GAAS,CAClB,GAAQ,GAAW,EAAa,eAAiB,IAAA,IACnD,0BAA4B,CAC1B,EAA0B,CAAO,CACnC,CAAC,CAEL,EAPF,SAAA,CASE,EAAC,EAAO,QAAR,CACE,UAAW,8CAA8C,IACzD,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAEN,SAAA,CACa,CAAA,EAChB,EAAC,EAAO,OAAR,CAAA,SAAA,CACE,EAAC,EAAO,SAAR,CAAiB,UAAU,gCAAkC,CAAA,EAC7D,EAAC,EAAO,SAAR,CAAiB,UAAU,iCACzB,SAAA,EAAC,EAAO,MAAR,CACE,UAAU,+BACV,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAHT,SAAA,CAKE,EAAC,EAAD,CACW,UACT,SAAU,IAAc,IACzB,CAAA,EACD,EAAC,EAAO,MAAR,CACE,aAAW,wBACX,UAAU,8BAEV,SAAA,EAAC,OAAD,CAAM,cAAY,OAAO,SAAA,GAAO,CAAA,CACpB,CAAA,EACb,CACW,GACC,CAAA,CACJ,CAAA,CAAA,CACJ,GAEjB"}
@@ -1,2 +1,2 @@
1
- import{t as e}from"./format-money.js";import{t}from"./host-callback.js";import{n,t as r}from"./accent-contrast.js";import{d as i,i as a,n as o,p as s,t as c,u as l}from"./phone-field.js";import{a as u,i as d,n as f,r as p,s as m}from"./custom-fields.js";import{t as h}from"./form-skeleton.js";import{t as g}from"./payment-summary.js";import{i as _,n as v,r as y,t as b}from"./stripe-loader.js";import{useCallback as x,useEffect as S,useId as C,useLayoutEffect as w,useMemo as T,useReducer as E,useRef as D,useState as O}from"react";import{Fragment as k,jsx as A,jsxs as j}from"react/jsx-runtime";import{LockerverseSdkError as M,estimateLockerverseCheckout as N}from"@lockerverse/sdk/checkout";import{AddressElement as P,Elements as F,PaymentElement as I,useElements as L,useStripe as R}from"@stripe/react-stripe-js";import{array as z,minLength as B,minValue as V,nonEmpty as H,number as U,pipe as W,regex as ee,safeInteger as te,safeParse as ne,strictObject as re,string as ie,trim as ae,union as G}from"valibot";function oe({ariaDescribedBy:e,ariaLabel:t,ariaLabelledBy:n,className:r,id:i,invalid:a=!1,name:o,onValueChange:s,options:c,value:l}){return A(`select`,{"aria-describedby":e,"aria-invalid":a||void 0,"aria-label":t,"aria-labelledby":n,className:[`lockerverse-form__control`,`lockerverse-form__select`,r].filter(Boolean).join(` `),id:i,name:o,onChange:e=>s(e.currentTarget.value),value:l,children:c.map(e=>A(`option`,{value:e.value,children:e.label},e.value))})}const se=[`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`],ce=[`15`,`12`,`10`,`5`],K=[...ce,`custom`];function le({enabled:e,error:t,errorId:n,onChange:r,values:i}){if(!e)return null;let a=e=>r({...i,...e}),o=(e,t)=>{let n=K.indexOf(t),r;switch(e.key){case`ArrowDown`:case`ArrowRight`:r=(n+1)%K.length;break;case`ArrowLeft`:case`ArrowUp`:r=(n-1+K.length)%K.length;break;case`Home`:r=0;break;case`End`:r=K.length-1;break;default:return}e.preventDefault();let i=K[r];i&&((e.currentTarget.closest(`[role="radiogroup"]`)?.querySelectorAll(`input[type="radio"]`))?.[r]?.focus(),a({tipPercent:i}))};return j(`div`,{className:`lockerverse-payment__tip-box`,children:[A(`p`,{children:`Add a tip to support the Lockerverse platform`}),j(`div`,{"aria-label":`Tip amount`,role:`radiogroup`,children:[ce.map(e=>j(`label`,{className:`lockerverse-payment__tip-choice`,children:[A(`input`,{checked:i.tipPercent===e,name:`tipPercent`,onChange:()=>a({tipPercent:e}),onKeyDown:t=>o(t,e),tabIndex:i.tipPercent===e?0:-1,type:`radio`,value:e}),j(`span`,{children:[e,`%`]})]},e)),j(`label`,{className:`lockerverse-payment__tip-choice`,children:[A(`input`,{checked:i.tipPercent===`custom`,name:`tipPercent`,onChange:()=>a({tipPercent:`custom`}),onKeyDown:e=>o(e,`custom`),tabIndex:i.tipPercent===`custom`?0:-1,type:`radio`,value:`custom`}),A(`span`,{children:`Other`})]})]}),i.tipPercent===`custom`?j(`label`,{children:[A(`span`,{children:`Custom tip`}),j(`span`,{className:`lockerverse-payment__money-input`,children:[A(`span`,{"aria-hidden":`true`,children:`$`}),A(`input`,{"aria-describedby":t?n:void 0,"aria-invalid":t?`true`:void 0,inputMode:`decimal`,name:`tip`,onChange:e=>a({customTip:e.currentTarget.value}),placeholder:`0.00`,value:i.customTip})]}),t?A(`span`,{className:`lockerverse-payment__field-message`,id:n,children:t}):null]}):A(`input`,{name:`tip`,type:`hidden`,value:i.tipPercent})]})}function ue({checked:e,children:t,name:n,onChange:r}){let i=C();return j(`label`,{className:`lockerverse-payment__check-row`,htmlFor:i,children:[A(l,{checked:e,id:i,name:n,onChange:e=>r(e.currentTarget.checked)}),A(`span`,{children:t})]})}function de({customFields:e,errors:t,fields:n,idPrefix:r,isPromoApplying:i,memberIdLabel:a,onChange:o,onApplyPromo:s,promoError:c,values:l}){let u=e=>o({...l,...e});return j(`div`,{className:`lockerverse-payment__additional-fields`,children:[n.memberId?j(`label`,{children:[A(`span`,{children:a?.trim()||`Member ID`}),A(`input`,{name:`memberId`,onChange:e=>u({memberId:e.currentTarget.value}),placeholder:`Optional`,value:l.memberId})]}):null,n.merchSize?j(`div`,{className:`lockerverse-payment__field`,children:[A(`span`,{id:`${r}-merch-size-label`,children:`Size`}),A(oe,{ariaLabelledBy:`${r}-merch-size-label`,name:`merchSize`,onValueChange:e=>{let t=se.find(t=>t===e);t&&u({merchSize:t})},options:se.map(e=>({label:e,value:e})),value:l.merchSize})]}):null,n.promoCode?j(`div`,{className:`lockerverse-payment__field`,children:[A(`span`,{id:`${r}-promo-code-label`,children:`Promo code`}),j(`div`,{className:`lockerverse-payment__promo-control`,children:[A(`input`,{"aria-describedby":c?`${r}-promo-code-error`:void 0,"aria-invalid":c?`true`:void 0,"aria-labelledby":`${r}-promo-code-label`,name:`promoCode`,onChange:e=>u({promoCode:e.currentTarget.value}),placeholder:`Optional`,value:l.promoCode}),A(`button`,{disabled:!l.promoCode.trim()||i,onClick:s,type:`button`,children:i?`Applying…`:`Apply`})]}),c?A(`p`,{className:`lockerverse-payment__field-message`,id:`${r}-promo-code-error`,role:`alert`,children:c}):null]}):null,A(f,{choiceClassName:`lockerverse-payment__check-row`,errorClassName:`lockerverse-payment__field-message`,errors:t,fields:e,idPrefix:r,onChange:e=>u({customFields:e}),values:l.customFields})]})}function fe({amountCents:t,enabled:n,onChange:r,values:i}){return n?j(ue,{checked:i.includeServiceFee,name:`includeServiceFee`,onChange:e=>r({...i,includeServiceFee:e}),children:[`Add `,e(t),` to help cover processing fees`]}):null}function q(e){return{error:void 0,message:void 0,status:e?`recovering`:`editing`}}function J(e,t,n){return t.includes(e.status)?{...e,...n}:e}function pe(e,t){if(e.status===`sold_out`||e.status===`succeeded`||e.status===`unresolved`)return e;switch(t.type){case`field_changed`:return J(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`editing`});case`validation_failed`:return J(e,[`editing`],{status:`invalid`});case`quote_refresh_started`:return J(e,[`editing`,`invalid`],{status:`refreshing_quote`});case`quote_refresh_succeeded`:return J(e,[`refreshing_quote`],{error:void 0,status:`editing`});case`quote_refresh_failed`:return J(e,[`refreshing_quote`],{error:t.error??e.error,status:`editing`});case`submission_started`:return J(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`submitting`});case`submission_validation_failed`:return J(e,[`submitting`],{error:void 0,status:`invalid`});case`quote_changed`:return J(e,[`submitting`],{status:`editing`});case`retryable_failure`:return J(e,[`editing`,`invalid`,`submitting`],{error:t.error,status:`editing`});case`recovery_failed`:return J(e,[`recovering`],{error:t.error,status:`editing`});case`sold_out`:return{error:void 0,message:void 0,status:`sold_out`};case`succeeded`:return J(e,[`recovering`,`submitting`],{message:t.message,status:`succeeded`});case`unresolved`:{let n={message:t.message,status:`unresolved`};return t.retryUrl&&(n.retryUrl=t.retryUrl),J(e,[`recovering`,`submitting`],n)}default:return e}}function me(e){return e.status===`editing`||e.status===`invalid`||e.status===`refreshing_quote`?e.error:void 0}function Y(e){return e.status===`sold_out`?`sold_out`:e.status===`succeeded`?`success`:e.status===`unresolved`?`unresolved`:e.status===`submitting`||e.status===`recovering`?`submitting`:e.status===`invalid`?`invalid`:me(e)?`error`:`idle`}function X(e){return e.status===`submitting`}const he=[`amountCents`,`discountableSubtotalCents`,`discountCents`,`serviceFeeCents`,`subtotalCents`,`tipCents`,`totalCents`],ge=[`discountableSubtotalCents`,`discountCents`,`subtotalCents`];function _e(e,t,n,r){return(n===t.totalCents?ge:he).some(n=>e[n]!==t[n])||r!==t.payment.connectedAccountId||e.authoritative&&(e.payment.connectedAccountId!==r||e.payment.currency!==t.payment.currency)||JSON.stringify(e.appliedDiscount)!==JSON.stringify(t.appliedDiscount)||JSON.stringify(e.lineItems)!==JSON.stringify(t.lineItems)}function ve(e){if(e.checkoutStatus===`success`)return{kind:`success`,payment:e};if(e.checkoutStatus===`failed`)return{kind:`failed`,payment:e};let t={kind:`unresolved`,paymentReference:e.paymentReference,reason:e.checkoutStatus===`action_required`?`action_required`:`pending`};return e.retryUrl&&(t.retryUrl=e.retryUrl),t}async function Z(e,t,n){if(t.checkoutStatus!==`action_required`||!t.requiresAction)return ve(t);if(!n)return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`};if(t.clientSecret)try{await n.handleNextAction({clientSecret:t.clientSecret})}catch{}try{return ve(await e.getPaymentStatus(t.paymentReference))}catch{return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`}}}async function ye(e,t,n){let r;try{r=await e.submitPayment(t)}catch(n){if(!(n instanceof M&&n.recoveryRecommended))throw n;try{r=await e.getPaymentStatus(t.checkout.paymentReference)}catch{return{kind:`unresolved`,paymentReference:t.checkout.paymentReference,reason:`recovery_failed`}}}return Z(e,r,n)}async function be(e,t,n){try{return Z(e,await e.getPaymentStatus(t),n)}catch{return{kind:`unresolved`,paymentReference:t,reason:`recovery_failed`}}}const xe=W(ie(),ae(),H()),Se=W(U(),te(),V(1)),Ce=W(z(G([re({amountCents:Se,productSlug:xe}),re({productSlug:xe,quantity:Se}),re({productSlug:xe})])),B(1)),we=W(ie(),ae(),ee(/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,`Enter a valid tip amount.`));function Te(e){let t=ne(we,e);if(!t.success)return{message:t.issues[0]?.message??`Enter a valid tip amount.`,success:!1};let[n=`0`,r=``]=t.output.split(`.`),i=BigInt(n)*100n+BigInt(r.padEnd(2,`0`));return i>BigInt(2**53-1)?{message:`Enter a valid tip amount.`,success:!1}:{cents:Number(i),success:!0}}function Ee(e){let t=ne(Ce,e);return t.success?{success:!0,value:t.output}:{message:`Lockerverse payment configuration is invalid.`,success:!1}}const De=`This promo code is invalid or cannot be applied.`;function Q(e,t){return t.tipPercent===`custom`?t.customTip.trim()?Te(t.customTip):{cents:0,success:!0}:{cents:Math.round(e*Number(t.tipPercent)/100),success:!0}}function Oe(e,t,n,r){let i={};return n&&(i.email=n),e.widget.fields.serviceFee&&(i.includeServiceFee=t.includeServiceFee),e.widget.fields.promoCode&&t.promoCode.trim()&&(i.promoCode=t.promoCode.trim()),e.widget.fields.tipping&&(i.tipCents=r),i}function ke(e,t,n){let r=e.widget.fields.tipping?Q(n.subtotalCents,t):{cents:0,success:!0};if(!r.success)return{parsedTip:r,totalCents:null};let i=e.widget.fields.serviceFee&&t.includeServiceFee?n.serviceFeeCents||Math.round(n.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0;return{parsedTip:r,totalCents:n.totalCents-n.serviceFeeCents-n.tipCents+i+r.cents}}function Ae(e,t){return{displayedTotalCents:e.totalCents,promoError:t&&e.appliedDiscount?.source!==`promo_code`?De:void 0}}function je(e,t){let n;return t||(n=e instanceof Error?e.message:`The order total could not be updated.`),{paymentError:n,promoError:t?De:void 0}}function Me(e,t){if(!e?.complete)throw Error(`${t} address is required.`);return e.value}function Ne(e,t,n,r){if(e.widget.fields.shipping)return t.shippingMatchesBilling?n:Me(r.shipping,`Shipping`)}function Pe({billingAddress:e,catalog:t,email:n,phone:r,shippingAddress:i}){let a={payment_method_data:{billing_details:t.widget.fields.phone?{address:e.address,email:n,name:e.name,phone:r}:{address:e.address,email:n,name:e.name}}};return i?{...a,shipping:{address:i.address,name:i.name,phone:t.widget.fields.phone?r:i.phone??null}}:a}function Fe({catalog:e,checkoutItems:t,confirmationToken:n,email:r,fieldValues:i,metadata:a,phone:o,shippingAddress:s}){let c={customFieldAnswers:p(u(e,t),i.customFields),email:r};if(n&&(c.confirmationToken=n),a&&(c.metadata=a),e.widget.fields.memberId&&i.memberId.trim()&&(c.memberId=i.memberId.trim()),e.widget.fields.merchSize&&(c.merchSize=i.merchSize),e.widget.fields.phone&&(c.phone=o),s){let e={city:s.address.city??``,country:s.address.country,line1:s.address.line1??``,postal_code:s.address.postal_code??``,state:s.address.state??``};s.address.line2&&(e.line2=s.address.line2),c.shipping={address:e,name:s.name}}return c}function Ie(e){if(!e())throw Error(`Payment component is no longer active.`)}function Le(e,n){t(e,n)}function Re(e,t,n,r){return e.kind===`failed`?{kind:`payment_failed`,message:r}:e.kind===`unresolved`?{kind:`payment_unresolved`,paymentReference:e.paymentReference,reason:e.reason,retryUrl:e.retryUrl}:{email:n,kind:`payment`,payment:e.payment,quote:t}}async function ze({addresses:e,catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:o,isAttemptActive:s,locallyPreviewedTotalCents:c,metadata:l,onPaymentRecoveryChange:u,phone:d,quote:f,stripe:p,stripeConnectedAccountId:m}){let h=a.trim().toLowerCase(),g=y(d),_=Q(f.subtotalCents,o);if(!_.success)throw Error(_.message);let v=await r.calculateTotal({...Oe(t,o,h,_.cents),catalog:t,items:n});if(Ie(s),v.totalCents>0&&_e(f,v,c,m))return{kind:`quote_changed`,quote:v};let b,x;if(v.totalCents===0)t.widget.fields.shipping&&(b=Ne(t,o,Me(e.billing,`Billing`),e));else{if(!(i&&p))throw Error(`Payment form is still loading.`);await i.update({amount:v.totalCents}),Ie(s);let n=await i.submit();if(Ie(s),n.error)throw Error(n.error.message);let r=Me(e.billing,`Billing`);b=Ne(t,o,r,e);let a=await p.createConfirmationToken({elements:i,params:Pe({billingAddress:r,catalog:t,email:h,phone:g,shippingAddress:b})});if(Ie(s),a.error)throw Error(a.error.message);x=a.confirmationToken.id}Le(u,{connectedAccountId:v.payment.connectedAccountId,paymentReference:v.paymentReference});let S=await ye(r,{checkout:v,submission:Fe({catalog:t,checkoutItems:n,confirmationToken:x,email:h,fieldValues:o,metadata:l,phone:g,shippingAddress:b})},p);return Ie(s),Re(S,v,h,v.totalCents===0?`Order could not be completed. Review the details and try again.`:`Payment was declined. Check your payment details and try again.`)}function Be(e,n){t(e,n)}function Ve(e,n){t(e,n)}function He(e,t){return{...e,...t}}function Ue(e){let t={message:e.reason===`action_required`?`Payment needs your attention. Keep this checkout open.`:`Payment is not complete. Check its status before you try again.`,type:`unresolved`};return e.retryUrl&&(t.retryUrl=e.retryUrl),t}function We(e,t,n){return e.kind===`unresolved`&&e.reason===`action_required`&&!e.retryUrl&&!t&&!n}function Ge(e){return e instanceof M&&e.serverCode===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`}function Ke({nextQuote:e,onQuoteChange:t,setDisplayedTotalCents:n,setPromoError:r,updateState:i,validatePromo:a}){let o=Ae(e,a);i({type:`quote_refresh_succeeded`}),n(o.displayedTotalCents),t(e),a&&r(o.promoError)}function qe({error:e,setPromoError:t,updateState:n,validatePromo:r}){let i=je(e,r);r&&t(i.promoError),n(i.paymentError===void 0?{type:`quote_refresh_failed`}:{error:i.paymentError,type:`quote_refresh_failed`})}function Je({onPaymentComplete:n,onPaymentRecoveryChange:r,onPaymentUncertain:i,onQuoteChange:a,result:o,setDisplayedTotalCents:s,dispatchState:c}){if(o.kind===`quote_changed`){let t=`The total changed to ${e(o.quote.totalCents)}. Review it and pay again.`;a(o.quote,t),s(o.quote.totalCents),c({type:`quote_changed`});return}if(o.kind===`payment_failed`){Be(r,null),c({error:o.message,type:`retryable_failure`});return}if(o.kind===`payment_unresolved`){c(Ue(o)),Ve(i,{paymentReference:o.paymentReference,reason:o.reason});return}a(o.quote),Be(r,null),c({message:o.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),t(n,He(o.payment,{email:o.email,lineItems:o.quote.lineItems}))}function Ye(e){let{catalog:n,checkoutItems:r,client:i,elements:o,email:s,fieldValues:c,metadata:l,onPaymentComplete:u,onResumePaymentFailed:d,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,onStateChange:h,quote:g,resumePayment:v,stripe:y,stripeConnectedAccountId:b,stripeLoadFailed:C,paymentState:w,updateState:T}=e,[E,k]=O(g.totalCents),[A,j]=O(),N=D(!1),P=D(0),F=D(0),I=x(e=>T(e,!0),[T]),L=x(()=>{let e=F.current+1;return F.current=e,()=>F.current===e},[]);S(()=>()=>{F.current+=1,P.current+=1},[]);let{parsedTip:R,totalCents:z}=ke(n,c,g);S(()=>{z!==null&&(k(z),z>0&&o?.update({amount:z}))},[n.pricingPolicy.serviceFeeRateBasisPoints,n.widget.fields.serviceFee,o,c.includeServiceFee,z,g.serviceFeeCents,g.tipCents,g.totalCents,g.subtotalCents]),S(()=>{if(!v||N.current||w.status!==`recovering`)return;N.current=!0;let e=L();return h(Y(w)),be(i,v.paymentReference,y).then(n=>{if(e()&&!We(n,y,C)){if(n.kind===`failed`){Be(f,null),d(),I({error:`The previous payment failed. Check your details and try again.`,type:`recovery_failed`});return}if(n.kind===`unresolved`){I(Ue(n)),Ve(p,{paymentReference:n.paymentReference,reason:n.reason});return}Be(f,null),I({message:n.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),t(u,He(n.payment,{email:null,lineItems:null}))}}),()=>{e()&&(F.current+=1),N.current=!1}},[i,u,d,f,p,h,v,y,C,L,I,w]);let B=x((e=!1,t=!1)=>{t||(P.current+=1),e&&j(void 0),T({type:`field_changed`})},[T]);async function V(e=!1,t=!1){let a=s.trim().toLowerCase(),o=_({email:a,phone:``},!1);if(!(R.success&&(o.value||e)))return;P.current+=1;let l=P.current;T({type:`quote_refresh_started`});try{let e=await i.calculateTotal({...Oe(n,c,o.value?.email??``,R.cents),catalog:n,items:r});if(l!==P.current)return;Ke({nextQuote:e,onQuoteChange:m,setDisplayedTotalCents:k,setPromoError:j,updateState:T,validatePromo:t})}catch(e){if(l!==P.current)return;if(Ge(e)){T({type:`sold_out`});return}qe({error:e,setPromoError:j,updateState:T,validatePromo:t})}}async function H(){j(void 0),await V(!0,!0)}async function U({addresses:e,phone:t}){I({type:`submission_started`});let d=L();try{let a=await ze({addresses:e,catalog:n,checkoutItems:r,client:i,elements:o,email:s,fieldValues:c,isAttemptActive:d,locallyPreviewedTotalCents:E,metadata:l,onPaymentRecoveryChange:f,phone:t,quote:g,stripe:y,stripeConnectedAccountId:b});if(!d())return;Je({dispatchState:I,onPaymentComplete:u,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,result:a,setDisplayedTotalCents:k})}catch(e){if(!d())return;if(Be(f,null),Ge(e)){I({type:`sold_out`});return}let t=e instanceof M?a(e.serverCode):void 0;if(t)return I({type:`submission_validation_failed`}),{phoneError:t};I({error:e instanceof Error?e.message:`Payment could not be completed.`,type:`retryable_failure`})}}let W=w.status===`succeeded`||w.status===`unresolved`?w.message:void 0;return{commands:{applyPromo:H,fieldChanged:B,refreshAuthoritativeTotal:V,reportStripeLoadError:e=>I({error:e,type:`retryable_failure`}),reportValidationFailure:()=>I({type:`validation_failed`}),submit:U},state:{displayedTotalCents:E,isRecovering:w.status===`recovering`,isRefreshingQuote:w.status===`refreshing_quote`,isSubmitting:X(w),parsedTip:R,paymentError:me(w),promoError:A,retryUrl:w.retryUrl,terminalMessage:W}}}const Xe=b;function Ze(e){let{connectedAccountId:t,publishableKey:n}=e.payment;return Xe(n,t?{stripeAccount:t}:void 0)}function Qe(e){return e===`monthly`?{interval:`month`,label:`Monthly`}:e===`annually`?{interval:`year`,label:`Annual`}:null}function $e(e,t,n){if(n){let{connectedAccountId:e}=n;return e}if(`payment`in t){let{connectedAccountId:e}=t.payment;return e}let{connectedAccountId:r}=e.payment;return r}function et({accentColor:e,catalog:t,checkoutItems:n,client:r,appearanceRoot:i,initialCustomFieldValues:a,metadata:o,onPaymentComplete:s,onResumePaymentFailed:c,onPaymentRecoveryChange:l,onPaymentUncertain:u,onQuoteChange:d,quote:f,resumePayment:p,onStateChange:m,stripeLoader:g,theme:_,visualStyle:y}){let[b,C]=O(()=>q(!!p)),w=D(b);w.current=b;let E=x((e,t=!1)=>{let n=pe(w.current,e);n!==w.current&&(w.current=n,C(n),t&&m(Y(n)))},[m]),k=$e(t,f,p),j=D({connectedAccountId:k,paymentOption:f.paymentOption});b.status!==`submitting`&&b.status!==`recovering`&&(j.current={connectedAccountId:k,paymentOption:f.paymentOption});let{connectedAccountId:M,paymentOption:N}=j.current,P=T(()=>g(t.payment.publishableKey,M?{stripeAccount:M}:void 0).catch(()=>null),[t.payment.publishableKey,M,g]),[I,L]=O(!1);S(()=>{let e=!0;return L(!1),P.then(t=>{e&&t===null&&L(!0)}),()=>{e=!1}},[P]);let R=v(i,_,y,b.status===`submitting`||b.status===`recovering`,e);return R?A(F,{options:{amount:Math.max(f.totalCents,100),appearance:R,currency:t.payment.currency,excludedPaymentMethodTypes:t.community?.widgetAchEnabled?[]:[`us_bank_account`],mode:N===`one-time`?`payment`:`subscription`,syncAddressCheckbox:`none`},stripe:P,children:A(ut,{catalog:t,checkoutItems:n,client:r,initialCustomFieldValues:a,metadata:o,onPaymentComplete:s,onPaymentRecoveryChange:l,onPaymentUncertain:u,onQuoteChange:d,onResumePaymentFailed:c,onStateChange:m,paymentState:b,quote:f,resumePayment:p,stripeConnectedAccountId:M,stripeLoadFailed:I,updateState:E})},`${t.payment.publishableKey}:${M??`platform`}:${N}`):A(h,{fieldCount:3,label:`Loading payment form`})}function tt({label:e}){return j(`div`,{className:`lockerverse-payment__stripe-loader`,role:`status`,children:[A(`p`,{children:e}),j(`div`,{"aria-hidden":`true`,children:[A(`span`,{}),A(`span`,{}),A(`span`,{})]})]})}function nt({onError:e,onReady:t,ready:n}){return j(`div`,{className:`lockerverse-payment__stripe-element`,"data-ready":n,children:[n?null:A(tt,{label:`Loading payment form...`}),A(`div`,{className:`lockerverse-payment__stripe-mount`,children:A(I,{onLoadError:({error:t})=>e(t.message??`Payment form failed to load.`),onReady:t,options:{business:{name:`Lockerverse`},fields:{billingDetails:{address:`never`,email:`never`,name:`never`,phone:`never`}},layout:`tabs`,terms:{applePay:`auto`,auBecsDebit:`never`,bancontact:`never`,card:`always`,cashapp:`never`,googlePay:`never`,ideal:`never`,paypal:`auto`,sepaDebit:`never`,sofort:`never`,usBankAccount:`auto`},wallets:{applePay:`auto`,googlePay:`never`}}})})]})}function rt({label:e,mode:t,onChange:n,onError:r,onReady:i,ready:a}){return j(`div`,{className:`lockerverse-payment__address`,children:[A(`h2`,{children:e}),j(`div`,{className:`lockerverse-payment__stripe-element lockerverse-payment__stripe-element--address`,"data-ready":a,children:[a?null:A(tt,{label:`Loading ${e.toLowerCase()}...`}),A(`div`,{className:`lockerverse-payment__stripe-mount`,children:A(P,{onChange:n,onLoadError:({error:t})=>r(t.message??`${e} failed to load.`),onReady:i,options:{autocomplete:{mode:`automatic`},mode:t}})})]})]})}function it({message:e}){return e?A(`p`,{className:`lockerverse-payment__field-message`,role:`alert`,children:e}):null}function at({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:i,isShippingAddressReady:a,onAddressChange:o,onFieldValuesChange:s,onStripeLoadError:c,setIsBillingAddressReady:l,setIsPaymentReady:u,setIsShippingAddressReady:d}){let f=t>0;return j(k,{children:[f?A(nt,{onError:c,onReady:()=>u(!0),ready:i}):null,f||e.widget.fields.shipping?A(rt,{label:f?`Billing address`:`Shipping address`,mode:`billing`,onChange:e=>o(`billing`,e),onError:c,onReady:()=>l(!0),ready:r}):null,e.widget.fields.shipping?j(`div`,{className:`lockerverse-payment__shipping`,children:[A(ue,{checked:n.shippingMatchesBilling,name:`shippingMatchesBilling`,onChange:e=>{s({...n,shippingMatchesBilling:e}),e?o(`shipping`,null):d(!1)},children:`Shipping is same as billing information`}),n.shippingMatchesBilling?null:A(rt,{label:`Shipping address`,mode:`shipping`,onChange:e=>o(`shipping`,e),onError:c,onReady:()=>d(!0),ready:a})]}):null]})}function ot({catalog:t,displayedTotalCents:n,fieldValues:r,isBillingAddressReady:i,isPaymentReady:a,isRequiredShippingReady:o,isSubmitting:s,onFieldValuesChange:c,quote:l}){let u=n===0,d=u?!t.widget.fields.shipping||i&&o:a&&i&&o,f=Qe(l.paymentOption),p=u?`Complete order`:`Pay ${e(n)}`;!u&&f&&(p=`Subscribe for ${e(n)}/${f.interval}`),s&&(p=u?`Completing…`:`Processing…`);let m=`Process payment for ${e(n)} total`;return u?m=`Complete order`:f&&(m=`Start ${f.label.toLowerCase()} subscription for ${e(n)}`),j(`div`,{className:`lockerverse-payment__actions`,children:[A(fe,{amountCents:l.serviceFeeCents||Math.round(l.subtotalCents*t.pricingPolicy.serviceFeeRateBasisPoints/1e4),enabled:t.widget.fields.serviceFee,onChange:c,values:r}),A(`button`,{"aria-busy":s,"aria-label":m,disabled:s||!d,type:`submit`,children:p})]})}function st(e,t){let n=e.elements.namedItem(t);if(n instanceof HTMLElement){n.focus();return}n instanceof RadioNodeList&&Array.from(n).find(e=>e instanceof HTMLElement)?.focus()}function ct({customFieldErrors:e,emailRef:t,form:n,parsedTipSuccess:r,phoneRef:i,validationErrors:a}){if(a.email){t.current?.focus();return}if(a.phone){i.current?.focus();return}if(!r){n.querySelector(`[name="tip"]`)?.focus();return}let[o]=Object.keys(e);o&&st(n,`custom:${o}`)}function lt({email:e,emailDiscountPercentOff:t,emailErrorId:n,emailId:r,emailRef:a,errors:o,onEmailBlur:l,onEmailChange:u,onPhoneChange:d,phone:f,phoneCountry:p,phoneEnabled:m,phoneErrorId:h,phoneId:g,phoneRef:_}){return j(`div`,{className:`lockerverse-payment__contact`,children:[A(i,{error:o.email,errorId:n,id:r,label:`Email`,name:`email`,onBlur:l,onChange:e=>u(e.currentTarget.value),ref:a,required:!0,value:e}),t===void 0?null:j(`p`,{className:`lockerverse-payment__discount-message`,role:`status`,children:[`Your email qualifies for `,t,`% off.`]}),m?A(s,{error:o.phone,errorId:h,id:g,label:`Phone`,children:A(c,{country:p,error:o.phone,errorId:h,id:g,inputRef:_,name:`phone`,onChange:d,required:!0,value:f})}):null]})}function ut({catalog:e,checkoutItems:t,client:n,initialCustomFieldValues:r,metadata:i,onPaymentComplete:a,onResumePaymentFailed:s,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:f,onStateChange:p,quote:h,resumePayment:v,stripeConnectedAccountId:y,stripeLoadFailed:b,paymentState:x,updateState:w}){let T=u(e,t),[E,M]=O(``),[N,P]=O(``),[F,I]=O(`US`),[z,B]=O({}),[V,H]=O({}),[U,W]=O(),[ee,te]=O(!1),[ne,re]=O(!1),[ie,ae]=O(!1),[G,oe]=O(()=>({customFields:d(T,r),customTip:``,includeServiceFee:e.widget.fields.serviceFee,memberId:``,merchSize:`M`,promoCode:``,shippingMatchesBilling:!0,tipPercent:`10`})),se=D({billing:null,shipping:null}),ce=D(null),K=D(null),ue=D(null),fe=D(h.totalCents>0),q=Ye({catalog:e,checkoutItems:t,client:n,elements:L(),email:E,fieldValues:G,metadata:i,onPaymentComplete:a,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:f,onResumePaymentFailed:s,onStateChange:p,paymentState:x,quote:h,resumePayment:v,stripe:R(),stripeConnectedAccountId:y,stripeLoadFailed:b,updateState:w}),{displayedTotalCents:J,isRecovering:pe,isRefreshingQuote:me,isSubmitting:Y,parsedTip:X,paymentError:he,promoError:ge,terminalMessage:_e,retryUrl:ve}=q.state,Z=`lockerverse-${C()}`,ye=`${Z}-email`,be=`${ye}-error`,xe=`${Z}-phone`,Se=`${xe}-error`,Ce=`${Z}-tip-error`,we=(X.success?X.cents:null)??0,Te=J-we,Ee=!e.widget.fields.shipping||G.shippingMatchesBilling||ie;S(()=>{Y&&ue.current?.focus({preventScroll:!0})},[Y]),S(()=>{Y||z.email||!z.phone||K.current?.focus()},[z.email,z.phone,Y]),S(()=>{let e=J>0;e&&!fe.current&&(te(!1),re(!1)),fe.current=e},[J]);function De(e){q.commands.fieldChanged(!1,e!==`email`),B(t=>{let n={...t};return delete n[e],n})}function Q(e){let t=e.promoCode!==G.promoCode,n=e.includeServiceFee!==G.includeServiceFee;q.commands.fieldChanged(t,!(t||n)),oe(e),H({}),W(void 0)}async function Oe(t){t.preventDefault();let n=e.widget.fields.phone?o(N,F):``,r=_({email:E,phone:n},e.widget.fields.phone),i=m(T,G.customFields);if(!(r.value&&X.success)||Object.keys(i).length>0){B(r.errors),H(i),W(X.success?void 0:X.message),q.commands.reportValidationFailure();let e=t.currentTarget;queueMicrotask(()=>{ct({customFieldErrors:i,emailRef:ce,form:e,parsedTipSuccess:X.success,phoneRef:K,validationErrors:r.errors})});return}B({}),H({});let a=await q.commands.submit({addresses:se.current,phone:n});a?.phoneError&&B({phone:a.phoneError})}return _e?j(`p`,{className:`lockerverse-payment__payment-status`,ref:ue,role:`status`,tabIndex:-1,children:[_e,ve?j(k,{children:[` `,A(`a`,{href:ve,rel:`noopener noreferrer`,target:`_blank`,children:`Complete payment`})]}):null]}):pe?A(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:`Recovering payment…`}):j(`form`,{"aria-busy":Y,className:`lockerverse-payment__form`,noValidate:!0,onSubmit:Oe,children:[A(`div`,{"data-lockerverse-input-region":``,inert:Y?!0:void 0,children:j(`fieldset`,{className:`lockerverse-payment__input-fieldset`,disabled:Y,children:[A(g,{displayedBaseCents:Te,displayedTipCents:we,displayedTotalCents:J,quote:h}),A(le,{enabled:e.widget.fields.tipping,error:U,errorId:Ce,onChange:Q,values:G}),A(lt,{email:E,emailDiscountPercentOff:h.appliedDiscount?.source===`email_list`?h.appliedDiscount.percentageOff:void 0,emailErrorId:be,emailId:ye,emailRef:ce,errors:z,onEmailBlur:()=>q.commands.refreshAuthoritativeTotal(),onEmailChange:e=>{M(e),De(`email`)},onPhoneChange:({value:e,country:t})=>{P(e),I(t),De(`phone`)},phone:N,phoneCountry:F,phoneEnabled:e.widget.fields.phone,phoneErrorId:Se,phoneId:xe,phoneRef:K}),A(at,{catalog:e,displayedTotalCents:J,fieldValues:G,isBillingAddressReady:ne,isPaymentReady:ee,isShippingAddressReady:ie,onAddressChange:(e,t)=>{se.current[e]=t},onFieldValuesChange:Q,onStripeLoadError:q.commands.reportStripeLoadError,setIsBillingAddressReady:re,setIsPaymentReady:te,setIsShippingAddressReady:ae}),A(de,{customFields:T,errors:V,fields:e.widget.fields,idPrefix:Z,isPromoApplying:me,memberIdLabel:e.community?.memberIdLabel,onApplyPromo:q.commands.applyPromo,onChange:Q,promoError:ge,values:G}),A(ot,{catalog:e,displayedTotalCents:J,fieldValues:G,isBillingAddressReady:ne,isPaymentReady:ee,isRequiredShippingReady:Ee,isSubmitting:Y,onFieldValuesChange:Q,quote:h})]})}),Y?A(`p`,{className:`lockerverse-payment__sr-only`,ref:ue,role:`status`,tabIndex:-1,children:J===0?`Completing order…`:`Processing payment…`}):null,A(it,{message:he})]})}function dt(){return A(h,{fieldCount:2,label:`Loading payment…`,sectionCount:2,showCheckbox:!0})}function ft(e,t){switch(t.type){case`loading`:return{phase:`loading`,revision:e.revision};case`ready`:return ht(t.displayedQuote,e.revision+1);case`error`:return{failure:t.failure,phase:`error`,revision:e.revision};case`checkout`:return e.phase===`ready`?{...e,displayedQuote:t.checkout,quoteFailure:void 0}:e;case`quote-error`:return e.phase===`ready`?{...e,quoteFailure:t.failure}:e;default:return e}}function $(e,t,n){return e?.catalog===t&&e.selectionKey===n}function pt({checkout:e}){return{displayedQuote:e,type:`ready`}}function mt(e){return e instanceof Error?e.message:`Lockerverse payment could not load.`}function ht(e,t){return{checkoutItems:[...e.items],displayedQuote:e,phase:`ready`,quoteFailure:void 0,revision:t}}function gt(e,t){let n=e.widget.fields.serviceFee;return N(e,{includeServiceFee:n,selection:t})}function _t(e,t){try{return ht(gt(e,t),1)}catch(e){return{failure:mt(e),phase:`error`,revision:0}}}function vt({catalog:e,client:t,paymentState:n,selection:r}){let i=Ee(r),a=i.success?JSON.stringify(i.value):`invalid-selection`,o=T(()=>i.success?i.value:[],[i.success,a]),[s,c]=E(ft,void 0,()=>i.success?_t(e,o):{phase:`loading`,revision:0}),l=D(void 0),u=D(0),d=D(s.phase===`ready`?{catalog:e,selectionKey:a}:void 0),f=D(s.phase===`error`?{catalog:e,selectionKey:a}:void 0),p=n===`submitting`||n===`success`||n===`unresolved`;S(()=>{if(!i.success||p||$(f.current,e,a)||$(l.current,e,a))return;let n=!0;l.current={catalog:e,selectionKey:a};let r=$(d.current,e,a);r||c({type:`loading`});function s(e){n&&c(e)}function m(){n&&(l.current=void 0,f.current={catalog:e,selectionKey:a})}let h;function g(t){if(!n||(l.current=void 0,f.current={catalog:e,selectionKey:a},r&&h!==void 0&&u.current!==h))return;let i=mt(t);if(i===`This option is sold out.`){c({failure:i,type:`error`});return}c(r?{failure:i,type:`quote-error`}:{failure:i,type:`error`})}async function _(){try{h=u.current;let n=e.widget.fields.serviceFee;if(!r){let t=gt(e,o);r=!0,d.current={catalog:e,selectionKey:a},s(pt({checkout:t}))}let i=await t.calculateTotal({catalog:e,includeServiceFee:n,selection:o});m(),u.current===h&&s({checkout:i,type:`checkout`})}catch(e){g(e)}}return _(),()=>{n=!1,$(l.current,e,a)&&(l.current=void 0)}},[e,t,i.success,p,a,o]);let m=$(d.current,e,a)||$(f.current,e,a)||$(l.current,e,a),h=p||m?s:{phase:`loading`,revision:s.revision};return{selectionError:i.success?void 0:i.message,session:h,updateCheckout:e=>{u.current+=1,c({checkout:e,type:`checkout`})}}}const yt={annually:`/year`,monthly:`/month`,"one-time":``};function bt({branding:e,catalog:t}){return j(`header`,{children:[t.widget.showCommunityBranding&&e?j(`div`,{className:`lockerverse-payment__branding`,children:[e.imageUrl?A(`img`,{alt:e.name,height:`48`,src:e.imageUrl,width:`48`}):null,A(`strong`,{children:e.name})]}):null,A(`h1`,{children:t.widget.title??t.widget.name}),t.widget.description?A(`p`,{children:t.widget.description}):null]})}function xt({catalog:t,selection:n}){let r=n?.length?t.products.filter(e=>n.some(t=>t.productSlug===e.slug)):t.products;return r.length===0?null:j(`div`,{className:`lockerverse-payment__payment-summary`,children:[A(`h2`,{children:`Products`}),A(`div`,{className:`lockerverse-payment__payment-summary-items`,children:r.map(t=>{let n=t.pricingMode===`fixed`?t.amountCents:t.minimumAmountCents,r=yt[t.paymentOption];return j(`div`,{className:`lockerverse-payment__payment-summary-row`,children:[A(`span`,{children:t.name}),A(`strong`,{children:n===null?`Choose amount`:`${t.pricingMode===`custom`?`From `:``}${e(n)}${r}`})]},t.id)})}),A(`p`,{children:`Base prices. Final total is checked at checkout.`})]})}function St(e,t){let i=n(e?.[`--lockerverse-accent`]??t?.accentColor??`#38d77a`),a=r(i),o={...e};return(e?.[`--lockerverse-accent`]!==void 0||t?.accentColor)&&(o[`--lockerverse-accent`]=i),a&&e?.[`--lockerverse-accent-contrast`]===void 0&&(o[`--lockerverse-accent-contrast`]=a),{accent:i,rootStyle:o}}function Ct({catalog:e,client:t,loadError:n,onRetry:r,...i}){let{branding:a,className:o,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:u,onPaymentUncertain:d,resumePayment:f,selection:p,style:m,stripeLoader:h=Xe,theme:g=`dark`,..._}=i,[v,y]=O(f),b=D(null),[C,T]=O(),[E,k]=O(`idle`),M=D(void 0),{selectionError:N,session:P,updateCheckout:F}=vt({catalog:e,client:t,paymentState:E,selection:p}),I=P.phase===`ready`?P.revision:void 0,L=x(e=>{I!==void 0&&(M.current=I),k(e)},[I]),R=x(e=>u?.(e),[u]),z=x(()=>{y(void 0)},[]);S(()=>{P.phase===`loading`&&T(void 0)},[P.phase]),w(()=>{P.phase===`ready`&&M.current!==P.revision&&k(e=>e===`success`||e===`unresolved`?e:`idle`)},[P.phase,P.revision]);let B=[`lockerverse-payment`,o].filter(Boolean).join(` `),V=a??e.community,{accent:H,rootStyle:U}=St(m,V);return N?A(`section`,{..._,className:B,"data-lockerverse-theme":g,role:`alert`,style:U,children:N}):P.phase===`error`&&P.failure===`This option is sold out.`||E===`sold_out`?j(`section`,{..._,className:B,"data-lockerverse-theme":g,role:`alert`,style:U,children:[A(`h1`,{children:`Sold out`}),A(`p`,{children:`This option is sold out.`})]}):P.phase===`error`?A(`section`,{..._,className:B,"data-lockerverse-theme":g,style:U,children:A(`p`,{role:`alert`,children:P.failure})}):P.phase===`ready`?j(`section`,{..._,"aria-label":`Payment`,className:B,"data-lockerverse-theme":g,"data-payment-state":E,ref:b,style:U,children:[A(bt,{branding:V,catalog:e}),n?j(`div`,{role:`alert`,children:[A(`p`,{children:n.message}),A(`button`,{onClick:r,type:`button`,children:`Retry`})]}):null,C?A(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:C}):null,P.quoteFailure?j(`div`,{className:`lockerverse-payment__payment-status`,role:`alert`,children:[A(`span`,{children:P.quoteFailure}),A(`span`,{children:` The final total will be checked when you submit.`})]}):null,A(et,{accentColor:H,appearanceRoot:b,catalog:e,checkoutItems:P.checkoutItems,client:t,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:R,onPaymentUncertain:d,onQuoteChange:(e,t)=>{T(t),F(e)},onResumePaymentFailed:z,onStateChange:L,quote:P.displayedQuote,resumePayment:v,stripeLoader:h,theme:g,visualStyle:U},P.revision)]}):j(`section`,{..._,"aria-busy":`true`,"aria-label":`Payment`,className:B,"data-lockerverse-theme":g,style:U,children:[A(bt,{branding:V,catalog:e}),n?j(`div`,{role:`alert`,children:[A(`p`,{children:n.message}),A(`button`,{onClick:r,type:`button`,children:`Retry`})]}):null,A(dt,{})]})}function wt({children:e,loading:t=!1,viewProps:i}){let{branding:a,className:o,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:u,onPaymentUncertain:d,resumePayment:f,selection:p,stripeLoader:m,style:h,theme:g=`dark`,..._}=i,v=n(h?.[`--lockerverse-accent`]??a?.accentColor??`#38d77a`),y=r(v),b={...h};return(h?.[`--lockerverse-accent`]!==void 0||a?.accentColor)&&(b[`--lockerverse-accent`]=v),y&&h?.[`--lockerverse-accent-contrast`]===void 0&&(b[`--lockerverse-accent-contrast`]=y),A(`section`,{..._,...t?{"aria-busy":!0,"aria-label":`Payment`}:{},className:[`lockerverse-payment`,o].filter(Boolean).join(` `),"data-lockerverse-theme":g,style:b,children:e})}function Tt({widget:e,...t}){return e.error&&!e.catalog?j(wt,{viewProps:t,children:[A(`p`,{role:`alert`,children:e.error.message}),A(`button`,{onClick:e.refresh,type:`button`,children:`Retry`})]}):e.loading?j(wt,{loading:!0,viewProps:t,children:[e.catalog?j(k,{children:[A(bt,{branding:t.branding??e.catalog.community,catalog:e.catalog}),A(xt,{catalog:e.catalog,selection:t.selection})]}):null,A(dt,{})]}):e.catalog?A(Ct,{catalog:e.catalog,client:e.client,loadError:e.error,onRetry:e.refresh,...t}):A(wt,{loading:!0,viewProps:t,children:A(dt,{})})}export{Ze as n,Tt as t};
1
+ import{t as e}from"./format-money.js";import{t}from"./host-callback.js";import{n,t as r}from"./accent-contrast.js";import{d as i,i as a,n as o,p as s,t as c,u as l}from"./phone-field.js";import{a as u,i as d,n as f,r as p,s as m}from"./custom-fields.js";import{t as h}from"./form-skeleton.js";import{t as g}from"./payment-summary.js";import{i as _,n as v,r as y,t as b}from"./stripe-loader.js";import{useCallback as x,useEffect as S,useId as C,useLayoutEffect as w,useMemo as T,useReducer as E,useRef as D,useState as O}from"react";import{Fragment as k,jsx as A,jsxs as j}from"react/jsx-runtime";import{LockerverseSdkError as M,estimateLockerverseCheckout as N}from"@lockerverse/sdk/checkout";import{AddressElement as P,Elements as F,PaymentElement as I,useElements as L,useStripe as R}from"@stripe/react-stripe-js";import{array as z,minLength as B,minValue as V,nonEmpty as H,number as U,pipe as W,regex as ee,safeInteger as te,safeParse as ne,strictObject as re,string as ie,trim as ae,union as G}from"valibot";function oe({ariaDescribedBy:e,ariaLabel:t,ariaLabelledBy:n,className:r,id:i,invalid:a=!1,name:o,onValueChange:s,options:c,value:l}){return A(`select`,{"aria-describedby":e,"aria-invalid":a||void 0,"aria-label":t,"aria-labelledby":n,className:[`lockerverse-form__control`,`lockerverse-form__select`,r].filter(Boolean).join(` `),id:i,name:o,onChange:e=>s(e.currentTarget.value),value:l,children:c.map(e=>A(`option`,{value:e.value,children:e.label},e.value))})}const se=[`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`],ce=[`15`,`12`,`10`,`5`],K=[...ce,`custom`];function le({enabled:e,error:t,errorId:n,onChange:r,values:i}){if(!e)return null;let a=e=>r({...i,...e}),o=(e,t)=>{let n=K.indexOf(t),r;switch(e.key){case`ArrowDown`:case`ArrowRight`:r=(n+1)%K.length;break;case`ArrowLeft`:case`ArrowUp`:r=(n-1+K.length)%K.length;break;case`Home`:r=0;break;case`End`:r=K.length-1;break;default:return}e.preventDefault();let i=K[r];i&&((e.currentTarget.closest(`[role="radiogroup"]`)?.querySelectorAll(`input[type="radio"]`))?.[r]?.focus(),a({tipPercent:i}))};return j(`div`,{className:`lockerverse-payment__tip-box`,children:[A(`p`,{children:`Add a tip to support the Lockerverse platform`}),j(`div`,{"aria-label":`Tip amount`,role:`radiogroup`,children:[ce.map(e=>j(`label`,{className:`lockerverse-payment__tip-choice`,children:[A(`input`,{checked:i.tipPercent===e,name:`tipPercent`,onChange:()=>a({tipPercent:e}),onKeyDown:t=>o(t,e),tabIndex:i.tipPercent===e?0:-1,type:`radio`,value:e}),j(`span`,{children:[e,`%`]})]},e)),j(`label`,{className:`lockerverse-payment__tip-choice`,children:[A(`input`,{checked:i.tipPercent===`custom`,name:`tipPercent`,onChange:()=>a({tipPercent:`custom`}),onKeyDown:e=>o(e,`custom`),tabIndex:i.tipPercent===`custom`?0:-1,type:`radio`,value:`custom`}),A(`span`,{children:`Other`})]})]}),i.tipPercent===`custom`?j(`label`,{children:[A(`span`,{children:`Custom tip`}),j(`span`,{className:`lockerverse-payment__money-input`,children:[A(`span`,{"aria-hidden":`true`,children:`$`}),A(`input`,{"aria-describedby":t?n:void 0,"aria-invalid":t?`true`:void 0,inputMode:`decimal`,name:`tip`,onChange:e=>a({customTip:e.currentTarget.value}),placeholder:`0.00`,value:i.customTip})]}),t?A(`span`,{className:`lockerverse-payment__field-message`,id:n,children:t}):null]}):A(`input`,{name:`tip`,type:`hidden`,value:i.tipPercent})]})}function ue({checked:e,children:t,name:n,onChange:r}){let i=C();return j(`label`,{className:`lockerverse-payment__check-row`,htmlFor:i,children:[A(l,{checked:e,id:i,name:n,onChange:e=>r(e.currentTarget.checked)}),A(`span`,{children:t})]})}function de({customFields:e,errors:t,fields:n,idPrefix:r,isPromoApplying:i,memberIdLabel:a,onChange:o,onApplyPromo:s,promoError:c,values:l}){let u=e=>o({...l,...e});return j(`div`,{className:`lockerverse-payment__additional-fields`,children:[n.memberId?j(`label`,{children:[A(`span`,{children:a?.trim()||`Member ID`}),A(`input`,{name:`memberId`,onChange:e=>u({memberId:e.currentTarget.value}),placeholder:`Optional`,value:l.memberId})]}):null,n.merchSize?j(`div`,{className:`lockerverse-payment__field`,children:[A(`span`,{id:`${r}-merch-size-label`,children:`Size`}),A(oe,{ariaLabelledBy:`${r}-merch-size-label`,name:`merchSize`,onValueChange:e=>{let t=se.find(t=>t===e);t&&u({merchSize:t})},options:se.map(e=>({label:e,value:e})),value:l.merchSize})]}):null,n.promoCode?j(`div`,{className:`lockerverse-payment__field`,children:[A(`span`,{id:`${r}-promo-code-label`,children:`Promo code`}),j(`div`,{className:`lockerverse-payment__promo-control`,children:[A(`input`,{"aria-describedby":c?`${r}-promo-code-error`:void 0,"aria-invalid":c?`true`:void 0,"aria-labelledby":`${r}-promo-code-label`,name:`promoCode`,onChange:e=>u({promoCode:e.currentTarget.value}),placeholder:`Optional`,value:l.promoCode}),A(`button`,{disabled:!l.promoCode.trim()||i,onClick:s,type:`button`,children:i?`Applying…`:`Apply`})]}),c?A(`p`,{className:`lockerverse-payment__field-message`,id:`${r}-promo-code-error`,role:`alert`,children:c}):null]}):null,A(f,{choiceClassName:`lockerverse-payment__check-row`,errorClassName:`lockerverse-payment__field-message`,errors:t,fields:e,idPrefix:r,onChange:e=>u({customFields:e}),values:l.customFields})]})}function fe({amountCents:t,enabled:n,onChange:r,values:i}){return n?j(ue,{checked:i.includeServiceFee,name:`includeServiceFee`,onChange:e=>r({...i,includeServiceFee:e}),children:[`Add `,e(t),` to help cover processing fees`]}):null}function q(e){return{error:void 0,message:void 0,status:e?`recovering`:`editing`}}function J(e,t,n){return t.includes(e.status)?{...e,...n}:e}function pe(e,t){if(e.status===`sold_out`||e.status===`succeeded`||e.status===`unresolved`)return e;switch(t.type){case`field_changed`:return J(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`editing`});case`validation_failed`:return J(e,[`editing`],{status:`invalid`});case`quote_refresh_started`:return J(e,[`editing`,`invalid`],{status:`refreshing_quote`});case`quote_refresh_succeeded`:return J(e,[`refreshing_quote`],{error:void 0,status:`editing`});case`quote_refresh_failed`:return J(e,[`refreshing_quote`],{error:t.error??e.error,status:`editing`});case`submission_started`:return J(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`submitting`});case`submission_validation_failed`:return J(e,[`submitting`],{error:void 0,status:`invalid`});case`quote_changed`:return J(e,[`submitting`],{status:`editing`});case`retryable_failure`:return J(e,[`editing`,`invalid`,`submitting`],{error:t.error,status:`editing`});case`recovery_failed`:return J(e,[`recovering`],{error:t.error,status:`editing`});case`sold_out`:return{error:void 0,message:void 0,status:`sold_out`};case`succeeded`:return J(e,[`recovering`,`submitting`],{message:t.message,status:`succeeded`});case`unresolved`:{let n={message:t.message,status:`unresolved`};return t.retryUrl&&(n.retryUrl=t.retryUrl),J(e,[`recovering`,`submitting`],n)}default:return e}}function me(e){return e.status===`editing`||e.status===`invalid`||e.status===`refreshing_quote`?e.error:void 0}function Y(e){return e.status===`sold_out`?`sold_out`:e.status===`succeeded`?`success`:e.status===`unresolved`?`unresolved`:e.status===`submitting`||e.status===`recovering`?`submitting`:e.status===`invalid`?`invalid`:me(e)?`error`:`idle`}function X(e){return e.status===`submitting`}const he=[`amountCents`,`discountableSubtotalCents`,`discountCents`,`serviceFeeCents`,`subtotalCents`,`tipCents`,`totalCents`],ge=[`discountableSubtotalCents`,`discountCents`,`subtotalCents`];function _e(e,t,n,r){return(n===t.totalCents?ge:he).some(n=>e[n]!==t[n])||r!==t.payment.connectedAccountId||e.authoritative&&(e.payment.connectedAccountId!==r||e.payment.currency!==t.payment.currency)||JSON.stringify(e.appliedDiscount)!==JSON.stringify(t.appliedDiscount)||JSON.stringify(e.lineItems)!==JSON.stringify(t.lineItems)}function ve(e){if(e.checkoutStatus===`success`)return{kind:`success`,payment:e};if(e.checkoutStatus===`failed`)return{kind:`failed`,payment:e};let t={kind:`unresolved`,paymentReference:e.paymentReference,reason:e.checkoutStatus===`action_required`?`action_required`:`pending`};return e.retryUrl&&(t.retryUrl=e.retryUrl),t}async function Z(e,t,n){if(t.checkoutStatus!==`action_required`||!t.requiresAction)return ve(t);if(!n)return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`};if(t.clientSecret)try{await n.handleNextAction({clientSecret:t.clientSecret})}catch{}try{return ve(await e.getPaymentStatus(t.paymentReference))}catch{return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`}}}async function ye(e,t,n){let r;try{r=await e.submitPayment(t)}catch(n){if(!(n instanceof M&&n.recoveryRecommended))throw n;try{r=await e.getPaymentStatus(t.checkout.paymentReference)}catch{return{kind:`unresolved`,paymentReference:t.checkout.paymentReference,reason:`recovery_failed`}}}return Z(e,r,n)}async function be(e,t,n){try{return Z(e,await e.getPaymentStatus(t),n)}catch{return{kind:`unresolved`,paymentReference:t,reason:`recovery_failed`}}}const xe=W(ie(),ae(),H()),Se=W(U(),te(),V(1)),Ce=W(z(G([re({amountCents:Se,productSlug:xe}),re({productSlug:xe,quantity:Se}),re({productSlug:xe})])),B(1)),we=W(ie(),ae(),ee(/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,`Enter a valid tip amount.`));function Te(e){let t=ne(we,e);if(!t.success)return{message:t.issues[0]?.message??`Enter a valid tip amount.`,success:!1};let[n=`0`,r=``]=t.output.split(`.`),i=BigInt(n)*100n+BigInt(r.padEnd(2,`0`));return i>BigInt(2**53-1)?{message:`Enter a valid tip amount.`,success:!1}:{cents:Number(i),success:!0}}function Ee(e){let t=ne(Ce,e);return t.success?{success:!0,value:t.output}:{message:`Lockerverse payment configuration is invalid.`,success:!1}}const De=`This promo code is invalid or cannot be applied.`;function Q(e,t){return t.tipPercent===`custom`?t.customTip.trim()?Te(t.customTip):{cents:0,success:!0}:{cents:Math.round(e*Number(t.tipPercent)/100),success:!0}}function Oe(e,t,n,r){let i={};return n&&(i.email=n),e.widget.fields.serviceFee&&(i.includeServiceFee=t.includeServiceFee),e.widget.fields.promoCode&&t.promoCode.trim()&&(i.promoCode=t.promoCode.trim()),e.widget.fields.tipping&&(i.tipCents=r),i}function ke(e,t,n){let r=e.widget.fields.tipping?Q(n.subtotalCents,t):{cents:0,success:!0};if(!r.success)return{parsedTip:r,totalCents:null};let i=e.widget.fields.serviceFee&&t.includeServiceFee?n.serviceFeeCents||Math.round(n.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0;return{parsedTip:r,totalCents:n.totalCents-n.serviceFeeCents-n.tipCents+i+r.cents}}function Ae(e,t){return{displayedTotalCents:e.totalCents,promoError:t&&e.appliedDiscount?.source!==`promo_code`?De:void 0}}function je(e,t){let n;return t||(n=e instanceof Error?e.message:`The order total could not be updated.`),{paymentError:n,promoError:t?De:void 0}}function Me(e,t){if(!e?.complete)throw Error(`${t} address is required.`);return e.value}function Ne(e,t,n,r){if(e.widget.fields.shipping)return t.shippingMatchesBilling?n:Me(r.shipping,`Shipping`)}function Pe({billingAddress:e,catalog:t,email:n,phone:r,shippingAddress:i}){let a={payment_method_data:{billing_details:t.widget.fields.phone?{address:e.address,email:n,name:e.name,phone:r}:{address:e.address,email:n,name:e.name}}};return i?{...a,shipping:{address:i.address,name:i.name,phone:t.widget.fields.phone?r:i.phone??null}}:a}function Fe({catalog:e,checkoutItems:t,confirmationToken:n,email:r,fieldValues:i,metadata:a,phone:o,shippingAddress:s}){let c={customFieldAnswers:p(u(e,t),i.customFields),email:r};if(n&&(c.confirmationToken=n),a&&(c.metadata=a),e.widget.fields.memberId&&i.memberId.trim()&&(c.memberId=i.memberId.trim()),e.widget.fields.merchSize&&(c.merchSize=i.merchSize),e.widget.fields.phone&&(c.phone=o),s){let e={city:s.address.city??``,country:s.address.country,line1:s.address.line1??``,postal_code:s.address.postal_code??``,state:s.address.state??``};s.address.line2&&(e.line2=s.address.line2),c.shipping={address:e,name:s.name}}return c}function Ie(e){if(!e())throw Error(`Payment component is no longer active.`)}function Le(e,n){t(e,n)}function Re(e,t,n,r){return e.kind===`failed`?{kind:`payment_failed`,message:r}:e.kind===`unresolved`?{kind:`payment_unresolved`,paymentReference:e.paymentReference,reason:e.reason,retryUrl:e.retryUrl}:{email:n,kind:`payment`,payment:e.payment,quote:t}}async function ze({addresses:e,catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:o,isAttemptActive:s,locallyPreviewedTotalCents:c,metadata:l,onPaymentRecoveryChange:u,phone:d,quote:f,stripe:p,stripeConnectedAccountId:m}){let h=a.trim().toLowerCase(),g=y(d),_=Q(f.subtotalCents,o);if(!_.success)throw Error(_.message);let v=await r.calculateTotal({...Oe(t,o,h,_.cents),catalog:t,items:n});if(Ie(s),v.totalCents>0&&_e(f,v,c,m))return{kind:`quote_changed`,quote:v};let b,x;if(v.totalCents===0)t.widget.fields.shipping&&(b=Ne(t,o,Me(e.billing,`Billing`),e));else{if(!(i&&p))throw Error(`Payment form is still loading.`);await i.update({amount:v.totalCents}),Ie(s);let n=await i.submit();if(Ie(s),n.error)throw Error(n.error.message);let r=Me(e.billing,`Billing`);b=Ne(t,o,r,e);let a=await p.createConfirmationToken({elements:i,params:Pe({billingAddress:r,catalog:t,email:h,phone:g,shippingAddress:b})});if(Ie(s),a.error)throw Error(a.error.message);x=a.confirmationToken.id}Le(u,{connectedAccountId:v.payment.connectedAccountId,paymentReference:v.paymentReference});let S=await ye(r,{checkout:v,submission:Fe({catalog:t,checkoutItems:n,confirmationToken:x,email:h,fieldValues:o,metadata:l,phone:g,shippingAddress:b})},p);return Ie(s),Re(S,v,h,v.totalCents===0?`Order could not be completed. Review the details and try again.`:`Payment was declined. Check your payment details and try again.`)}function Be(e,n){t(e,n)}function Ve(e,n){t(e,n)}function He(e,t){return{...e,...t}}function Ue(e){let t={message:e.reason===`action_required`?`Payment needs your attention. Keep this checkout open.`:`Payment is not complete. Check its status before you try again.`,type:`unresolved`};return e.retryUrl&&(t.retryUrl=e.retryUrl),t}function We(e,t,n){return e.kind===`unresolved`&&e.reason===`action_required`&&!e.retryUrl&&!t&&!n}function Ge(e){return e instanceof M&&e.serverCode===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`}function Ke({nextQuote:e,onQuoteChange:t,setDisplayedTotalCents:n,setPromoError:r,updateState:i,validatePromo:a}){let o=Ae(e,a);i({type:`quote_refresh_succeeded`}),n(o.displayedTotalCents),t(e),a&&r(o.promoError)}function qe({error:e,setPromoError:t,updateState:n,validatePromo:r}){let i=je(e,r);r&&t(i.promoError),n(i.paymentError===void 0?{type:`quote_refresh_failed`}:{error:i.paymentError,type:`quote_refresh_failed`})}function Je({onPaymentComplete:n,onPaymentRecoveryChange:r,onPaymentUncertain:i,onQuoteChange:a,result:o,setDisplayedTotalCents:s,dispatchState:c}){if(o.kind===`quote_changed`){let t=`The total changed to ${e(o.quote.totalCents)}. Review it and pay again.`;a(o.quote,t),s(o.quote.totalCents),c({type:`quote_changed`});return}if(o.kind===`payment_failed`){Be(r,null),c({error:o.message,type:`retryable_failure`});return}if(o.kind===`payment_unresolved`){c(Ue(o)),Ve(i,{paymentReference:o.paymentReference,reason:o.reason});return}a(o.quote),Be(r,null),c({message:o.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),t(n,He(o.payment,{email:o.email,lineItems:o.quote.lineItems}))}function Ye(e){let{catalog:n,checkoutItems:r,client:i,elements:o,email:s,fieldValues:c,metadata:l,onPaymentComplete:u,onResumePaymentFailed:d,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,onStateChange:h,quote:g,resumePayment:v,stripe:y,stripeConnectedAccountId:b,stripeLoadFailed:C,paymentState:w,updateState:T}=e,[E,k]=O(g.totalCents),[A,j]=O(),N=D(!1),P=D(0),F=D(0),I=x(e=>T(e,!0),[T]),L=x(()=>{let e=F.current+1;return F.current=e,()=>F.current===e},[]);S(()=>()=>{F.current+=1,P.current+=1},[]);let{parsedTip:R,totalCents:z}=ke(n,c,g);S(()=>{z!==null&&(k(z),z>0&&o?.update({amount:z}))},[n.pricingPolicy.serviceFeeRateBasisPoints,n.widget.fields.serviceFee,o,c.includeServiceFee,z,g.serviceFeeCents,g.tipCents,g.totalCents,g.subtotalCents]),S(()=>{if(!v||N.current||w.status!==`recovering`)return;N.current=!0;let e=L();return h(Y(w)),be(i,v.paymentReference,y).then(n=>{if(e()&&!We(n,y,C)){if(n.kind===`failed`){Be(f,null),d(),I({error:`The previous payment failed. Check your details and try again.`,type:`recovery_failed`});return}if(n.kind===`unresolved`){I(Ue(n)),Ve(p,{paymentReference:n.paymentReference,reason:n.reason});return}Be(f,null),I({message:n.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),t(u,He(n.payment,{email:null,lineItems:null}))}}),()=>{e()&&(F.current+=1),N.current=!1}},[i,u,d,f,p,h,v,y,C,L,I,w]);let B=x((e=!1,t=!1)=>{t||(P.current+=1),e&&j(void 0),T({type:`field_changed`})},[T]);async function V(e=!1,t=!1){let a=s.trim().toLowerCase(),o=_({email:a,phone:``},!1);if(!(R.success&&(o.value||e)))return;P.current+=1;let l=P.current;T({type:`quote_refresh_started`});try{let e=await i.calculateTotal({...Oe(n,c,o.value?.email??``,R.cents),catalog:n,items:r});if(l!==P.current)return;Ke({nextQuote:e,onQuoteChange:m,setDisplayedTotalCents:k,setPromoError:j,updateState:T,validatePromo:t})}catch(e){if(l!==P.current)return;if(Ge(e)){T({type:`sold_out`});return}qe({error:e,setPromoError:j,updateState:T,validatePromo:t})}}async function H(){j(void 0),await V(!0,!0)}async function U({addresses:e,phone:t}){I({type:`submission_started`});let d=L();try{let a=await ze({addresses:e,catalog:n,checkoutItems:r,client:i,elements:o,email:s,fieldValues:c,isAttemptActive:d,locallyPreviewedTotalCents:E,metadata:l,onPaymentRecoveryChange:f,phone:t,quote:g,stripe:y,stripeConnectedAccountId:b});if(!d())return;Je({dispatchState:I,onPaymentComplete:u,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,result:a,setDisplayedTotalCents:k})}catch(e){if(!d())return;if(Be(f,null),Ge(e)){I({type:`sold_out`});return}let t=e instanceof M?a(e.serverCode):void 0;if(t)return I({type:`submission_validation_failed`}),{phoneError:t};I({error:e instanceof Error?e.message:`Payment could not be completed.`,type:`retryable_failure`})}}let W=w.status===`succeeded`||w.status===`unresolved`?w.message:void 0;return{commands:{applyPromo:H,fieldChanged:B,refreshAuthoritativeTotal:V,reportStripeLoadError:e=>I({error:e,type:`retryable_failure`}),reportValidationFailure:()=>I({type:`validation_failed`}),submit:U},state:{displayedTotalCents:E,isRecovering:w.status===`recovering`,isRefreshingQuote:w.status===`refreshing_quote`,isSubmitting:X(w),parsedTip:R,paymentError:me(w),promoError:A,retryUrl:w.retryUrl,terminalMessage:W}}}const Xe=b;function Ze(e){let{connectedAccountId:t,publishableKey:n}=e.payment;return Xe(n,t?{stripeAccount:t}:void 0)}function Qe(e){return e===`monthly`?{interval:`month`,label:`Monthly`}:e===`annually`?{interval:`year`,label:`Annual`}:e===`every-six-months`?{interval:`6 months`,label:`Every 6 months`}:null}function $e(e,t,n){if(n){let{connectedAccountId:e}=n;return e}if(`payment`in t){let{connectedAccountId:e}=t.payment;return e}let{connectedAccountId:r}=e.payment;return r}function et({accentColor:e,catalog:t,checkoutItems:n,client:r,appearanceRoot:i,initialCustomFieldValues:a,metadata:o,onPaymentComplete:s,onResumePaymentFailed:c,onPaymentRecoveryChange:l,onPaymentUncertain:u,onQuoteChange:d,quote:f,resumePayment:p,onStateChange:m,stripeLoader:g,theme:_,visualStyle:y}){let[b,C]=O(()=>q(!!p)),w=D(b);w.current=b;let E=x((e,t=!1)=>{let n=pe(w.current,e);n!==w.current&&(w.current=n,C(n),t&&m(Y(n)))},[m]),k=$e(t,f,p),j=D({connectedAccountId:k,paymentOption:f.paymentOption});b.status!==`submitting`&&b.status!==`recovering`&&(j.current={connectedAccountId:k,paymentOption:f.paymentOption});let{connectedAccountId:M,paymentOption:N}=j.current,P=T(()=>g(t.payment.publishableKey,M?{stripeAccount:M}:void 0).catch(()=>null),[t.payment.publishableKey,M,g]),[I,L]=O(!1);S(()=>{let e=!0;return L(!1),P.then(t=>{e&&t===null&&L(!0)}),()=>{e=!1}},[P]);let R=v(i,_,y,b.status===`submitting`||b.status===`recovering`,e);return R?A(F,{options:{amount:Math.max(f.totalCents,100),appearance:R,currency:t.payment.currency,excludedPaymentMethodTypes:t.community?.widgetAchEnabled?[]:[`us_bank_account`],mode:N===`one-time`?`payment`:`subscription`,syncAddressCheckbox:`none`},stripe:P,children:A(ut,{catalog:t,checkoutItems:n,client:r,initialCustomFieldValues:a,metadata:o,onPaymentComplete:s,onPaymentRecoveryChange:l,onPaymentUncertain:u,onQuoteChange:d,onResumePaymentFailed:c,onStateChange:m,paymentState:b,quote:f,resumePayment:p,stripeConnectedAccountId:M,stripeLoadFailed:I,updateState:E})},`${t.payment.publishableKey}:${M??`platform`}:${N}`):A(h,{fieldCount:3,label:`Loading payment form`})}function tt({label:e}){return j(`div`,{className:`lockerverse-payment__stripe-loader`,role:`status`,children:[A(`p`,{children:e}),j(`div`,{"aria-hidden":`true`,children:[A(`span`,{}),A(`span`,{}),A(`span`,{})]})]})}function nt({onError:e,onReady:t,ready:n}){return j(`div`,{className:`lockerverse-payment__stripe-element`,"data-ready":n,children:[n?null:A(tt,{label:`Loading payment form...`}),A(`div`,{className:`lockerverse-payment__stripe-mount`,children:A(I,{onLoadError:({error:t})=>e(t.message??`Payment form failed to load.`),onReady:t,options:{business:{name:`Lockerverse`},fields:{billingDetails:{address:`never`,email:`never`,name:`never`,phone:`never`}},layout:`tabs`,terms:{applePay:`auto`,auBecsDebit:`never`,bancontact:`never`,card:`always`,cashapp:`never`,googlePay:`never`,ideal:`never`,paypal:`auto`,sepaDebit:`never`,sofort:`never`,usBankAccount:`auto`},wallets:{applePay:`auto`,googlePay:`never`}}})})]})}function rt({label:e,mode:t,onChange:n,onError:r,onReady:i,ready:a}){return j(`div`,{className:`lockerverse-payment__address`,children:[A(`h2`,{children:e}),j(`div`,{className:`lockerverse-payment__stripe-element lockerverse-payment__stripe-element--address`,"data-ready":a,children:[a?null:A(tt,{label:`Loading ${e.toLowerCase()}...`}),A(`div`,{className:`lockerverse-payment__stripe-mount`,children:A(P,{onChange:n,onLoadError:({error:t})=>r(t.message??`${e} failed to load.`),onReady:i,options:{autocomplete:{mode:`automatic`},mode:t}})})]})]})}function it({message:e}){return e?A(`p`,{className:`lockerverse-payment__field-message`,role:`alert`,children:e}):null}function at({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:i,isShippingAddressReady:a,onAddressChange:o,onFieldValuesChange:s,onStripeLoadError:c,setIsBillingAddressReady:l,setIsPaymentReady:u,setIsShippingAddressReady:d}){let f=t>0;return j(k,{children:[f?A(nt,{onError:c,onReady:()=>u(!0),ready:i}):null,f||e.widget.fields.shipping?A(rt,{label:f?`Billing address`:`Shipping address`,mode:`billing`,onChange:e=>o(`billing`,e),onError:c,onReady:()=>l(!0),ready:r}):null,e.widget.fields.shipping?j(`div`,{className:`lockerverse-payment__shipping`,children:[A(ue,{checked:n.shippingMatchesBilling,name:`shippingMatchesBilling`,onChange:e=>{s({...n,shippingMatchesBilling:e}),e?o(`shipping`,null):d(!1)},children:`Shipping is same as billing information`}),n.shippingMatchesBilling?null:A(rt,{label:`Shipping address`,mode:`shipping`,onChange:e=>o(`shipping`,e),onError:c,onReady:()=>d(!0),ready:a})]}):null]})}function ot({catalog:t,displayedTotalCents:n,fieldValues:r,isBillingAddressReady:i,isPaymentReady:a,isRequiredShippingReady:o,isSubmitting:s,onFieldValuesChange:c,quote:l}){let u=n===0,d=u?!t.widget.fields.shipping||i&&o:a&&i&&o,f=Qe(l.paymentOption),p=u?`Complete order`:`Pay ${e(n)}`;!u&&f&&(p=`Subscribe for ${e(n)}/${f.interval}`),s&&(p=u?`Completing…`:`Processing…`);let m=`Process payment for ${e(n)} total`;return u?m=`Complete order`:f&&(m=`Start ${f.label.toLowerCase()} subscription for ${e(n)}`),j(`div`,{className:`lockerverse-payment__actions`,children:[A(fe,{amountCents:l.serviceFeeCents||Math.round(l.subtotalCents*t.pricingPolicy.serviceFeeRateBasisPoints/1e4),enabled:t.widget.fields.serviceFee,onChange:c,values:r}),A(`button`,{"aria-busy":s,"aria-label":m,disabled:s||!d,type:`submit`,children:p})]})}function st(e,t){let n=e.elements.namedItem(t);if(n instanceof HTMLElement){n.focus();return}n instanceof RadioNodeList&&Array.from(n).find(e=>e instanceof HTMLElement)?.focus()}function ct({customFieldErrors:e,emailRef:t,form:n,parsedTipSuccess:r,phoneRef:i,validationErrors:a}){if(a.email){t.current?.focus();return}if(a.phone){i.current?.focus();return}if(!r){n.querySelector(`[name="tip"]`)?.focus();return}let[o]=Object.keys(e);o&&st(n,`custom:${o}`)}function lt({email:e,emailDiscountPercentOff:t,emailErrorId:n,emailId:r,emailRef:a,errors:o,onEmailBlur:l,onEmailChange:u,onPhoneChange:d,phone:f,phoneCountry:p,phoneEnabled:m,phoneErrorId:h,phoneId:g,phoneRef:_}){return j(`div`,{className:`lockerverse-payment__contact`,children:[A(i,{error:o.email,errorId:n,id:r,label:`Email`,name:`email`,onBlur:l,onChange:e=>u(e.currentTarget.value),ref:a,required:!0,value:e}),t===void 0?null:j(`p`,{className:`lockerverse-payment__discount-message`,role:`status`,children:[`Your email qualifies for `,t,`% off.`]}),m?A(s,{error:o.phone,errorId:h,id:g,label:`Phone`,children:A(c,{country:p,error:o.phone,errorId:h,id:g,inputRef:_,name:`phone`,onChange:d,required:!0,value:f})}):null]})}function ut({catalog:e,checkoutItems:t,client:n,initialCustomFieldValues:r,metadata:i,onPaymentComplete:a,onResumePaymentFailed:s,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:f,onStateChange:p,quote:h,resumePayment:v,stripeConnectedAccountId:y,stripeLoadFailed:b,paymentState:x,updateState:w}){let T=u(e,t),[E,M]=O(``),[N,P]=O(``),[F,I]=O(`US`),[z,B]=O({}),[V,H]=O({}),[U,W]=O(),[ee,te]=O(!1),[ne,re]=O(!1),[ie,ae]=O(!1),[G,oe]=O(()=>({customFields:d(T,r),customTip:``,includeServiceFee:e.widget.fields.serviceFee,memberId:``,merchSize:`M`,promoCode:``,shippingMatchesBilling:!0,tipPercent:`10`})),se=D({billing:null,shipping:null}),ce=D(null),K=D(null),ue=D(null),fe=D(h.totalCents>0),q=Ye({catalog:e,checkoutItems:t,client:n,elements:L(),email:E,fieldValues:G,metadata:i,onPaymentComplete:a,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:f,onResumePaymentFailed:s,onStateChange:p,paymentState:x,quote:h,resumePayment:v,stripe:R(),stripeConnectedAccountId:y,stripeLoadFailed:b,updateState:w}),{displayedTotalCents:J,isRecovering:pe,isRefreshingQuote:me,isSubmitting:Y,parsedTip:X,paymentError:he,promoError:ge,terminalMessage:_e,retryUrl:ve}=q.state,Z=`lockerverse-${C()}`,ye=`${Z}-email`,be=`${ye}-error`,xe=`${Z}-phone`,Se=`${xe}-error`,Ce=`${Z}-tip-error`,we=(X.success?X.cents:null)??0,Te=J-we,Ee=!e.widget.fields.shipping||G.shippingMatchesBilling||ie;S(()=>{Y&&ue.current?.focus({preventScroll:!0})},[Y]),S(()=>{Y||z.email||!z.phone||K.current?.focus()},[z.email,z.phone,Y]),S(()=>{let e=J>0;e&&!fe.current&&(te(!1),re(!1)),fe.current=e},[J]);function De(e){q.commands.fieldChanged(!1,e!==`email`),B(t=>{let n={...t};return delete n[e],n})}function Q(e){let t=e.promoCode!==G.promoCode,n=e.includeServiceFee!==G.includeServiceFee;q.commands.fieldChanged(t,!(t||n)),oe(e),H({}),W(void 0)}async function Oe(t){t.preventDefault();let n=e.widget.fields.phone?o(N,F):``,r=_({email:E,phone:n},e.widget.fields.phone),i=m(T,G.customFields);if(!(r.value&&X.success)||Object.keys(i).length>0){B(r.errors),H(i),W(X.success?void 0:X.message),q.commands.reportValidationFailure();let e=t.currentTarget;queueMicrotask(()=>{ct({customFieldErrors:i,emailRef:ce,form:e,parsedTipSuccess:X.success,phoneRef:K,validationErrors:r.errors})});return}B({}),H({});let a=await q.commands.submit({addresses:se.current,phone:n});a?.phoneError&&B({phone:a.phoneError})}return _e?j(`p`,{className:`lockerverse-payment__payment-status`,ref:ue,role:`status`,tabIndex:-1,children:[_e,ve?j(k,{children:[` `,A(`a`,{href:ve,rel:`noopener noreferrer`,target:`_blank`,children:`Complete payment`})]}):null]}):pe?A(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:`Recovering payment…`}):j(`form`,{"aria-busy":Y,className:`lockerverse-payment__form`,noValidate:!0,onSubmit:Oe,children:[A(`div`,{"data-lockerverse-input-region":``,inert:Y?!0:void 0,children:j(`fieldset`,{className:`lockerverse-payment__input-fieldset`,disabled:Y,children:[A(g,{displayedBaseCents:Te,displayedTipCents:we,displayedTotalCents:J,quote:h}),A(le,{enabled:e.widget.fields.tipping,error:U,errorId:Ce,onChange:Q,values:G}),A(lt,{email:E,emailDiscountPercentOff:h.appliedDiscount?.source===`email_list`?h.appliedDiscount.percentageOff:void 0,emailErrorId:be,emailId:ye,emailRef:ce,errors:z,onEmailBlur:()=>q.commands.refreshAuthoritativeTotal(),onEmailChange:e=>{M(e),De(`email`)},onPhoneChange:({value:e,country:t})=>{P(e),I(t),De(`phone`)},phone:N,phoneCountry:F,phoneEnabled:e.widget.fields.phone,phoneErrorId:Se,phoneId:xe,phoneRef:K}),A(at,{catalog:e,displayedTotalCents:J,fieldValues:G,isBillingAddressReady:ne,isPaymentReady:ee,isShippingAddressReady:ie,onAddressChange:(e,t)=>{se.current[e]=t},onFieldValuesChange:Q,onStripeLoadError:q.commands.reportStripeLoadError,setIsBillingAddressReady:re,setIsPaymentReady:te,setIsShippingAddressReady:ae}),A(de,{customFields:T,errors:V,fields:e.widget.fields,idPrefix:Z,isPromoApplying:me,memberIdLabel:e.community?.memberIdLabel,onApplyPromo:q.commands.applyPromo,onChange:Q,promoError:ge,values:G}),A(ot,{catalog:e,displayedTotalCents:J,fieldValues:G,isBillingAddressReady:ne,isPaymentReady:ee,isRequiredShippingReady:Ee,isSubmitting:Y,onFieldValuesChange:Q,quote:h})]})}),Y?A(`p`,{className:`lockerverse-payment__sr-only`,ref:ue,role:`status`,tabIndex:-1,children:J===0?`Completing order…`:`Processing payment…`}):null,A(it,{message:he})]})}function dt(){return A(h,{fieldCount:2,label:`Loading payment…`,sectionCount:2,showCheckbox:!0})}function ft(e,t){switch(t.type){case`loading`:return{phase:`loading`,revision:e.revision};case`ready`:return ht(t.displayedQuote,e.revision+1);case`error`:return{failure:t.failure,phase:`error`,revision:e.revision};case`checkout`:return e.phase===`ready`?{...e,displayedQuote:t.checkout,quoteFailure:void 0}:e;case`quote-error`:return e.phase===`ready`?{...e,quoteFailure:t.failure}:e;default:return e}}function $(e,t,n){return e?.catalog===t&&e.selectionKey===n}function pt({checkout:e}){return{displayedQuote:e,type:`ready`}}function mt(e){return e instanceof Error?e.message:`Lockerverse payment could not load.`}function ht(e,t){return{checkoutItems:[...e.items],displayedQuote:e,phase:`ready`,quoteFailure:void 0,revision:t}}function gt(e,t){let n=e.widget.fields.serviceFee;return N(e,{includeServiceFee:n,selection:t})}function _t(e,t){try{return ht(gt(e,t),1)}catch(e){return{failure:mt(e),phase:`error`,revision:0}}}function vt({catalog:e,client:t,paymentState:n,selection:r}){let i=Ee(r),a=i.success?JSON.stringify(i.value):`invalid-selection`,o=T(()=>i.success?i.value:[],[i.success,a]),[s,c]=E(ft,void 0,()=>i.success?_t(e,o):{phase:`loading`,revision:0}),l=D(void 0),u=D(0),d=D(s.phase===`ready`?{catalog:e,selectionKey:a}:void 0),f=D(s.phase===`error`?{catalog:e,selectionKey:a}:void 0),p=n===`submitting`||n===`success`||n===`unresolved`;S(()=>{if(!i.success||p||$(f.current,e,a)||$(l.current,e,a))return;let n=!0;l.current={catalog:e,selectionKey:a};let r=$(d.current,e,a);r||c({type:`loading`});function s(e){n&&c(e)}function m(){n&&(l.current=void 0,f.current={catalog:e,selectionKey:a})}let h;function g(t){if(!n||(l.current=void 0,f.current={catalog:e,selectionKey:a},r&&h!==void 0&&u.current!==h))return;let i=mt(t);if(i===`This option is sold out.`){c({failure:i,type:`error`});return}c(r?{failure:i,type:`quote-error`}:{failure:i,type:`error`})}async function _(){try{h=u.current;let n=e.widget.fields.serviceFee;if(!r){let t=gt(e,o);r=!0,d.current={catalog:e,selectionKey:a},s(pt({checkout:t}))}let i=await t.calculateTotal({catalog:e,includeServiceFee:n,selection:o});m(),u.current===h&&s({checkout:i,type:`checkout`})}catch(e){g(e)}}return _(),()=>{n=!1,$(l.current,e,a)&&(l.current=void 0)}},[e,t,i.success,p,a,o]);let m=$(d.current,e,a)||$(f.current,e,a)||$(l.current,e,a),h=p||m?s:{phase:`loading`,revision:s.revision};return{selectionError:i.success?void 0:i.message,session:h,updateCheckout:e=>{u.current+=1,c({checkout:e,type:`checkout`})}}}const yt={annually:`/year`,"every-six-months":` every 6 months`,monthly:`/month`,"one-time":``};function bt({branding:e,catalog:t}){return j(`header`,{children:[t.widget.showCommunityBranding&&e?j(`div`,{className:`lockerverse-payment__branding`,children:[e.imageUrl?A(`img`,{alt:e.name,height:`48`,src:e.imageUrl,width:`48`}):null,A(`strong`,{children:e.name})]}):null,A(`h1`,{children:t.widget.title??t.widget.name}),t.widget.description?A(`p`,{children:t.widget.description}):null]})}function xt({catalog:t,selection:n}){let r=n?.length?t.products.filter(e=>n.some(t=>t.productSlug===e.slug)):t.products;return r.length===0?null:j(`div`,{className:`lockerverse-payment__payment-summary`,children:[A(`h2`,{children:`Products`}),A(`div`,{className:`lockerverse-payment__payment-summary-items`,children:r.map(t=>{let n=t.pricingMode===`fixed`?t.amountCents:t.minimumAmountCents,r=yt[t.paymentOption];return j(`div`,{className:`lockerverse-payment__payment-summary-row`,children:[A(`span`,{children:t.name}),A(`strong`,{children:n===null?`Choose amount`:`${t.pricingMode===`custom`?`From `:``}${e(n)}${r}`})]},t.id)})}),A(`p`,{children:`Base prices. Final total is checked at checkout.`})]})}function St(e,t){let i=n(e?.[`--lockerverse-accent`]??t?.accentColor??`#38d77a`),a=r(i),o={...e};return(e?.[`--lockerverse-accent`]!==void 0||t?.accentColor)&&(o[`--lockerverse-accent`]=i),a&&e?.[`--lockerverse-accent-contrast`]===void 0&&(o[`--lockerverse-accent-contrast`]=a),{accent:i,rootStyle:o}}function Ct({catalog:e,client:t,loadError:n,onRetry:r,...i}){let{branding:a,className:o,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:u,onPaymentUncertain:d,resumePayment:f,selection:p,style:m,stripeLoader:h=Xe,theme:g=`dark`,..._}=i,[v,y]=O(f),b=D(null),[C,T]=O(),[E,k]=O(`idle`),M=D(void 0),{selectionError:N,session:P,updateCheckout:F}=vt({catalog:e,client:t,paymentState:E,selection:p}),I=P.phase===`ready`?P.revision:void 0,L=x(e=>{I!==void 0&&(M.current=I),k(e)},[I]),R=x(e=>u?.(e),[u]),z=x(()=>{y(void 0)},[]);S(()=>{P.phase===`loading`&&T(void 0)},[P.phase]),w(()=>{P.phase===`ready`&&M.current!==P.revision&&k(e=>e===`success`||e===`unresolved`?e:`idle`)},[P.phase,P.revision]);let B=[`lockerverse-payment`,o].filter(Boolean).join(` `),V=a??e.community,{accent:H,rootStyle:U}=St(m,V);return N?A(`section`,{..._,className:B,"data-lockerverse-theme":g,role:`alert`,style:U,children:N}):P.phase===`error`&&P.failure===`This option is sold out.`||E===`sold_out`?j(`section`,{..._,className:B,"data-lockerverse-theme":g,role:`alert`,style:U,children:[A(`h1`,{children:`Sold out`}),A(`p`,{children:`This option is sold out.`})]}):P.phase===`error`?A(`section`,{..._,className:B,"data-lockerverse-theme":g,style:U,children:A(`p`,{role:`alert`,children:P.failure})}):P.phase===`ready`?j(`section`,{..._,"aria-label":`Payment`,className:B,"data-lockerverse-theme":g,"data-payment-state":E,ref:b,style:U,children:[A(bt,{branding:V,catalog:e}),n?j(`div`,{role:`alert`,children:[A(`p`,{children:n.message}),A(`button`,{onClick:r,type:`button`,children:`Retry`})]}):null,C?A(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:C}):null,P.quoteFailure?j(`div`,{className:`lockerverse-payment__payment-status`,role:`alert`,children:[A(`span`,{children:P.quoteFailure}),A(`span`,{children:` The final total will be checked when you submit.`})]}):null,A(et,{accentColor:H,appearanceRoot:b,catalog:e,checkoutItems:P.checkoutItems,client:t,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:R,onPaymentUncertain:d,onQuoteChange:(e,t)=>{T(t),F(e)},onResumePaymentFailed:z,onStateChange:L,quote:P.displayedQuote,resumePayment:v,stripeLoader:h,theme:g,visualStyle:U},P.revision)]}):j(`section`,{..._,"aria-busy":`true`,"aria-label":`Payment`,className:B,"data-lockerverse-theme":g,style:U,children:[A(bt,{branding:V,catalog:e}),n?j(`div`,{role:`alert`,children:[A(`p`,{children:n.message}),A(`button`,{onClick:r,type:`button`,children:`Retry`})]}):null,A(dt,{})]})}function wt({children:e,loading:t=!1,viewProps:i}){let{branding:a,className:o,initialCustomFieldValues:s,metadata:c,onPaymentComplete:l,onPaymentRecoveryChange:u,onPaymentUncertain:d,resumePayment:f,selection:p,stripeLoader:m,style:h,theme:g=`dark`,..._}=i,v=n(h?.[`--lockerverse-accent`]??a?.accentColor??`#38d77a`),y=r(v),b={...h};return(h?.[`--lockerverse-accent`]!==void 0||a?.accentColor)&&(b[`--lockerverse-accent`]=v),y&&h?.[`--lockerverse-accent-contrast`]===void 0&&(b[`--lockerverse-accent-contrast`]=y),A(`section`,{..._,...t?{"aria-busy":!0,"aria-label":`Payment`}:{},className:[`lockerverse-payment`,o].filter(Boolean).join(` `),"data-lockerverse-theme":g,style:b,children:e})}function Tt({widget:e,...t}){return e.error&&!e.catalog?j(wt,{viewProps:t,children:[A(`p`,{role:`alert`,children:e.error.message}),A(`button`,{onClick:e.refresh,type:`button`,children:`Retry`})]}):e.loading?j(wt,{loading:!0,viewProps:t,children:[e.catalog?j(k,{children:[A(bt,{branding:t.branding??e.catalog.community,catalog:e.catalog}),A(xt,{catalog:e.catalog,selection:t.selection})]}):null,A(dt,{})]}):e.catalog?A(Ct,{catalog:e.catalog,client:e.client,loadError:e.error,onRetry:e.refresh,...t}):A(wt,{loading:!0,viewProps:t,children:A(dt,{})})}export{Ze as n,Tt as t};
2
2
  //# sourceMappingURL=lockerverse-payment.js.map