"use client";
import { create } from "@bufbuild/protobuf";
import { GetPrincipalsCountInputSchema } from "@stigmer/protos/ai/stigmer/iam/iampolicy/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches the count of principals with access to an
 * organization.
 *
 * Wraps `iamPolicy.getPrincipalsCount()`. Useful for member count
 * badges in navigation and summary statistics.
 *
 * Pass `null` as `orgId` to skip fetching (stable no-op).
 *
 * @param orgId         - Organization ID, or `null` to skip.
 * @param principalKind - Kind of principals to count. Defaults to `"identity_account"`.
 *
 * @example
 * ```tsx
 * const { count, isLoading } = usePrincipalsCount(orgId);
 * // count = 5
 * ```
 */
export function usePrincipalsCount(orgId, principalKind = "identity_account") {
    const stigmer = useStigmer();
    const { data: count, isLoading, isRefetching, error, refetch } = useFetch(orgId
        ? () => stigmer.iamPolicy
            .getPrincipalsCount(create(GetPrincipalsCountInputSchema, { orgId, principalKind }))
            .then((r) => r.count)
        : null, [orgId, principalKind, stigmer], 0);
    return { count, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=usePrincipalsCount.js.map