import { append, addDisposableListener, EventType, $ as $$1 } from '../../dom.js';
import { StandardKeyboardEvent } from '../../keyboardEvent.js';
import { DomScrollableElement } from '../scrollbar/scrollableElement.js';
import { Disposable } from '../../../common/lifecycle.js';
import './hoverWidget.css.js';
import { localizeWithPath } from '../../../../nls.js';
const $ = $$1;
class HoverWidget extends Disposable {
    constructor() {
        super();
        this.containerDomNode = document.createElement('div');
        this.containerDomNode.className = 'monaco-hover';
        this.containerDomNode.tabIndex = 0;
        this.containerDomNode.setAttribute('role', 'tooltip');
        this.contentsDomNode = document.createElement('div');
        this.contentsDomNode.className = 'monaco-hover-content';
        this.scrollbar = this._register(( new DomScrollableElement(this.contentsDomNode, {
            consumeMouseWheelIfScrollbarIsNeeded: true
        })));
        this.containerDomNode.appendChild(this.scrollbar.getDomNode());
    }
    onContentsChanged() {
        this.scrollbar.scanDomNode();
    }
}
class HoverAction extends Disposable {
    static render(parent, actionOptions, keybindingLabel) {
        return ( new HoverAction(parent, actionOptions, keybindingLabel));
    }
    constructor(parent, actionOptions, keybindingLabel) {
        super();
        this.actionContainer = append(parent, $('div.action-container'));
        this.actionContainer.setAttribute('tabindex', '0');
        this.action = append(this.actionContainer, $('a.action'));
        this.action.setAttribute('role', 'button');
        if (actionOptions.iconClass) {
            append(this.action, $(`span.icon.${actionOptions.iconClass}`));
        }
        const label = append(this.action, $('span'));
        label.textContent = keybindingLabel ? `${actionOptions.label} (${keybindingLabel})` : actionOptions.label;
        this._register(addDisposableListener(this.actionContainer, EventType.CLICK, e => {
            e.stopPropagation();
            e.preventDefault();
            actionOptions.run(this.actionContainer);
        }));
        this._register(addDisposableListener(this.actionContainer, EventType.KEY_DOWN, e => {
            const event = ( new StandardKeyboardEvent(e));
            if (event.equals(3 ) || event.equals(10 )) {
                e.stopPropagation();
                e.preventDefault();
                actionOptions.run(this.actionContainer);
            }
        }));
        this.setEnabled(true);
    }
    setEnabled(enabled) {
        if (enabled) {
            this.actionContainer.classList.remove('disabled');
            this.actionContainer.removeAttribute('aria-disabled');
        }
        else {
            this.actionContainer.classList.add('disabled');
            this.actionContainer.setAttribute('aria-disabled', 'true');
        }
    }
}
function getHoverAccessibleViewHint(shouldHaveHint, keybinding) {
    return shouldHaveHint && keybinding ? ( localizeWithPath(
        'vs/base/browser/ui/hover/hoverWidget',
        'acessibleViewHint',
        "Inspect this in the accessible view with {0}.",
        keybinding
    )) : shouldHaveHint ? ( localizeWithPath(
        'vs/base/browser/ui/hover/hoverWidget',
        'acessibleViewHintNoKbOpen',
        "Inspect this in the accessible view via the command Open Accessible View which is currently not triggerable via keybinding."
    )) : '';
}
export { HoverAction, HoverWidget, getHoverAccessibleViewHint };
