import { a as create$6 } from './index.esm-KCSohgHx.js';
import { P as ProvinceOptions, a as countryValidation } from './country-config-CEJVOOGe.js';
import { S as StateOptions, C as CountryCode } from './Business-BcNb9bVO.js';
import { a as businessServiceReceivedOptions, c as bankAccountTypeOptions } from './business-form-options-DXjZp4Rl.js';

/**
 * US states/territories + Canadian provinces/territories for checkout billing only.
 * Do not use for USA-only business forms (see country-config).
 */
const checkoutBillingStateOptions = [
    { label: 'Choose state / province', value: '' },
    ...StateOptions.filter((option) => option.value !== ''),
    ...ProvinceOptions.filter((option) => option.value !== ''),
];

const transformEmptyString = (value) => {
    return value === '' ? null : value;
};
const validateRoutingNumber = (routingNumber) => {
    if (!routingNumber)
        return false;
    const integers = Array.from(String(routingNumber), Number);
    if (integers.length === 9) {
        const checksum = ((3 * (integers[0] + integers[3] + integers[6])) +
            (7 * (integers[1] + integers[4] + integers[7])) +
            (integers[2] + integers[5] + integers[8])) % 10;
        if (checksum === 0)
            return true;
    }
    return false;
};
const phoneRegex = /^\d{10}$/;
const urlRegex = /^(?:http(s)?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/;
const numbersOnlyRegex = /^\d+$/;
const ssnRegex = /^(?!000|666|9\d{2})\d{3}(?!00)\d{2}(?!0000)\d{4}$/;
const poBoxRegex = /P\.?\s?O\.?\s?Box|Postal\sBox/i;

// Common Validations
const emailValidation = create$6()
    .email('Enter valid email')
    .transform(transformEmptyString);
const phoneValidation = create$6()
    .matches(phoneRegex, 'Enter valid phone number')
    .transform(transformEmptyString);
// Core Info Validations
const businessNameValidation = create$6()
    .min(2, 'Name must be at least 2 characters')
    .max(100, 'Name must be less than 100 characters')
    .transform(transformEmptyString);
const doingBusinessAsValidation = create$6()
    .min(2, 'Name must be at least 2 characters')
    .max(100, 'Name must be less than 100 characters')
    .transform(transformEmptyString);
const websiteUrlValidation = create$6()
    .matches(urlRegex, 'Enter valid website url')
    .transform(transformEmptyString);
const businessClassificationValidation = create$6().transform(transformEmptyString);
const industryValidation = create$6()
    .min(2, 'Industry must be at least 2 characters')
    .max(50, 'Industry must be less than 50 characters')
    .transform(transformEmptyString);
const taxIdValidation = create$6()
    .matches(numbersOnlyRegex, 'Enter valid tax id, SSN, or EIN')
    .test('not-repeat', 'Enter valid tax id, SSN, or EIN', (value) => {
    return !/^(\d)\1+$/.test(value);
})
    .test('not-seq', 'Enter valid tax id, SSN, or EIN', (value) => {
    return value !== '123456789';
})
    .transform(transformEmptyString);
// Country-aware helpers (backward compatible)
const makePostalValidation = (country) => create$6()
    .matches(countryValidation[country].postalRegex, 'Enter valid postal code')
    .transform(transformEmptyString);
const makeIdentityNumberValidation = (country) => {
    if (country === CountryCode.CAN) {
        return create$6()
            .matches(numbersOnlyRegex, 'Enter valid SIN')
            .length(countryValidation[country].identityDigits, 'Enter valid SIN')
            .test('not-repeat', 'Enter valid SIN', (value) => {
            return !/^(\d)\1+$/.test(value);
        })
            .test('not-seq', 'Enter valid SIN', (value) => {
            return value !== '123456789';
        })
            .transform(transformEmptyString);
    }
    // USA default (SSN)
    return ssnValidation;
};
const makeTaxIdValidation = (country) => {
    if (country === CountryCode.CAN) {
        return create$6()
            .matches(numbersOnlyRegex, 'Enter valid Business Number (BN)')
            .length(countryValidation[country].taxIdDigits, 'Enter valid Business Number (BN)')
            .test('not-repeat', 'Enter valid Business Number (BN)', (value) => {
            if (!value)
                return true;
            return !/^(\d)\1+$/.test(value);
        })
            .test('not-seq', 'Enter valid Business Number (BN)', (value) => {
            if (!value)
                return true;
            return value !== '123456789';
        })
            .transform(transformEmptyString);
    }
    // USA default
    return taxIdValidation;
};
const dateOfIncorporationValidation = create$6()
    .test('past-date', 'Date of registration must be in the past', (value) => {
    const inputDate = new Date(value);
    inputDate.setDate(inputDate.getDate() + 1);
    const today = new Date();
    return inputDate <= today;
})
    .transform(transformEmptyString);
// Identity Validations
const identityNameValidation = create$6()
    .min(2, 'Name must be at least 2 characters')
    .max(100, 'Name must be less than 100 characters')
    .transform(transformEmptyString);
const identityTitleValidation = create$6()
    .min(2, 'Title must be at least 2 characters')
    .max(50, 'Title must be less than 50 characters')
    .transform(transformEmptyString);
const dobValidation = (role) => {
    return create$6()
        .test('min', 'Enter a valid date', (value) => {
        const date = new Date(value);
        const minDate = new Date('1902-01-01');
        return date >= minDate;
    })
        .test('age', `${role} must be at least 18 years old`, (value) => {
        const date = new Date(value);
        const minAgeDate = new Date();
        minAgeDate.setFullYear(minAgeDate.getFullYear() - 18);
        return date <= minAgeDate;
    })
        .transform(transformEmptyString);
};
const ssnValidation = create$6()
    .matches(ssnRegex, 'Enter valid SSN')
    .when('ssn_last4', {
    is: (val) => !val || val.length === 0,
    then: (schema) => schema.required('Enter SSN'),
    otherwise: (schema) => schema.nullable(),
})
    .test('not-repeat', 'Enter valid SSN', (value) => {
    return !/^(\d)\1+$/.test(value);
})
    .test('not-seq', 'Enter valid SSN', (value) => {
    return value !== '123456789';
})
    .transform(transformEmptyString);
const ownershipPercentageValidation = create$6()
    .matches(numbersOnlyRegex, 'Enter valid percentage')
    .test('min', 'Percentage must be at least 0', (value) => {
    if (!value)
        return true;
    const num = parseFloat(value);
    return num >= 0;
})
    .test('max', 'Percentage must be at most 100', (value) => {
    if (!value)
        return true;
    const num = parseFloat(value);
    return num <= 100;
})
    .transform(transformEmptyString);
// Address Validations
const lineOneValidation = create$6()
    .min(5, 'Address must be at least 5 characters')
    .max(100, 'Address must be less than 100 characters')
    .test('not-po-box', 'A PO Box is not a valid address entry', (value) => {
    return !poBoxRegex.test(value);
})
    .transform(transformEmptyString);
const lineTwoValidation = create$6()
    .max(100, 'Address must be less than 100 characters')
    .test('not-po-box', 'A PO Box is not a valid address entry', (value) => {
    return !poBoxRegex.test(value);
})
    .transform(transformEmptyString);
const cityValidation = create$6()
    .min(2, 'City must be at least 2 characters')
    .max(50, 'City must be less than 50 characters')
    .transform(transformEmptyString);
const stateValidation = create$6()
    .oneOf(checkoutBillingStateOptions.map((option) => option.value), 'Select a valid state or province')
    .transform(transformEmptyString);
const postalValidation = create$6()
    .matches(/^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$/, 'Enter valid postal code')
    .transform(transformEmptyString);
// Additional Questions Validations
const revenueValidation = create$6()
    .matches(numbersOnlyRegex, 'Enter valid revenue')
    .transform(transformEmptyString);
const paymentVolumeValidation = create$6()
    .matches(numbersOnlyRegex, 'Enter valid payment volume')
    .transform(transformEmptyString);
const whenServiceReceivedValidation = create$6()
    .oneOf(businessServiceReceivedOptions.map((option) => option.value), 'Select when service is received')
    .transform(transformEmptyString);
const otherPaymentDetailsValidation = create$6().transform(transformEmptyString);
// Bank Account Validations
const bankNameValidation = create$6()
    .min(2, 'Name must be at least 2 characters')
    .max(50, 'Name must be less than 50 characters')
    .transform(transformEmptyString);
const nicknameValidation = create$6()
    .min(2, 'Name must be at least 2 characters')
    .max(50, 'Name must be less than 50 characters')
    .transform(transformEmptyString);
const accountTypeValidation = create$6()
    .oneOf(bankAccountTypeOptions.map((option) => option.value), 'Select account type')
    .transform(transformEmptyString);
const accountNumberValidation = create$6()
    .min(4, 'Account number must be at least 4 digits')
    .max(17, 'Account number must be less than 17 digits')
    .matches(numbersOnlyRegex, 'Enter valid account number')
    .test('not-repeat', 'Enter valid account number', (value) => {
    return !/^(\d)\1+$/.test(value);
})
    .transform(transformEmptyString);
const routingNumberValidation = create$6()
    .length(9, 'Routing number must be 9 digits')
    .matches(numbersOnlyRegex, 'Enter valid routing number')
    .test('not-repeat', 'Enter valid routing number', (value) => {
    if (!value)
        return true;
    return !/^(\d)\1+$/.test(value);
})
    .test('valid', 'Enter valid routing number', (value) => {
    if (!value)
        return true;
    return validateRoutingNumber(value);
})
    .transform(transformEmptyString);

export { checkoutBillingStateOptions as A, accountNumberValidation as B, accountTypeValidation as C, nicknameValidation as D, bankNameValidation as E, numbersOnlyRegex as F, routingNumberValidation as G, doingBusinessAsValidation as a, businessClassificationValidation as b, businessNameValidation as c, dateOfIncorporationValidation as d, emailValidation as e, whenServiceReceivedValidation as f, paymentVolumeValidation as g, cityValidation as h, industryValidation as i, lineOneValidation as j, makePostalValidation as k, lineTwoValidation as l, makeTaxIdValidation as m, ownershipPercentageValidation as n, otherPaymentDetailsValidation as o, phoneValidation as p, dobValidation as q, revenueValidation as r, ssnValidation as s, taxIdValidation as t, identityTitleValidation as u, identityNameValidation as v, websiteUrlValidation as w, makeIdentityNumberValidation as x, postalValidation as y, stateValidation as z };
