export class CliV2PickerService {
    static modelQuery(draft) {
        return queryAfterPrefix(draft, '/model set');
    }
    static sessionQuery(draft) {
        return queryAfterPrefix(draft, '/session choose');
    }
    static reasoningQuery(draft) {
        return queryAfterPrefix(draft, '/reasoning set');
    }
    static filterModels(modelOptions, query) {
        if (query === undefined) {
            return [];
        }
        const normalized = normalize(query);
        const models = modelOptions?.groups.flatMap((group) => group.options) ?? [];
        if (!normalized) {
            return models;
        }
        return models.filter((model) => (model.id.toLowerCase().includes(normalized) ||
            (model.label ?? '').toLowerCase().includes(normalized)));
    }
    static filterSessions(sessions, query) {
        if (query === undefined) {
            return [];
        }
        const normalized = normalize(query);
        if (!normalized) {
            return sessions.map(({ id, name }) => ({ id, name }));
        }
        return sessions
            .filter((session) => (session.id.toLowerCase().includes(normalized) ||
            session.name.toLowerCase().includes(normalized)))
            .map(({ id, name }) => ({ id, name }));
    }
    static filterReasoningOptions(runtimeContext, query) {
        if (query === undefined) {
            return [];
        }
        const normalized = normalize(query);
        const options = runtimeContext?.reasoningOptions ?? [];
        if (!normalized) {
            return options;
        }
        return options.filter((option) => (option.id.toLowerCase().includes(normalized) ||
            option.label.toLowerCase().includes(normalized) ||
            option.description.toLowerCase().includes(normalized)));
    }
    static clampIndex(index, itemCount) {
        return itemCount === 0 ? 0 : Math.min(index, Math.max(0, itemCount - 1));
    }
    static nextIndex(index, itemCount) {
        return itemCount === 0 ? 0 : (index + 1) % itemCount;
    }
    static previousIndex(index, itemCount) {
        return itemCount === 0 ? 0 : index <= 0 ? itemCount - 1 : index - 1;
    }
}
function queryAfterPrefix(draft, prefix) {
    const trimmedStart = draft.trimStart();
    if (!trimmedStart.startsWith(prefix)) {
        return undefined;
    }
    return trimmedStart.slice(prefix.length).trim();
}
function normalize(value) {
    return value.trim().toLowerCase();
}
//# sourceMappingURL=picker-service.js.map