"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_toolbar_buttons_exports = {};
__export(get_toolbar_buttons_exports, {
  getToolbarButtons: () => getToolbarButtons
});
module.exports = __toCommonJS(get_toolbar_buttons_exports);
var import_lodash = __toESM(require("lodash"));
var import_create_color_button = require("./../../_shared/plugin-toolbar/create-color-button.js");
var import_create_delete_button = require("./../../_shared/plugin-toolbar/create-delete-button.js");
var import_create_node_alignment_button = require("./../../_shared/plugin-toolbar/create-node-alignment-button.js");
var import_create_replace_button = require("./../../_shared/plugin-toolbar/create-replace-button.js");
var import_create_node_size_button = require("./../../_shared/plugin-toolbar/node-size-button/create-node-size-button.js");
var import_shape_color_picker_modal = require("./../components/shape-color-picker-modal.js");
var import_shape_colors_modal = require("./../components/shape-colors-modal.js");
var import_toolbars_v3 = require("./../../toolbars-v3/index.js");
var import_shape_select_modal = require("../components/shape-select-modal.js");
var import_consts = require("../utils/consts.js");
var import_data_hooks = require("../utils/data-hooks.js");
const getShapeColorMap = (selectedNode) => {
  const colors = selectedNode.attrs?.styles?.colors;
  if (!colors) {
    return { [import_consts.DEFAULT_COLOR]: import_consts.DEFAULT_COLOR };
  }
  return colors;
};
const getShapeColors = (selectedNode) => {
  const colors = getShapeColorMap(selectedNode);
  return Object.entries(colors).map(([originalColor, customColor]) => customColor || originalColor);
};
const getToolbarButtons = (config, services) => {
  const { modals } = services;
  const color = (0, import_create_color_button.createColorButton)({
    getColors: (selectedNode) => getShapeColors(selectedNode),
    modalId: import_consts.SHAPE_COLORS_MODAL_ID,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      const colors = getShapeColors(selectedNode);
      const isSingleColor = colors.length === 1;
      const basePanelParams = {
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${import_toolbars_v3.FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "bottom"
        },
        onClickOutside: {
          on: "pointerup",
          handler: import_lodash.default.noop
        },
        focusReturnElement: referenceElement
      };
      if (isSingleColor) {
        const colorMap = getShapeColorMap(selectedNode);
        const [originalColor] = Object.entries(colorMap);
        modals.togglePluginPanel({
          id: import_consts.SHAPE_COLORS_MODAL_ID,
          Component: import_shape_color_picker_modal.ShapeColorPickerModal,
          componentProps: {
            nodeId: selectedNode.attrs.id,
            originalColor: originalColor[0],
            initialColor: originalColor[1] || originalColor[0]
          },
          ...basePanelParams
        });
        return;
      }
      modals.togglePluginPanel({
        id: import_consts.SHAPE_COLORS_MODAL_ID,
        Component: import_shape_colors_modal.ShapeColorsModal,
        componentProps: {
          nodeId: selectedNode.attrs.id
        },
        ...basePanelParams
      });
    }
  });
  const nodeSize = (0, import_create_node_size_button.createNodeSizeButton)({
    services,
    modalId: import_consts.SHAPE_SIZE_MODAL_ID,
    options: ["SMALL", "CONTENT", "FULL_WIDTH", "ORIGINAL"]
  });
  const nodeAlignment = (0, import_create_node_alignment_button.createNodeAlignmentButton)({
    services,
    modalId: import_consts.SHAPE_ALIGNMENT_MODAL_ID
  });
  const replace = (0, import_create_replace_button.createReplaceButton)({
    tooltip: "ReplaceShapeButton_Tooltip",
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      modals.togglePluginPanel({
        id: import_data_hooks.SHAPE_SELECT_MODAL,
        Component: import_shape_select_modal.ShapeSelectModal,
        componentProps: {
          nodeId: selectedNode.attrs.id,
          getShapeUrl: config.getShapeUrl
        },
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${import_toolbars_v3.FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "bottom"
        }
      });
    }
  });
  const deleteButton = (0, import_create_delete_button.createDeleteButton)({});
  return [color, nodeSize, nodeAlignment, replace, deleteButton];
};
//# sourceMappingURL=get-toolbar-buttons.js.map
