"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useQuery } from "@tanstack/react-query";
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { StatusBadge } from "@open-mercato/ui/primitives/status-badge";
function CompanyUsersWidget({ context }) {
  const t = useT();
  const customerEntityId = context?.recordId;
  const { data, isLoading } = useQuery({
    queryKey: ["customer-company-users", customerEntityId],
    queryFn: async () => {
      if (!customerEntityId) return [];
      const result = await apiCall(`/api/customer_accounts/admin/users?customerEntityId=${customerEntityId}&pageSize=50`);
      if (!result.ok) return [];
      const json = result.result;
      return json?.items || [];
    },
    enabled: !!customerEntityId
  });
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: t("common.loading", "Loading...") });
  }
  const users = data || [];
  return /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-3", children: [
    /* @__PURE__ */ jsxs("div", { className: "text-sm font-medium mb-2", children: [
      t("customer_accounts.widgets.portalUsers", "Portal Users"),
      users.length > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-1 text-muted-foreground", children: [
        "(",
        users.length,
        ")"
      ] })
    ] }),
    users.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: t("customer_accounts.widgets.noUsers", "No portal users for this company") }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: users.map((user) => /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-sm", children: [
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("div", { className: "font-medium", children: user.displayName }),
        /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground", children: user.email })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ jsx(StatusBadge, { variant: user.isActive ? "success" : "error", dot: true, children: user.isActive ? t("common.active", "Active") : t("common.inactive", "Inactive") }),
        /* @__PURE__ */ jsx(
          "a",
          {
            href: `/backend/customer_accounts/users/${user.id}`,
            className: "text-xs text-primary hover:underline",
            children: t("common.view", "View")
          }
        )
      ] })
    ] }, user.id)) })
  ] });
}
export {
  CompanyUsersWidget as default
};
//# sourceMappingURL=widget.client.js.map
