"use strict";const watchers=require("./watchers-db03ec4e.js"),mutations$1=require("./mutations-10a18c83.js"),mutations=require("./mutations-2db027c4.js"),addQueryArgs=require("./add-query-args-49dcb630.js"),submitCartForm=async e=>{var t,o,d,r,i,a;const s=watchers.state[e];if(s&&(null===(t=s.selectedPrice)||void 0===t?void 0:t.id)&&(!(null===(o=s.selectedPrice)||void 0===o?void 0:o.ad_hoc)||null!==s.adHocAmount&&void 0!==s.adHocAmount))try{watchers.setProduct(e,{busy:!0}),await mutations.addCheckoutLineItem({price:null===(d=s.selectedPrice)||void 0===d?void 0:d.id,quantity:Math.max((null===(r=s.selectedPrice)||void 0===r?void 0:r.ad_hoc)?1:s.quantity,1),...(null===(i=s.selectedPrice)||void 0===i?void 0:i.ad_hoc)?{ad_hoc_amount:s.adHocAmount}:{},variant:null===(a=s.selectedVariant)||void 0===a?void 0:a.id,...s.note?{note:s.note}:{}}),mutations$1.toggleCart(!0),watchers.setProduct(e,{dialog:null})}catch(e){throw console.error(e),watchers.state.error=e,e}finally{watchers.setProduct(e,{busy:!1})}},getProductBuyLink=(e,t,o={})=>{var d,r,i,a,s,c,n;const l=watchers.state[e];if(l&&(null===(d=l.selectedPrice)||void 0===d?void 0:d.id)&&(!(null===(r=l.selectedPrice)||void 0===r?void 0:r.ad_hoc)||l.adHocAmount||0===l.adHocAmount))return addQueryArgs.addQueryArgs(t,{line_items:[{price:null===(i=l.selectedPrice)||void 0===i?void 0:i.id,quantity:Math.max((null===(a=l.selectedPrice)||void 0===a?void 0:a.ad_hoc)?1:l.quantity,1),...(null===(s=l.selectedPrice)||void 0===s?void 0:s.ad_hoc)?{ad_hoc_amount:l.adHocAmount}:{},...(null===(c=l.selectedVariant)||void 0===c?void 0:c.id)?{variant:null===(n=l.selectedVariant)||void 0===n?void 0:n.id}:{},...l.note?{note:l.note}:{}}],...o})},getAdditionalErrorMessages=e=>((null==e?void 0:e.additional_errors)||[]).map((e=>e.message)),getTopLevelError=e=>{var t;return"checkout.invalid"===(null==e?void 0:e.code)&&(null===(t=getAdditionalErrorMessages(e))||void 0===t?void 0:t.length)?"":null==e?void 0:e.message};exports.getAdditionalErrorMessages=getAdditionalErrorMessages,exports.getProductBuyLink=getProductBuyLink,exports.getTopLevelError=getTopLevelError,exports.submitCartForm=submitCartForm;