import{onChange as onChangeCheckout}from"../checkout";import{onChange as onChangeProcessor,state as selectedProcessor}from"../selected-processor";import{availableManualPaymentMethods,availableMethodTypes,availableProcessors,isMethodAwareProcessor}from"./getters";import{onChange}from"./store";const maybeUpdateProcessor=()=>{var e,o;const s=[...availableProcessors().map((({processor_type:e})=>e)),...availableManualPaymentMethods().map((({id:e})=>e))];s.includes(selectedProcessor.id)||(null===(o=null===(e=null===window||void 0===window?void 0:window.wp)||void 0===e?void 0:e.hooks)||void 0===o?void 0:o.applyFilters)&&!window.wp.hooks.applyFilters("surecart_auto_select_payment_method",!0)||(selectedProcessor.id=(null==s?void 0:s.length)?null==s?void 0:s[0]:null)},maybeUpdateMethod=()=>{const e=(availableMethodTypes()||[]).map((({id:e})=>e));isMethodAwareProcessor(null==selectedProcessor?void 0:selectedProcessor.id)?e.includes(selectedProcessor.method)||(selectedProcessor.method=(null==e?void 0:e.length)?null==e?void 0:e[0]:null):selectedProcessor.method=null};onChangeCheckout("checkout",(()=>{maybeUpdateProcessor(),maybeUpdateMethod()})),onChangeProcessor("id",(()=>{maybeUpdateProcessor(),maybeUpdateMethod()})),onChange("processors",(()=>maybeUpdateProcessor())),onChange("disabled",(()=>maybeUpdateProcessor())),onChange("methods",(()=>maybeUpdateMethod()));