/**
 * @fileoverview Pure helpers for the Dashboard Browser's AI-agent integration.
 *
 * These functions are intentionally free of Angular / component dependencies so
 * they can be unit-tested in isolation. The resource component
 * ({@link DashboardBrowserResourceComponent}) supplies a plain snapshot of its
 * current state and these helpers shape it into the flat key-value `AgentContext`
 * object that flows to the async chat agent and the realtime co-agent via
 * `NavigationService.SetAgentContext`.
 *
 * 🔒 SAFETY: this module only *describes* state and validates input. It performs
 * no mutation and has no side effects.
 */
/** The two record-view modes the browser list supports. */
const VALID_BROWSER_VIEW_MODES = ['cards', 'list'];
/**
 * Upper bound on how many names we publish in a name-list context field
 * (VisibleDashboards, AvailableCategories). Keeping the streamed note bounded
 * avoids flooding the co-agent with hundreds of names; when the underlying list
 * is larger we surface a companion total-count field instead. Mirrors the cap
 * used by the Data Explorer's agent context.
 */
export const AGENT_CONTEXT_NAME_LIST_CAP = 25;
/**
 * Cap an array of names to {@link AGENT_CONTEXT_NAME_LIST_CAP} entries.
 * Pure + deterministic so the context shape stays unit-testable.
 *
 * @param names - the full list of names (already de-duplicated by the caller)
 * @returns the first N names, where N is the cap
 */
function capNames(names) {
    return names.slice(0, AGENT_CONTEXT_NAME_LIST_CAP);
}
/**
 * Type-guard / validator for a browser view-mode string. Keeps the
 * `SwitchViewMode` client tool tolerant of arbitrary agent input — only the two
 * known modes are accepted.
 *
 * @param mode - candidate mode string (may be anything the agent passes)
 * @returns true when `mode` is one of cards | list
 */
export function isValidBrowserViewMode(mode) {
    return typeof mode === 'string' && VALID_BROWSER_VIEW_MODES.includes(mode);
}
/**
 * Build the agent-visible context object for the Dashboard Browser.
 *
 * Keeping this a pure function (no `this`) makes the context shape unit-testable
 * and decouples it from change-detection timing.
 *
 * @param input - the component's current state snapshot
 * @returns a flat key-value object suitable for `SetAgentContext`
 */
export function buildDashboardBrowserAgentContext(input) {
    const hasSearch = input.SearchText.trim().length > 0;
    const context = {
        Mode: input.Mode,
        SelectedDashboardId: input.SelectedDashboardId,
        SelectedDashboardName: input.SelectedDashboardName,
        VisibleDashboards: capNames(input.VisibleDashboardNames),
        TotalDashboardCount: input.TotalDashboardCount,
        FilteredDashboardCount: input.FilteredDashboardCount,
        HasSearch: hasSearch,
        SearchText: input.SearchText,
        AvailableCategories: capNames(input.AvailableCategoryNames),
        SelectedCategoryId: input.SelectedCategoryId,
        SelectedCategoryName: input.SelectedCategoryName,
        ViewMode: input.ViewMode,
        IsLoading: input.IsLoading,
    };
    // When more dashboards/categories are visible than we publish names for, tell
    // the co-agent the true total so it knows the streamed list is truncated.
    if (input.VisibleDashboardNames.length > AGENT_CONTEXT_NAME_LIST_CAP) {
        context['VisibleDashboardCount'] = input.VisibleDashboardNames.length;
    }
    if (input.AvailableCategoryNames.length > AGENT_CONTEXT_NAME_LIST_CAP) {
        context['AvailableCategoryCount'] = input.AvailableCategoryNames.length;
    }
    // Opened-dashboard awareness: only publish these fields when a dashboard is
    // actually open (view/edit). At the list level we omit them entirely so the
    // agent's context stays focused on browse/filter state.
    if (input.Mode !== 'list') {
        context['OpenedDashboardName'] = input.OpenedDashboardName ?? null;
        context['OpenedDashboardId'] = input.OpenedDashboardId ?? null;
        context['OpenedDashboardIsEditing'] = input.OpenedDashboardIsEditing ?? false;
        context['OpenedDashboardCanEdit'] = input.OpenedDashboardCanEdit ?? false;
        const panels = input.OpenedDashboardPanels ?? [];
        context['OpenedDashboardPanelCount'] = panels.length;
        context['OpenedDashboardPanels'] = panels.slice(0, AGENT_CONTEXT_NAME_LIST_CAP);
    }
    return context;
}
//# sourceMappingURL=dashboard-browser-agent-context.js.map