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 { Component, Host, h, Prop, Element, State } from '@stencil/core';
import { generateResponsiveClass, generateTextAlignClass } from '../utils';
import { arrayToClassString } from '../../../utils/ui';
import { sanitizeVegaComponent } from '../../../utils/component';
import { VegaTableCellStateController } from './slimmers/controllers/vega-table-cell-state-controller';
import ResponsiveFormatFacade from '../../../helpers/formatter/responsive-map-formatter/responsive-format-facade';
import { getCurrentBreakpoint } from '../../../utils/breakpoints';
import { PageResizeObserverSlimmer } from '../../../helpers/slimmers/page-resize-observer-slimmer';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer } from 'vega-slimmer/core';
import { FeatureFlag } from '../../../helpers/feature-control/feature-flag-controller';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../../helpers/slimmers/component-usage-runtime-metrics';
import { VegaTableRowStateSubscriber } from './slimmers/controllers/vega-table-row-state-subscriber';
import { VegaTableChildRenderInputConsumerSlimmer } from '../../../helpers/slimmers/vega-table-child-render-input-consumer-slimmer';
import { VegaInternalColumnBodyCellRenderInputRIC } from '../../../helpers/event-manager/event-id/vega-internal-event-id';
/**
 * @vegaVersion 1.44.0
 */
export class VegaTableCell {
  constructor() {
    this.globalSlimmers = {};
    this.vegaTableCellStateController = new VegaTableCellStateController();
    this.vegaTableRowStateSubscriber = new VegaTableRowStateSubscriber();
    this.pageResizeObserverSlimmer = new PageResizeObserverSlimmer();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.vegaTableRenderInputConsumerSlimmer = new VegaTableChildRenderInputConsumerSlimmer(VegaInternalColumnBodyCellRenderInputRIC);
    this.currentBreakpoint = getCurrentBreakpoint();
    this.getCellOverflowClass = () => {
      switch (this.overflow) {
        case 'ellipsis':
          return 'vega-table-cell-ellipsis';
        case 'scroll':
          return 'vega-table-cell-scroll';
      }
    };
  }
  render() {
    var _a, _b, _c;
    const responsiveClass = generateResponsiveClass(this.breakpoint, 'v-table-cell');
    const columnAlignClass = generateTextAlignClass(this.textAlign);
    const overflowClass = this.getCellOverflowClass();
    const columnClasses = [responsiveClass, columnAlignClass, 'vega-table-cell'];
    if (!FeatureFlag.isEnabled('VEGA_TABLE.ENABLE_NEW_CELL_BREAK_WORDS_STYLE')) {
      columnClasses.push('break-word');
    }
    if ((_a = this.renderInput) === null || _a === void 0 ? void 0 : _a.isRightStartPinned) {
      columnClasses.push('left-divider');
    }
    if ((_b = this.renderInput) === null || _b === void 0 ? void 0 : _b.isLeftEndPinned) {
      columnClasses.push('right-divider');
    }
    if ((_c = this.renderInput) === null || _c === void 0 ? void 0 : _c.isNoPinnedEnd) {
      columnClasses.push('hide-right-border');
    }
    return sanitizeVegaComponent(h(Host, { class: arrayToClassString([
        `density-${ResponsiveFormatFacade.formatCustom(this.density)}`,
        this.rowDivider && 'row-divider',
        this.columnDivider && 'column-divider',
        this.clickable && 'clickable',
        this.checked && 'checked',
        this.striped && 'striped',
        this.expanded && 'expanded',
      ]) },
      h("td", { class: arrayToClassString(columnClasses), part: "cell", 
        /* eslint-disable-next-line react/jsx-no-bind */
        onMouseEnter: this.onMouseEnter.bind(this), 
        /* eslint-disable-next-line react/jsx-no-bind */
        onMouseLeave: this.onMouseLeave.bind(this), style: { width: this.width } },
        h("div", { class: overflowClass },
          h("slot", null)))), this.host);
  }
  onMouseEnter() {
    const row = this.host.parentElement;
    row.querySelectorAll('vega-table-cell').forEach((cell) => cell.classList.add('hovered'));
  }
  onMouseLeave() {
    const row = this.host.parentElement;
    row.querySelectorAll('vega-table-cell').forEach((cell) => cell.classList.remove('hovered'));
  }
  static get is() { return "vega-table-cell"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-table-cell.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-table-cell.css"]
  }; }
  static get properties() { return {
    "textAlign": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'left' | 'right' | 'center'",
        "resolved": "\"center\" | \"left\" | \"right\"",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.44.0"
          }],
        "text": "Determines the alignment of text within the cell."
      },
      "attribute": "text-align",
      "reflect": false
    },
    "breakpoint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "VegaTableColumnBreakpoint",
        "resolved": "\"L\" | \"M\" | \"S\" | \"XL\"",
        "references": {
          "VegaTableColumnBreakpoint": {
            "location": "import",
            "path": "../interface"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.44.0"
          }],
        "text": "Defines the screen width at which the column becomes hidden.\n   If not set, the column remains visible at all times."
      },
      "attribute": "breakpoint",
      "reflect": false
    },
    "overflow": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'ellipsis' | 'scroll'",
        "resolved": "\"ellipsis\" | \"scroll\"",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.44.0"
          }],
        "text": "Determines the text overflow behavior within cells.\n`ellipsis`: Replaces overflowed text with ellipsis.\n`scroll`: Enables cell scrolling; scroll bars are displayed only when the content overflows,\n    remaining hidden by default."
      },
      "attribute": "overflow",
      "reflect": false
    },
    "width": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.44.0"
          }],
        "text": "Specifies the width of the cell."
      },
      "attribute": "width",
      "reflect": false
    }
  }; }
  static get states() { return {
    "currentBreakpoint": {},
    "density": {},
    "rowDivider": {},
    "columnDivider": {},
    "clickable": {},
    "checked": {},
    "striped": {},
    "expanded": {},
    "renderInput": {}
  }; }
  static get elementRef() { return "host"; }
}
__decorate([
  InjectVegaGlobalSlimmer()
], VegaTableCell.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableCell.prototype, "vegaTableCellStateController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableCell.prototype, "vegaTableRowStateSubscriber", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableCell.prototype, "pageResizeObserverSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableCell.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaTableCell.prototype, "vegaTableRenderInputConsumerSlimmer", void 0);
