import {TypedNumericParam} from "./_Numeric";
import {ParamType as ParamType2} from "../poly/ParamType";
import {CoreString} from "../../core/String";
import {CoreType} from "../../core/Type";
export class FloatParam extends TypedNumericParam {
  static type() {
    return ParamType2.FLOAT;
  }
  get default_value_serialized() {
    return this.default_value;
  }
  get raw_input_serialized() {
    return this._raw_input;
  }
  get value_serialized() {
    return this.value;
  }
  _copy_value(param) {
    this.set(param.value_serialized);
  }
  _prefilter_invalid_raw_input(raw_input) {
    if (CoreType.isArray(raw_input)) {
      return raw_input[0];
    }
    if (CoreType.isString(raw_input) && CoreString.isNumber(raw_input)) {
      return parseFloat(raw_input);
    }
    return raw_input;
  }
  static are_raw_input_equal(raw_input1, raw_input2) {
    return raw_input1 == raw_input2;
  }
  static are_values_equal(val1, val2) {
    return val1 == val2;
  }
  static convert(raw_val) {
    if (CoreType.isNumber(raw_val)) {
      return raw_val;
    } else {
      if (CoreType.isBoolean(raw_val)) {
        return raw_val ? 1 : 0;
      } else {
        if (CoreString.isNumber(raw_val)) {
          const parsed = parseFloat(raw_val);
          if (CoreType.isNumber(parsed)) {
            return parsed;
          }
        }
      }
      return null;
    }
  }
  convert(raw_val) {
    const result = FloatParam.convert(raw_val);
    if (result) {
      return this.options.ensure_in_range(result);
    } else {
      return result;
    }
  }
}
