import ReactTestUtils from 'react-dom/test-utils';
import { tooltipLegacyDriverFactory } from '../Tooltip/Tooltip.driver';
import { dataAttr, dataHooks } from './constants';
const inputAreaDriverFactory = ({ element, eventTrigger }) => {
    const counterSelector = '[data-hook="counter"]';
    const textArea = () => element.querySelector('textarea');
    const name = () => textArea().getAttribute('name');
    const statusExclamation = () => element.querySelector(`[data-hook='${dataHooks.tooltip}']`);
    const getTooltipDriver = dataHook => tooltipLegacyDriverFactory({
        element: element.querySelector(`[data-hook="${dataHook}"]`),
        eventTrigger,
    });
    return {
        trigger: (trigger, event) => ReactTestUtils.Simulate[trigger](textArea(), event),
        focus: () => textArea().focus(),
        enterText: text => {
            textArea().value = text;
            ReactTestUtils.Simulate.change(textArea(), {
                target: { name: name(), value: text },
            });
        },
        getValue: () => textArea().value,
        getName: name,
        getPlaceholder: () => textArea().placeholder,
        getDefaultValue: () => textArea().defaultValue,
        getRowsCount: () => textArea().rows,
        getMaxLength: () => textArea().maxLength,
        getMinLength: () => textArea().minLength,
        getTabIndex: () => textArea().tabIndex,
        getReadOnly: () => textArea().readOnly,
        getCursorLocation: () => textArea().selectionStart,
        getResizable: () => element.hasAttribute(dataAttr.RESIZABLE),
        getDisabled: () => element.hasAttribute(dataAttr.DISABLED) && textArea().disabled,
        getRequired: () => textArea().required,
        getHasCounter: () => !!element.querySelectorAll(counterSelector).length,
        getCounterValue: () => element.querySelector(counterSelector).textContent,
        hasExclamation: () => !!statusExclamation(),
        isFocusedStyle: () => element.hasAttribute(dataAttr.FOCUS),
        isSizeSmall: () => element.getAttribute(dataAttr.SIZE) === 'small',
        isHoveredStyle: () => element.hasAttribute(dataAttr.HOVER),
        isFocus: () => document.activeElement === textArea(),
        exists: () => !!textArea(),
        getStyle: () => textArea().style,
        getAriaLabel: () => textArea().getAttribute('aria-label'),
        getAriaControls: () => textArea().getAttribute('aria-controls'),
        getAriaDescribedby: () => textArea().getAttribute('aria-describedby'),
        // Status
        /** Return true if the given status is displayed */
        hasStatus: status => {
            const statusElement = statusExclamation();
            if (statusElement) {
                return (element.getAttribute(dataAttr.STATUS) === status &&
                    statusElement.getAttribute('data-status') === status);
            }
            return element.getAttribute(dataAttr.STATUS) === status;
        },
        /** If there's a status message, returns its text value */
        getStatusMessage: () => getTooltipDriver('status-indicator-tooltip').getTooltipText(),
    };
};
export default inputAreaDriverFactory;
//# sourceMappingURL=InputArea.driver.js.map