'use strict';

import IMask from 'imask';

const maskCepOptions = {
  mask: '00000-000',
};
const maskCep = inputElement => {
  return IMask(inputElement, maskCepOptions);
};

const maskNumberOptions = {
  mask: /^[0-9]+$/,
  signed: true,
};

const maskDecimalOptions = {
  mask: /^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/,
  signed: true,
};


const maskAlphaNumeric = {///
  mask: /^([a-zA-Zà-úÀ-Ú0-9]|-|_|\s|'|,|@|\.|%|!)+$/,
  signed: true,
};


const maskIntegerOptions = {
  mask: Number,
  signed: true,
  scale: 0,
};

const maskPositiveNumberOptions = {
  mask: Number,
  padFractionalZeros: true,
};

const maskPositiveIntegerOptions = {
  mask: Number,
  scale: 0,
};

const maskPercentageOptions = {
  mask: 'percentage%',
  lazy: false,
  blocks: {
    percentage: {
      mask: Number,
      min: 0,
      max: 100,
    },
  },
};

const maskCentimeterOptions = {
  mask: 'centimetercm',
  lazy: false,
  blocks: {
    centimeter: {
      mask: Number,
      signed: false,
    },
  },
};

const maskBrazilCurrencyOptions = {
  mask: 'R$ value',
  blocks: {
    value: {
      mask: Number,
      signed: false,
      padFractionalZeros: true,
      thousandsSeparator: '.',
      min: 0,
      max: 100000000,
    },
  },
};

const maskKilogramOptions = {
  mask: 'kilogramkg',
  lazy: false,
  blocks: {
    kilogram: {
      mask: Number,
      signed: false,
      padFractionalZeros: true,
      scale: 3,
      min: 0,
      max: 10000,
    },
  },
};



const maskCpfOptions = {
  mask: '000.000.000-00',
};

const maskCnpjOptions = {
  mask: '00.000.000/0000-00',
};

const maskCpfCnpjOptions = {
  mask: [
    {
      mask: '000.000.000-00',
    },
    {
      mask: '00.000.000/0000-00',
    },
  ],
};

const maskTelephoneOptions = {
  mask: '(00) 0000-0000',
};

const maskTelephoneCountryOptions = {
  mask: [
    {
      mask: '+00 (00) 0000-0000',
    },
    {
      mask: '+00 (00) 00000-0000',
    },
  ],
};

const maskCellphoneOptions = {
  mask: [
    {
      mask: '(00) 0000-0000',
    },
    {
      mask: '(00) 00000-0000',
    },
  ],
};

const maskDateOptions = {
  mask: 'd/m/Y',

  blocks: {
    d: {
      mask: IMask.MaskedRange,
      from: 1,
      to: 31,
      maxLength: 2,
    },
    m: {
      mask: IMask.MaskedRange,
      from: 1,
      to: 12,
      maxLength: 2,
    },
    Y: {
      mask: IMask.MaskedRange,
      from: 1900,
      to: 9999,
    },
  },
};

export { maskCep };

export default {
  cep: maskCepOptions,
  number: maskNumberOptions,
  integer: maskIntegerOptions,
  positiveNumber: maskPositiveNumberOptions,
  positiveInteger: maskPositiveIntegerOptions,
  percentage: maskPercentageOptions,
  centimeter: maskCentimeterOptions,
  brazilCurrency: maskBrazilCurrencyOptions,
  kilogram: maskKilogramOptions,
  cpf: maskCpfOptions,
  cnpj: maskCnpjOptions,
  cpfCnpj: maskCpfCnpjOptions,
  telephone: maskTelephoneOptions,
  cellphone: maskCellphoneOptions,
  telephoneCountry: maskTelephoneCountryOptions,
  date: maskDateOptions,
  alphanumeric: maskAlphaNumeric,
  decimal: maskDecimalOptions
};
