import {
  ArrowDown,
  ArrowLeft,
  ArrowRight,
  ArrowUp,
  MergeCell,
  SplitCell
} from "@wix/wix-ui-icons-common";
import React, { useContext } from "react";
import { RicosContext } from "./../../../ricos-context/index.js";
import { ToolbarButton as ToolbarButtonComponent } from "./../../../_shared/toolbar-button/toolbar-button.js";
import { TABLE_BUTTONS } from "../../consts.js";
import {
  PLUGIN_TOOLBAR_MERGE_CELLS_BUTTON,
  PLUGIN_TOOLBAR_MOVE_COLUMN_LEFT_BUTTON,
  PLUGIN_TOOLBAR_MOVE_COLUMN_RIGHT_BUTTON,
  PLUGIN_TOOLBAR_MOVE_ROW_DOWN_BUTTON,
  PLUGIN_TOOLBAR_MOVE_ROW_UP_BUTTON,
  PLUGIN_TOOLBAR_SPLIT_CELL_BUTTON
} from "../../data-hooks.js";
import {
  cannotMergeCellsResolver,
  cannotMoveColumnLeftResolver,
  cannotMoveColumnRightResolver,
  cannotMoveRowDownResolver,
  cannotMoveRowUpResolver,
  cannotSplitCellResolver,
  isCellSelectionResolver,
  isColumnSelectedResolver,
  isRowSelectedResolver
} from "../resolvers.js";
const SimpleToggleButton = ({
  toolbarItem,
  tooltipKey
}) => {
  const { t } = useContext(RicosContext);
  return /* @__PURE__ */ React.createElement(
    ToolbarButtonComponent,
    {
      tooltip: t(tooltipKey),
      onClick: () => toolbarItem.commands.click(),
      prefix: toolbarItem.presentation?.icon,
      dataHook: toolbarItem.presentation?.dataHook,
      tabIndex: toolbarItem.presentation.tabIndex,
      disabled: toolbarItem.attributes.disabled
    }
  );
};
const createToggleButton = (config) => ({
  id: config.id,
  type: "toggle",
  tooltip: config.tooltip,
  icon: config.icon,
  dataHook: config.dataHook,
  command: ({ tiptapEditor }) => {
    config.execute(tiptapEditor.chain().focus()).run();
  },
  renderer: (toolbarItem) => /* @__PURE__ */ React.createElement(SimpleToggleButton, { toolbarItem, tooltipKey: config.tooltip }),
  attributes: {
    disabled: config.disabled,
    visible: config.visible,
    alwaysVisible: config.visible
  }
});
const createMoveColumnLeftButton = () => createToggleButton({
  id: TABLE_BUTTONS.MOVE_COLUMN_LEFT,
  tooltip: "TablePlugin_Toolbar_MoveColumnLeft_Tooltip",
  icon: ArrowLeft,
  dataHook: PLUGIN_TOOLBAR_MOVE_COLUMN_LEFT_BUTTON,
  execute: (chain) => chain.moveColumns("left"),
  disabled: cannotMoveColumnLeftResolver,
  visible: isColumnSelectedResolver
});
const createMoveColumnRightButton = () => createToggleButton({
  id: TABLE_BUTTONS.MOVE_COLUMN_RIGHT,
  tooltip: "TablePlugin_Toolbar_MoveColumnRight_Tooltip",
  icon: ArrowRight,
  dataHook: PLUGIN_TOOLBAR_MOVE_COLUMN_RIGHT_BUTTON,
  execute: (chain) => chain.moveColumns("right"),
  disabled: cannotMoveColumnRightResolver,
  visible: isColumnSelectedResolver
});
const createMoveRowUpButton = () => createToggleButton({
  id: TABLE_BUTTONS.MOVE_ROW_UP,
  tooltip: "TablePlugin_Toolbar_MoveRowUp_Tooltip",
  icon: ArrowUp,
  dataHook: PLUGIN_TOOLBAR_MOVE_ROW_UP_BUTTON,
  execute: (chain) => chain.moveRows("up"),
  disabled: cannotMoveRowUpResolver,
  visible: isRowSelectedResolver
});
const createMoveRowDownButton = () => createToggleButton({
  id: TABLE_BUTTONS.MOVE_ROW_DOWN,
  tooltip: "TablePlugin_Toolbar_MoveRowDown_Tooltip",
  icon: ArrowDown,
  dataHook: PLUGIN_TOOLBAR_MOVE_ROW_DOWN_BUTTON,
  execute: (chain) => chain.moveRows("down"),
  disabled: cannotMoveRowDownResolver,
  visible: isRowSelectedResolver
});
const createMergeCellsButton = () => createToggleButton({
  id: TABLE_BUTTONS.MERGE_CELLS,
  tooltip: "TablePlugin_Toolbar_MergeCells_Button",
  icon: MergeCell,
  dataHook: PLUGIN_TOOLBAR_MERGE_CELLS_BUTTON,
  execute: (chain) => chain.mergeCells(),
  disabled: cannotMergeCellsResolver,
  visible: isCellSelectionResolver
});
const createSplitCellButton = () => createToggleButton({
  id: TABLE_BUTTONS.SPLIT_CELL,
  tooltip: "TablePlugin_Toolbar_SplitCell_Button",
  icon: SplitCell,
  dataHook: PLUGIN_TOOLBAR_SPLIT_CELL_BUTTON,
  execute: (chain) => chain.splitCell(),
  disabled: cannotSplitCellResolver,
  visible: isCellSelectionResolver
});
export {
  createMergeCellsButton,
  createMoveColumnLeftButton,
  createMoveColumnRightButton,
  createMoveRowDownButton,
  createMoveRowUpButton,
  createSplitCellButton
};
//# sourceMappingURL=simple-toggle-buttons.js.map
