import{a as on}from"./watchers.js";import{i as isUpsellExpired,g as getExitUrl}from"./getters.js";import{p as preview}from"./mutations.js";import{s as state,o as onChange}from"./store.js";import{a as addQueryArgs}from"./add-query-args.js";on("set",((t,e,i)=>{JSON.stringify(null==e?void 0:e.line_item)!==JSON.stringify(null==i?void 0:i.line_item)&&preview()})),setInterval((()=>{isUpsellExpired()&&(state.loading="complete")}),1e3),onChange("line_item",(()=>{var t,e,i;state.amount_due=(null===(t=null==state?void 0:state.line_item)||void 0===t?void 0:t.total_amount)+(null!==(i=null===(e=null==state?void 0:state.line_item)||void 0===e?void 0:e.trial_amount)&&void 0!==i?i:0)})),onChange("upsell",(t=>{var e;if(!(null==t?void 0:t.permalink))return state.loading="complete";state.loading="redirecting",window.location.assign(addQueryArgs(null==t?void 0:t.permalink,{sc_checkout_id:null===(e=state.checkout)||void 0===e?void 0:e.id,sc_form_id:state.form_id}))})),onChange("loading",(t=>{var e;if("complete"===t){const t=getExitUrl();if(!t)return state.loading="complete";state.loading="redirecting",window.location.assign(addQueryArgs(t,{sc_order:null===(e=state.checkout)||void 0===e?void 0:e.id}))}}));