import { keyEnter } from '@ni/fast-web-utilities';
import { Button } from '@ni/nimble-components/dist/esm/button';
import { iconPaperPlaneTag } from '@ni/nimble-components/dist/esm/icons/paper-plane';
import { iconStopSquareTag } from '@ni/nimble-components/dist/esm/icons/stop-square';
import { processUpdates, waitForUpdatesAsync } from '@ni/nimble-components/dist/esm/testing/async-helpers';
import { sendKeyDownEvent } from '@ni/nimble-components/dist/esm/utilities/testing/component';
/**
 * Page object for the `spright-chat-input` component to provide consistent ways
 * of querying and interacting with the component during tests.
 */
export class ChatInputPageObject {
    constructor(element) {
        this.element = element;
    }
    isButtonEnabled() {
        return !this.getActionButton().disabled;
    }
    isProcessing() {
        return this.element.processing;
    }
    isTextAreaFocused() {
        return this.element.textArea === this.element.shadowRoot?.activeElement;
    }
    clickSendButton() {
        if (!this.element.processing) {
            this.getActionButton().click();
        }
    }
    clickStopButton() {
        if (this.element.processing) {
            this.getActionButton().click();
        }
    }
    getButtonTitle() {
        return this.getActionButton().title;
    }
    buttonHasSendIcon() {
        return this.getActionButton().querySelector(iconPaperPlaneTag) !== null;
    }
    buttonHasStopIcon() {
        return this.getActionButton().querySelector(iconStopSquareTag) !== null;
    }
    getButtonTextContent() {
        return this.getActionButton().textContent?.trim() ?? '';
    }
    getButtonTabIndex() {
        return this.getActionButton().getAttribute('tabindex');
    }
    textAreaHasFocus() {
        return (document.activeElement === this.element
            && this.element.shadowRoot?.activeElement === this.element.textArea);
    }
    getTextAreaTabIndex() {
        return this.element.textArea.getAttribute('tabindex');
    }
    getTextAreaMaxLength() {
        return this.element.textArea.maxLength;
    }
    getPlaceholder() {
        if (this.element.textArea.value) {
            throw Error('Placeholder not visible');
        }
        return this.element.textArea.placeholder;
    }
    getRenderedText() {
        return this.element.textArea.value;
    }
    setText(text) {
        this.element.textArea.focus();
        this.element.textArea.value = text;
        this.element.textAreaInputHandler();
        processUpdates();
    }
    async pressEnterKey() {
        this.element.textArea.focus();
        await this.sendEnterKeyEvents(false);
    }
    async pressShiftEnterKey() {
        this.element.textArea.focus();
        await this.sendEnterKeyEvents(true);
    }
    getActionButton() {
        const actionButton = this.element.shadowRoot.querySelector('.action-button');
        return actionButton;
    }
    async sendEnterKeyEvents(shiftKey) {
        const keyDownEvent = await sendKeyDownEvent(this.element.textArea, keyEnter, { shiftKey });
        if (!keyDownEvent.defaultPrevented) {
            this.element.textArea.value += '\n';
            this.element.textArea.dispatchEvent(new InputEvent('input'));
        }
        await waitForUpdatesAsync();
    }
}
//# sourceMappingURL=chat-input.pageobject.js.map