"use client";
import { useMemo } from "react";
import { useTaskKindRegistryContext } from "./TaskKindRegistryContext";
/**
 * Data hook that exposes the task kind registry with lookup and grouping helpers.
 *
 * Pure data layer — no rendering, no side effects. Platform builders
 * who want full control over rendering import this hook and build
 * their own UI (task palettes, form generators, validation).
 *
 * The registry data is fetched from the task kind registry API by
 * {@link StigmerProvider} and cached in context. During loading,
 * `isLoading` is `true` and `descriptors` is empty.
 *
 * @example
 * ```tsx
 * function TaskPalette() {
 *   const { categories, isLoading, error } = useTaskKindRegistry();
 *
 *   if (isLoading) return <Skeleton />;
 *   if (error) return <ErrorMessage error={error} />;
 *
 *   return (
 *     <div>
 *       {Array.from(categories).map(([category, tasks]) => (
 *         <CategorySection key={category} label={category}>
 *           {tasks.map(task => (
 *             <TaskCard key={task.kind} descriptor={task} />
 *           ))}
 *         </CategorySection>
 *       ))}
 *     </div>
 *   );
 * }
 * ```
 *
 * @example
 * ```tsx
 * // YAML editor integration
 * function WorkflowEditor({ taskKind }: { taskKind: string }) {
 *   const { getJsonSchema } = useTaskKindRegistry();
 *   const schema = getJsonSchema(taskKind);
 *   // Pass schema to Monaco for autocomplete + validation
 * }
 * ```
 *
 * @since T04 (Task Schema Registry)
 */
export function useTaskKindRegistry() {
    const { descriptors, isLoading, error, refetch } = useTaskKindRegistryContext();
    return useMemo(() => {
        const byKind = new Map();
        const byCategory = new Map();
        for (const descriptor of descriptors) {
            byKind.set(descriptor.kind, descriptor);
            const group = byCategory.get(descriptor.category);
            if (group) {
                group.push(descriptor);
            }
            else {
                byCategory.set(descriptor.category, [descriptor]);
            }
        }
        return {
            descriptors,
            getByKind: (kind) => byKind.get(kind),
            getJsonSchema: (kind) => byKind.get(kind)?.configJsonSchema,
            categories: byCategory,
            isLoading,
            error,
            refetch,
        };
    }, [descriptors, isLoading, error, refetch]);
}
//# sourceMappingURL=useTaskKindRegistry.js.map