import type { ComponentRegistry } from "../registry.js";

interface DiscoverInput { intent: string; maxResults?: number; }
interface DiscoverResult { name: string; description: string; exportPath: string; parts: readonly string[]; hasStyledVersion: boolean; score: number; }

/** Searches components by natural language intent description. */
export function handleDiscover(registry: ComponentRegistry, input: DiscoverInput): DiscoverResult[] {
  const max = input.maxResults ?? 10;
  return registry.search(input.intent).slice(0, max).map((r) => ({
    name: r.meta.name, description: r.meta.description, exportPath: r.exportPath,
    parts: r.meta.parts, hasStyledVersion: r.hasStyledVersion, score: r.score,
  }));
}
