"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 node_builder_methods_exports = {};
__export(node_builder_methods_exports, {
  DEFAULT_BUTTON_DATA: () => DEFAULT_BUTTON_DATA,
  DEFAULT_CODE_DATA: () => DEFAULT_CODE_DATA,
  DEFAULT_CONTAINER_DATA: () => DEFAULT_CONTAINER_DATA,
  DEFAULT_DIVIDER_DATA: () => DEFAULT_DIVIDER_DATA,
  DEFAULT_HEADING_DATA: () => DEFAULT_HEADING_DATA,
  DEFAULT_HTML_DATA: () => DEFAULT_HTML_DATA,
  DEFAULT_PARAGRAPH_DATA: () => DEFAULT_PARAGRAPH_DATA,
  DEFAULT_POLL_DATA: () => DEFAULT_POLL_DATA,
  addListNode: () => addListNode,
  addNode: () => addNode,
  addTextNode: () => addTextNode,
  createNode: () => createNode,
  createTextNode: () => createTextNode,
  makeListNode: () => makeListNode,
  makeNode: () => makeNode,
  makeTextNode: () => makeTextNode
});
module.exports = __toCommonJS(node_builder_methods_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_bulleted_list_defaults_json = __toESM(require("./../../ricos-schema/legacy/statics/bulleted_list.defaults.json.js"));
var import_ordered_list_defaults_json = __toESM(require("./../../ricos-schema/legacy/statics/ordered_list.defaults.json.js"));
var import_node_utils = require("../converters/node-utils.js");
var import_builder_utils = require("./builder-utils.js");
const DEFAULT_PARAGRAPH_DATA = {
  textStyle: { textAlignment: import_v1.TextStyle_TextAlignment.AUTO },
  indentation: 0
};
const DEFAULT_CONTAINER_DATA = {
  alignment: import_v1.PluginContainerData_Alignment.CENTER,
  textWrap: true,
  width: { size: import_v1.PluginContainerData_Width_Type.CONTENT }
};
const DEFAULT_DIVIDER_DATA = {
  lineStyle: import_v1.DividerData_LineStyle.SINGLE,
  width: import_v1.DividerData_Width.LARGE,
  alignment: import_v1.DividerData_Alignment.CENTER,
  containerData: { ...DEFAULT_CONTAINER_DATA, textWrap: false }
};
const DEFAULT_BUTTON_DATA = {
  type: import_v1.ButtonData_Type.ACTION,
  containerData: DEFAULT_CONTAINER_DATA,
  text: "Click Me"
};
const DEFAULT_CODE_DATA = {
  textStyle: {
    textAlignment: import_v1.TextStyle_TextAlignment.AUTO
  }
};
const DEFAULT_HEADING_DATA = {
  level: 2,
  indentation: 0,
  textStyle: { textAlignment: import_v1.TextStyle_TextAlignment.AUTO }
};
const DEFAULT_HTML_DATA = {
  containerData: DEFAULT_CONTAINER_DATA,
  html: "<div/>",
  url: void 0,
  widgetId: void 0,
  source: import_v1.HTMLData_Source.HTML
};
const DEFAULT_POLL_DATA = {
  containerData: DEFAULT_CONTAINER_DATA,
  poll: {
    options: [],
    title: "",
    settings: {
      permissions: {
        view: import_v1.PollData_Poll_Settings_Permissions_ViewRole.VOTERS,
        vote: import_v1.PollData_Poll_Settings_Permissions_VoteRole.SITE_MEMBERS,
        allowMultipleVotes: false
      },
      showVoters: true,
      showVotesCount: true
    }
  },
  layout: {
    poll: {
      type: import_v1.PollData_Layout_PollLayout_Type.LIST,
      direction: import_v1.PollData_Layout_PollLayout_Direction.LTR,
      enableImage: false
    },
    options: {
      enableImage: false
    }
  },
  design: {
    poll: {
      background: {
        type: import_v1.PollData_Design_PollDesign_Background_Type.IMAGE
      },
      borderRadius: 0
    },
    options: {
      borderRadius: 0
    }
  }
};
const createNode = (generateId) => (type, data, nodes) => {
  return {
    id: generateId(),
    type,
    ...(0, import_node_utils.dataByNodeType)(type, data),
    nodes: nodes || []
  };
};
const createListNode = (generateId) => (type, items, data) => createNode(generateId)(
  type,
  data,
  items.map(
    ({ text, data: data2 }) => createNode(generateId)(import_v1.Node_Type.LIST_ITEM, {}, [
      createTextNode(generateId)(import_v1.Node_Type.PARAGRAPH, text, data2)
    ])
  )
);
const createTextNode = (generateId) => (type, text, data) => ({
  ...createNode(generateId)(type, data),
  nodes: text.map((textData) => ({
    nodes: [],
    id: "",
    type: import_v1.Node_Type.TEXT,
    ...(0, import_node_utils.dataByNodeType)(import_v1.Node_Type.TEXT, textData)
  }))
});
const makeNode = (generateId) => ({ data, type }) => createNode(generateId)(type, data);
const addNode = (generateId) => ({ data, type, index, before, after, content }) => {
  const node = makeNode(generateId)({ type, data });
  return (0, import_builder_utils.addNode)({ node, index, before, after, content });
};
const makeTextNode = (generateId) => ({
  text,
  data,
  type
}) => {
  const textData = (0, import_builder_utils.toTextDataArray)(text);
  return createTextNode(generateId)(type, textData, data);
};
const addTextNode = (generateId) => ({
  text,
  data,
  type,
  index,
  before,
  after,
  content
}) => {
  const node = makeTextNode(generateId)({ text, data, type });
  return (0, import_builder_utils.addNode)({ node, index, before, after, content });
};
const makeListNode = (generateId) => ({
  items,
  data = DEFAULT_PARAGRAPH_DATA,
  type,
  listData = type === import_v1.Node_Type.BULLETED_LIST ? import_bulleted_list_defaults_json.default : import_ordered_list_defaults_json.default
}) => {
  const listItemData = (0, import_builder_utils.toListDataArray)(items, data);
  return createListNode(generateId)(type, listItemData, listData);
};
const addListNode = (generateId) => ({
  items,
  data,
  listData,
  type,
  index,
  before,
  after,
  content
}) => {
  const node = makeListNode(generateId)({ items, data, type, listData });
  return (0, import_builder_utils.addNode)({ node, index, before, after, content });
};
//# sourceMappingURL=node-builder-methods.js.map
