var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { h, Fragment } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { formatAndValidResponsiveToken } from '../../../utils/public-api';
import { arrayToClassString } from '../../../utils/ui';
import { DomNodeSubjectObserverFactory } from '../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick } from '../../../helpers/event-manager/event-id/vega-event-id';
import chevronUp from '../../../global/icons/chevron-up';
import chevronDown from '../../../global/icons/chevron-down';
import { VegaInternalIconManager } from '../../../helpers/icon/internal-icon-manager';
export class VegaAccordionRenderer extends VegaSlimmer {
  render() {
    return (h("div", { class: {
        'accordion': true,
        'background': this.drawsBackground,
        'expanded': this.expand,
        'collapsed': !this.expand,
        'icon-position-center': this.iconPosition === 'center',
      } },
      this.renderHeader(),
      this.renderContent()));
  }
  renderHeader() {
    const titleDom = (h(Fragment, null,
      this.renderPrefixIcon(),
      this.accordionTitle ? this.renderTitle() : this.renderTitleSlot()));
    return (h("div", { class: "accordion-header" },
      h("vega-flex", { gap: "size-8", "align-items": "start" },
        this.expandIconAlign === 'left' && this.renderExpandIcon(),
        titleDom,
        this.expandIconAlign === 'right' && this.renderExpandIcon())));
  }
  renderPrefixIcon() {
    return (this.prefixIcon && (h("div", { class: "accordion-prefix-icon" },
      h("vega-icon", { icon: this.prefixIcon, size: "size-24" }))));
  }
  renderTitle() {
    return h("div", { class: "accordion-title" }, this.accordionTitle);
  }
  renderExpandIcon() {
    const classes = [
      'accordion-expand-icon',
      `accordion-expand-icon-align-${this.expandIconAlign}`,
      formatAndValidResponsiveToken(this.showExpandIcon, 'display'),
    ];
    return (h("div", { class: `${arrayToClassString(classes)}` },
      h("vega-button-circle", { size: "small", "icon-color": "text-link", variant: "icon-only", "data-aria-label": this.getExpandIconAriaLabel(), "data-aria-expanded": `${this.expand}`, icon: VegaInternalIconManager.getIconKey(this.expandIconAlign === 'left' ? 'chevron-down' : 'chevron-up'), ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
            this.expandController.flipExpand();
          });
        } })));
  }
  renderContent() {
    return (h("div", { class: "accordion-content" },
      h("slot", { name: "content" }),
      h("slot", { name: "accordion-content" })));
  }
  renderTitleSlot() {
    return (h("div", { class: "accordion-title-slot" },
      h("slot", { name: "title" }),
      h("slot", { name: "accordion-title" })));
  }
  getExpandIconAriaLabel() {
    if (this.accordionTitle) {
      return this.expand
        ? this.translationSlimmer.t('Collapse {0} accordion', this.accordionTitle)
        : this.translationSlimmer.t('Expand {0} accordion', this.accordionTitle);
    }
    return this.expand
      ? this.translationSlimmer.t('Collapse accordion')
      : this.translationSlimmer.t('Expand accordion');
  }
}
(() => {
  VegaInternalIconManager.register({
    'chevron-up': chevronUp,
    'chevron-down': chevronDown,
  });
})();
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "drawsBackground", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "prefixIcon", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "accordionTitle", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "expandIconAlign", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "expand", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "iconPosition", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "showExpandIcon", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "expandController", void 0);
__decorate([
  MapToComponentField()
], VegaAccordionRenderer.prototype, "translationSlimmer", void 0);
