import { property } from "lit/decorators.js";
import { customElement } from "../../decorator.js";
import { ObcChartLineBase, XAxisType, YAxisPosition, LineMode, TimeDisplay } from "../../building-blocks/chart-line/chart-line-base.js";
import { BorderRadiusPosition } from "../types.js";
import "../../building-blocks/bar-vertical/bar-vertical.js";
import { SetpointMixin } from "../../svghelpers/setpoint-mixin.js";
import { ScaleType, FillMode, AdvicePosition, BarContainerStyle } from "../../building-blocks/external-scale/external-scale.js";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
let ObcGaugeTrend = class extends SetpointMixin(ObcChartLineBase) {
  constructor() {
    super();
    this._isFirstUpdate = false;
    this.scaleType = ScaleType.regular;
    this.minValue = 0;
    this.maxValue = 100;
    this.chartMinValue = void 0;
    this.chartMaxValue = void 0;
    this.value = void 0;
    this.hasBar = false;
    this.hasScale = false;
    this.hasAdvice = false;
    this.fillMode = FillMode.fill;
    this.fillMin = 0;
    this.fillMax = void 0;
    this.advice = [];
    this.primaryTickmarkInterval = void 0;
    this.secondaryTickmarkInterval = 0.5;
    this.tertiaryTickmarkInterval = void 0;
    this.chartFill = false;
    this.legend = false;
    this.showDebugOverlay = false;
    this.showGrid = false;
    this.showTickMarks = false;
    this.showPoints = false;
    this.xAxisType = XAxisType.category;
    this.yAxisPosition = YAxisPosition.left;
    this.lineMode = LineMode.smooth;
    this.unit = "";
    this.timeDisplay = TimeDisplay.date;
    this.fixedAspectRatioScaling = true;
    this.instrumentMode = true;
    this.borderRadius = 8;
    this.borderRadiusPosition = BorderRadiusPosition.innerFirstChild;
    this.borderRadiusPositionExternalScales = BorderRadiusPosition.middleChild;
    this.yAxes = [
      {
        id: "y",
        position: "left",
        min: this.chartMinValue ?? this.minValue,
        max: this.chartMaxValue ?? this.maxValue
      }
    ];
  }
  async firstUpdated() {
    this._createBarVerticalElement();
    this._updateBorderRadiusPosition();
    await super.firstUpdated();
    this._isFirstUpdate = false;
  }
  disconnectedCallback() {
    super.disconnectedCallback();
  }
  _createBarVerticalElement() {
    if (!this._barVerticalElement) {
      const barVertical = document.createElement("obc-bar-vertical");
      barVertical.setAttribute("slot", "right-scale");
      this._barVerticalElement = barVertical;
      this.appendChild(barVertical);
      this._updateBarVerticalProperties();
    }
  }
  _updateBorderRadiusPosition() {
    if (!this.hasBar && !this.hasScale) {
      this.borderRadiusPosition = BorderRadiusPosition.middleRoundedChild;
    } else {
      this.borderRadiusPosition = BorderRadiusPosition.innerFirstChild;
    }
  }
  _updateBarVerticalProperties() {
    if (!this._barVerticalElement) {
      return;
    }
    const barVertical = this._barVerticalElement;
    const effectiveHeight = this.getEffectiveHeight();
    barVertical.minValue = this.minValue;
    barVertical.maxValue = this.maxValue;
    barVertical.height = effectiveHeight;
    barVertical.side = "right";
    barVertical.hasScale = this.hasScale;
    barVertical.hasBar = this.hasBar;
    barVertical.barThickness = this.hasScale ? 48 : 24;
    barVertical.scaleType = this.scaleType;
    barVertical.fillMode = this.fillMode;
    barVertical.fillMin = this.fillMin;
    barVertical.fillMax = this.fillMode === FillMode.fill ? this.value : this.fillMax ?? this.value;
    barVertical.value = this.value;
    barVertical.setpoint = this.setpoint;
    barVertical.newSetpoint = this.newSetpoint;
    barVertical.touching = this.touching;
    barVertical.atSetpoint = this.atSetpoint;
    barVertical.autoAtSetpoint = this.autoAtSetpoint;
    barVertical.autoAtSetpointDeadband = this.autoAtSetpointDeadband;
    barVertical.setpointAtZeroDeadband = this.setpointAtZeroDeadband;
    barVertical.animateSetpoint = this.animateSetpoint;
    barVertical.setpointOverride = this.setpointOverride;
    barVertical.advicePosition = AdvicePosition.inner;
    barVertical.advices = this.hasAdvice ? this.advice : [];
    barVertical.primaryTickmarkInterval = this.primaryTickmarkInterval;
    barVertical.secondaryTickmarkInterval = this.secondaryTickmarkInterval;
    barVertical.tertiaryTickmarkInterval = this.tertiaryTickmarkInterval;
    barVertical.scaleBackground = this.hasScale;
    barVertical.barContainerStyle = this.hasScale ? void 0 : BarContainerStyle.secondary;
    barVertical.fixedAspectRatio = this.fixedAspectRatioScaling;
    barVertical.scaleReferenceSize = this.scaleReferenceSize;
    barVertical.hasPrimaryTickmarks = this.primaryTickmarkInterval !== void 0;
    barVertical.hasTertiaryTickmarks = this.tertiaryTickmarkInterval !== void 0;
    barVertical.priority = this.priority;
    barVertical.state = this.state;
    barVertical.instrumentMode = true;
    barVertical.borderRadius = 8;
    barVertical.borderRadiusPosition = this.hasScale ? BorderRadiusPosition.middleChild : BorderRadiusPosition.outerLastChild;
    barVertical.highlightCurrentValue = !this.hasBar;
  }
  /**
   * Apply fill when chartFill is true.
   */
  shouldApplyFill() {
    return this.chartFill;
  }
  /**
   * Return the fill mode for area rendering.
   * Maps chartFill boolean to base class fillMode.
   */
  getFillMode() {
    return this.chartFill ? "semitransparent" : void 0;
  }
  /**
   * Stacking is not used in gauge-trend (always false).
   */
  shouldStack() {
    return false;
  }
  willUpdate(changed) {
    super.willUpdate(changed);
    if (changed.has("chartMinValue") || changed.has("chartMaxValue") || changed.has("minValue") || changed.has("maxValue")) {
      const chartMin = this.chartMinValue ?? this.minValue;
      const chartMax = this.chartMaxValue ?? this.maxValue;
      this.yAxes = [
        {
          id: "y",
          position: "left",
          min: chartMin,
          max: chartMax
        }
      ];
    }
    if (changed.has("hasScale")) {
      this.borderRadiusPositionExternalScales = this.hasScale ? BorderRadiusPosition.middleChild : BorderRadiusPosition.outerLastChild;
    }
  }
  updated(changed) {
    if (changed.has("chartFill") && this.data) {
      this.data = [...this.data];
    }
    super.updated(changed);
    if (changed.has("hasBar") || changed.has("hasScale")) {
      this._updateBorderRadiusPosition();
    }
    if (!this._barVerticalElement || this._isFirstUpdate) return;
    const shouldUpdateScale = changed.has("minValue") || changed.has("maxValue") || changed.has("value") || changed.has("setpoint") || changed.has("newSetpoint") || changed.has("touching") || changed.has("atSetpoint") || changed.has("autoAtSetpoint") || changed.has("autoAtSetpointDeadband") || changed.has("setpointAtZeroDeadband") || changed.has("setpointOverride") || changed.has("hasBar") || changed.has("hasScale") || changed.has("hasAdvice") || changed.has("fillMode") || changed.has("fillMin") || changed.has("fillMax") || changed.has("advice") || changed.has("primaryTickmarkInterval") || changed.has("secondaryTickmarkInterval") || changed.has("tertiaryTickmarkInterval") || changed.has("scaleType") || changed.has("state") || // Scale state inherits from parent 'state'
    changed.has("priority") || changed.has("height") || changed.has("width") || changed.has("scaleReferenceSize") || changed.has("chartMinValue") || changed.has("chartMaxValue");
    if (shouldUpdateScale) this._updateBarVerticalProperties();
  }
};
__decorateClass([
  property({ type: String })
], ObcGaugeTrend.prototype, "scaleType", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "minValue", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "maxValue", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "chartMinValue", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "chartMaxValue", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "value", 2);
__decorateClass([
  property({ type: Boolean })
], ObcGaugeTrend.prototype, "hasBar", 2);
__decorateClass([
  property({ type: Boolean })
], ObcGaugeTrend.prototype, "hasScale", 2);
__decorateClass([
  property({ type: Boolean })
], ObcGaugeTrend.prototype, "hasAdvice", 2);
__decorateClass([
  property({ type: String })
], ObcGaugeTrend.prototype, "fillMode", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "fillMin", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "fillMax", 2);
__decorateClass([
  property({ attribute: false })
], ObcGaugeTrend.prototype, "advice", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "primaryTickmarkInterval", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "secondaryTickmarkInterval", 2);
__decorateClass([
  property({ type: Number })
], ObcGaugeTrend.prototype, "tertiaryTickmarkInterval", 2);
__decorateClass([
  property({ type: Boolean })
], ObcGaugeTrend.prototype, "chartFill", 2);
ObcGaugeTrend = __decorateClass([
  customElement("obc-gauge-trend")
], ObcGaugeTrend);
export {
  FillMode,
  ObcGaugeTrend,
  ScaleType
};
//# sourceMappingURL=gauge-trend.js.map
