"use client";
import { useFetch } from "../internal/useFetch";
const DEFAULT_PAGE_SIZE = 20;
const DEFAULT_PAGE = 1;
const INITIAL_DATA = {
    entries: [],
    totalCount: 0,
    totalPages: 0,
};
/**
 * Internal hook that provides paginated, scope-aware resource listing.
 *
 * Powers the public resource list hooks (`useAgentList`, `useSkillList`,
 * `useMcpServerList`) — not exported from the public API.
 *
 * Unlike {@link useResourceSearch} which manages its own debounced query
 * state for picker/type-ahead UX, this hook accepts all parameters
 * externally, giving the consumer full control over query timing,
 * pagination state, and scope toggling.
 */
export function useResourceList(listFn, org, options) {
    const pageSize = options?.pageSize ?? DEFAULT_PAGE_SIZE;
    const page = options?.page ?? DEFAULT_PAGE;
    const query = options?.query;
    const scope = options?.scope ?? "org";
    const { data, isLoading, isRefetching, error, refetch } = useFetch(org
        ? async () => {
            const params = {
                org,
                query: query || undefined,
                excludePublic: false,
                crossOrgPublic: scope === "all",
                page: { num: page, size: pageSize },
            };
            const result = await listFn(params);
            return {
                entries: [...result.entries],
                totalCount: result.totalCount,
                totalPages: result.totalPages,
            };
        }
        : null, [listFn, org, query, scope, page, pageSize], INITIAL_DATA);
    return {
        entries: data.entries,
        totalCount: data.totalCount,
        totalPages: data.totalPages,
        currentPage: page,
        isLoading,
        isRefetching,
        error,
        refetch,
    };
}
//# sourceMappingURL=useResourceList.js.map