"use client";
import { create } from "@bufbuild/protobuf";
import { ListInvitationsByOrgInputSchema } from "@stigmer/protos/ai/stigmer/iam/invitation/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches all {@link Invitation} entries for an
 * organization.
 *
 * Pass `null` to skip fetching (stable no-op). When the `org` slug
 * changes, the previous in-flight request is discarded and a fresh
 * fetch begins. Call `refetch()` to re-query after mutations
 * (create / revoke).
 *
 * Requires `can_view_access` permission on the organization —
 * only admins and owners can list invitation links.
 *
 * @param org - Organization slug, or `null` to skip fetching.
 *
 * @example
 * ```tsx
 * const { invitations, isLoading, error, refetch } = useOrgInvitations("acme");
 *
 * if (isLoading) return <Spinner />;
 * invitations.map((inv) => inv.spec?.label);
 * ```
 */
export function useOrgInvitations(org) {
    const stigmer = useStigmer();
    const { data: invitations, isLoading, isRefetching, error, refetch } = useFetch(org
        ? () => stigmer.invitation
            .listByOrg(create(ListInvitationsByOrgInputSchema, { org }))
            .then((r) => [...r.entries])
        : null, [org, stigmer], []);
    return { invitations, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useOrgInvitations.js.map