import { baseUniDriverFactory } from '../utils/test-utils/unidriver';
const dataContentHook = 'data-content-hook';
export const popoverUniDriverFactory = (base, body) => {
    const byHook = (hook) => base.$(`[data-hook="${hook}"]`);
    const queryDocumentOrElement = async (query) => {
        const elm = base.$$(query).get(0);
        if (await elm.exists()) {
            return elm;
        }
        return body.$(query);
    };
    const getBasePopupElement = async () => {
        const contentHook = await base.attr(dataContentHook);
        if (contentHook) {
            return base;
        }
        return queryDocumentOrElement('[data-content-hook]');
    };
    const getContentElement = async () => {
        const basePopupElm = await getBasePopupElement();
        const contentHook = await basePopupElm.attr(dataContentHook);
        const contentSelector = `[data-content-element="${contentHook}"]`;
        return await queryDocumentOrElement(contentSelector);
    };
    return {
        ...baseUniDriverFactory(base),
        /**
         * Clicks on the target element
         * @returns {Promise<void>}
         */
        click: async () => byHook('popover-element').click(),
        /**
         * Gets the target element
         * @returns {Promise<any>}
         */
        getTargetElement: async () => byHook('popover-element').getNative(),
        /**
         * Checks whether target element exists
         * @returns {Promise<boolean>}
         */
        isTargetElementExists: async () => byHook('popover-element').exists(),
        /**
         * Gets the portal element
         * @returns {Promise<any>}
         */
        getPortalElement: async () => byHook('popover-portal').getNative(),
        /**
         * Gets the content element
         * @returns {Promise<any>}
         */
        getContentElement: async () => (await getContentElement()).getNative(),
        /**
         * Checks whether content element exists
         * @returns {Promise<boolean>}
         */
        isContentElementExists: async () => (await getContentElement()).exists(),
        /**
         * Triggers a mouseEnter event
         * @returns {Promise<void>}
         */
        mouseEnter: async () => (await getBasePopupElement()).hover(),
        /**
         * Triggers a mouseLeave event
         * @returns {Promise<void>}
         */
        mouseLeave: async () => (await getBasePopupElement()).mouse.leave(),
        /**
         * Clicks outside the target element (triggers mouseDown and mouseUp events)
         * @returns {Promise<void>}
         */
        clickOutside: async () => body.click(),
        /**
         * Gets the arrow offset
         * @returns {Promise<any>}
         */
        getArrowOffset: async () => (await byHook('popover-arrow').getNative()).style,
        /**
         * Gets content as unidriver element
         * @private
         */
        getContentElementUniDriver: async () => getContentElement(),
    };
};
//# sourceMappingURL=Popover.uni.driver.js.map