import{b as setProduct,s as state}from"./watchers-fbf07f32.js";import{t as toggleCart}from"./mutations-6bbbe793.js";import{a as addCheckoutLineItem}from"./mutations-766c6622.js";import{a as addQueryArgs}from"./add-query-args-0e2a8393.js";const submitCartForm=async e=>{var o,t,d,i,a,r;const l=state[e];if(l&&(null===(o=l.selectedPrice)||void 0===o?void 0:o.id)&&(!(null===(t=l.selectedPrice)||void 0===t?void 0:t.ad_hoc)||null!==l.adHocAmount&&void 0!==l.adHocAmount))try{setProduct(e,{busy:!0}),await addCheckoutLineItem({price:null===(d=l.selectedPrice)||void 0===d?void 0:d.id,quantity:Math.max((null===(i=l.selectedPrice)||void 0===i?void 0:i.ad_hoc)?1:l.quantity,1),...(null===(a=l.selectedPrice)||void 0===a?void 0:a.ad_hoc)?{ad_hoc_amount:l.adHocAmount}:{},variant:null===(r=l.selectedVariant)||void 0===r?void 0:r.id,...l.note?{note:l.note}:{}}),toggleCart(!0),setProduct(e,{dialog:null})}catch(e){throw console.error(e),state.error=e,e}finally{setProduct(e,{busy:!1})}},getProductBuyLink=(e,o,t={})=>{var d,i,a,r,l,s,n;const c=state[e];if(c&&(null===(d=c.selectedPrice)||void 0===d?void 0:d.id)&&(!(null===(i=c.selectedPrice)||void 0===i?void 0:i.ad_hoc)||c.adHocAmount||0===c.adHocAmount))return addQueryArgs(o,{line_items:[{price:null===(a=c.selectedPrice)||void 0===a?void 0:a.id,quantity:Math.max((null===(r=c.selectedPrice)||void 0===r?void 0:r.ad_hoc)?1:c.quantity,1),...(null===(l=c.selectedPrice)||void 0===l?void 0:l.ad_hoc)?{ad_hoc_amount:c.adHocAmount}:{},...(null===(s=c.selectedVariant)||void 0===s?void 0:s.id)?{variant:null===(n=c.selectedVariant)||void 0===n?void 0:n.id}:{},...c.note?{note:c.note}:{}}],...t})},getAdditionalErrorMessages=e=>((null==e?void 0:e.additional_errors)||[]).map((e=>e.message)),getTopLevelError=e=>{var o;return"checkout.invalid"===(null==e?void 0:e.code)&&(null===(o=getAdditionalErrorMessages(e))||void 0===o?void 0:o.length)?"":null==e?void 0:e.message};export{getTopLevelError as a,getAdditionalErrorMessages as b,getProductBuyLink as g,submitCartForm as s};