import { baseUniDriverFactory, ReactBase } from '../utils/test-utils/unidriver';
import { statusIndicatorDriverFactory } from '../StatusIndicator/StatusIndicator.uni.driver';
import { dataAttr, dataHooks } from './constants';
export const inputAreaUniDriverFactory = (base, body) => {
    const textArea = base.$('textarea');
    const counterSelector = '[data-hook="counter"]';
    const getStatusIndicatorDriver = () => statusIndicatorDriverFactory(base.$(`[data-hook="${dataHooks.tooltip}"]`), body);
    const textAreaBase = ReactBase(textArea);
    return {
        ...baseUniDriverFactory(base),
        trigger: (trigger, event) => textAreaBase[trigger](event),
        focus: () => textAreaBase.focus(),
        enterText: (text) => textArea.enterValue(text),
        getValue: () => textArea.value(),
        getName: () => textArea.attr('name'),
        getPlaceholder: () => textArea.prop('placeholder'),
        getDefaultValue: () => textArea.prop('defaultValue'),
        getRowsCount: () => textArea.prop('rows'),
        getMaxLength: () => textArea.prop('maxLength'),
        getMinLength: () => textArea.prop('minLength'),
        getTabIndex: () => textArea.prop('tabIndex'),
        getReadOnly: () => textArea.prop('readOnly'),
        getCursorLocation: () => textArea.prop('selectionStart'),
        getResizable: async () => !!(await base.attr(dataAttr.RESIZABLE)),
        getDisabled: async () => !!(await base.attr(dataAttr.DISABLED)) &&
            !!(await textArea.prop('disabled')),
        getRequired: () => textArea.prop('required'),
        getHasCounter: async () => (await base.$$(counterSelector).count()) > 0,
        getCounterValue: () => base.$(counterSelector).text(),
        hasExclamation: () => getStatusIndicatorDriver().exists(),
        isFocusedStyle: async () => !!(await base.attr(dataAttr.FOCUS)),
        isSizeSmall: async () => (await base.attr(dataAttr.SIZE)) === 'small',
        isHoveredStyle: async () => !!(await base.attr(dataAttr.HOVER)),
        isFocus: () => textAreaBase.isFocus(),
        exists: () => textArea.exists(),
        getStyle: () => textArea.prop('style'),
        getAriaLabel: () => textArea.attr('aria-label'),
        getAriaControls: () => textArea.attr('aria-controls'),
        getAriaDescribedby: () => textArea.attr('aria-describedby'),
        getTooltipDataHook: () => dataHooks.tooltip,
        getTooltipElement: () => base,
        // Status
        /** Return true if there's a status */
        hasStatus: async (status) => {
            const statusIndicatorDriver = getStatusIndicatorDriver();
            if (await statusIndicatorDriver.exists()) {
                return ((await base.attr(dataAttr.STATUS)) === status &&
                    (await statusIndicatorDriver.getStatus()) === status);
            }
            return (await base.attr(dataAttr.STATUS)) === status;
        },
        /** If there's a status message, returns its text value */
        getStatusMessage: async () => {
            const statusIndicatorDriver = getStatusIndicatorDriver();
            let tooltipText = null;
            if (await statusIndicatorDriver.hasMessage()) {
                tooltipText = await statusIndicatorDriver.getMessage();
            }
            return tooltipText;
        },
    };
};
//# sourceMappingURL=InputArea.uni.driver.js.map