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, Element, h, Host, Event, State, Prop } from '@stencil/core';
import { sanitizeVegaComponent } from '../../../../../utils/component';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer, MapToComponentMethod, } from 'vega-slimmer/core';
import { TranslationSlimmer } from '../../../../../helpers/slimmers/translation';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../../../../helpers/slimmers/component-usage-runtime-metrics';
import { VegaRichTextTableSettingRenderer } from './slimmers/renderers/vega-rich-text-table-setting-renderer';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import { Icons } from './assets/icon';
import chevronDown from '../../../../../global/icons/chevron-down';
import { CaptionButtonSlimmer } from './slimmers/renderers/caption-button-slimmer';
import { ColumnButtonSlimmer } from './slimmers/renderers/column-button-slimmer';
import { TablePropertiesButtonSlimmer } from './slimmers/renderers/table-properties-button-slimmer';
import { RowButtonSlimmer } from './slimmers/renderers/row-button-slimmer';
import { CellPropertiesButtonSlimmer } from './slimmers/renderers/cell-properties-button-slimmer';
import { DomNodeSubjectObserverFactory } from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaInternalRTEExtensionTableCellSelectionChange } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
import { isArrayEqual } from '../../../../../utils/array';
import { MergeCellsButtonSlimmer } from './slimmers/renderers/merge-cells-button-slimmer';
/**
 * Table setting popover renderer for managing table operations.
 *
 * @vegaVersion 2.79.0
 */
export class VegaRichTextTableSetting {
  constructor() {
    this.globalSlimmers = {};
    this.translationSlimmer = new TranslationSlimmer();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.renderer = new VegaRichTextTableSettingRenderer();
    this.captionButtonSlimmer = new CaptionButtonSlimmer();
    this.columnButtonSlimmer = new ColumnButtonSlimmer();
    this.tablePropertiesButtonSlimmer = new TablePropertiesButtonSlimmer();
    this.rowButtonSlimmer = new RowButtonSlimmer();
    this.cellPropertiesButtonSlimmer = new CellPropertiesButtonSlimmer();
    this.mergeCellsButtonSlimmer = new MergeCellsButtonSlimmer();
    this.isColumnDropdownOpen = false;
    this.isMergeCellsDropdownOpen = false;
    /**
     * Indicates whether the current table already has a caption.
     *
     * @vegaVersion 2.79.0
     */
    this.hasCaption = false;
    /**
     * The selected cells in the table.
     *
     * @vegaVersion 2.79.0
     */
    this.selectedCells = [];
  }
  connectedCallback() {
    this.registerTableCellSelectionChangeObserver();
  }
  disconnectedCallback() {
    if (this.target) {
      DomNodeSubjectObserverFactory.removeUniqueObserverFromNode(this.target, VegaInternalRTEExtensionTableCellSelectionChange);
    }
  }
  render() {
    return sanitizeVegaComponent(h(Host, null, this.renderer.render()), this.host);
  }
  registerTableCellSelectionChangeObserver() {
    // the target may be null when the table ref becomes ready after rendering vega-rich-text-table-setting.
    if (this.target) {
      DomNodeSubjectObserverFactory.addUniqueObserverToNode(this.target, VegaInternalRTEExtensionTableCellSelectionChange, (input) => {
        if (!isArrayEqual(this.selectedCells, input.detail)) {
          this.selectedCells = input.detail;
        }
      });
    }
  }
  static get is() { return "vega-rich-text-table-setting"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-rich-text-table-setting.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-rich-text-table-setting.css"]
  }; }
  static get properties() { return {
    "hasCaption": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.79.0"
          }],
        "text": "Indicates whether the current table already has a caption."
      },
      "attribute": "has-caption",
      "reflect": false,
      "defaultValue": "false"
    },
    "selectedCells": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "RTETableCellBlock[]",
        "resolved": "RTETableCellBlock[]",
        "references": {
          "RTETableCellBlock": {
            "location": "import",
            "path": "../dto/table-cell-block"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.79.0"
          }],
        "text": "The selected cells in the table."
      },
      "defaultValue": "[]"
    },
    "target": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "HTMLElement",
        "resolved": "HTMLElement",
        "references": {
          "HTMLElement": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.79.0"
          }],
        "text": "Specifies the target table element for the table setting."
      }
    }
  }; }
  static get states() { return {
    "isColumnDropdownOpen": {},
    "isMergeCellsDropdownOpen": {}
  }; }
  static get events() { return [{
      "method": "vegaClick",
      "name": "vegaClick",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.79.0"
          }],
        "text": ""
      },
      "complexType": {
        "original": "Array<string>",
        "resolved": "string[]",
        "references": {
          "Array": {
            "location": "global"
          }
        }
      }
    }]; }
  static get elementRef() { return "host"; }
}
(() => {
  VegaInternalIconManager.register(Object.assign(Object.assign({}, Icons), { 'chevron-down': chevronDown }));
})();
__decorate([
  InjectVegaGlobalSlimmer()
], VegaRichTextTableSetting.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "translationSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "renderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "captionButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "columnButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "tablePropertiesButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "rowButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "cellPropertiesButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRichTextTableSetting.prototype, "mergeCellsButtonSlimmer", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaRichTextTableSetting.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaRichTextTableSetting.prototype, "disconnectedCallback", null);
