"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));
var _constants = require("./constants");
var breadcrumbsDriverFactory = _ref => {
  var {
    element
  } = _ref;
  var optionAt = position => element.childNodes[position];
  return {
    exists: () => !!element,
    /** return the number of the items in the breadcrumbs */
    breadcrumbsLength: () => element.childNodes.length,
    /** return the breadcrumb item content at position  */
    breadcrumbContentAt: position => optionAt(position).textContent,
    /** click on breadcrumb item at position */
    clickBreadcrumbAt: position => _testUtils.default.Simulate.click(optionAt(position).querySelector("[data-hook^=\"".concat(_constants.DATA_HOOKS.BREADCRUMB_CLICKABLE, "\"]"))),
    /** return the active breadcrumb item position or return null if no active item exists */
    getActiveItemId: () => {
      var activeItem = element.querySelector("[".concat(_constants.DATA_ATTRIBUTES.DATA_ACTIVE, "=\"true\"]"));
      if (!activeItem) {
        return null;
      }
      return Array.from(activeItem.parentNode.children).indexOf(activeItem);
    },
    /** fulfilled if breadcrumbs component is large */
    isLarge: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SIZE) === _constants.SIZES.large,
    /** fulfilled if breadcrumbs component is medium */
    isMedium: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SIZE) === _constants.SIZES.medium,
    /** fulfilled if breadcrumbs component is small */
    isSmall: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SIZE) === _constants.SIZES.small,
    /** fulfilled if breadcrumbs component is on white background */
    isOnWhiteBackground: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SKIN) === _constants.SKINS.onWhiteBackground,
    /** fulfilled if breadcrumbs component is on gray background */
    isOnGrayBackground: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SKIN) === _constants.SKINS.onGrayBackground,
    /** fulfilled if breadcrumbs component is on dark background */
    isOnDarkBackground: () => element.getAttribute(_constants.DATA_ATTRIBUTES.DATA_SKIN) === _constants.SKINS.onDarkBackground,
    /** returns true if the item is a link */
    isActiveLinkAt: index => !!optionAt(index).querySelector('a')
  };
};
var _default = exports.default = breadcrumbsDriverFactory;
//# sourceMappingURL=Breadcrumbs.driver.js.map