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 { VegaInternalIconManager } from '../../../../../../../helpers/icon/internal-icon-manager';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
export class TableSettingButtonSlimmer extends VegaSlimmer {
  constructor({ icon, title, showArrowIcon }) {
    super();
    this.renderBtn = () => {
      const selected = this.isSelected();
      const disable = this.isDisabled();
      return (h("vega-tooltip", { key: `table-setting-${this.icon}`, text: this.getTitle(), placement: ['bottom', 'top'], trigger: "hover" },
        h("button", { type: "button", class: {
            'rte-table-setting-item': true,
            'rte-table-setting-item-disabled': disable,
            'rte-table-setting-item-selected': selected,
          }, disabled: disable, 
          /* eslint-disable-next-line react/jsx-no-bind */
          onClick: (event) => {
            if (disable) {
              return;
            }
            this.handleClick(event);
          }, onKeyDown: this.preventDefaultEvent, onMouseDown: this.preventDefaultEvent },
          h("vega-flex", { alignItems: "center", justifyContent: "center" },
            h("vega-icon", { icon: VegaInternalIconManager.getIconKey(this.icon), size: "size-16", color: this.getIconColor() }),
            this.showArrowIcon ? (h("vega-icon", { size: "size-8", style: { marginLeft: '8px' }, icon: VegaInternalIconManager.getIconKey('chevron-down'), color: this.getIconColor() })) : null))));
    };
    this.icon = icon;
    this.title = title;
    this.showArrowIcon = showArrowIcon;
  }
  render() {
    return typeof this.renderBtnWrapper === 'function'
      ? this.renderBtnWrapper(this.renderBtn)
      : this.renderBtn();
  }
  emitClickEvent(setting) {
    this.vegaClick.emit(setting);
  }
  /**
   * Prevent the default behavior to keep the cursor position.
   *
   * @param {Event} e - The event object.
   */
  preventDefaultEvent(e) {
    e.preventDefault();
  }
  getTitle() {
    return this.title;
  }
  getIconColor() {
    const selected = this.isSelected();
    const disable = this.isDisabled();
    if (selected) {
      return 'text-link-active';
    }
    else if (disable) {
      return 'text-disabled';
    }
    return 'text-primary';
  }
}
__decorate([
  MapToComponentField()
], TableSettingButtonSlimmer.prototype, "hasCaption", void 0);
__decorate([
  MapToComponentField()
], TableSettingButtonSlimmer.prototype, "vegaClick", void 0);
__decorate([
  MapToComponentField()
], TableSettingButtonSlimmer.prototype, "selectedCells", void 0);
