"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { getVersionHistoryActionLabel, getVersionHistoryStatusLabel } from "./labels.js";
import {
  ChangedFieldsTable,
  CollapsibleJsonSection,
  extractChangeRows,
  formatDate
} from "@open-mercato/core/modules/audit_logs/lib/display-helpers";
function VersionHistoryDetail({ entry, t }) {
  const noneLabel = t("audit_logs.common.none");
  const statusLabel = getVersionHistoryStatusLabel(entry.executionState, t);
  const actionLabel = getVersionHistoryActionLabel(entry, t);
  const changeRows = React.useMemo(
    () => extractChangeRows(entry.changes, entry.snapshotBefore),
    [entry.changes, entry.snapshotBefore]
  );
  const hasContext = !!entry.context && typeof entry.context === "object" && Object.keys(entry.context).length > 0;
  const snapshots = React.useMemo(() => {
    const items = [];
    if (entry.snapshotBefore != null) {
      items.push({ label: t("audit_logs.actions.details.snapshot_before"), value: entry.snapshotBefore });
    }
    if (entry.snapshotAfter != null) {
      items.push({ label: t("audit_logs.actions.details.snapshot_after"), value: entry.snapshotAfter });
    }
    return items;
  }, [entry.snapshotAfter, entry.snapshotBefore, t]);
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col gap-6", children: [
    /* @__PURE__ */ jsx("section", { className: "space-y-3 text-sm", children: /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: [
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("dt", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: t("audit_logs.version_history.detail.action") }),
        /* @__PURE__ */ jsx("dd", { className: "break-words text-sm", children: actionLabel })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("dt", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: t("audit_logs.version_history.detail.date") }),
        /* @__PURE__ */ jsx("dd", { className: "break-words text-sm", children: formatDate(entry.createdAt) })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("dt", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: t("audit_logs.version_history.detail.actor") }),
        /* @__PURE__ */ jsx("dd", { className: "break-words text-sm", children: entry.actorUserName || entry.actorUserId || noneLabel })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("dt", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: t("audit_logs.version_history.detail.status") }),
        /* @__PURE__ */ jsx("dd", { className: "break-words text-sm", children: statusLabel })
      ] })
    ] }) }),
    /* @__PURE__ */ jsx(ChangedFieldsTable, { changeRows, noneLabel, t }),
    hasContext ? /* @__PURE__ */ jsx("section", { children: /* @__PURE__ */ jsx(CollapsibleJsonSection, { label: t("audit_logs.actions.details.context"), value: entry.context }) }) : null,
    snapshots.length ? /* @__PURE__ */ jsx("section", { className: "space-y-4", children: snapshots.map((snapshot) => /* @__PURE__ */ jsx(CollapsibleJsonSection, { label: snapshot.label, value: snapshot.value }, snapshot.label)) }) : null
  ] });
}
export {
  VersionHistoryDetail
};
//# sourceMappingURL=VersionHistoryDetail.js.map
