"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _vanilla = require("@wix/wix-ui-test-utils/vanilla");
var _PopoverMenuUni = require("../PopoverMenu/PopoverMenu.uni.driver");
var _Tooltip = require("../Tooltip/Tooltip.driver");
var _constants = require("./constants");
var _ButtonLegacy = _interopRequireDefault(require("../Button/Button.legacy.driver"));
var popoverMenuTestkitFactory = (0, _vanilla.uniTestkitFactoryCreator)(_PopoverMenuUni.PopoverMenuDriver);
var createButtonDriver = element => (0, _ButtonLegacy.default)({
  element
});
var tableActionCellDriverFactory = _ref => {
  var {
    element: _element,
    wrapper,
    eventTrigger
  } = _ref;
  var visibleActions = () => _element.querySelectorAll("[data-hook=\"".concat(_constants.DATA_HOOKS.visibleAction, "\"]"));
  var getPrimaryActionButtonVisibility = () => _element.querySelector("[data-hook=\"".concat(_constants.DATA_HOOKS.primaryActionWrapper, "\"]")).getAttribute('data-display');
  var getPrimaryActionButtonDriver = () => createButtonDriver(_element.querySelector("[data-hook=\"".concat(_constants.DATA_HOOKS.primaryAction, "\"]")));
  var getVisibleActionTooltipDriver = actionIndex => (0, _Tooltip.tooltipLegacyDriverFactory)({
    element: _element.querySelectorAll("[data-hook=\"".concat(_constants.DATA_HOOKS.visibleActionTooltip, "\"]"))[actionIndex],
    eventTrigger
  });
  var getVisibleActionByDataHookTooltipDriver = dataHook => {
    var _ref2;
    return (0, _Tooltip.tooltipLegacyDriverFactory)({
      element: (_ref2 = _element.querySelector("[data-hook=\"".concat(dataHook, "\"]"))) !== null && _ref2 !== void 0 ? _ref2 : undefined,
      eventTrigger
    });
  };
  var getVisibleActionButtonDriver = actionIndex => {
    var _visibleActions$actio;
    return createButtonDriver((_visibleActions$actio = visibleActions()[actionIndex]) !== null && _visibleActions$actio !== void 0 ? _visibleActions$actio : null);
  };
  var getVisibleActionByDataHookButtonDriver = dataHook => createButtonDriver(_element.querySelector("[data-hook=\"".concat(dataHook, "\"]")));
  var getHiddenActionsPopoverMenuDriver = () => popoverMenuTestkitFactory({
    wrapper,
    dataHook: _constants.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(_constants.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')
  };
};
var _default = exports.default = tableActionCellDriverFactory;
//# sourceMappingURL=TableActionCell.driver.js.map