import {SpotLight as SpotLight2} from "three/src/lights/SpotLight";
import {BaseLightTransformedObjNode} from "./_BaseLightTransformed";
import {TransformedParamConfig} from "./utils/TransformController";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
import {HelperController as HelperController2} from "./utils/HelperController";
import {SpotLightHelper as SpotLightHelper2} from "./utils/helpers/SpotLightHelper";
import {ColorConversion} from "../../../core/Color";
class SpotLightObjParamsConfig extends TransformedParamConfig(NodeParamsConfig) {
  constructor() {
    super(...arguments);
    this.light = ParamConfig.FOLDER();
    this.color = ParamConfig.COLOR([1, 1, 1], {
      conversion: ColorConversion.SRGB_TO_LINEAR
    });
    this.intensity = ParamConfig.FLOAT(1);
    this.angle = ParamConfig.FLOAT(45, {range: [0, 180]});
    this.penumbra = ParamConfig.FLOAT(0.1);
    this.decay = ParamConfig.FLOAT(0.1, {range: [0, 1]});
    this.distance = ParamConfig.FLOAT(100, {range: [0, 100]});
    this.showHelper = ParamConfig.BOOLEAN(0);
    this.helperSize = ParamConfig.FLOAT(1, {visibleIf: {showHelper: 1}});
    this.shadow = ParamConfig.FOLDER();
    this.castShadow = ParamConfig.BOOLEAN(1);
    this.shadowAutoUpdate = ParamConfig.BOOLEAN(1, {
      visibleIf: {castShadow: 1}
    });
    this.shadowUpdateOnNextRender = ParamConfig.BOOLEAN(0, {
      visibleIf: {castShadow: 1, shadowAutoUpdate: 0}
    });
    this.shadowRes = ParamConfig.VECTOR2([256, 256], {
      visibleIf: {castShadow: 1}
    });
    this.shadowBias = ParamConfig.FLOAT(1e-3, {
      visibleIf: {castShadow: 1},
      range: [-0.01, 0.01],
      rangeLocked: [false, false]
    });
    this.shadowNear = ParamConfig.FLOAT(0.1, {
      visibleIf: {castShadow: 1},
      range: [0, 100],
      rangeLocked: [true, false]
    });
    this.shadowFar = ParamConfig.FLOAT(100, {
      visibleIf: {castShadow: 1},
      range: [0, 100],
      rangeLocked: [true, false]
    });
  }
}
const ParamsConfig2 = new SpotLightObjParamsConfig();
export class SpotLightObjNode extends BaseLightTransformedObjNode {
  constructor() {
    super(...arguments);
    this.params_config = ParamsConfig2;
    this._helper_controller = new HelperController2(this, SpotLightHelper2, "SpotLightHelper");
  }
  static type() {
    return "spotLight";
  }
  initializeNode() {
    this._helper_controller.initializeNode();
  }
  create_light() {
    const light = new SpotLight2();
    light.matrixAutoUpdate = false;
    light.castShadow = true;
    light.shadow.bias = -1e-3;
    light.shadow.mapSize.x = 256;
    light.shadow.mapSize.y = 256;
    light.shadow.camera.near = 0.1;
    this._target_target = light.target;
    this._target_target.name = "SpotLight Default Target";
    this._target_target.matrixAutoUpdate = false;
    this.object.add(this._target_target);
    return light;
  }
  update_light_params() {
    this.light.color = this.pv.color;
    this.light.intensity = this.pv.intensity;
    this.light.angle = this.pv.angle * (Math.PI / 180);
    this.light.penumbra = this.pv.penumbra;
    this.light.decay = this.pv.decay;
    this.light.distance = this.pv.distance;
    this._helper_controller.update();
  }
  update_shadow_params() {
    this.light.castShadow = this.pv.castShadow;
    this.light.shadow.autoUpdate = this.pv.shadowAutoUpdate;
    this.light.shadow.needsUpdate = this.pv.shadowUpdateOnNextRender;
    this.light.shadow.mapSize.copy(this.pv.shadowRes);
    this.light.shadow.camera.near = this.pv.shadowNear;
    this.light.shadow.camera.far = this.pv.shadowFar;
    this.light.shadow.bias = this.pv.shadowBias;
  }
}
