import { SETPOINT_ANIMATION_DURATION_MS, computeAtSetpoint } from "./setpoint.js";
class SetpointBundle {
  constructor(options) {
    this.atSetpoint = false;
    this.touching = false;
    this.autoAtSetpoint = true;
    this.setpointOverride = false;
    this.animateSetpoint = false;
    this.autoAtSetpointDeadband = options?.defaultDeadband ?? 2;
    this.setpointAtZeroDeadband = options?.defaultZeroDeadband ?? 0.5;
    this._angularWraparound = options?.angularWraparound ?? false;
    this._onAnimationEnd = options?.onAnimationEnd;
  }
  /**
   * Bulk-update bundle state from component properties.
   * Only provided properties are updated; others keep their current value.
   *
   * Call this in `willUpdate()` to sync prefixed public props → bundle.
   *
   * Automatically detects confirm transitions (newSetpoint defined → undefined)
   * and manages `departingNewSetpoint` state for animation.
   */
  sync(input) {
    const prevNewSetpoint = this.newSetpoint;
    if (input.setpoint !== void 0 || "setpoint" in input)
      this.setpoint = input.setpoint;
    if (input.newSetpoint !== void 0 || "newSetpoint" in input)
      this.newSetpoint = input.newSetpoint;
    if (input.atSetpoint !== void 0) this.atSetpoint = input.atSetpoint;
    if (input.touching !== void 0) this.touching = input.touching;
    if (input.autoAtSetpoint !== void 0)
      this.autoAtSetpoint = input.autoAtSetpoint;
    if (input.autoAtSetpointDeadband !== void 0)
      this.autoAtSetpointDeadband = input.autoAtSetpointDeadband;
    if (input.setpointAtZeroDeadband !== void 0)
      this.setpointAtZeroDeadband = input.setpointAtZeroDeadband;
    if (input.setpointOverride !== void 0)
      this.setpointOverride = input.setpointOverride;
    if (input.animateSetpoint !== void 0)
      this.animateSetpoint = input.animateSetpoint;
    if (prevNewSetpoint !== void 0 && this.newSetpoint === void 0 && this.animateSetpoint) {
      this.departingNewSetpoint = prevNewSetpoint;
      clearTimeout(this._animationTimer);
      this._animationTimer = setTimeout(() => {
        this.departingNewSetpoint = void 0;
        this._onAnimationEnd?.();
      }, SETPOINT_ANIMATION_DURATION_MS);
    }
  }
  /**
   * Clean up pending animation timer.
   * Call from the host component's `disconnectedCallback()`.
   */
  dispose() {
    clearTimeout(this._animationTimer);
  }
  /**
   * Compute whether the current value is at the setpoint.
   * Delegates to the unified `computeAtSetpoint()` from `setpoint.ts`.
   *
   * @param currentValue - The instrument's current value for this axis
   * @returns Whether the value is within deadband of the setpoint
   */
  computeAtSetpoint(currentValue) {
    return computeAtSetpoint({
      value: currentValue,
      setpoint: this.setpoint,
      touching: this.touching,
      auto: this.autoAtSetpoint,
      deadband: this.autoAtSetpointDeadband,
      atSetpointManual: this.atSetpoint,
      angularWraparound: this._angularWraparound
    });
  }
}
export {
  SetpointBundle
};
//# sourceMappingURL=setpoint-bundle.js.map
