"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_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_react = __toESM(require("react"));
var import_ricos_content = require("./../ricos-content/index.js");
var import_create_delete_button = require("./../_shared/plugin-toolbar/create-delete-button.js");
var import_create_settings_button = require("./../_shared/plugin-toolbar/create-settings-button.js");
var import_create_separator = require("./../_shared/plugin-toolbar/separator/create-separator.js");
var import_get_node_in_selection = require("./../_shared/resolvers/get-node-in-selection.js");
var import_toolbars_v3 = require("./../toolbars-v3/index.js");
var import_settings_modal = require("./components/settings-modal/settings-modal.js");
var import_consts = require("./consts.js");
var import_data_hooks = require("./data-hooks.js");
var import_poll_layout_dropdown_button = require("./toolbar/poll-layout-dropdown-button.js");
var import_poll_layout_dropdown = require("./toolbar/poll-layout-dropdown.js");
const getToolbarButtons = (config, services) => {
  const { modals } = services;
  const { isMobile } = services?.context ?? {};
  const openSettingsModal = ({
    modalId,
    node,
    referenceElement,
    activeTab
  }) => {
    modals?.togglePluginPanel({
      id: modalId,
      Component: import_settings_modal.SettingsModal,
      componentProps: {
        nodeId: node.attrs.id,
        activeTab,
        config,
        modalId
      },
      positioning: {
        referenceElement: referenceElement?.closest(`[data-hook~=${import_toolbars_v3.FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
        placement: "right-start"
      },
      focusReturnElement: referenceElement,
      isMobile
    });
  };
  const settingsButton = (0, import_create_settings_button.createSettingsButton)({
    modalId: import_consts.POLL_SETTINGS_MODAL_ID,
    showLabel: true,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      openSettingsModal({
        modalId: import_consts.POLL_SETTINGS_MODAL_ID,
        node: selectedNode,
        referenceElement,
        activeTab: import_consts.SETTINGS_TAB.settings
      });
    }
  });
  const separator1 = (0, import_create_separator.createSeparator)();
  const layoutButton = {
    id: import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID,
    type: "modal",
    dataHook: import_data_hooks.PLUGIN_TOOLBAR_LAYOUT_DROPDOWN_BUTTON,
    attributes: {
      layout: selectedLayoutResolver,
      selectedNode: import_get_node_in_selection.getNodeInSelection,
      active: (_, { modals: modals2 }) => Boolean(modals2?.getModal(import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID))
    },
    getIcon: ({ attributes }) => {
      const selectedLayout = import_poll_layout_dropdown.dropdownOptions[attributes.layout] || import_poll_layout_dropdown.dropdownOptions.GRID;
      return selectedLayout?.icon || import_wix_ui_icons_common.LayoutGallery;
    },
    tooltip: "Poll_PollSettings_Tab_Layout_TabName",
    command: ({ referenceElement, tiptapEditor, attributes }) => {
      if (modals?.isModalOpen(import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID)) {
        modals?.closeModal(import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID);
        return;
      }
      modals?.openModal({
        id: import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID,
        Component: import_poll_layout_dropdown.PollLayoutDropdown,
        componentProps: {
          selectedLayout: attributes?.layout || "GRID",
          onLayoutClick: (layout) => {
            tiptapEditor.chain().focus().updateAttributes(import_ricos_content.TIPTAP_POLL_TYPE, {
              layout: {
                poll: { ...attributes.selectedNode.attrs.layout.poll, type: layout }
              }
            }).run();
            modals?.closeModal(import_consts.POLL_LAYOUT_DROPDOWN_MODAL_ID);
          },
          onCustomizeButtonClick: () => {
            openSettingsModal({
              modalId: import_consts.POLL_SETTINGS_MODAL_ID,
              node: attributes.selectedNode,
              referenceElement,
              activeTab: import_consts.SETTINGS_TAB.layout
            });
          }
        },
        layout: isMobile ? "drawer" : "floating",
        positioning: { referenceElement, placement: "bottom" },
        type: "exclusive"
      });
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_poll_layout_dropdown_button.PollLayoutDropdownButton, { toolbarItem })
  };
  const separator2 = (0, import_create_separator.createSeparator)();
  const deleteButton = (0, import_create_delete_button.createDeleteButton)();
  if (services.context.environment === "wixel") {
    return [settingsButton, layoutButton, deleteButton];
  }
  return [settingsButton, separator1, layoutButton, separator2, deleteButton];
};
const selectedLayoutResolver = (content) => {
  const pollNode = Array.isArray(content) && content.find((node) => node.type.name === "POLL");
  if (!pollNode) {
    return void 0;
  }
  return pollNode.attrs.layout?.poll.type;
};
//# sourceMappingURL=get-toolbar-buttons.js.map
