import React, { forwardRef, useImperativeHandle, useState } from "react";
import maskInputCompose from "@salutejs/react-maskinput";
const defaultFormatChars = [
    {
        str: '*',
        regexp: /./
    },
    {
        str: '0',
        regexp: /[0-9]/
    },
    {
        str: 'a',
        regexp: /[a-zA-Z]/
    },
    {
        str: 'я',
        regexp: /[а-яА-ЯёЁ]/
    }
];
export const composeMask = (InputComponent)=>{
    const MaskedInput = maskInputCompose(InputComponent);
    return /*#__PURE__*/ forwardRef(({ mask, maskFormat = defaultFormatChars, ...rest }, outerRef)=>{
        // TODO: replace inside react-maskinput 'getReference' on 'forwardRef'
        const [ref, setRef] = useState(null);
        useImperativeHandle(outerRef, ()=>ref, [
            ref
        ]);
        if (!mask) {
            return /*#__PURE__*/ React.createElement(InputComponent, {
                ref: setRef,
                ...rest
            });
        }
        return /*#__PURE__*/ React.createElement(MaskedInput, {
            getReference: setRef,
            mask: mask,
            maskFormat: maskFormat,
            ...rest
        });
    });
};
