import Payment from "payment";
import visa from "../../../assets/paymentIcons/visa.svg";
import mastercard from "../../../assets/paymentIcons/mastercard.svg";
import amex from "../../../assets/paymentIcons/amex.svg";
import discover from "../../../assets/paymentIcons/discover.svg";
import diners from "../../../assets/paymentIcons/diners.svg";
import unionpay from "../../../assets/paymentIcons/unionpay.svg";
import jcb from "../../../assets/paymentIcons/jcb.svg";
//#region src/utilities/form/paymentForm/CreditCardUtils.ts
/**
* clearNumber
*
* @param {string} [value='']
* @return {*}
*/
function clearNumber(value = "") {
	return value.replace(/\D+/g, "");
}
/**
* formatCreditCardNumber - Format credit card number
*
* @export
* @param {*} value
* @return {*}
*/
function formatCreditCardNumber(value) {
	if (!value) return value;
	const issuer = Payment.fns.cardType(value);
	const clearValue = clearNumber(value);
	let nextValue;
	switch (issuer) {
		case "amex":
			nextValue = `${clearValue.slice(0, 4)} ${clearValue.slice(4, 10)} ${clearValue.slice(10, 15)}`;
			break;
		case "dinersclub":
			nextValue = `${clearValue.slice(0, 4)} ${clearValue.slice(4, 10)} ${clearValue.slice(10, 14)}`;
			break;
		default:
			nextValue = `${clearValue.slice(0, 4)} ${clearValue.slice(4, 8)} ${clearValue.slice(8, 12)} ${clearValue.slice(12, 19)}`;
			break;
	}
	return nextValue.trim();
}
/**
* formatCVC - formats the CVC value
*
* @export
* @param {*} value
* @param {*} prevValue
* @param {*} [allValues={}]
* @return {*}
*/
function formatCVC(value, prevValue, allValues = {}) {
	const clearValue = clearNumber(value);
	let maxLength = 4;
	if (allValues?.number) maxLength = Payment.fns.cardType(allValues?.number) === "amex" ? 4 : 3;
	return clearValue.slice(0, maxLength);
}
/**
* formatExpirationDate - format expiration date
* @export
* @param {*} value
* @return {*}
*/
function formatExpirationDate(value) {
	const clearValue = clearNumber(value);
	if (clearValue.length >= 3) return `${clearValue.slice(0, 2)}/${clearValue.slice(2, 4)}`;
	return clearValue;
}
/**
* formatBankAccountNumber - Format bank account number
* @export
* @param {*} value
* @return {*}
*/
function formatBankAccountNumber(value) {
	const clearValue = clearNumber(value);
	return `${clearValue.slice(0, 4)} ${clearValue.slice(4, 8)} ${clearValue.slice(8, 12)} ${clearValue.slice(12, 16)} ${clearValue.slice(16, 20)}`;
}
/**
* formatRoutingNumber - format routing number
* @export
* @param {*} value
* @return {*}
*/
function formatRoutingNumber(value) {
	const clearValue = clearNumber(value);
	return `${clearValue.slice(0, 3)} ${clearValue.slice(3, 9)}`;
}
const CreditCardBrandIconUrls = {
	visa,
	mastercard,
	amex,
	discover,
	jcb,
	dinersclub: diners,
	unionpay
};
const getCreditCardMethodIconUrl = (creditCardNumber) => {
	return CreditCardBrandIconUrls[Payment.fns.cardType(creditCardNumber)] ?? null;
};
const getCreditCardMethodIcon = getCreditCardMethodIconUrl;
//#endregion
export { formatBankAccountNumber, formatCVC, formatCreditCardNumber, formatExpirationDate, formatRoutingNumber, getCreditCardMethodIcon };

//# sourceMappingURL=CreditCardUtils.mjs.map