"use client";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { DataTable } from "@open-mercato/ui/backend/DataTable";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function AccessLogsTable({ items, isLoading, actions, pagination }) {
  const t = useT();
  const accessItems = Array.isArray(items) ? items : [];
  const noneLabel = t("audit_logs.common.none");
  const columns = React.useMemo(() => [
    {
      accessorKey: "resourceKind",
      header: t("audit_logs.access.columns.resource"),
      cell: (info) => formatResource(info.row.original, noneLabel)
    },
    {
      accessorKey: "accessType",
      header: t("audit_logs.access.columns.access")
    },
    {
      accessorKey: "actorUserId",
      header: t("audit_logs.access.columns.user"),
      cell: (info) => info.row.original.actorUserName || info.getValue() || noneLabel,
      meta: { priority: 3 }
    },
    {
      accessorKey: "tenantId",
      header: t("audit_logs.access.columns.tenant"),
      cell: (info) => info.row.original.tenantName || info.getValue() || noneLabel,
      meta: { priority: 4 }
    },
    {
      accessorKey: "organizationId",
      header: t("audit_logs.access.columns.organization"),
      cell: (info) => info.row.original.organizationName || info.getValue() || noneLabel,
      meta: { priority: 4 }
    },
    {
      accessorKey: "fields",
      header: t("audit_logs.access.columns.fields"),
      cell: (info) => {
        const value = info.getValue();
        return value?.length ? value.join(", ") : noneLabel;
      }
    },
    {
      accessorKey: "createdAt",
      header: t("audit_logs.access.columns.when"),
      cell: (info) => formatDate(info.getValue())
    }
  ], [t, noneLabel]);
  return /* @__PURE__ */ jsx(
    DataTable,
    {
      title: t("audit_logs.access.title"),
      data: accessItems,
      columns,
      perspective: { tableId: "audit_logs.access.list" },
      isLoading: Boolean(isLoading),
      actions,
      pagination
    }
  );
}
function formatResource(item, fallback) {
  if (!item.resourceKind && !item.resourceId) return fallback;
  return [item.resourceKind, item.resourceId].filter(Boolean).join(" \xB7 ");
}
function formatDate(value) {
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return value;
  return new Intl.DateTimeFormat(void 0, {
    dateStyle: "medium",
    timeStyle: "short"
  }).format(date);
}
export {
  AccessLogsTable
};
//# sourceMappingURL=AccessLogsTable.js.map
