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 { InjectVegaSlimmer, MapToComponentField, MapToComponentMethod } from 'vega-slimmer/core';
import { VegaInternalIconManager } from '../../../../../../helpers/icon/internal-icon-manager';
import ListUL from '../../../../assets/list-ul';
import ListOL from '../../../../assets/list-ol';
import { BulletsToolbarButtonSlimmer } from './bullets-toolbar-button-slimmer';
import { NumbersToolbarButtonSlimmer } from './numbers-toolbar-button-slimmer';
import { VisualModeToolbarButtonSlimmer } from '../visual-mode-toolbar-button-slimmer.abstract';
import { ActionHandleStrategyRegistry } from '../../../../dto/action-handle-strategies/action-handle-strategy-registry';
import { ModifyContentActionType } from '../../../../dto/actions/modify-content-action.abstract';
export class BulletsNumbersToolbarButtonSlimmer extends VisualModeToolbarButtonSlimmer {
  constructor() {
    super({
      icon: 'list-ul',
      tooltip: {
        text: 'Bullets',
      },
    });
    this.bulletsToolbarButtonSlimmer = new BulletsToolbarButtonSlimmer();
    this.numbersToolbarButtonSlimmer = new NumbersToolbarButtonSlimmer();
  }
  componentWillRender() {
    if (this.numbersToolbarButtonSlimmer.isSelected()) {
      super.setIcon('list-ol');
    }
    else {
      super.setIcon('list-ul');
    }
  }
  renderBtnWrapper(renderBtn) {
    return (h("vega-popover", { showArrow: false, trigger: "click", placement: "bottom", alignment: "center", ref: (ref) => (this.popoverRef = ref) },
      h("div", { slot: "popover-content" }, renderBtn({ showArrowIcon: true })),
      h("div", { slot: "popover" }, this.renderContent())));
  }
  renderContent() {
    return (h("vega-flex", { gap: "size-8", "justify-content": "center" },
      h("div", null, this.bulletsToolbarButtonSlimmer.render()),
      h("div", null, this.numbersToolbarButtonSlimmer.render())));
  }
  isSelected() {
    return false;
  }
  isDisabled() {
    return super.isDisabled() || this.shouldDisabledListToolbar();
  }
  shouldDisabledListToolbar() {
    const selectedBlocks = this.selectionController.getSelectedBlocks();
    return selectedBlocks.some((block) => {
      return (block &&
        (this.unableToConvertListOrParagraph(block) || this.unableToInsertBlock(block.parent)));
    });
  }
  /**
   * Check if unable to insert blocks before or after the given block.
   *
   * @param {RTEBlock | VegaRTEContent} block - The block to check.
   * @returns {boolean} - Boolean result.
   */
  unableToInsertBlock(block) {
    return !(ActionHandleStrategyRegistry.canHandle(ModifyContentActionType.INSERT_CHILDREN_AFTER, block) ||
      ActionHandleStrategyRegistry.canHandle(ModifyContentActionType.INSERT_CHILDREN_BEFORE, block));
  }
  /**
   * Check if unable to convert the block to list or paragraph.
   *
   * @param {RTEBlock} block - The block to check.
   * @returns {boolean} - Boolean result.
   */
  unableToConvertListOrParagraph(block) {
    return (!ActionHandleStrategyRegistry.canHandle(ModifyContentActionType.TRANSFORM_LIST_BLOCK, block) &&
      !ActionHandleStrategyRegistry.canHandle(ModifyContentActionType.TRANSFORM_PARAGRAPH_BLOCK, block.parent));
  }
}
(() => {
  VegaInternalIconManager.register({
    'list-ul': ListUL,
    'list-ol': ListOL,
  });
})();
__decorate([
  MapToComponentField()
], BulletsNumbersToolbarButtonSlimmer.prototype, "selectionController", void 0);
__decorate([
  InjectVegaSlimmer()
], BulletsNumbersToolbarButtonSlimmer.prototype, "bulletsToolbarButtonSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], BulletsNumbersToolbarButtonSlimmer.prototype, "numbersToolbarButtonSlimmer", void 0);
__decorate([
  MapToComponentMethod('componentWillRender')
], BulletsNumbersToolbarButtonSlimmer.prototype, "componentWillRender", null);
