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 { Fragment, h } from '@stencil/core';
import { VegaSlimmer, MapToComponentField } from 'vega-slimmer/core';
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';
export class VegaBreadcrumbItemRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.onButtonLinkClick = (payload, item) => {
      const event = this.clickEventEmitter.emit(item);
      if (event && event.defaultPrevented) {
        payload.preventDefault();
      }
    };
  }
  render(item, options) {
    return (h("div", { class: "vega-breadcrumb-item", key: item.label }, this.renderContent(item, options)));
  }
  renderContent(item, options) {
    if (options.isCompactMode && (!options.isLastItem || this.lastItemClickable)) {
      return (h(Fragment, null,
        this.renderIcon('chevron-left-rounded', 'text-link'),
        this.renderLabel(item)));
    }
    else if (options.isLastItem) {
      return this.renderLabel(item, !this.lastItemClickable);
    }
    else if (options.isInDropdown) {
      return this.renderLink(item, false, true);
    }
    else {
      return (h(Fragment, null,
        this.renderLabel(item),
        this.renderIcon('chevron-right-rounded', 'text-secondary')));
    }
  }
  renderIcon(icon, color) {
    return h("vega-icon", { icon: icon, size: "size-12", color: color });
  }
  renderLabel(item, isPlainLabel) {
    return item.tooltip ? (h("vega-tooltip", { text: item.tooltip, placement: ['bottom'] }, this.renderLink(item, isPlainLabel))) : (this.renderLink(item, isPlainLabel));
  }
  renderLink(item, isPlainLabel, isInDropdown = false) {
    return isPlainLabel ? (h("span", { class: "vega-breadcrumb-last-label" }, item.label)) : (h("vega-button-link", { label: item.label, link: item.href, eventful: true, class: {
        'vega-breadcrumb-dropdown-link': isInDropdown,
      }, ref: (ref) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, (payload) => {
          this.onButtonLinkClick(payload, item);
        });
      } }));
  }
}
__decorate([
  MapToComponentField()
], VegaBreadcrumbItemRenderer.prototype, "lastItemClickable", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbItemRenderer.prototype, "clickEventEmitter", void 0);
