import { LitElement, nothing, html } from "lit";
import { property, queryAssignedElements } from "lit/decorators.js";
import { AutomationButtonReadoutPosition, AutomationButtonPositioning, AutomationButtonDirection, AutomationButtonState } from "./automation-button.js";
import { AutomationButtonReadoutStackSize } from "../../components/automation-button-readout-stack/automation-button-readout-stack.js";
import { ObcAlertFrameType, ObcAlertFrameThickness, ObcAlertFrameStatus } from "../../components/alert-frame/alert-frame.js";
import "../automation-badge/automation-badge.js";
import { CircularProgressMode } from "../../building-blocks/circular-progress/circular-progress.js";
var __defProp = Object.defineProperty;
var __decorateClass = (decorators, target, key, kind) => {
  var result = void 0;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = decorator(target, key, result) || result;
  if (result) __defProp(target, key, result);
  return result;
};
class ObcAbstractAutomationButton extends LitElement {
  constructor() {
    super(...arguments);
    this.showReadoutStack = true;
    this.hasIdTag = false;
    this.readoutPosition = AutomationButtonReadoutPosition.bottom;
    this.readoutSize = AutomationButtonReadoutStackSize.regular;
    this.positioning = AutomationButtonPositioning.point;
    this.alert = false;
    this.alertFrameType = ObcAlertFrameType.SmallSideFlip;
    this.alertFrameThickness = ObcAlertFrameThickness.Small;
    this.alertFrameStatus = ObcAlertFrameStatus.Alarm;
    this.showAlertCategoryIcon = true;
    this.showAlertIcon = false;
    this.progress = false;
    this.progressMode = CircularProgressMode.indeterminate;
    this.progressValue = 0;
    this.tag = "";
    this.direction = AutomationButtonDirection.forward;
    this.badgeAuto = false;
    this.badgeCommandLocked = false;
    this.badgeDuty = false;
    this.badgeAlertOff = false;
  }
  get icon() {
    throw new Error('Method "icon" must be implemented in subclass');
  }
  get _on() {
    throw new Error('Method "_on" must be implemented in subclass');
  }
  get _variant() {
    return this.variant;
  }
  get extraReadouts() {
    return [];
  }
  getBadgeSpacer() {
    if (!this.showReadoutStack) {
      return false;
    }
    const topLeft = this.badgeTopLeft.length > 0 || this.badgeAuto;
    const topRight = this.badgeTopRight.length > 0 || this.badgeAlertOff;
    const bottomLeft = this.badgeBottomLeft.length > 0 || this.badgeDuty;
    const bottomRight = this.badgeBottomRight.length > 0 || this.badgeCommandLocked;
    if (this.readoutPosition === AutomationButtonReadoutPosition.top) {
      return topRight || topLeft;
    } else if (this.readoutPosition === AutomationButtonReadoutPosition.bottom) {
      return bottomLeft || bottomRight;
    } else if (this.readoutPosition === AutomationButtonReadoutPosition.left) {
      return topLeft || bottomLeft;
    } else if (this.readoutPosition === AutomationButtonReadoutPosition.right) {
      return topRight || bottomRight;
    }
    return false;
  }
  handleBadgeSlotChange() {
    this.requestUpdate();
  }
  render() {
    const readouts = [...this.extraReadouts];
    const tagValue = this.tag ? { value: this.parseTagToNumber(this.tag) } : null;
    return html`<obc-automation-button
      .state=${this._on ? AutomationButtonState.open : AutomationButtonState.closed}
      .readouts=${readouts}
      .tag=${tagValue}
      .showReadoutStack=${this.showReadoutStack}
      .hasIdTag=${this.hasIdTag}
      .readoutPosition=${this.readoutPosition}
      .readoutSize=${this.readoutSize}
      ?alert=${this.alert}
      .alertFrameType=${this.alertFrameType}
      .alertFrameThickness=${this.alertFrameThickness}
      .alertFrameStatus=${this.alertFrameStatus}
      .showAlertCategoryIcon=${this.showAlertCategoryIcon}
      .showAlertIcon=${this.showAlertIcon}
      ?progress=${this.progress}
      .progressMode=${this.progressMode}
      .progressValue=${this.progressValue}
      .variant=${this._variant}
      .direction=${this.direction}
      .hasBadgeSpacer=${this.getBadgeSpacer()}
      .positioning=${this.positioning}
    >
      ${this.icon}
      <slot
        name="badge-top-right"
        slot="badge-top-right"
        @slotchange=${this.handleBadgeSlotChange}
      >
        ${this.badgeAlertOff ? html`<obc-automation-badge type="alert-off"></obc-automation-badge>` : nothing}
      </slot>
      <slot
        name="badge-top-left"
        slot="badge-top-left"
        @slotchange=${this.handleBadgeSlotChange}
      >
        ${this.badgeAuto ? html`<obc-automation-badge type="auto"></obc-automation-badge>` : nothing}
      </slot>
      <slot
        name="badge-bottom-left"
        slot="badge-bottom-left"
        @slotchange=${this.handleBadgeSlotChange}
      >
        ${this.badgeDuty ? html`<obc-automation-badge type="duty"></obc-automation-badge>` : nothing}
      </slot>
      <slot
        name="badge-bottom-right"
        slot="badge-bottom-right"
        @slotchange=${this.handleBadgeSlotChange}
      >
        ${this.badgeCommandLocked ? html`<obc-automation-badge
              type="command-locked"
            ></obc-automation-badge>` : nothing}
      </slot>
    </obc-automation-button>`;
  }
  parseTagToNumber(tag) {
    const num = parseInt(tag.replace(/#/g, ""), 10);
    return isNaN(num) ? 0 : num;
  }
}
__decorateClass([
  property({ type: Boolean, attribute: false })
], ObcAbstractAutomationButton.prototype, "showReadoutStack");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "hasIdTag");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "readoutPosition");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "readoutSize");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "positioning");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "alert");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "alertFrameType");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "alertFrameThickness");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "alertFrameStatus");
__decorateClass([
  property({ type: Boolean, attribute: false })
], ObcAbstractAutomationButton.prototype, "showAlertCategoryIcon");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "showAlertIcon");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "progress");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "progressMode");
__decorateClass([
  property({ type: Number })
], ObcAbstractAutomationButton.prototype, "progressValue");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "tag");
__decorateClass([
  property({ type: String })
], ObcAbstractAutomationButton.prototype, "direction");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "badgeAuto");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "badgeCommandLocked");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "badgeDuty");
__decorateClass([
  property({ type: Boolean })
], ObcAbstractAutomationButton.prototype, "badgeAlertOff");
__decorateClass([
  queryAssignedElements({ slot: "badge-top-right" })
], ObcAbstractAutomationButton.prototype, "badgeTopRight");
__decorateClass([
  queryAssignedElements({ slot: "badge-top-left" })
], ObcAbstractAutomationButton.prototype, "badgeTopLeft");
__decorateClass([
  queryAssignedElements({ slot: "badge-bottom-left" })
], ObcAbstractAutomationButton.prototype, "badgeBottomLeft");
__decorateClass([
  queryAssignedElements({ slot: "badge-bottom-right" })
], ObcAbstractAutomationButton.prototype, "badgeBottomRight");
export {
  ObcAbstractAutomationButton
};
//# sourceMappingURL=abstract-automation-button.js.map
