"use strict";

exports.__esModule = true;
exports.SuggestionsUniDriver = void 0;
var _unidriver = require("@wix/design-system/dist/testkit/unidriver");
var _unidriver2 = require("@wix/wix-ui-test-utils/unidriver");
const SuggestionsUniDriver = (base, body) => {
  const dataHook = 'suggestions';
  const carouselIdle = (0, _unidriver.CarouselWIPUniDriver)(base.$(`[data-hook="${dataHook}-carousel-idle"]`), body);
  const carouselLoading = (0, _unidriver.CarouselWIPUniDriver)(base.$(`[data-hook="${dataHook}-carousel-loading"]`), body);
  const containerIdle = base.$(`[data-hook="${dataHook}-container-idle"]`);
  const containerLoading = base.$(`[data-hook="${dataHook}-container-loading"]`);
  const getCarouselChildren = async () => {
    if (await carouselIdle.exists()) {
      return carouselIdle.getChildren();
    }
    if (await carouselLoading.exists()) {
      return carouselLoading.getChildren();
    }
    return null;
  };
  const getContainerChildren = async () => {
    if (await containerIdle.exists()) {
      return containerIdle.$$(`[data-hook="suggestion-item"]`);
    }
    if (await containerLoading.exists()) {
      return containerLoading.$$(`[data-hook="suggestion-item"]`);
    }
    return null;
  };
  const isLoadingState = async () => {
    const isContainerLoading = await containerLoading.exists();
    const isCarouselLoading = await carouselLoading.exists();
    return isContainerLoading || isCarouselLoading;
  };
  return {
    ...(0, _unidriver2.baseUniDriverFactory)(base),
    isLoading: isLoadingState,
    hasOffers: async () => {
      const carouselExists = await carouselIdle.exists();
      const containerExists = await containerIdle.exists();
      return carouselExists || containerExists;
    },
    isEmpty: async () => {
      const carouselExists = await carouselIdle.exists();
      const containerExists = await containerIdle.exists();
      return !carouselExists && !containerExists;
    },
    getCardsCount: async () => {
      const carouselChildren = await getCarouselChildren();
      if (carouselChildren) {
        return carouselChildren.length;
      }
      const containerChildren = await getContainerChildren();
      if (containerChildren) {
        return containerChildren.count();
      }
      return 0;
    },
    getCardAt: async index => {
      const carouselChildren = await getCarouselChildren();
      if (carouselChildren) {
        return carouselChildren[index];
      }
      const containerChildren = await getContainerChildren();
      if (containerChildren) {
        return containerChildren.at(index);
      }
      throw new Error(`No cards found at index ${index}`);
    },
    carousel: async () => (await carouselIdle.exists()) ? carouselIdle : carouselLoading,
    container: async () => (await containerIdle.exists()) ? containerIdle : containerLoading
  };
};
exports.SuggestionsUniDriver = SuggestionsUniDriver;
//# sourceMappingURL=Suggestions.uni.driver.js.map