import infoIconDriverFactory from '../InfoIcon/InfoIcon.driver';
import { DATA_HOOKS } from './FormField.constants';
import textDriverFactory from '../Text/Text.driver';
const formFieldDriver = ({ element, eventTrigger }) => {
    const byHook = hook => element.querySelector(`[data-hook*="${hook}"]`);
    const charactersCounter = () => byHook(DATA_HOOKS.counter);
    const labelElement = () => byHook(DATA_HOOKS.label);
    const labelTextDriver = () => textDriverFactory({ element: labelElement() });
    return {
        exists: () => !!element,
        element: () => element,
        /** get children */
        getChildren: () => byHook(DATA_HOOKS.children),
        /** get label */
        getLabel: () => labelElement(),
        /** returns label size */
        getLabelSize: () => labelTextDriver().getSize(),
        /** returns true whether form field is required */
        isRequired: () => !!byHook(DATA_HOOKS.asterisk),
        /** returns the length left */
        getLengthLeft: () => {
            const counter = charactersCounter();
            return counter ? parseInt(counter.innerHTML, 10) : null;
        },
        /** returns whether the form field length is exceeded */
        isLengthExceeded: () => {
            const counter = charactersCounter();
            if (counter) {
                const length = parseInt(counter.innerHTML, 10);
                return length < 0;
            }
            return false;
        },
        /** returns true whether form field has tooltip */
        hasTooltip: () => !!element.querySelector(`[data-hook="${DATA_HOOKS.infoIcon}"]`),
        /** returns tooltip text of the info content */
        getInfoContent: () => infoIconDriverFactory({
            element: element.querySelector(`[data-hook="${DATA_HOOKS.infoIcon}"]`),
            eventTrigger,
        }).getContent(),
        /** get form field suffix */
        getSuffix: () => byHook(DATA_HOOKS.suffix),
        /** hovers over the formfield infoicon */
        hoverInfoIcon: () => infoIconDriverFactory({
            element: element.querySelector(`[data-hook="${DATA_HOOKS.infoIcon}"]`),
            eventTrigger,
        }).hover(),
        /** returns status message text */
        getStatusMessage: () => textDriverFactory({
            element: byHook(DATA_HOOKS.statusMessage),
        }).getText(),
        /** return true if it has a given status */
        hasStatus: status => element.getAttribute('data-status') === status,
    };
};
export default formFieldDriver;
//# sourceMappingURL=FormField.driver.js.map