"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const enums_1 = require("../../../enums");
const styles_1 = require("./styles");
const optionDefault = {
    mask: '*'.repeat(400),
    validator: () => true,
    translation: {
        '*': (val) => val,
    },
};
const MaskedTextInput = (0, react_1.forwardRef)(({ maskType = 'no-mask', id, accessibility, contrast = false, multiline = false, status = enums_1.InputStatus.Default, value = '', onChangeText, options = optionDefault, ...rest }, inputRef) => {
    const [maskSelected, setMaskSelected] = (0, react_1.useState)({
        typeMask: 'custom',
        options: options,
    });
    // Função para controlar o tipo de máscara
    const maskTypeControll = () => {
        switch (maskType) {
            case 'cpf':
            case 'document':
                setMaskSelected({
                    typeMask: 'cpf',
                    options: { mask: '' },
                });
                break;
            case 'cnpj':
                setMaskSelected({
                    typeMask: 'cnpj',
                    options: { mask: '' },
                });
                break;
            case 'no-mask':
                handleSetMask({
                    typeMask: 'custom',
                    options: {
                        mask: '*'.repeat(400),
                    },
                });
                break;
            case 'uppercase':
                handleSetMask({
                    typeMask: 'custom',
                    options: {
                        ...optionDefault,
                        getRawValue: (val) => val.toUpperCase(),
                    },
                });
                break;
            default:
                handleSetMask({
                    typeMask: maskType,
                    options: options,
                });
                break;
        }
    };
    // Função para atualizar a máscara selecionada
    const handleSetMask = ({ typeMask, options }) => {
        if (typeMask !== maskSelected.typeMask ||
            JSON.stringify(options) !== JSON.stringify(maskSelected.options)) {
            setMaskSelected({ typeMask, options });
        }
    };
    // Atualiza a máscara quando o valor ou as opções mudam
    (0, react_1.useEffect)(() => {
        maskTypeControll();
    }, [value, options]);
    return (<styles_1.TextInput {...rest} ref={inputRef} onChangeText={onChangeText} value={value} id={id || accessibility} status={status} accessibility={accessibility} testID={id || accessibility} accessibilityLabel={accessibility} contrast={contrast} multiline={multiline} type={maskSelected.typeMask} options={maskSelected.options} underlineColorAndroid="transparent"/>);
});
exports.default = MaskedTextInput;
//# sourceMappingURL=index.js.map