import { unsafeCSS, LitElement, html } from "lit";
import { customElement } from "../../decorator.js";
import componentStyle from "./pivot-item-group.css.js";
import { property } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { ObcPivotItemDirection } from "../pivot-item/pivot-item.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 ObcPivotItemGroup = class extends LitElement {
  constructor() {
    super(...arguments);
    this.direction = ObcPivotItemDirection.horizontal;
    this.selectedValue = "";
    this.allowDeselect = false;
  }
  handleItemSelected(event) {
    event.stopPropagation();
    const { value } = event.detail;
    if (this.allowDeselect && this.selectedValue === value) {
      this.selectedValue = "";
    } else {
      this.selectedValue = value;
    }
    this.updateChildItems();
    this.dispatchEvent(
      new CustomEvent("change", {
        detail: { selectedValue: this.selectedValue },
        bubbles: true,
        composed: true
      })
    );
  }
  updateChildItems() {
    const items = this.querySelectorAll(
      "obc-pivot-item"
    );
    items.forEach((item) => {
      item.selected = item.value === this.selectedValue;
      item.direction = this.direction;
    });
  }
  firstUpdated() {
    this.updateComplete.then(() => {
      this.updateChildItems();
    });
  }
  updated(changedProperties) {
    if (changedProperties.has("selectedValue") || changedProperties.has("direction")) {
      this.updateChildItems();
    }
  }
  render() {
    const classes = classMap({
      "pivot-group": true,
      "direction-horizontal": this.direction === ObcPivotItemDirection.horizontal,
      "direction-vertical": this.direction === ObcPivotItemDirection.vertical
    });
    return html`
      <div class=${classes} @selected=${this.handleItemSelected}>
        <slot></slot>
      </div>
    `;
  }
};
ObcPivotItemGroup.styles = unsafeCSS(componentStyle);
__decorateClass([
  property({ type: String })
], ObcPivotItemGroup.prototype, "direction", 2);
__decorateClass([
  property({ type: String })
], ObcPivotItemGroup.prototype, "selectedValue", 2);
__decorateClass([
  property({ type: Boolean })
], ObcPivotItemGroup.prototype, "allowDeselect", 2);
ObcPivotItemGroup = __decorateClass([
  customElement("obc-pivot-item-group")
], ObcPivotItemGroup);
export {
  ObcPivotItemGroup
};
//# sourceMappingURL=pivot-item-group.js.map
