import { uiKitI18n } from '@/configs';

export const correctDateValidator = () => ({
    name: 'correct-date',
    message: uiKitI18n?.global.t('helpers.validation.correctDate'),
    test: (val?: string) => {
        if (!val) return true;
        const cleaned = val.replace(/_/g, '').trim();
        return !/^(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[0-2])\.(19|20)\d{2}$/.test(cleaned);
    },
});

export const requiredValueValidator = () => ({
    name: 'required-value',
    message: () => {
        return uiKitI18n?.global.t('helpers.validation.required');
    },
    test: (value?: string) => !!value,
});

export const birthDateValidator = () => ({
    name: 'birthday',
    message: uiKitI18n?.global.t('helpers.validation.error'),
    test: (value?: string) => {
        if (!value) {
            return true;
        }

        const inputData = new Date(value);
        return inputData < new Date();
    },
});
