import{state}from"./store";export const isBusy=()=>["loading","busy","redirecting"].includes(state.loading);export const getExitUrl=()=>{var t,e;return(null===(e=null===(t=null==state?void 0:state.checkout)||void 0===t?void 0:t.metadata)||void 0===e?void 0:e.success_url)||state.success_url||null};export const getDiscountedAmount=t=>{var e,o;return null!==(o=null===(e=null==state?void 0:state.line_item)||void 0===e?void 0:e.total_amount)&&void 0!==o?o:t};export const getScratchAmount=t=>{var e,o,i;return(null===(e=null==state?void 0:state.line_item)||void 0===e?void 0:e.total_savings_amount)?-(null===(o=null==state?void 0:state.line_item)||void 0===o?void 0:o.total_savings_amount)+(null===(i=null==state?void 0:state.line_item)||void 0===i?void 0:i.total_amount):t};export const getUpsellRemainingTime=(t="seconds")=>{var e;const o=null===(e=state.checkout)||void 0===e?void 0:e.upsells_expire_at;if(!o)return null;const i=Date.now(),n=Math.floor((1e3*o-i)/1e3);return n<0?0:"seconds"===t?n:"minutes"===t?Math.floor(n/60):"hours"===t?Math.floor(n/60/60):void 0};export const formatTimeUnit=t=>t<10?`0${t}`:`${t}`;export const getFormattedRemainingTime=()=>{var t;if(!(null===(t=state.checkout)||void 0===t?void 0:t.upsells_expire_at))return"--:--";const e=getUpsellRemainingTime("seconds"),o=Math.floor(e/86400),i=Math.floor(e%86400/3600),n=Math.floor(e%3600/60),l=Math.floor(e%60);return o>0?`${formatTimeUnit(o)}:${formatTimeUnit(i)}:${formatTimeUnit(n)}:${formatTimeUnit(l)}`:i>0?`${formatTimeUnit(i)}:${formatTimeUnit(n)}:${formatTimeUnit(l)}`:`${formatTimeUnit(n)}:${formatTimeUnit(l)}`};export const isUpsellExpired=()=>{const t=getUpsellRemainingTime();return null!==getUpsellRemainingTime()&&t<=0};