"use client";
import { create } from "@bufbuild/protobuf";
import { ListPlatformClientsByOrgInputSchema } from "@stigmer/protos/ai/stigmer/iam/platformclient/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches all platform clients for an organization.
 *
 * Platform clients are admin-level resources with small cardinality
 * (typically 1–5 per org), so results are returned as a flat list
 * without pagination.
 *
 * Pass `null` to skip fetching (stable no-op). Call `refetch()` to
 * re-query after mutations (create / update / delete / rotateSecret).
 *
 * @example
 * ```tsx
 * function PlatformClientSettings({ org }: { org: string }) {
 *   const { platformClients, isLoading, error } = usePlatformClientList(org);
 *
 *   if (isLoading) return <Skeleton />;
 *   if (error) return <ErrorMessage error={error} />;
 *
 *   return (
 *     <ul>
 *       {platformClients.map((pc) => (
 *         <li key={pc.metadata?.id}>{pc.metadata?.name}</li>
 *       ))}
 *     </ul>
 *   );
 * }
 * ```
 */
export function usePlatformClientList(org) {
    const stigmer = useStigmer();
    const { data: platformClients, isLoading, isRefetching, error, refetch } = useFetch(org
        ? () => stigmer.platformclient
            .listByOrg(create(ListPlatformClientsByOrgInputSchema, { org }))
            .then((r) => [...r.entries])
        : null, [org, stigmer], []);
    return { platformClients, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=usePlatformClientList.js.map