fcf.module({
  name: "fcfControls:templates/float-edit.wrapper.js",
  dependencies: ["fcfControls:templates/view.wrapper.js"],
  module: function(Wrapper){
    return class FloatWrapper extends Wrapper{
      
      constructor(a_initializeOptions){
        super(a_initializeOptions);
        this._lastValue = this.getArg("value");
      }

      getActionDomElement(){
        return fcf.first(fcf.select(this.getDomElement(), "input"));
      }

      onInput(a_event) {
        var dotCount = 0;
        var charCode0 = "0".charCodeAt(0);
        var charCode9 = "9".charCodeAt(0);
        var incorrect = false;
        fcf.each(this.getActionDomElement().value, function(a_key, a_char){
          var cc = a_char.charCodeAt()
          if (a_char == ".")
            ++dotCount;
          if ( (cc >= charCode0 && cc <= charCode9) ||
               (a_key == 0 && a_char == "-") ||
               (dotCount == 1 && a_char == ".")
              ) {
            return;
          } else {
            incorrect = true;
            return false;
          }
        });

        let value = this.getActionDomElement().value;
        if (value == "")
          value = 0;
        value = parseFloat(value);
        if (isNaN(value))
          incorrect = true;
        if (isNaN(this._lastValue))
          this._lastValue = 0;

        if (!incorrect && typeof this.getArg("min") == "number"){
          if (value < this.getArg("min")){
            value = this.getArg("min");
            this.getActionDomElement().value = value;
          }
        }

        if (!incorrect && typeof this.getArg("max") == "number"){
          if (value > this.getArg("max")){
            value = this.getArg("max");
            this.getActionDomElement().value = value;
          }
        }

        if (!incorrect)
          this._lastValue = value;

        this.setArg("value", this._lastValue);

        if (incorrect)
          this.getActionDomElement().value = fcf.str(this._lastValue);

      }

    };
  }
});
