/**
 * @fileoverview Pure, framework-agnostic helpers for the Knowledge Hub
 * "Visualize" host surface's AI-agent integration.
 *
 * These functions are free of Angular / component dependencies so they can be
 * unit-tested in isolation. The host component
 * ({@link VisualizeResourceComponent}) supplies a plain snapshot of its current
 * state (active visualization mode plus the shared record-drilldown state) and
 * these helpers shape it into the key-value `AgentContext` object that flows to
 * the async chat agent and the realtime co-agent via
 * `NavigationService.SetAgentContext`. They also resolve agent-supplied
 * references (a drilldown record by id/title) the way a user refers to them.
 *
 * 🚨 SAFETY: these helpers only SHAPE read-only state and RESOLVE references —
 * no mutation, no side effects. Nothing here lists tagged record bodies beyond
 * the salient title/subtitle the surface already shows on screen.
 */
/** Visualization modes hosted by the Visualize surface. */
export const VISUALIZATION_MODES = ['clusters', 'tagcloud'];
/** Type-guard for a visualization mode id; keeps the switch tool tolerant. */
export function isValidVisualizationMode(mode) {
    return typeof mode === 'string' && VISUALIZATION_MODES.includes(mode);
}
/** Upper bound on how many drilldown record summaries we publish. */
export const VISUALIZE_CONTEXT_LIST_CAP = 25;
/** Cap an array to {@link VISUALIZE_CONTEXT_LIST_CAP} entries. Pure; never mutates input. */
export function capVisualizeList(items) {
    return items.slice(0, VISUALIZE_CONTEXT_LIST_CAP);
}
/**
 * Resolve an agent-supplied drilldown-record reference (id or title) to one of
 * the records currently listed in the panel. Tries, in order:
 *   1. exact record id (case-insensitive — SQL-Server-uppercase vs PG-lowercase UUIDs)
 *   2. exact title (case-insensitive)
 *   3. first case-insensitive *contains* match on the title
 *
 * Pure + deterministic; returns the matched candidate, or null on a miss.
 */
export function resolveDrilldownRecord(input, candidates) {
    const needle = (input ?? '').trim().toLowerCase();
    if (!needle) {
        return null;
    }
    const byId = candidates.find(c => c.RecordID.toLowerCase() === needle);
    if (byId) {
        return byId;
    }
    const byTitle = candidates.find(c => c.Title.toLowerCase() === needle);
    if (byTitle) {
        return byTitle;
    }
    return candidates.find(c => c.Title.toLowerCase().includes(needle)) ?? null;
}
/**
 * Build the agent-visible context object for the Visualize host surface.
 * Pure function (no `this`) so the context shape is unit-testable.
 *
 * @param input - the host's current state snapshot
 * @returns a flat key-value object suitable for `SetAgentContext`
 */
export function buildVisualizeAgentContext(input) {
    const context = {
        // Surfaced under the tool's parameter name so the agent can correlate
        // context with the SwitchVisualizationMode tool.
        ActiveVisualizationMode: input.ActiveMode,
        AvailableVisualizationModes: input.AvailableModes,
        DrilldownVisible: input.DrilldownVisible,
        DrilldownLoading: input.DrilldownLoading,
    };
    if (input.DrilldownVisible) {
        context['DrilldownTitle'] = input.DrilldownTitle || null;
        context['DrilldownSubtitle'] = input.DrilldownSubtitle || null;
        if (input.DrilldownRecords.length > 0) {
            context['DrilldownRecords'] = capVisualizeList(input.DrilldownRecords);
            context['DrilldownRecordCount'] = input.DrilldownRecords.length;
        }
    }
    return context;
}
//# sourceMappingURL=visualize-agent-context.js.map