"use client";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches the billing account for an organization.
 *
 * Calls `billing.getOrCreateBillingAccount` which is idempotent —
 * creates the account on first call, returns the existing account
 * on subsequent calls. The returned `BillingAccount` includes
 * the embedded `CreditBalance` with available, reserved,
 * promotional, and purchased breakdowns.
 *
 * Pass `null` as `orgId` to skip fetching (stable no-op).
 *
 * @param orgId - Organization ID, or `null` to skip.
 *
 * @example
 * ```tsx
 * const { account, isLoading, error } = useBillingAccount(orgId);
 *
 * if (isLoading) return <Skeleton />;
 * if (error) return <ErrorMessage error={error} />;
 * if (!account) return null;
 *
 * return <div>Balance: {formatCreditBalance(account.balance?.availableMicros)}</div>;
 * ```
 */
export function useBillingAccount(orgId) {
    const stigmer = useStigmer();
    const { data: account, isLoading, isRefetching, error, refetch } = useFetch(orgId
        ? () => stigmer.billing.getOrCreateBillingAccount(orgId)
        : null, [orgId, stigmer], null);
    return { account, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useBillingAccount.js.map