"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var TextAlignPlugin_exports = {};
__export(TextAlignPlugin_exports, {
  TextAlignPlugin: () => TextAlignPlugin,
  withTextAlign: () => withTextAlign
});
module.exports = __toCommonJS(TextAlignPlugin_exports);
var import_controls = require("@makeswift/controls");
var import_style_v2 = require("../../controls/style-v2/style-v2");
var import_responsive = require("../utils/responsive");
var import_getValue = require("./getValue");
var import_plugin = require("../../controls/rich-text-v2/plugin");
const TEXT_ALIGN_KEY = "textAlign";
const withTextAlign = (editor) => {
  const { normalizeNode } = editor;
  editor.normalizeNode = (entry) => {
    if ((0, import_responsive.normalizeResponsiveValue)(editor, TEXT_ALIGN_KEY, { match: import_controls.Slate.isRootBlock })(
      entry
    )) {
      return;
    }
    normalizeNode(entry);
  };
  return editor;
};
function TextAlignPlugin() {
  return (0, import_plugin.Plugin)({
    control: {
      definition: (0, import_style_v2.unstable_StyleV2)({
        type: (0, import_controls.unstable_IconRadioGroup)({
          label: "Alignment",
          options: [
            {
              icon: import_controls.unstable_IconRadioGroup.Icon.TextAlignLeft,
              label: "Left Align",
              value: "left"
            },
            {
              icon: import_controls.unstable_IconRadioGroup.Icon.TextAlignCenter,
              label: "Center Align",
              value: "center"
            },
            {
              icon: import_controls.unstable_IconRadioGroup.Icon.TextAlignRight,
              label: "Right Align",
              value: "right"
            },
            {
              icon: import_controls.unstable_IconRadioGroup.Icon.TextAlignJustify,
              label: "Justify",
              value: "justify"
            }
          ],
          defaultValue: "left"
        }),
        getStyle(textAlign) {
          return { textAlign };
        }
      }),
      onChange: (editor, value) => (0, import_responsive.setResponsiveValue)(editor, TEXT_ALIGN_KEY, value, {
        match: import_controls.Slate.isRootBlock,
        split: false
      }),
      getValue: import_getValue.getValue,
      getElementValue: (element) => {
        return import_controls.Slate.isRootBlock(element) ? element.textAlign : void 0;
      }
    },
    withPlugin: withTextAlign,
    renderElement: (renderElement, className) => (props) => {
      return renderElement({
        ...props,
        element: {
          ...props.element,
          className
        }
      });
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TextAlignPlugin,
  withTextAlign
});
//# sourceMappingURL=index.js.map