"use strict";const watchers=require("./watchers-d2dd8b04.js"),mutations$1=require("./mutations-927be23d.js"),mutations=require("./mutations-06bf0ea4.js"),addQueryArgs=require("./add-query-args-49dcb630.js"),submitCartForm=async e=>{var t,o,d,r,i,n;const a=watchers.state[e];if(a&&(null===(t=a.selectedPrice)||void 0===t?void 0:t.id)&&(!(null===(o=a.selectedPrice)||void 0===o?void 0:o.ad_hoc)||null!==a.adHocAmount&&void 0!==a.adHocAmount))try{watchers.setProduct(e,{busy:!0}),await mutations.addCheckoutLineItem({price:null===(d=a.selectedPrice)||void 0===d?void 0:d.id,quantity:Math.max((null===(r=a.selectedPrice)||void 0===r?void 0:r.ad_hoc)?1:a.quantity,1),...(null===(i=a.selectedPrice)||void 0===i?void 0:i.ad_hoc)?{ad_hoc_amount:a.adHocAmount}:{},variant:null===(n=a.selectedVariant)||void 0===n?void 0:n.id,...a.note?{note:a.note}:{},...a.bundleComponentVariants&&Object.keys(a.bundleComponentVariants).length?{bundle_component_variants:a.bundleComponentVariants}:{}}),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,n,a,s,l;const u=watchers.state[e];if(u&&(null===(d=u.selectedPrice)||void 0===d?void 0:d.id)&&(!(null===(r=u.selectedPrice)||void 0===r?void 0:r.ad_hoc)||u.adHocAmount||0===u.adHocAmount))return addQueryArgs.addQueryArgs(t,{line_items:[{price:null===(i=u.selectedPrice)||void 0===i?void 0:i.id,quantity:Math.max((null===(n=u.selectedPrice)||void 0===n?void 0:n.ad_hoc)?1:u.quantity,1),...(null===(a=u.selectedPrice)||void 0===a?void 0:a.ad_hoc)?{ad_hoc_amount:u.adHocAmount}:{},...(null===(s=u.selectedVariant)||void 0===s?void 0:s.id)?{variant:null===(l=u.selectedVariant)||void 0===l?void 0:l.id}:{},...u.note?{note:u.note}:{},...u.bundleComponentVariants&&Object.keys(u.bundleComponentVariants).length?{bundle_component_variants:u.bundleComponentVariants}:{}}],...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;