// packages/editor/src/components/revision-fields-diff/index.js
import { diffWords } from "diff/lib/diff/word";
import { useSelect } from "@wordpress/data";
import { useMemo } from "@wordpress/element";
import { __ } from "@wordpress/i18n";
import RevisionDiffPanel from "../revision-diff-panel/index.mjs";
import { store as editorStore } from "../../store/index.mjs";
import { unlock } from "../../lock-unlock.mjs";
import { jsx } from "react/jsx-runtime";
function stringifyValue(value) {
  if (value === null || value === void 0) {
    return "";
  }
  if (typeof value === "object") {
    return JSON.stringify(value, null, 2);
  }
  return String(value);
}
function RevisionFieldsDiffPanel() {
  const { revision, previousRevision } = useSelect((select) => {
    const { getCurrentRevision, getPreviousRevision } = unlock(
      select(editorStore)
    );
    return {
      revision: getCurrentRevision(),
      previousRevision: getPreviousRevision()
    };
  }, []);
  const entries = useMemo(() => {
    if (!revision) {
      return null;
    }
    const revisionMeta = revision.meta ?? {};
    const previousMeta = previousRevision?.meta ?? {};
    const allMetaKeys = /* @__PURE__ */ new Set([
      ...Object.keys(revisionMeta),
      ...Object.keys(previousMeta)
    ]);
    const result = {};
    for (const key of allMetaKeys) {
      const revStr = stringifyValue(revisionMeta[key]);
      const prevStr = stringifyValue(previousMeta[key]);
      if (!revStr && !prevStr) {
        continue;
      }
      result[key] = diffWords(prevStr, revStr);
    }
    if (Object.keys(result).length === 0) {
      return null;
    }
    return result;
  }, [revision, previousRevision]);
  return /* @__PURE__ */ jsx(
    RevisionDiffPanel,
    {
      title: __("Meta"),
      entries,
      initialOpen: false
    }
  );
}
export {
  RevisionFieldsDiffPanel as default
};
//# sourceMappingURL=index.mjs.map
