"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ntpSourceValidationSchema = void 0;
const tslib_1 = require("tslib");
const Yup = tslib_1.__importStar(require("yup"));
const utils_1 = require("../components/ui/formik/utils");
const utils_2 = require("./utils");
const ntpSourceValidationSchema = (t, allowEmpty = true) => {
    let schema = Yup.string();
    if (!allowEmpty) {
        schema = schema.trim().required(t('ai:Required field'));
    }
    return schema
        .test('ntp-source-validation', t('ai:Provide a comma separated list of valid DNS names or IP addresses.'), (value) => {
        if (!value || value.trim() === '') {
            return true;
        }
        const parts = (0, utils_1.trimCommaSeparatedList)(value).split(',');
        return parts.length > 0 && parts.every((v) => (0, utils_2.isIPorDN)(v));
    })
        .test('ntp-source-validation-unique', t('ai:DNS names and IP addresses must be unique.'), (value) => {
        if (!value || value.trim() === '') {
            return true;
        }
        const arr = (0, utils_1.trimCommaSeparatedList)(value).split(',');
        return arr.length === new Set(arr).size;
    });
};
exports.ntpSourceValidationSchema = ntpSourceValidationSchema;
//# sourceMappingURL=ntpValidation.js.map