import { unsafeCSS, LitElement, nothing, html } from "lit";
import { property } from "lit/decorators.js";
import compentStyle from "./instrument-field.css.js";
import { classMap } from "lit/directives/class-map.js";
import "../../components/button/button.js";
import "../../icons/icon-drop-down-google.js";
import "../../components/navigation-item/navigation-item.js";
import { customElement } from "../../decorator.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;
};
var InstrumentFieldSize = /* @__PURE__ */ ((InstrumentFieldSize2) => {
  InstrumentFieldSize2["regular"] = "regular";
  InstrumentFieldSize2["enhanced"] = "enhanced";
  return InstrumentFieldSize2;
})(InstrumentFieldSize || {});
let ObcInstrumentField = class extends LitElement {
  constructor() {
    super(...arguments);
    this.size = "regular";
    this.hasSetpoint = false;
    this.hasSrc = false;
    this.maxDigits = 1;
    this.showZeroPadding = false;
    this.fractionDigits = 0;
    this.tag = "";
    this.unit = "";
    this.src = "";
    this.neutralColor = false;
    this.horizontal = false;
    this.center = false;
    this.labelOnly = false;
    this.off = false;
    this.autoHideSetpoint = false;
    this.autoHideDeadband = 0;
  }
  /**
   * Generates a dashed string representation for undefined values.
   * @returns A string of dashes formatted according to the current numeric settings.
   */
  dashedGenerator() {
    const n = this.showZeroPadding ? Math.max(this.maxDigits, 1) : 1;
    if (this.fractionDigits < 1) {
      return "-".repeat(n);
    } else {
      const diff = n - this.fractionDigits;
      return "-".repeat(Math.max(diff, 1)) + "." + "-".repeat(this.fractionDigits);
    }
  }
  render() {
    const hideSetpoint = this.hasSetpoint && this.autoHideSetpoint && this.setpoint !== void 0 && this.value !== void 0 && Math.abs(this.setpoint - this.value) <= this.autoHideDeadband;
    return html`
      <div
        class=${classMap({
      wrapper: true,
      [this.size]: true,
      "neutral-color": this.neutralColor,
      off: this.off,
      horizontal: this.horizontal,
      center: this.center,
      "left-aligned": this.labelOnly || this.horizontal && !this.hasSetpoint,
      "hide-setpoint": hideSetpoint,
      "show-zero-padding": this.showZeroPadding
    })}
      >
        ${this.horizontal && this.size === "regular" ? html`<div class="label">
              <div class="tag" part="tag">${this.tag}</div>
            </div>` : nothing}
        ${this.hasSetpoint ? html`<div class="setpoint">
              <svg
                class="setpoint-arrow"
                width="16"
                height="16"
                viewBox="0 0 16 16"
                fill="none"
                xmlns="http://www.w3.org/2000/svg"
              >
                <path
                  fill="var(--instrument-enhanced-secondary-color)"
                  d="M4.66797 4.80263C4.66797 4.14363 5.45194 3.76746 6.0013 4.16286L10.4456 7.17243C11.0312 7.56899 11.0314 8.43154 10.4459 8.82828L6.0013 11.8401C5.45194 12.2355 4.66797 11.8593 4.66797 11.2003L4.66797 4.80263Z"
                  fill="var(--instrument-enhanced-primary-color)"
                />
              </svg>
              <div class="setpoint-value">${this.setpointValueBlueNumbers}</div>
            </div>` : nothing}
        ${this.horizontal && !this.labelOnly && this.hasSetpoint ? html`<div class="divider"></div>` : nothing}
        ${!this.labelOnly ? html` <div class="value">
              ${this.off ? html`<div class="value-blue">
                    <slot name="off-value">OFF</slot>
                  </div>` : html` <div class="value-hint-zero">${this.hintZeros}</div>
                    <div class="value-blue">${this.valueBlueNumbers}</div>`}
            </div>` : nothing}
        <div class="label" part="label">
          ${this.horizontal && this.size === "regular" ? nothing : html`<div class="tag" part="tag">${this.tag}</div>`}
          <div class="unit">${this.unit}</div>
        </div>
        ${this.hasSrc && this.horizontal ? html`<div class="divider src-divider"></div>` : nothing}
        ${this.hasSrc ? html`<div class="src">${this.src}</div>` : nothing}
      </div>
    `;
  }
  /**
   * Returns the formatted setpoint value as a string.
   * If the setpoint is undefined, it returns a dashed string.
   */
  get setpointValueBlueNumbers() {
    if (this.setpoint === void 0) {
      return this.dashedGenerator();
    }
    return this.setpoint.toFixed(this.fractionDigits);
  }
  /**
   * Returns the formatted primary value as a string.
   * If the value is undefined, it returns a dashed string.
   */
  get valueBlueNumbers() {
    if (this.value === void 0) {
      return this.dashedGenerator();
    }
    return this.value.toFixed(this.fractionDigits);
  }
  /**
   * Generates a string of hint zeros for alignment when `showZeroPadding` is false.
   * These zeros are typically displayed with lower opacity.
   */
  get hintZeros() {
    if (this.value === void 0 || this.value < 0) {
      return "";
    }
    const nBlues = this.valueBlueNumbers.length;
    const nHints = this.maxDigits - nBlues;
    if (nHints > 0) {
      return "0".repeat(nHints);
    }
    return "";
  }
};
ObcInstrumentField.styles = unsafeCSS(compentStyle);
__decorateClass([
  property({ type: String })
], ObcInstrumentField.prototype, "size", 2);
__decorateClass([
  property({ type: Number })
], ObcInstrumentField.prototype, "setpoint", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "hasSetpoint", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "hasSrc", 2);
__decorateClass([
  property({ type: Number })
], ObcInstrumentField.prototype, "value", 2);
__decorateClass([
  property({ type: Number })
], ObcInstrumentField.prototype, "maxDigits", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "showZeroPadding", 2);
__decorateClass([
  property({ type: Number })
], ObcInstrumentField.prototype, "fractionDigits", 2);
__decorateClass([
  property({ type: String })
], ObcInstrumentField.prototype, "tag", 2);
__decorateClass([
  property({ type: String })
], ObcInstrumentField.prototype, "unit", 2);
__decorateClass([
  property({ type: String })
], ObcInstrumentField.prototype, "src", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "neutralColor", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "horizontal", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "center", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "labelOnly", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "off", 2);
__decorateClass([
  property({ type: Boolean })
], ObcInstrumentField.prototype, "autoHideSetpoint", 2);
__decorateClass([
  property({ type: Number })
], ObcInstrumentField.prototype, "autoHideDeadband", 2);
ObcInstrumentField = __decorateClass([
  customElement("obc-instrument-field")
], ObcInstrumentField);
export {
  InstrumentFieldSize,
  ObcInstrumentField
};
//# sourceMappingURL=instrument-field.js.map
