import {TypedSopNode} from "./_Base";
import {
  AttribNormalizeSopOperation,
  NORMALIZE_MODES
} from "../../../core/operations/sop/AttribNormalize";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
const DEFAULT = AttribNormalizeSopOperation.DEFAULT_PARAMS;
class AttribNormalizeSopParamsConfig extends NodeParamsConfig {
  constructor() {
    super(...arguments);
    this.mode = ParamConfig.INTEGER(DEFAULT.mode, {
      menu: {
        entries: NORMALIZE_MODES.map((name, value) => {
          return {name, value};
        })
      }
    });
    this.name = ParamConfig.STRING(DEFAULT.name);
    this.changeName = ParamConfig.BOOLEAN(DEFAULT.changeName);
    this.newName = ParamConfig.STRING(DEFAULT.newName, {visibleIf: {changeName: 1}});
  }
}
const ParamsConfig2 = new AttribNormalizeSopParamsConfig();
export class AttribNormalizeSopNode extends TypedSopNode {
  constructor() {
    super(...arguments);
    this.params_config = ParamsConfig2;
  }
  static type() {
    return "attribNormalize";
  }
  initializeNode() {
    this.io.inputs.setCount(1);
    this.io.inputs.initInputsClonedState(AttribNormalizeSopOperation.INPUT_CLONED_STATE);
    this.scene().dispatchController.onAddListener(() => {
      this.params.onParamsCreated("params_label", () => {
        this.params.label.init([this.p.name]);
      });
    });
  }
  set_mode(mode) {
    this.p.mode.set(NORMALIZE_MODES.indexOf(mode));
  }
  cook(input_contents) {
    this._operation = this._operation || new AttribNormalizeSopOperation(this.scene(), this.states);
    const core_group = this._operation.cook(input_contents, this.pv);
    this.setCoreGroup(core_group);
  }
}
