import { uniTestkitFactoryCreator } from '@wix/wix-ui-test-utils/vanilla';
import { PopoverMenuDriver, } from '../PopoverMenu/PopoverMenu.uni.driver';
import { tooltipLegacyDriverFactory } from '../Tooltip/Tooltip.driver';
import { DATA_HOOKS } from './constants';
import buttonDriverFactory from '../Button/Button.legacy.driver';
const popoverMenuTestkitFactory = uniTestkitFactoryCreator(PopoverMenuDriver);
const createButtonDriver = (element) => buttonDriverFactory({ element });
const tableActionCellDriverFactory = ({ element, wrapper, eventTrigger, }) => {
    const visibleActions = () => element.querySelectorAll(`[data-hook="${DATA_HOOKS.visibleAction}"]`);
    const getPrimaryActionButtonVisibility = () => element
        .querySelector(`[data-hook="${DATA_HOOKS.primaryActionWrapper}"]`)
        .getAttribute('data-display');
    const getPrimaryActionButtonDriver = () => createButtonDriver(element.querySelector(`[data-hook="${DATA_HOOKS.primaryAction}"]`));
    const getVisibleActionTooltipDriver = (actionIndex) => tooltipLegacyDriverFactory({
        element: element.querySelectorAll(`[data-hook="${DATA_HOOKS.visibleActionTooltip}"]`)[actionIndex],
        eventTrigger,
    });
    const getVisibleActionByDataHookTooltipDriver = (dataHook) => tooltipLegacyDriverFactory({
        element: element.querySelector(`[data-hook="${dataHook}"]`) ?? undefined,
        eventTrigger,
    });
    const getVisibleActionButtonDriver = (actionIndex) => createButtonDriver(visibleActions()[actionIndex] ?? null);
    const getVisibleActionByDataHookButtonDriver = (dataHook) => createButtonDriver(element.querySelector(`[data-hook="${dataHook}"]`));
    const getHiddenActionsPopoverMenuDriver = () => popoverMenuTestkitFactory({
        wrapper,
        dataHook: DATA_HOOKS.popoverMenu,
    });
    return {
        /** Get the element */
        element: () => element,
        /** Whether the element exists */
        exists: () => !!element,
        /** Get the driver of the primary action <Button/> from the action column */
        getPrimaryActionButtonDriver,
        /** Click the primary action button from the action column */
        clickPrimaryActionButton: () => getPrimaryActionButtonDriver().click(),
        /** Get whether the primary action button is disabled */
        getIsPrimaryActionButtonDisabled: () => getPrimaryActionButtonDriver().isButtonDisabled(),
        /**
         * Gets primary action visibility value
         * @returns {Promise<'onHover' | 'always'>}
         */
        getPrimaryActionButtonVisibility,
        /** Get whether the primary action button prefix icon exists */
        primaryActionButtonPrefixIconExists: () => getPrimaryActionButtonDriver().isPrefixIconExists(),
        /** Get whether the primary action button suffix icon exists */
        primaryActionButtonSuffixIconExists: () => getPrimaryActionButtonDriver().isSuffixIconExists(),
        /** Get the number of the visible secondary actions */
        getVisibleActionsCount: () => visibleActions().length,
        /** Get the number of hidden secondary actions (in the <PopoverMenu/>, requires it to be open) */
        getHiddenActionsCount: () => getHiddenActionsPopoverMenuDriver().childrenCount(),
        /** Get the driver of a specific visible secondary action <Tooltip/> */
        getVisibleActionTooltipDriver,
        /** Get the driver of a specific visible secondary action <Tooltip/> by its specified dataHook */
        getVisibleActionByDataHookTooltipDriver,
        /** Get the driver of a specific visible secondary action <Button/> */
        getVisibleActionButtonDriver,
        /** Get the driver of a specific visible secondary action <Button/> by its specified dataHook */
        getVisibleActionByDataHookButtonDriver,
        /** Get the driver of the hidden secondary action <PopoverMenu/> */
        getHiddenActionsPopoverMenuDriver,
        /** Click an a visible secondary action */
        clickVisibleAction: (actionIndex) => getVisibleActionButtonDriver(actionIndex).click(),
        /** Click an a visible secondary action by its specified dataHook */
        clickVisibleActionByDataHook: (actionDataHook) => getVisibleActionByDataHookButtonDriver(actionDataHook).click(),
        /** Click on the hidden secondary actions <PopoverMenu/> */
        clickPopoverMenu: () => getHiddenActionsPopoverMenuDriver()
            .getTriggerElement(DATA_HOOKS.triggerElement)
            .click(),
        /** Click on a hidden secondary action (requires the <PopoverMenu/> to be open) */
        clickHiddenAction: (actionIndex) => getHiddenActionsPopoverMenuDriver().clickAtChild(actionIndex),
        clickHiddenActionByDataHook: (actionDataHook) => getHiddenActionsPopoverMenuDriver().clickAtChildByDataHook(actionDataHook),
        getMoreActionsTooltipText: () => element.getAttribute('data-more-actions-tooltip-text'),
    };
};
export default tableActionCellDriverFactory;
//# sourceMappingURL=TableActionCell.driver.js.map