"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 compare_exports = {};
__export(compare_exports, {
  compare: () => compare
});
module.exports = __toCommonJS(compare_exports);
var import_lodash = __toESM(require("lodash"));
var import_omit_deep = __toESM(require("omit-deep"));
var import_utils = require("../utils.js");
const IGNORED_KEYS = [
  "updatedTimestamp",
  "createdTimestamp",
  "tempData",
  "isCustomVideo",
  "VERSION"
];
const IGNORED_POLL_CONFIG_KEYS = ["alignment", "size", "width"];
const IGNORED_SRC_KEYS = ["id", "original_file_name"];
const IGNORED_BUTTON_DESIGN_KEYS = ["activeButton", "padding"];
const OEMBED_KEYS = ["thumbnail_url", "width", "height"];
function compare(object, base, options = {}) {
  const { verbose, ignoredKeys } = options;
  const allIgnoredKeys = [...IGNORED_KEYS, ...ignoredKeys || []];
  const objectWithoutIgnored = (0, import_omit_deep.default)(import_lodash.default.cloneDeep(object), allIgnoredKeys);
  const basetWithoutIgnored = (0, import_omit_deep.default)(import_lodash.default.cloneDeep(base), allIgnoredKeys);
  objectWithoutIgnored.blocks && removeEmoji(objectWithoutIgnored);
  basetWithoutIgnored.blocks && removeEmoji(basetWithoutIgnored);
  const ARE_EQUAL = {};
  const getChanges = (value, base2) => {
    if (value === base2) {
      return ARE_EQUAL;
    } else if (import_lodash.default.isEqualWith(value, base2, comparator)) {
      return ARE_EQUAL;
    } else if (import_lodash.default.isArray(value) && import_lodash.default.isArray(base2)) {
      const items = value.map((valueItem, i) => getChanges(valueItem, base2[i])).filter((item) => item !== ARE_EQUAL);
      if (items.length) {
        return items;
      } else {
        return ARE_EQUAL;
      }
    } else if (import_lodash.default.isObject(value) && import_lodash.default.isObject(base2)) {
      const keys = Array.from(/* @__PURE__ */ new Set([...Object.keys(value), ...Object.keys(base2)]));
      const entries = keys.map((key) => [
        key,
        getChanges(value[key], base2[key])
      ]).filter(([_, result2]) => result2 !== ARE_EQUAL);
      if (entries.length) {
        return Object.fromEntries(entries);
      } else {
        return ARE_EQUAL;
      }
    } else {
      return value;
    }
  };
  const result = getChanges(objectWithoutIgnored, basetWithoutIgnored);
  if (verbose && result !== ARE_EQUAL) {
    console.dir(result);
  }
  return result;
}
const comparator = (left, right, key) => {
  if (left?.enableVoteRole !== void 0 || right?.enableVoteRole !== void 0) {
    return import_lodash.default.isEqual(
      import_lodash.default.omit(left, IGNORED_POLL_CONFIG_KEYS),
      import_lodash.default.omit(right, IGNORED_POLL_CONFIG_KEYS)
    );
  }
  if (left?.thumbnail_url || right?.thumbnail_url) {
    return import_lodash.default.isEqual(import_lodash.default.pick(left, OEMBED_KEYS), import_lodash.default.pick(right, OEMBED_KEYS));
  }
  if (key === "src") {
    return import_lodash.default.isEqual(
      import_lodash.default.omit(left, IGNORED_SRC_KEYS),
      import_lodash.default.omit(right, IGNORED_SRC_KEYS)
    );
  }
  if (key === "design") {
    return import_lodash.default.isEqual(
      import_lodash.default.omit(left, IGNORED_BUTTON_DESIGN_KEYS),
      import_lodash.default.omit(right, IGNORED_BUTTON_DESIGN_KEYS)
    );
  }
  if (key === "link" && (right?.rel === "noopener" || left?.rel === "noopener")) {
    return import_lodash.default.isEqual(import_lodash.default.omit(left, ["rel"]), import_lodash.default.omit(right, ["rel"]));
  }
  return void 0;
};
const removeEmoji = (object) => {
  const emojiEntityKeys = [];
  Object.entries(object.entityMap).forEach(
    ([key, value]) => value.type === "EMOJI_TYPE" && emojiEntityKeys.push(parseInt(key, 10))
  );
  object.entityMap = (0, import_utils.fromEntries)(
    Object.entries(object.entityMap).filter(([, value]) => value.type !== "EMOJI_TYPE")
  );
  object.blocks = object.blocks.map((block) => ({
    ...block,
    entityRanges: block.entityRanges.filter(
      (range) => !emojiEntityKeys.includes(range.key)
    )
  }));
};
//# sourceMappingURL=compare.js.map
