import { PaymentSelectors, ValidationActions } from '@greenpay/redux'
import { BankLoginCheckoutContext, BankLoginClassicPayloadContext } from './types'

export function createBankLoginCheckoutContext(
	payment: Pick<PaymentSelectors, 'getPlaid' | 'getRibbit'>,
	validation: Pick<ValidationActions, 'validatePlaid' | 'validateRibbit'>,
): BankLoginCheckoutContext {
	return {
		getPlaid: payment.getPlaid,
		getRibbit: payment.getRibbit,
		validatePlaid: validation.validatePlaid,
		validateRibbit: validation.validateRibbit,
		getHiddenInputValue: (name: string) =>
			document.querySelector<HTMLInputElement>(`input[name="${name}"]`)?.value,
	}
}

export function createBankLoginClassicPayloadContext(
	checkoutContext: BankLoginCheckoutContext,
	setValue: (name: string, value: string) => void,
): BankLoginClassicPayloadContext {
	return {
		...checkoutContext,
		setValue,
	}
}
