"use client";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * 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 } = options;
    const typeFilterKey = typeFilter?.join(",") ?? "";
    const { data: ledger, isLoading, isRefetching, error, refetch } = useFetch(orgId
        ? () => stigmer.billing.getCreditLedger({
            orgId,
            page: { num: pageNum, size: pageSize },
            typeFilter,
        })
        : null, [orgId, pageNum, pageSize, typeFilterKey, stigmer], null);
    return { ledger, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useCreditLedger.js.map