import { KeyMod as KeyMod$1, KeyCode } from '../../../../base/common/keyCodes.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { localizeWithPath } from '../../../../nls.js';
import { ContextKeyExpr, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { Emitter } from '../../../../base/common/event.js';
import { CommentsViewFilterFocusContextKey } from './comments.js';
import { registerAction2 } from '../../../../platform/actions/common/actions.js';
import { ViewAction } from '../../../browser/parts/views/viewPane.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { COMMENTS_VIEW_ID } from './commentsTreeViewer.js';
import { FocusedViewContext } from '../../../common/contextkeys.js';
import { viewFilterSubmenu } from '../../../browser/parts/views/viewFilter.js';
const _moduleId = "vs/workbench/contrib/comments/browser/commentsViewActions";
const CONTEXT_KEY_SHOW_RESOLVED = ( (new RawContextKey('commentsView.showResolvedFilter', true)));
const CONTEXT_KEY_SHOW_UNRESOLVED = ( (new RawContextKey('commentsView.showUnResolvedFilter', true)));
class CommentsFilters extends Disposable {
    constructor(options, contextKeyService) {
        super();
        this.contextKeyService = contextKeyService;
        this._onDidChange = this._register(( (new Emitter())));
        this.onDidChange = this._onDidChange.event;
        this._showUnresolved = CONTEXT_KEY_SHOW_UNRESOLVED.bindTo(this.contextKeyService);
        this._showResolved = CONTEXT_KEY_SHOW_RESOLVED.bindTo(this.contextKeyService);
        this._showResolved.set(options.showResolved);
        this._showUnresolved.set(options.showUnresolved);
    }
    get showUnresolved() {
        return !!this._showUnresolved.get();
    }
    set showUnresolved(showUnresolved) {
        if (this._showUnresolved.get() !== showUnresolved) {
            this._showUnresolved.set(showUnresolved);
            this._onDidChange.fire({ showUnresolved: true });
        }
    }
    get showResolved() {
        return !!this._showResolved.get();
    }
    set showResolved(showResolved) {
        if (this._showResolved.get() !== showResolved) {
            this._showResolved.set(showResolved);
            this._onDidChange.fire({ showResolved: true });
        }
    }
}
registerAction2(class extends ViewAction {
    constructor() {
        super({
            id: 'commentsFocusViewFromFilter',
            title: ( localizeWithPath(_moduleId, 0, "Focus Comments view")),
            keybinding: {
                when: CommentsViewFilterFocusContextKey,
                weight: KeybindingWeight.WorkbenchContrib,
                primary: KeyMod$1.CtrlCmd | KeyCode.DownArrow
            },
            viewId: COMMENTS_VIEW_ID
        });
    }
    async runInView(serviceAccessor, commentsView) {
        commentsView.focus();
    }
});
registerAction2(class extends ViewAction {
    constructor() {
        super({
            id: 'commentsClearFilterText',
            title: ( localizeWithPath(_moduleId, 1, "Clear filter text")),
            keybinding: {
                when: CommentsViewFilterFocusContextKey,
                weight: KeybindingWeight.WorkbenchContrib,
                primary: KeyCode.Escape
            },
            viewId: COMMENTS_VIEW_ID
        });
    }
    async runInView(serviceAccessor, commentsView) {
        commentsView.clearFilterText();
    }
});
registerAction2(class extends ViewAction {
    constructor() {
        super({
            id: 'commentsFocusFilter',
            title: ( localizeWithPath(_moduleId, 2, "Focus comments filter")),
            keybinding: {
                when: ( (FocusedViewContext.isEqualTo(COMMENTS_VIEW_ID))),
                weight: KeybindingWeight.WorkbenchContrib,
                primary: KeyMod$1.CtrlCmd | KeyCode.KeyF
            },
            viewId: COMMENTS_VIEW_ID
        });
    }
    async runInView(serviceAccessor, commentsView) {
        commentsView.focusFilter();
    }
});
registerAction2(class extends ViewAction {
    constructor() {
        super({
            id: `workbench.actions.${COMMENTS_VIEW_ID}.toggleUnResolvedComments`,
            title: ( localizeWithPath(_moduleId, 3, "Show Unresolved")),
            category: ( localizeWithPath(_moduleId, 4, "Comments")),
            toggled: {
                condition: CONTEXT_KEY_SHOW_UNRESOLVED,
                title: ( localizeWithPath(_moduleId, 5, "Show Unresolved")),
            },
            menu: {
                id: viewFilterSubmenu,
                group: '1_filter',
                when: ( (ContextKeyExpr.equals('view', COMMENTS_VIEW_ID))),
                order: 1
            },
            viewId: COMMENTS_VIEW_ID
        });
    }
    async runInView(serviceAccessor, view) {
        view.filters.showUnresolved = !view.filters.showUnresolved;
    }
});
registerAction2(class extends ViewAction {
    constructor() {
        super({
            id: `workbench.actions.${COMMENTS_VIEW_ID}.toggleResolvedComments`,
            title: ( localizeWithPath(_moduleId, 6, "Show Resolved")),
            category: ( localizeWithPath(_moduleId, 4, "Comments")),
            toggled: {
                condition: CONTEXT_KEY_SHOW_RESOLVED,
                title: ( localizeWithPath(_moduleId, 7, "Show Resolved")),
            },
            menu: {
                id: viewFilterSubmenu,
                group: '1_filter',
                when: ( (ContextKeyExpr.equals('view', COMMENTS_VIEW_ID))),
                order: 1
            },
            viewId: COMMENTS_VIEW_ID
        });
    }
    async runInView(serviceAccessor, view) {
        view.filters.showResolved = !view.filters.showResolved;
    }
});
export { CommentsFilters };
