'use strict';

import IMask from 'imask';

const maskLinkOptions = {
  mask: /^([a-zA-Z0-9]|-|_|\s|'|,|@|\.|:|;|#|\/|\?|&|=|%|!)+$/,
  signed: true,
};

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

const maskAcronymState = {
  mask: /^[A-Za-z]{0,2}$/,
};

const maskIntervalNumber = {
  mask: 'value',
  lazy: false,
  signed: true,
  blocks: {
    value: {
      mask: Number,
      thousandsSeparator: '',
      min: 0,
      max: 1000,
    },
  },
};

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

const maskParcelOptions = {
  mask: /^([0-9]|1[012])$/,
  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 maskAlphaNumericNoSpecial = {
  ///
  mask: /^([a-zA-Zà-úÀ-Ú0-9]|-|\s|)+$/,
  signed: true,
};

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

const maskNoSpace = {
  ///
  mask: /^[^\s].*[^\s]$/,
  signed: true,
};

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

const maskHexadecimal = {
  mask: /^#|[0-9a-f]+$/,
  signed: true,
};

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,
  parcel: maskParcelOptions,
  integer: maskIntegerOptions,
  hexadecimal: maskHexadecimal,
  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,
  alphanumericNoSpecial: maskAlphaNumericNoSpecial,
  intervalNumber: maskIntervalNumber,
  acronymState: maskAcronymState,
  password: maskPassword,
  link: maskLinkOptions,
  noSpace: maskNoSpace,
};
