import { EInputComponentType, EInputType } from '@/UI-kit/types';
import { getPassportValidator } from '@/modules/documents/constants';
import { IDocsSchemaType } from '@/modules/form/types';
import { IFsspFieldsOptions } from '@/modules/documents/type';
import { uiKitI18n } from '@/configs';
import { COUNTRY_TYPE, SEX_TYPE_RU } from '@/modules/documents/constants/directory';
import { buildYupChain } from '@/UI-kit/utils';
import { string } from 'yup';
import { requiredValueValidator } from '@/modules/documents/constants/validation/common.validation';

export function useFsspFieldsScheme(options?: IFsspFieldsOptions): IDocsSchemaType[] {
    const {
        lastName,
        firstName,
        middleName,
        birthDate,
        gender,
        passportNumber,
        passportSeries,
        citizenship,
        issueDate,
    } = getPassportValidator();

    const residenceRegion = buildYupChain(string(), [requiredValueValidator()]);

    return [
        {
            name: 'last_name',
            label: uiKitI18n?.global.t('moduleDocuments.forms.nonresident_passport.lastName.label'),
            type: EInputType.text,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.lastName.placeholder',
            ),
            validateOnChange: false,
            validator: lastName,
            isShowClear: true,
            isCapitalize: true,
        },
        {
            name: 'first_name',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.firstName.label',
            ),
            type: EInputType.text,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.firstName.placeholder',
            ),
            validateOnChange: false,
            validator: firstName,
            isShowClear: true,
            isCapitalize: true,
        },
        {
            name: 'middle_name',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.middleName.label',
            ),
            type: EInputType.text,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.middleName.placeholder',
            ),
            validateOnChange: false,
            validator: middleName,
            isShowClear: true,
            isCapitalize: true,
        },
        {
            name: 'birth_date',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.birthDate.label',
            ),
            type: EInputType.text,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.birthDate.placeholder',
            ),
            validateOnChange: false,
            masked: true,
            isDate: true,
            validator: birthDate,
            mask: '##.##.####',
            components: EInputComponentType.mask,
            isShowClear: true,
        },
        {
            name: 'seria',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.passportSeries.label',
            ),
            type: EInputType.text,
            placeholder: 'FA',
            validateOnChange: false,
            validator: passportSeries,
            mask: 'SSSSSSSSSSSSSSSSSSSSSSSSS',
            components: EInputComponentType.mask,
            isShowClear: true,
        },
        {
            name: 'number',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.passportNumber.label',
            ),
            type: EInputType.text,
            placeholder: '0000000',
            validateOnChange: false,
            validator: passportNumber,
            mask: '#########################',
            components: EInputComponentType.mask,
            isShowClear: true,
        },
        {
            name: 'issue_date',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.issue_date.label',
            ),
            type: EInputType.text,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.issue_date.placeholder',
            ),
            validateOnChange: false,
            validator: issueDate,
            mask: '##.##.####',
            isDate: true,
            masked: true,
            components: EInputComponentType.mask,
            isShowClear: true,
        },
        {
            name: 'citizenship',
            label: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.citizenship.label',
            ),
            type: EInputType.select,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.nonresident_passport.citizenship.placeholder',
            ),
            validateOnChange: false,
            validator: citizenship,
            select: {
                showSearchInput: true,
                placeholderSearchInput: uiKitI18n?.global.t(
                    'moduleDocuments.forms.nonresident_passport.citizenship.placeholderSearchInput',
                ),
                options: options?.citizenshipOptions || COUNTRY_TYPE,
            },
        },
        {
            name: 'residence_region',
            label: uiKitI18n?.global.t('moduleDocuments.forms.fssp.residenceRegion.label'),
            type: EInputType.select,
            placeholder: uiKitI18n?.global.t(
                'moduleDocuments.forms.fssp.residenceRegion.placeholder',
            ),
            validateOnChange: false,
            validator: residenceRegion,
            select: {
                showSearchInput: true,
                placeholderSearchInput: uiKitI18n?.global.t(
                    'moduleDocuments.forms.fssp.residenceRegion.placeholderSearchInput',
                ),
                options: options?.regionOptions || [],
            },
        },
        {
            name: 'sex',
            label: uiKitI18n?.global.t('moduleDocuments.forms.nonresident_passport.gender.label'),
            type: EInputType.radio,
            validateOnChange: false,
            validator: gender,
            radioButtonData: [
                {
                    value: SEX_TYPE_RU[0].value,
                    label: uiKitI18n?.global.t(
                        'moduleDocuments.forms.nonresident_passport.gender.options.male',
                    ),
                },
                {
                    value: SEX_TYPE_RU[1].value,
                    label: uiKitI18n?.global.t(
                        'moduleDocuments.forms.nonresident_passport.gender.options.female',
                    ),
                },
            ],
        },
    ];
}
