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 } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
export class VegaSelectionTileRenderer extends VegaSlimmer {
  getSelectorContainerRef() {
    return this.selectorContainerRef;
  }
  render() {
    return (h("vega-flex", { "align-items": "start", "justify-content": "start", gap: "size-16", class: {
        'selection-tile': true,
        'disabled': this.disabled,
        'checked': this.checked,
        'error': this.showError,
      }, "aria-label": this.titleText || 'No label defined', tabIndex: this.disabled ? -1 : 0, 
      /* eslint-disable-next-line react/jsx-no-bind */
      onClick: () => {
        if (!(this.selectType === 'radio' && this.checked)) {
          this.checkedController.onCheck(!this.checked);
        }
      }, onKeyDown: createEnterKeyHandlerToTriggerClick() },
      h("div", { class: "vega-flex-grow" }, this.renderContent()),
      this.renderSelect()));
  }
  renderContent() {
    if (this.hasContentSlot()) {
      return h("slot", { name: "content" });
    }
    else {
      return (h("vega-flex", { gap: "size-12" },
        h("vega-flex", { class: "vega-flex-shrink-0" }, this.renderPrefixIcon()),
        h("div", { class: "vega-flex-grow" }, this.renderText())));
    }
  }
  renderPrefixIcon() {
    if (this.hasPrefixSlot()) {
      return h("slot", { name: "prefix" });
    }
    else if (this.prefixIcon) {
      return (h("vega-icon", { icon: this.prefixIcon, size: "size-16", color: this.disabled ? 'text-secondary' : 'text-primary', class: "selection-tile-icon" }));
    }
  }
  renderText() {
    return (h("vega-flex", { class: "vega-flex-grow", direction: "col", "align-items": "start", "justify-content": "start" },
      h("div", { class: "selection-tile-title" }, this.titleText),
      this.note && h("div", { class: "selection-tile-note" }, this.note)));
  }
  renderSelect() {
    return (h("vega-flex", { "align-items": "start", class: "vega-flex-shrink-0 selection-tile-select", ref: (ref) => (this.selectorContainerRef = ref) }, this.selectType === 'checkbox' ? this.renderCheckbox() : this.renderRadio()));
  }
  renderCheckbox() {
    return h("vega-checkbox", { size: "small", disabled: this.disabled, checked: this.checked });
  }
  renderRadio() {
    return h("vega-radio", { size: "small", disabled: this.disabled, checked: this.checked });
  }
  hasPrefixSlot() {
    return this.host.querySelector(`[slot=prefix]`) !== null;
  }
  hasContentSlot() {
    return this.host.querySelector(`[slot=content]`) !== null;
  }
}
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "prefixIcon", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "titleText", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "note", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "selectType", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "checked", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "showError", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileRenderer.prototype, "checkedController", void 0);
