import React, { useState } from 'react';
import { RGMask, NumberMask, CEPMask, CNPJMask, CPFMask, NoSpaceMask, PhoneMask } from './mask.utils';

export interface IPropsMask {
   value: string;
   RG?: boolean;
   Number?: boolean;
   CEP?: boolean;
   CNPJ?: boolean;
   CPF?: boolean;
   NoSpace?: boolean;
   Phone?: boolean;
}

export const MaskText: React.FunctionComponent<IPropsMask> = (props: IPropsMask) => {
   const { RG, value, Number, CEP, CNPJ, CPF, NoSpace, Phone } = props;

   let newVal = '';

   if (RG) {
      newVal = RGMask(value);
   }
   if (Number) {
      newVal = NumberMask(value);
   }

   if (CEP) {
      newVal = CEPMask(value);
   }

   if (CNPJ) {
      newVal = CNPJMask(value);
   }

   if (CPF) {
      newVal = CPFMask(value);
   }

   if (NoSpace) {
      newVal = NoSpaceMask(value);
   }

   if (Phone) {
      newVal = PhoneMask(value);
   }

   return <>{newVal}</>;
};
