import inputDriverFactory from '../Input/Input.driver';
import calendarDriverFactory from '../Calendar/Calendar.driver';
import { dataHooks } from './constants';
//FIXME: use PopoverNext legacy driver
/** @deprecated use datePickerUniDriverFactory instead  */
const datePickerDriverFactory = ({ element, eventTrigger }) => {
    const popoverElement = element.querySelector(`[data-hook="${dataHooks.datePickerPopover}"]`);
    const popoverTrigger = () => {
        return element.querySelector(`[data-hook="${dataHooks.datePickerPopover}-trigger"]`);
    };
    const popoverContent = () => document.body.querySelector(`[data-hook="${dataHooks.datePickerPopover}-content"]`);
    const clickOutside = () => {
        document.dispatchEvent(new Event('mousedown'));
        document.dispatchEvent(new Event('mouseup'));
    };
    const calendarTestkit = () => calendarDriverFactory({ element: popoverContent() });
    const calendarDriver = {
        ...Object.keys(calendarDriverFactory({ element })).reduce((prev, current) => ({
            ...prev,
            [current]: args => {
                if (current === 'isVisible') {
                    return !!popoverContent();
                }
                if (current === 'mouseClickOutside') {
                    return clickOutside();
                }
                return calendarTestkit()[current](args);
            },
        }), {}),
    };
    // here we have a dirty hack for getting input element directly
    // this is not the best way to do it, but knowing that we exposed
    // input datahook - we cannot change this for now.
    const inputElement = popoverTrigger().querySelector('[data-size]');
    const inputDriver = inputDriverFactory({
        element: inputElement,
        eventTrigger,
    });
    const driver = {
        exists: () => !!element,
        open: () => {
            inputDriver.click();
            inputDriver.trigger('keyDown', {
                key: 'ArrowUp',
                keyCode: 38,
            });
        },
        getWidth: () => element.style.width,
        clickOutside,
        getFooter: () => element.$(`[data-hook="${dataHooks.datePickerFooter}"] > *`),
    };
    return {
        exists: driver.exists,
        driver,
        inputDriver,
        calendarDriver,
    };
};
export default datePickerDriverFactory;
//# sourceMappingURL=DatePicker.driver.js.map