"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Clock } from "lucide-react";
import { Button } from "../../primitives/button.js";
import { cn } from "@open-mercato/shared/lib/utils";
import { useVersionHistory } from "./useVersionHistory.js";
import { VersionHistoryPanel } from "./VersionHistoryPanel.js";
function VersionHistoryAction({
  config,
  t,
  buttonClassName,
  iconClassName,
  canUndoRedo,
  autoCheckAcl
}) {
  const enabled = Boolean(
    config?.resourceKind && config?.resourceId && String(config.resourceId).trim().length > 0
  );
  const [open, setOpen] = React.useState(false);
  const stableConfig = React.useMemo(() => {
    if (!enabled || !config) return null;
    return {
      resourceKind: config.resourceKind,
      resourceId: config.resourceId,
      resourceIdFallback: config.resourceIdFallback,
      organizationId: config.organizationId,
      includeRelated: config.includeRelated
    };
  }, [enabled, config?.resourceKind, config?.resourceId, config?.resourceIdFallback, config?.organizationId, config?.includeRelated]);
  const historyData = useVersionHistory(stableConfig, open);
  if (!enabled) return null;
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(
      Button,
      {
        type: "button",
        variant: "ghost",
        size: "icon",
        onClick: () => setOpen(true),
        "aria-label": t("audit_logs.version_history.title"),
        title: t("audit_logs.version_history.title"),
        className: buttonClassName,
        children: /* @__PURE__ */ jsx(Clock, { className: cn("size-4", iconClassName) })
      }
    ),
    /* @__PURE__ */ jsx(
      VersionHistoryPanel,
      {
        open,
        onOpenChange: setOpen,
        entries: historyData.entries,
        isLoading: historyData.isLoading,
        error: historyData.error,
        hasMore: historyData.hasMore,
        onLoadMore: historyData.loadMore,
        t,
        canUndoRedo,
        autoCheckAcl
      }
    )
  ] });
}
export {
  VersionHistoryAction
};
//# sourceMappingURL=VersionHistoryAction.js.map
