"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 table_cell_extension_exports = {};
__export(table_cell_extension_exports, {
  tableCell: () => tableCell
});
module.exports = __toCommonJS(table_cell_extension_exports);
var import_ricos_content = require("./../../ricos-content/index.js");
var import_theme_color_token = require("./../../_shared/theme-color-token.js");
var import_plugin_commons = require("./../../plugin-commons/index.js");
var import_plugins = require("./plugins/index.js");
var import_table_scss = __toESM(require("./plugins/table-scss.js"));
const tableCell = (0, import_plugin_commons.createRicosNodeExtension)({
  groups: [],
  type: "html-node",
  reconfigure: (config, _extensions, _props, settings, services) => ({
    ...config,
    addOptions: () => ({
      services,
      ...settings
    })
  }),
  name: import_ricos_content.TIPTAP_TABLE_CELL_TYPE,
  createExtensionConfig() {
    return {
      name: this.name,
      tableRole: "cell",
      isolating: true,
      content: "(PARAGRAPH|tableCellContent)+",
      addAttributes: () => ({
        cellStyle: {
          default: null,
          parseHTML: (element) => {
            const cellStyle = element.getAttribute("cellstyle");
            return cellStyle ? JSON.parse(cellStyle) : null;
          },
          renderHTML: (attributes) => {
            return attributes.cellStyle && {
              cellstyle: JSON.stringify(attributes.cellStyle)
            };
          }
        },
        borderColors: {
          default: null,
          parseHTML: (element) => {
            const borderColors = element.getAttribute("bordercolors");
            return borderColors ? JSON.parse(borderColors) : null;
          },
          renderHTML: (attributes) => {
            return attributes.borderColors && {
              bordercolors: JSON.stringify(attributes.borderColors)
            };
          }
        },
        borderWidths: {
          default: null,
          parseHTML: (element) => {
            const borderWidths = element.getAttribute("borderwidths");
            return borderWidths ? JSON.parse(borderWidths) : null;
          },
          renderHTML: (attributes) => {
            return attributes.borderWidths && {
              borderwidths: JSON.stringify(attributes.borderWidths)
            };
          }
        },
        colspan: {
          default: 1,
          parseHTML: (element) => {
            const colspan = element.getAttribute("colspan");
            return colspan ? parseInt(colspan, 10) : 1;
          }
        },
        rowspan: {
          default: 1,
          parseHTML: (element) => {
            const rowspan = element.getAttribute("rowspan");
            return rowspan ? parseInt(rowspan, 10) : 1;
          }
        },
        colwidth: {
          default: null,
          parseHTML: (element) => {
            const colwidth = element.getAttribute("colwidth");
            const value = colwidth ? [parseInt(colwidth, 10)] : null;
            return value;
          }
        },
        verticalAlignment: {
          default: "top",
          parseHTML: () => null,
          // Handled by cellStyle parseHTML above
          renderHTML: (attributes) => {
            return attributes.cellStyle?.verticalAlignment && {
              style: `vertical-align: ${attributes.cellStyle.verticalAlignment.toLowerCase()}`
            };
          }
        },
        backgroundColor: {
          default: null,
          parseHTML: () => null,
          // Handled by cellStyle parseHTML above
          renderHTML: (attributes) => {
            return attributes.cellStyle?.backgroundColor && {
              style: `background-color: ${(0, import_theme_color_token.resolveDocumentColorToCss)(
                attributes.cellStyle.backgroundColor
              )}`
            };
          }
        }
      }),
      parseHTML() {
        return [{ tag: "td" }];
      },
      renderHTML({ node, HTMLAttributes }) {
        return [
          "td",
          { ...HTMLAttributes, "data-node-id": node.attrs.id },
          ["div", { class: import_table_scss.default.borderTop }],
          ["div", { class: import_table_scss.default.borderBottom }],
          ["div", { class: import_table_scss.default.borderLeft }],
          ["div", { class: import_table_scss.default.borderRight }],
          ["div", { class: import_table_scss.default.cell }, 0]
        ];
      },
      addProseMirrorPlugins() {
        return [
          (0, import_plugins.cellStatesPlugin)(
            this.editor,
            this.options.services,
            this.options.services.context.isMobile
          )
        ];
      }
    };
  }
});
//# sourceMappingURL=table-cell-extension.js.map
