import{b as o,s as i}from"./p-7d44e2d5.js";import{t as n}from"./p-6c74654a.js";import{a as l}from"./p-75923b89.js";import{a as d}from"./p-401e165e.js";const t=async e=>{var d,t,a,c,r,s;const v=i[e];if(v&&(null===(d=v.selectedPrice)||void 0===d?void 0:d.id)&&(!(null===(t=v.selectedPrice)||void 0===t?void 0:t.ad_hoc)||null!==v.adHocAmount&&void 0!==v.adHocAmount))try{o(e,{busy:!0}),await l({price:null===(a=v.selectedPrice)||void 0===a?void 0:a.id,quantity:Math.max((null===(c=v.selectedPrice)||void 0===c?void 0:c.ad_hoc)?1:v.quantity,1),...(null===(r=v.selectedPrice)||void 0===r?void 0:r.ad_hoc)?{ad_hoc_amount:v.adHocAmount}:{},variant:null===(s=v.selectedVariant)||void 0===s?void 0:s.id,...v.note?{note:v.note}:{}}),n(!0),o(e,{dialog:null})}catch(o){throw console.error(o),i.error=o,o}finally{o(e,{busy:!1})}},v=(o,e,t={})=>{var a,l,n,c,r,s,v;const u=i[o];if(u&&(null===(a=u.selectedPrice)||void 0===a?void 0:a.id)&&(!(null===(l=u.selectedPrice)||void 0===l?void 0:l.ad_hoc)||u.adHocAmount||0===u.adHocAmount))return d(e,{line_items:[{price:null===(n=u.selectedPrice)||void 0===n?void 0:n.id,quantity:Math.max((null===(c=u.selectedPrice)||void 0===c?void 0:c.ad_hoc)?1:u.quantity,1),...(null===(r=u.selectedPrice)||void 0===r?void 0:r.ad_hoc)?{ad_hoc_amount:u.adHocAmount}:{},...(null===(s=u.selectedVariant)||void 0===s?void 0:s.id)?{variant:null===(v=u.selectedVariant)||void 0===v?void 0:v.id}:{},...u.note?{note:u.note}:{}}],...t})},r=o=>((null==o?void 0:o.additional_errors)||[]).map((o=>o.message)),u=o=>{var i;return"checkout.invalid"===(null==o?void 0:o.code)&&(null===(i=r(o))||void 0===i?void 0:i.length)?"":null==o?void 0:o.message};export{u as a,r as b,v as g,t as s};