"use client";
import { useStigmer } from "../hooks.js";
import { useFetch } from "../internal/useFetch.js";
/**
 * Data hook that fetches paginated credit ledger entries for an organization.
 *
 * Calls `billing.getCreditLedger` with optional pagination and type
 * filtering. Returns the entries and total page count for building
 * pagination controls.
 *
 * Pass `null` as `orgId` to skip fetching (stable no-op).
 *
 * @param orgId - Organization ID, or `null` to skip.
 * @param options - Pagination and filter options.
 *
 * @example
 * ```tsx
 * const { ledger, isLoading } = useCreditLedger(orgId, { pageNum: 1 });
 *
 * if (isLoading) return <Skeleton />;
 * if (!ledger) return null;
 *
 * return ledger.entries.map(entry => <LedgerRow key={entry.entryId} entry={entry} />);
 * ```
 */
export function useCreditLedger(orgId, options = {}) {
    const stigmer = useStigmer();
    const { pageNum = 1, pageSize = 20, typeFilter, view } = options;
    const typeFilterKey = typeFilter?.join(",") ?? "";
    const { data: ledger, isLoading, isRefetching, error, refetch } = useFetch(orgId
        ? () => stigmer.billing.getCreditLedger({
            orgId,
            // The SDK page number is 0-based (matches the proto/backend); the
            // hook's pageNum is 1-based for ergonomic UI controls.
            page: { num: pageNum - 1, size: pageSize },
            typeFilter,
            view,
        })
        : null, [orgId, pageNum, pageSize, typeFilterKey, view, stigmer], null);
    return { ledger, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useCreditLedger.js.map