import{sortByArray}from"../../functions/util";import state from"./store";import{state as checkoutState}from"../checkout/index";import{state as selectedProcessor}from"../selected-processor/index";export const METHOD_AWARE_PROCESSORS=["mollie","razorpay"];export const isMethodAwareProcessor=e=>!!e&&METHOD_AWARE_PROCESSORS.includes(e);export const availableProcessors=()=>sortByArray(state.processors,"processor_type",state.sortOrder.processors).filter((e=>(null==e?void 0:e.live_mode)===("live"===(null==checkoutState?void 0:checkoutState.mode)))).filter((e=>!(state.disabled.processors||[]).includes(e.processor_type))).filter((e=>{var o;return!(null===(o=null==checkoutState?void 0:checkoutState.checkout)||void 0===o?void 0:o.reusable_payment_method_required)||!!(null==e?void 0:e.recurring_enabled)})).filter(((e,o,r)=>!r.some((e=>"mollie"===e.processor_type))||"mollie"===e.processor_type||"mock"===e.processor_type));export const getProcessorByType=e=>availableProcessors().find((({processor_type:o})=>o===e));export const getAvailableProcessor=e=>availableProcessors().find((({processor_type:o})=>o===e));export const processorSupportsCurrentCurrency=e=>{var o,r;return!!e&&(null!==(o=e.supported_currencies)&&void 0!==o?o:[]).includes(null===(r=null===window||void 0===window?void 0:window.scData)||void 0===r?void 0:r.currency)};export const hasOtherAvailableCreditCardProcessor=e=>availableProcessors().some((({processor_type:o})=>o!==e&&"paypal"!==o&&"mock"!==o));export const availableManualPaymentMethods=()=>sortByArray(state.manualPaymentMethods,"id",state.sortOrder.manualPaymentMethods).filter((e=>!(state.disabled.processors||[]).includes(null==e?void 0:e.id))).filter((e=>{var o;return!(null===(o=null==checkoutState?void 0:checkoutState.checkout)||void 0===o?void 0:o.reusable_payment_method_required)||!!(null==e?void 0:e.reusable)}));export const availableMethodTypes=()=>{const e=null==selectedProcessor?void 0:selectedProcessor.id,o=isMethodAwareProcessor(e)?state.sortOrder.paymentMethods[e]:[];return sortByArray(state.methods,"id",o||[]).filter((e=>{var o,r;return"applepay"!==e.id||(null===window||void 0===window?void 0:window.ApplePaySession)&&(null===(r=null===(o=null===window||void 0===window?void 0:window.ApplePaySession)||void 0===o?void 0:o.canMakePayments)||void 0===r?void 0:r.call(o))}))};export const availableProcessorChoices=()=>[...availableProcessors(),...availableManualPaymentMethods()];export const hasMultipleProcessorChoices=()=>{var e;return(null===(e=availableProcessorChoices())||void 0===e?void 0:e.length)>1};export const availableMethodChoices=()=>[...availableMethodTypes(),...availableManualPaymentMethods(),getProcessorByType("mock")].filter(Boolean);export const hasMultipleMethodChoices=()=>{var e;return(null===(e=availableMethodChoices())||void 0===e?void 0:e.length)>1};