
import { Codicon } from '../../../../base/common/codicons.js';
import { basename } from '../../../../base/common/resources.js';
import { URI } from '../../../../base/common/uri.js';
import { isLocation } from '../../../../editor/common/languages.js';
import { localize } from '../../../../nls.js';

var OmittedState;
(function (OmittedState) {
    OmittedState[OmittedState["NotOmitted"] = 0] = "NotOmitted";
    OmittedState[OmittedState["Partial"] = 1] = "Partial";
    OmittedState[OmittedState["Full"] = 2] = "Full";
})(OmittedState || (OmittedState = {}));
var IDiagnosticVariableEntryFilterData;
(function (IDiagnosticVariableEntryFilterData) {
    IDiagnosticVariableEntryFilterData.icon = Codicon.error;
    function fromMarker(marker) {
        return {
            filterUri: marker.resource,
            owner: marker.owner,
            problemMessage: marker.message,
            filterRange: { startLineNumber: marker.startLineNumber, endLineNumber: marker.endLineNumber, startColumn: marker.startColumn, endColumn: marker.endColumn }
        };
    }
    IDiagnosticVariableEntryFilterData.fromMarker = fromMarker;
    function toEntry(data) {
        return {
            id: id(data),
            name: label(data),
            icon: IDiagnosticVariableEntryFilterData.icon,
            value: data,
            kind: 'diagnostic',
            ...data,
        };
    }
    IDiagnosticVariableEntryFilterData.toEntry = toEntry;
    function id(data) {
        return [data.filterUri, data.owner, data.filterSeverity, data.filterRange?.startLineNumber].join(':');
    }
    IDiagnosticVariableEntryFilterData.id = id;
    function label(data) {
        let TrimThreshold;
        (function (TrimThreshold) {
            TrimThreshold[TrimThreshold["MaxChars"] = 30] = "MaxChars";
            TrimThreshold[TrimThreshold["MaxSpaceLookback"] = 10] = "MaxSpaceLookback";
        })(TrimThreshold || (TrimThreshold = {}));
        if (data.problemMessage) {
            if (data.problemMessage.length < TrimThreshold.MaxChars) {
                return data.problemMessage;
            }
            const lastSpace = data.problemMessage.lastIndexOf(' ', TrimThreshold.MaxChars);
            if (lastSpace === -1 || lastSpace + TrimThreshold.MaxSpaceLookback < TrimThreshold.MaxChars) {
                return data.problemMessage.substring(0, TrimThreshold.MaxChars) + '…';
            }
            return data.problemMessage.substring(0, lastSpace) + '…';
        }
        let labelStr = ( localize(5420, "All Problems"));
        if (data.filterUri) {
            labelStr = ( localize(5421, "Problems in {0}", basename(data.filterUri)));
        }
        return labelStr;
    }
    IDiagnosticVariableEntryFilterData.label = label;
})(IDiagnosticVariableEntryFilterData || (IDiagnosticVariableEntryFilterData = {}));
var IChatRequestVariableEntry;
(function (IChatRequestVariableEntry) {
    function toUri(entry) {
        return URI.isUri(entry.value)
            ? entry.value
            : isLocation(entry.value)
                ? entry.value.uri
                : undefined;
    }
    IChatRequestVariableEntry.toUri = toUri;
})(IChatRequestVariableEntry || (IChatRequestVariableEntry = {}));
function isPasteVariableEntry(obj) {
    return obj.kind === 'paste';
}
function isImageVariableEntry(obj) {
    return obj.kind === 'image';
}
function isNotebookOutputVariableEntry(obj) {
    return obj.kind === 'notebookOutput';
}
function isElementVariableEntry(obj) {
    return obj.kind === 'element';
}
function isPromptFileVariableEntry(obj) {
    return obj.kind === 'promptFile';
}
function isPromptTextVariableEntry(obj) {
    return obj.kind === 'promptText';
}
function isSCMHistoryItemVariableEntry(obj) {
    return obj.kind === 'scmHistoryItem';
}
var PromptFileVariableKind;
(function (PromptFileVariableKind) {
    PromptFileVariableKind["Instruction"] = "vscode.prompt.instructions.root";
    PromptFileVariableKind["InstructionReference"] = "vscode.prompt.instructions";
    PromptFileVariableKind["PromptFile"] = "vscode.prompt.file";
})(PromptFileVariableKind || (PromptFileVariableKind = {}));
function toPromptFileVariableEntry(uri, kind, originLabel, automaticallyAdded = false) {
    return {
        id: `${kind}__${( uri.toString())}`,
        name: `prompt:${basename(uri)}`,
        value: uri,
        kind: 'promptFile',
        modelDescription: 'Prompt instructions file',
        isRoot: kind !== PromptFileVariableKind.InstructionReference,
        originLabel,
        automaticallyAdded
    };
}
function toPromptTextVariableEntry(content, settingId, automaticallyAdded = false) {
    return {
        id: `vscode.prompt.instructions.text${settingId ? `.${settingId}` : ''}`,
        name: `prompt:text`,
        value: content,
        settingId,
        kind: 'promptText',
        modelDescription: 'Prompt instructions text',
        automaticallyAdded
    };
}
class ChatRequestVariableSet {
    constructor(entries) {
        this._ids = ( new Set());
        this._entries = [];
        if (entries) {
            this.add(...entries);
        }
    }
    add(...entry) {
        for (const e of entry) {
            if (!( this._ids.has(e.id))) {
                this._ids.add(e.id);
                this._entries.push(e);
            }
        }
    }
    insertFirst(entry) {
        if (!( this._ids.has(entry.id))) {
            this._ids.add(entry.id);
            this._entries.unshift(entry);
        }
    }
    remove(entry) {
        this._ids.delete(entry.id);
        this._entries = this._entries.filter(e => e.id !== entry.id);
    }
    has(entry) {
        return ( this._ids.has(entry.id));
    }
    asArray() {
        return this._entries.slice(0);
    }
}

export { ChatRequestVariableSet, IChatRequestVariableEntry, IDiagnosticVariableEntryFilterData, OmittedState, PromptFileVariableKind, isElementVariableEntry, isImageVariableEntry, isNotebookOutputVariableEntry, isPasteVariableEntry, isPromptFileVariableEntry, isPromptTextVariableEntry, isSCMHistoryItemVariableEntry, toPromptFileVariableEntry, toPromptTextVariableEntry };
