import state from"./store";import{toggleCart}from"../ui";import{addQueryArgs}from"@wordpress/url";import{setProduct}from"./setters";import{addCheckoutLineItem}from"../checkout/mutations";export const submitCartForm=async t=>{var e,o,n,d,i,a;const r=state[t];if(r&&(null===(e=r.selectedPrice)||void 0===e?void 0:e.id)&&(!(null===(o=r.selectedPrice)||void 0===o?void 0:o.ad_hoc)||null!==r.adHocAmount&&void 0!==r.adHocAmount))try{setProduct(t,{busy:!0}),await addCheckoutLineItem({price:null===(n=r.selectedPrice)||void 0===n?void 0:n.id,quantity:Math.max((null===(d=r.selectedPrice)||void 0===d?void 0:d.ad_hoc)?1:r.quantity,1),...(null===(i=r.selectedPrice)||void 0===i?void 0:i.ad_hoc)?{ad_hoc_amount:r.adHocAmount}:{},variant:null===(a=r.selectedVariant)||void 0===a?void 0:a.id,...r.note?{note:r.note}:{},...r.bundleComponentVariants&&Object.keys(r.bundleComponentVariants).length?{bundle_component_variants:r.bundleComponentVariants}:{}}),toggleCart(!0),setProduct(t,{dialog:null})}catch(t){throw console.error(t),state.error=t,t}finally{setProduct(t,{busy:!1})}};export const getProductBuyLink=(t,e,o={})=>{var n,d,i,a,r,l,c;const u=state[t];if(u&&(null===(n=u.selectedPrice)||void 0===n?void 0:n.id)&&(!(null===(d=u.selectedPrice)||void 0===d?void 0:d.ad_hoc)||u.adHocAmount||0===u.adHocAmount))return addQueryArgs(e,{line_items:[{price:null===(i=u.selectedPrice)||void 0===i?void 0:i.id,quantity:Math.max((null===(a=u.selectedPrice)||void 0===a?void 0:a.ad_hoc)?1:u.quantity,1),...(null===(r=u.selectedPrice)||void 0===r?void 0:r.ad_hoc)?{ad_hoc_amount:u.adHocAmount}:{},...(null===(l=u.selectedVariant)||void 0===l?void 0:l.id)?{variant:null===(c=u.selectedVariant)||void 0===c?void 0:c.id}:{},...u.note?{note:u.note}:{},...u.bundleComponentVariants&&Object.keys(u.bundleComponentVariants).length?{bundle_component_variants:u.bundleComponentVariants}:{}}],...o})};