import { baseUniDriverFactory as testUtilsBaseUniDriverFactory } from '@wix/wix-ui-test-utils/unidriver';
import { ReactBase } from './ReactBase';
export * from './ReactBase';
export { ReactBase };
/**
 * Find element by `data-hook` (exact match)
 * @param {UniDriver} base
 * @param {string} hook
 */
export const findByHook = (base, hook) => base.$(`[data-hook="${hook}"]`);
/**
 * Async find element by `data-hook` (exact match)
 * @param {UniDriver} base
 * @param {string} hook
 * @returns {Promise<import('@wix/unidriver-core').UniDriver>}
 */
export const getByHook = (base, hook) => base.$(`[data-hook="${hook}"]`);
/**
 * Async find all elements by `data-hook` (exact match)
 * @param {UniDriver} base
 * @param {string} hook
 * @returns {Promise<import('@wix/wix-ui-test-utils/dist/types/unidriver').UniDriverList>}
 */
export const getAllByHook = (base, hook) => base.$$(`[data-hook="${hook}"]`);
/**
 * Find element by `data-hook` at index (exact match)
 * @param {UniDriver} base
 * @param {string} hook
 * @param index index
 */
export const findByHookAtIndex = (base, hook, index) => base.$$(`[data-hook="${hook}"]`).get(index);
/**
 * Counts elements by `data-hook` (exact match)
 * @param {UniDriver} base
 * @param {string} hook
 */
export const countByHook = (base, hook) => base.$$(`[data-hook="${hook}"]`).count();
/**
 * Wrapper function which returns null if base doesn't exist.
 * @param {UniDriver} base
 */
export const getElement = async (base) => (await base.exists()) ? base : null;
/**
 * Gets data attribute value
 * @param {UniDriver} base
 * @param {string} attr
 */
export const getDataAttributeValue = async (base, attr) => base.attr(attr);
/** Checks if given element is focused
 * @param {UniDriver} element
 * @returns {Promise<boolean>}
 */
export const isElementFocused = async (element) => {
    const nativeElement = await element.getNative();
    switch (element.type) {
        case 'react':
            return ReactBase(element).isFocus();
        case 'puppeteer':
            return page.evaluate(el => document.activeElement === el, nativeElement);
        default:
            return;
    }
};
export const baseUniDriverFactory = (base) => {
    const baseUniDriver = testUtilsBaseUniDriverFactory(base);
    return {
        /**
         * Checks whether the component found with the given data hook
         * @returns {Promise<boolean>}
         */
        exists: () => baseUniDriver.exists(),
        /**
         * Gets the component root element
         * @returns {Promise<any>}
         */
        element: () => baseUniDriver.element(),
        /**
         * Clicks on the component root element
         * @returns {Promise<void>}
         */
        click: () => baseUniDriver.click(),
        /**
         * Returns UniDriver for the base element
         * @return {UniDriver}
         */
        get base() {
            return baseUniDriver.base;
        },
    };
};
//# sourceMappingURL=index.js.map