import store from"./store";import{state as checkoutState,reset as resetCheckoutState}from"../checkout/index";import{addQueryArgs,removeQueryArgs}from"@wordpress/url";export const getCheckout=(t,e)=>{var o;return(null===(o=store.state[e])||void 0===o?void 0:o[t])||{}};export const setCheckout=(t,e)=>{const o=(null==t?void 0:t.live_mode)?"live":"test";store.set(o,{...store.state[o],[e]:t}),checkoutState.formId===e&&checkoutState.mode===o&&(checkoutState.checkout=t),"url"===checkoutState.persist&&(null==t?void 0:t.id)&&window.history.replaceState({},document.title,addQueryArgs(window.location.href,{checkout_id:null==t?void 0:t.id}));const r=new CustomEvent("scCheckoutUpdated",{detail:{checkout:checkoutState.checkout,formId:checkoutState.formId,mode:checkoutState.mode},bubbles:!0});document.dispatchEvent(r)};export const clearCheckout=(t,e,o="")=>{var r,c,s;const{[t]:u,...i}=store.state[e];window.history.replaceState({},document.title,removeQueryArgs(window.location.href,"redirect_status","coupon","line_items","confirm_checkout_id","checkout_id")),store.set(e,i);const d=JSON.parse(localStorage.getItem("surecart-local-storage")||"{}");if(null===(r=d[e])||void 0===r?void 0:r[t]){if(o&&(null===(s=null===(c=d[e])||void 0===c?void 0:c[t])||void 0===s?void 0:s.id)!==o)return;delete d[e][t],localStorage.setItem("surecart-local-storage",JSON.stringify(d))}resetCheckoutState()};