import{getCheckout}from"../checkouts/mutations";import state from"./store";import{state as userState}from"../user";import{isAddressComplete}from"../../functions/address";export const currentCheckout=()=>getCheckout(state.formId,state.mode);export const checkoutIsLocked=(e="")=>{var t;return e?state.locks.some((t=>t===e)):!!(null===(t=state.locks)||void 0===t?void 0:t.length)};export const getLineItemByProductId=e=>{var t,o;return((null===(o=null===(t=state.checkout)||void 0===t?void 0:t.line_items)||void 0===o?void 0:o.data)||[]).find((t=>{var o,i;return(null===(i=null===(o=null==t?void 0:t.price)||void 0===o?void 0:o.product)||void 0===i?void 0:i.id)===e}))};export const fullShippingAddressRequired=()=>{var e;return"full"===(null===(e=state.checkout)||void 0===e?void 0:e.shipping_address_accuracy_requirement)};export const shippingAddressRequired=()=>{var e,t;return"full"===(null===(e=state.checkout)||void 0===e?void 0:e.shipping_address_accuracy_requirement)||"tax"===(null===(t=state.checkout)||void 0===t?void 0:t.shipping_address_accuracy_requirement)};export const getCompleteAddress=(e="shipping")=>{var t,o;if(!isAddressComplete(null===(t=state.checkout)||void 0===t?void 0:t[`${e}_address`]))return;const{line_1:i,line_2:s,...r}=(null===(o=state.checkout)||void 0===o?void 0:o[`${e}_address`])||{};return{line1:i,line2:s,...r}};export const getResolvedBillingAddress=e=>{const t=e||state.checkout,o=!1===(null==t?void 0:t.billing_matches_shipping)&&(null==t?void 0:t.billing_address)?t.billing_address:void 0,i=(null==o?void 0:o.line_1)?o:null==t?void 0:t.shipping_address;if(null==i?void 0:i.line_1)return i};export const getResolvedBillingEmail=e=>{var t;const o=e||state.checkout;return(null==o?void 0:o.email)||(null===(t=null==o?void 0:o.customer)||void 0===t?void 0:t.email)||(null==userState?void 0:userState.email)||void 0};export const toStripeAddress=e=>{if(!(null==e?void 0:e.line_1))return;const{line_1:t,line_2:o,city:i,state:s,country:r,postal_code:l}=e;return{line1:t,line2:o,city:i,state:s,postal_code:l,country:r}};