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 { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { getDeviceType } from '../../../../utils/ui';
import { DeviceType } from '../../../../types/ui.type';
export class VegaBreadcrumbRenderer extends VegaSlimmer {
  /**
   * get the component container div element
   *
   * @returns {HTMLDivElement} the container element ref
   */
  getBreadcrumbContainerRef() {
    return this.vegaBreadcrumbContainerRef;
  }
  render() {
    return (h("div", { class: {
        'vega-breadcrumb': true,
        'compact-mode': this.isCompactMode,
        'last-item-clickable': this.lastItemClickable,
        'collapsed': this.isCollapsed(),
        'single': this.items.length === 1,
      }, ref: (node) => (this.vegaBreadcrumbContainerRef = node) }, this.renderItems()));
  }
  renderItems() {
    const htmlItems = this.items.map((item, index) => this.itemRenderer.render(item, {
      isCompactMode: this.isCompactMode,
      isLastItem: this.items.length === index + 1,
    }));
    if (this.isCollapsed()) {
      htmlItems.splice(1, 0, this.collapsedItemRenderer.render(this.items.slice(1, this.items.length - 1)));
    }
    return h(Fragment, null, htmlItems);
  }
  isCollapsed() {
    return (!this.isCompactMode &&
      this.maxItems !== 'none' &&
      this.maxItems >= 4 &&
      this.items.length > this.maxItems);
  }
  // True when device is mobile and compact mode is enabled.
  // Used to switch into the compact single-item mobile rendering mode.
  get isCompactMode() {
    return this.compactOnMobile && getDeviceType() === DeviceType.MOBILE;
  }
}
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "items", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "compactOnMobile", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "lastItemClickable", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "maxItems", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "itemRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaBreadcrumbRenderer.prototype, "collapsedItemRenderer", void 0);
