
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { createElement, trackFocus } from '../../../../base/browser/dom.js';
import { Toggle } from '../../../../base/browser/ui/toggle/toggle.js';
import { Widget } from '../../../../base/browser/ui/widget.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { Emitter } from '../../../../base/common/event.js';
import { KeyCode } from '../../../../base/common/keyCodes.js';
import { localize } from '../../../../nls.js';
import { ContextScopedHistoryInputBox } from '../../../../platform/history/browser/contextScopedHistoryWidget.js';
import { showHistoryKeybindingHint } from '../../../../platform/history/browser/historyWidgetKeybindingHint.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.service.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.service.js';
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.service.js';
import { defaultToggleStyles } from '../../../../platform/theme/browser/defaultStyles.js';

let PatternInputWidget = class PatternInputWidget extends Widget {
    static {
        this.OPTION_CHANGE = "optionChange";
    }
    constructor(
        parent,
        contextViewProvider,
        options,
        contextKeyService,
        configurationService,
        keybindingService
    ) {
        super();
        this.contextViewProvider = contextViewProvider;
        this.contextKeyService = contextKeyService;
        this.configurationService = configurationService;
        this.keybindingService = keybindingService;
        this._onSubmit = this._register(( new Emitter()));
        this.onSubmit = this._onSubmit.event;
        this._onCancel = this._register(( new Emitter()));
        this.onCancel = this._onCancel.event;
        options = {
            ...{
                ariaLabel: ( localize(12377, "input"))
            },
            ...options
        };
        this.width = options.width ?? 100;
        this.render(options);
        parent.appendChild(this.domNode);
    }
    dispose() {
        super.dispose();
        this.inputFocusTracker?.dispose();
    }
    setWidth(newWidth) {
        this.width = newWidth;
        this.contextViewProvider.layout();
        this.setInputWidth();
    }
    getValue() {
        return this.inputBox.value;
    }
    setValue(value) {
        if (this.inputBox.value !== value) {
            this.inputBox.value = value;
        }
    }
    select() {
        this.inputBox.select();
    }
    focus() {
        this.inputBox.focus();
    }
    inputHasFocus() {
        return this.inputBox.hasFocus();
    }
    setInputWidth() {
        this.inputBox.width = this.width - this.getSubcontrolsWidth() - 2;
    }
    getSubcontrolsWidth() {
        return 0;
    }
    getHistory() {
        return this.inputBox.getHistory();
    }
    clearHistory() {
        this.inputBox.clearHistory();
    }
    prependHistory(history) {
        this.inputBox.prependHistory(history);
    }
    clear() {
        this.setValue("");
    }
    onSearchSubmit() {
        this.inputBox.addToHistory();
    }
    showNextTerm() {
        this.inputBox.showNextValue();
    }
    showPreviousTerm() {
        this.inputBox.showPreviousValue();
    }
    render(options) {
        this.domNode = createElement("div");
        this.domNode.classList.add("monaco-findInput");
        const history = options.history || [];
        this.inputBox = this._register(( new ContextScopedHistoryInputBox(this.domNode, this.contextViewProvider, {
            placeholder: options.placeholder,
            showPlaceholderOnFocus: options.showPlaceholderOnFocus,
            tooltip: options.tooltip,
            ariaLabel: options.ariaLabel,
            validationOptions: {
                validation: undefined
            },
            history: ( new Set(history)),
            showHistoryHint: () => showHistoryKeybindingHint(this.keybindingService),
            inputBoxStyles: options.inputBoxStyles
        }, this.contextKeyService)));
        this._register(this.inputBox.onDidChange(() => this._onSubmit.fire(true)));
        this.inputFocusTracker = trackFocus(this.inputBox.inputElement);
        this.onkeyup(
            this.inputBox.inputElement,
            keyboardEvent => this.onInputKeyUp(keyboardEvent)
        );
        const controls = createElement("div");
        controls.className = "controls";
        this.renderSubcontrols(controls);
        this.domNode.appendChild(controls);
        this.setInputWidth();
    }
    renderSubcontrols(_controlsDiv) {}
    onInputKeyUp(keyboardEvent) {
        switch (keyboardEvent.keyCode) {
        case KeyCode.Enter:
            this.onSearchSubmit();
            this._onSubmit.fire(false);
            return;
        case KeyCode.Escape:
            this._onCancel.fire();
            return;
        }
    }
};
PatternInputWidget = ( __decorate([( __param(3, IContextKeyService)), ( __param(4, IConfigurationService)), ( __param(5, IKeybindingService))], PatternInputWidget));
let IncludePatternInputWidget = class IncludePatternInputWidget extends PatternInputWidget {
    constructor(
        parent,
        contextViewProvider,
        options,
        contextKeyService,
        configurationService,
        keybindingService
    ) {
        super(
            parent,
            contextViewProvider,
            options,
            contextKeyService,
            configurationService,
            keybindingService
        );
        this._onChangeSearchInEditorsBoxEmitter = this._register(( new Emitter()));
        this.onChangeSearchInEditorsBox = this._onChangeSearchInEditorsBoxEmitter.event;
    }
    dispose() {
        super.dispose();
        this.useSearchInEditorsBox.dispose();
    }
    onlySearchInOpenEditors() {
        return this.useSearchInEditorsBox.checked;
    }
    setOnlySearchInOpenEditors(value) {
        this.useSearchInEditorsBox.checked = value;
        this._onChangeSearchInEditorsBoxEmitter.fire();
    }
    getSubcontrolsWidth() {
        return super.getSubcontrolsWidth() + this.useSearchInEditorsBox.width();
    }
    renderSubcontrols(controlsDiv) {
        this.useSearchInEditorsBox = this._register(( new Toggle({
            icon: Codicon.book,
            title: ( localize(12378, "Search only in Open Editors")),
            isChecked: false,
            ...defaultToggleStyles
        })));
        this._register(this.useSearchInEditorsBox.onChange(viaKeyboard => {
            this._onChangeSearchInEditorsBoxEmitter.fire();
            if (!viaKeyboard) {
                this.inputBox.focus();
            }
        }));
        controlsDiv.appendChild(this.useSearchInEditorsBox.domNode);
        super.renderSubcontrols(controlsDiv);
    }
};
IncludePatternInputWidget = ( __decorate([( __param(3, IContextKeyService)), ( __param(4, IConfigurationService)), ( __param(5, IKeybindingService))], IncludePatternInputWidget));
let ExcludePatternInputWidget = class ExcludePatternInputWidget extends PatternInputWidget {
    constructor(
        parent,
        contextViewProvider,
        options,
        contextKeyService,
        configurationService,
        keybindingService
    ) {
        super(
            parent,
            contextViewProvider,
            options,
            contextKeyService,
            configurationService,
            keybindingService
        );
        this._onChangeIgnoreBoxEmitter = this._register(( new Emitter()));
        this.onChangeIgnoreBox = this._onChangeIgnoreBoxEmitter.event;
    }
    dispose() {
        super.dispose();
        this.useExcludesAndIgnoreFilesBox.dispose();
    }
    useExcludesAndIgnoreFiles() {
        return this.useExcludesAndIgnoreFilesBox.checked;
    }
    setUseExcludesAndIgnoreFiles(value) {
        this.useExcludesAndIgnoreFilesBox.checked = value;
        this._onChangeIgnoreBoxEmitter.fire();
    }
    getSubcontrolsWidth() {
        return super.getSubcontrolsWidth() + this.useExcludesAndIgnoreFilesBox.width();
    }
    renderSubcontrols(controlsDiv) {
        this.useExcludesAndIgnoreFilesBox = this._register(( new Toggle({
            icon: Codicon.exclude,
            actionClassName: "useExcludesAndIgnoreFiles",
            title: ( localize(12379, "Use Exclude Settings and Ignore Files")),
            isChecked: true,
            ...defaultToggleStyles
        })));
        this._register(this.useExcludesAndIgnoreFilesBox.onChange(viaKeyboard => {
            this._onChangeIgnoreBoxEmitter.fire();
            if (!viaKeyboard) {
                this.inputBox.focus();
            }
        }));
        controlsDiv.appendChild(this.useExcludesAndIgnoreFilesBox.domNode);
        super.renderSubcontrols(controlsDiv);
    }
};
ExcludePatternInputWidget = ( __decorate([( __param(3, IContextKeyService)), ( __param(4, IConfigurationService)), ( __param(5, IKeybindingService))], ExcludePatternInputWidget));

export { ExcludePatternInputWidget, IncludePatternInputWidget, PatternInputWidget };
