import i18next from 'i18next';
import maskInput from 'text-mask-all/vanilla';
import createNumberMask from 'text-mask-all/addons/dist/createNumberMask';
import _get from 'lodash/get';
import { NumberComponent } from '../number/Number';
export class CurrencyComponent extends NumberComponent {
  constructor(component, options, data) {
    super(component, options, data);

    this.currency = this.component.currency || 'USD';
    this.decimalLimit = this.component.decimalLimit || 2;

    // Get the prefix and suffix from the localized string.
    const regex = '(.*)?100(' + (this.decimalSeparator === '.' ? '\.' : this.decimalSeparator) + '0{' + this.decimalLimit + '})?(.*)?';
    const parts = (100).toLocaleString(i18next.language, this.getFormatOptions()).match(new RegExp(regex));
    this.prefix = parts[1] || '';
    this.suffix = parts[3] || '';
  }

  getFormatOptions() {
    return {
      style: 'currency',
      currency: this.currency,
      useGrouping: true,
      maximumFractionDigits: this.decimalLimit
    };
  }

  setInputMask(input) {
    this.localize().then(() => {
      this.inputMask = maskInput({
        inputElement: input,
        mask: createNumberMask({
          prefix: this.prefix,
          suffix: this.suffix,
          thousandsSeparatorSymbol: _get(this.component, 'thousandsSeparator', this.thousandsSeparator),
          decimalSymbol: _get(this.component, 'decimalSymbol', this.decimalSeparator),
          decimalLimit: this.decimalLimit,
          allowNegative: _get(this.component, 'allowNegative', true),
          allowDecimal: _get(this.component, 'allowDecimal', true)
        })
      });
    });
  }
}

@@ -1060,43 +1060,8 @@
 ) %7B%0A
-    this.localize().then(() =%3E %7B%0A  
     
@@ -1089,18 +1089,16 @@
 Input(%7B%0A
-  
       in
@@ -1122,18 +1122,16 @@
 ,%0A      
-  
 mask: cr
@@ -1147,18 +1147,16 @@
 rMask(%7B%0A
-  
         
@@ -1184,18 +1184,16 @@
         
-  
 suffix: 
@@ -1201,26 +1201,24 @@
 his.suffix,%0A
-  
         thou
@@ -1312,26 +1312,24 @@
 r),%0A        
-  
 decimalSymbo
@@ -1389,26 +1389,24 @@
 Separator),%0A
-  
         deci
@@ -1438,26 +1438,24 @@
 it,%0A        
-  
 allowNegativ
@@ -1502,18 +1502,16 @@
  true),%0A
-  
         
@@ -1577,22 +1577,10 @@
     
-  %7D)%0A      %7D);
+%7D)
 %0A   

Remove localize on currency.