import { baseUniDriverFactory, findByHook, findByHookAtIndex, countByHook, getDataAttributeValue, } from '../utils/test-utils/unidriver';
import { DATA_HOOKS } from './constants';
import { buttonDriverFactory } from '../Button/Button.uni.driver';
import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver';
import { PopoverMenuDriver } from '../PopoverMenu/PopoverMenu.uni.driver';
export const tableActionCellUniDriverFactory = (base, body) => {
    const getPrimaryActionButtonVisibility = () => getDataAttributeValue(findByHook(base, DATA_HOOKS.primaryActionWrapper), 'data-display');
    const getPrimaryActionButtonDriver = () => buttonDriverFactory(findByHook(base, DATA_HOOKS.primaryAction));
    const getPrimaryActionButtonDriverByDataHook = (dataHook) => buttonDriverFactory(findByHook(base, dataHook));
    const getVisibleActionTooltipDriver = (actionIndex) => tooltipDriverFactory(findByHookAtIndex(base, DATA_HOOKS.visibleActionTooltip, actionIndex), body);
    const getVisibleActionByDataHookTooltipDriver = (dataHook) => tooltipDriverFactory(findByHook(base, dataHook), body);
    const getVisibleActionButtonDriver = (actionIndex) => buttonDriverFactory(findByHookAtIndex(base, DATA_HOOKS.visibleAction, actionIndex));
    const getVisibleActionByDataHookButtonDriver = (dataHook) => buttonDriverFactory(findByHook(base, dataHook));
    const getHiddenActionsPopoverMenuDriver = () => PopoverMenuDriver(findByHook(base, DATA_HOOKS.popoverMenu), body);
    return {
        ...baseUniDriverFactory(base),
        /**
         * Get the driver of the primary action <Button/> from the action column
         * @returns {Promise<buttonDriverFactory>}
         */
        getPrimaryActionButtonDriver,
        /**
         * Get the driver of a specific primary action <Button/> by dataHook (for array format)
         * @param {string} dataHook - DataHook of the primary action
         * @returns {Promise<buttonDriverFactory>}
         */
        getPrimaryActionButtonDriverByDataHook,
        /**
         * Get the number of primary actions (for array format)
         * @returns {Promise<number>} number of primary actions
         */
        getPrimaryActionsCount: () => {
            const primaryActionWrapper = findByHook(base, DATA_HOOKS.primaryActionWrapper);
            return primaryActionWrapper.$$('button').count();
        },
        /**
         * Gets primary action visibility value
         * @returns {Promise<'onHover' | 'always'>}
         */
        getPrimaryActionButtonVisibility,
        /**
         * Clicks the primary action button of the action column
         * @returns {Promise<void>}
         */
        clickPrimaryActionButton: async () => await getPrimaryActionButtonDriver().click(),
        /**
         * Clicks a specific primary action button by index (for array format)
         * @param {number} actionIndex - Index of the primary action to click
         * @returns {Promise<void>}
         */
        clickPrimaryAction: async (actionIndex) => {
            const primaryActionWrapper = findByHook(base, DATA_HOOKS.primaryActionWrapper);
            const button = primaryActionWrapper.$$('button').at(actionIndex);
            await buttonDriverFactory(button).click();
        },
        /**
         * Clicks a specific primary action button by dataHook (for array format)
         * @param {string} dataHook - DataHook of the primary action to click
         * @returns {Promise<void>}
         */
        clickPrimaryActionByDataHook: async (dataHook) => await getPrimaryActionButtonDriverByDataHook(dataHook).click(),
        /**
         * Checks whether the primary action button is disabled
         * @returns {Promise<boolean>}
         */
        getIsPrimaryActionButtonDisabled: async () => await getPrimaryActionButtonDriver().isButtonDisabled(),
        /**
         * Checks whether the primary action button has an prefix icon
         * @returns {Promise<boolean>}
         */
        primaryActionButtonPrefixIconExists: async () => await getPrimaryActionButtonDriver().isPrefixIconExists(),
        /**
         * Checks whether the primary action button has an suffix icon
         * @returns {Promise<boolean>}
         */
        primaryActionButtonSuffixIconExists: async () => await getPrimaryActionButtonDriver().isSuffixIconExists(),
        /**
         * Get the number of the visible secondary actions
         * @returns {Promise<number>} number of visible secondary actions
         */
        getVisibleActionsCount: () => countByHook(base, DATA_HOOKS.visibleAction),
        /**
         * Get the number of hidden secondary actions (in the <PopoverMenu/>, requires it to be open)
         * @returns {Promise<number>} number of hidden secondary actions
         */
        getHiddenActionsCount: () => getHiddenActionsPopoverMenuDriver().childrenCount(),
        /**
         * Gets a specific visible secondary action <Tooltip/> driver
         * @param {actionIndex} actionIndex
         * @returns {Promise<tooltipDriverFactory>}
         */
        getVisibleActionTooltipDriver,
        /**
         * Get the driver of a specific visible secondary action <Tooltip/> by its specified dataHook
         * @param {dataHook} tooltip dataHook
         * @returns {Promise<tooltipDriverFactory>}
         */
        getVisibleActionByDataHookTooltipDriver,
        /**
         * Get the driver of a specific visible secondary action <Button/>
         * @param {actionIndex} actionIndex
         * @returns {Promise<buttonDriverFactory>}
         */
        getVisibleActionButtonDriver,
        /**
         * Gets a specific visible secondary action <Button/> driver by its specified dataHook
         * @param {dataHook} button dataHook
         * @returns {Promise<buttonDriverFactory>} visible action button driver
         */
        getVisibleActionByDataHookButtonDriver,
        /**
         * Gets the hidden secondary action <PopoverMenu/> driver
         * @returns {Promise<PopoverMenuUniDriver>}
         */
        getHiddenActionsPopoverMenuDriver,
        /**
         * Clicks on a visible secondary action
         * @param {actionIndex} actionIndex
         * @returns {Promise<void>}
         */
        clickVisibleAction: (actionIndex) => getVisibleActionButtonDriver(actionIndex).click(),
        /**
         * Clicks on a visible secondary action by its specified dataHook
         * @param {actionDataHook} actionDataHook
         * @returns {Promise<void>}
         */
        clickVisibleActionByDataHook: (actionDataHook) => getVisibleActionByDataHookButtonDriver(actionDataHook).click(),
        /**
         * Clicks on the hidden secondary actions <PopoverMenu/>
         * @returns {Promise<void>}
         */
        clickPopoverMenu: () => getHiddenActionsPopoverMenuDriver()
            .getTriggerElement(DATA_HOOKS.triggerElement)
            .click(),
        /**
         * Clicks on a hidden secondary action (requires the <PopoverMenu/> to be open)
         * @param {actionIndex} actionIndex
         * @returns {Promise<void>}
         */
        clickHiddenAction: (actionIndex) => getHiddenActionsPopoverMenuDriver().clickAtChild(actionIndex),
        /**
         * Clicks hidden action by data hook
         * @param {actionDataHook} actionDataHook
         * @returns {Promise<void>}
         */
        clickHiddenActionByDataHook: (actionDataHook) => getHiddenActionsPopoverMenuDriver().clickAtChildByDataHook(actionDataHook),
        /**
         * Gets tooltip text of more actions toggle button
         * @return {Promise<string>}
         */
        getMoreActionsTooltipText: () => base.attr('data-more-actions-tooltip-text'),
    };
};
//# sourceMappingURL=TableActionCell.uni.driver.js.map