import{addQueryArgs}from"@wordpress/url";import{on}from"../product";import{getExitUrl,isUpsellExpired}from"./getters";import{preview}from"./mutations";import state,{onChange}from"./store";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}))}}));