"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _unidriver = require("@wix/wix-ui-test-utils/unidriver");
var _unidriver2 = require("../../unidriver");
var _unidriver3 = require("@wix/design-system/dist/testkit/unidriver");
var _CustomFieldPanelUni = require("../CustomFieldsPanel/CustomFieldPanel.uni.driver");
var _CustomFieldModalUni = require("../CustomFieldModal/CustomFieldModal.uni.driver");
var _CustomFieldsFormUni = _interopRequireDefault(require("../CustomFieldsForm/CustomFieldsForm.uni.driver"));
var _ArchiveFieldModalUni = require("../CustomFieldsPanel/ArchiveFieldModal.uni.driver");
var _DisabledTooltipButtonUni = require("../DisabledTooltip/DisabledTooltipButton.uni.driver");
var _CardContainerUni = _interopRequireDefault(require("../CardContainer/CardContainer.uni.driver"));
var _default = (base, body) => {
  const addCustomFieldButton = () => (0, _DisabledTooltipButtonUni.DisabledTooltipButtonUniDriver)(base, body, {
    dataHook: 'add-custom-field-btn'
  });
  const manageFieldsButton = () => (0, _DisabledTooltipButtonUni.DisabledTooltipButtonUniDriver)(base, body, {
    dataHook: 'manage-fields-button'
  });
  const emptyState = () => (0, _unidriver3.EmptyStateUniDriver)(base.$(`[data-hook="empty-state"]`), body);
  const cardContainer = () => (0, _CardContainerUni.default)(base, body);
  const getFormByNamespace = (namespace = '_user_fields') => (0, _CustomFieldsFormUni.default)(base.$(`[data-hook="custom-fields-form-${namespace}"]`), body);
  return {
    /** Returns title text */
    getTitle: () => base.$(`[data-hook="title"]`).text(),
    /** Returns subtitle text */
    getSubtitle: async () => {
      const infoIcon = (0, _unidriver3.InfoIconUniDriver)(base.$('[data-hook="subtitle-info-icon"]'), body);
      if (await infoIcon.exists()) {
        return infoIcon.getContent();
      }
      return base.$(`[data-hook="subtitle"]`).text();
    },
    getFormSection: namespace => {
      const sectionBase = base.$(`[data-hook="custom-fields-namespace-form-${namespace}"]`);
      const infoIcon = (0, _unidriver3.InfoIconUniDriver)(sectionBase.$('[data-hook="info-icon"]'), body);
      const sectionHeader = (0, _unidriver3.SectionHeaderUniDriver)(sectionBase.$('[data-hook="section-header"]'), body);
      return {
        ...sectionBase,
        ...sectionHeader,
        infoExists: () => infoIcon.exists(),
        getInfoContent: () => infoIcon.getContent(),
        _hasDivider: async () => Array.from((await sectionHeader.element()).classList).some(className => className.includes('divider') && className.includes('top'))
      };
    },
    /** Checks whether the form component rendered */
    isFormExists: namespace => getFormByNamespace(namespace).exists(),
    onlyUserFieldsFormExists: namespace => getFormByNamespace(namespace).exists(),
    /** Waits for form rendering */
    waitForForm: (timeout = 5000, namespace) => (0, _unidriver.waitFor)(() => getFormByNamespace(namespace).exists(), timeout),
    addCustomFieldButton,
    manageFieldsButton,
    /** Gets add field button text */
    getAddFieldContent: () => addCustomFieldButton().getButtonTextContent(),
    /** Gets manage fields button text */
    getManageFieldsContent: () => manageFieldsButton().getButtonTextContent(),
    /** Indicates whether the widget loading state shows */
    isLoading: (theme = 'card') => theme === 'card' ? cardContainer().showsSkeletonHeader() : (0, _unidriver3.SkeletonLineUniDriver)(body.$('[data-hook="widget-inline-loading"]'), body).exists(),
    /** Clicks on add field button */
    clickAddField: () => addCustomFieldButton().click(),
    /** Checks whether the add field button rendered */
    addCustomFieldButtonExists: () => addCustomFieldButton().exists(),
    /** Clicks on manage fields button */
    clickManageFieldsContent: () => manageFieldsButton().click(),
    /** Checks whether the manage fields button rendered */
    manageCustomFieldsButtonExists: () => manageFieldsButton().exists(),
    /** Returns the error state title */
    getErrorTitle: (theme = 'card') => theme === 'card' ? cardContainer().getErrorState().getTitleText() : (0, _unidriver3.EmptyStateUniDriver)(body.$('[data-hook="custom-fields-widget-inline-error"]'), body).getTitleText(),
    /** Returns the error state subtitle */
    getErrorSubtitle: (theme = 'card') => theme === 'card' ? cardContainer().getErrorState().getSubtitleText() : (0, _unidriver3.EmptyStateUniDriver)(body.$('[data-hook="custom-fields-widget-inline-error"]'), body).getSubtitleText(),
    /** Returns the empty state title */
    getEmptyTitle: () => emptyState().getTitleText(),
    /** Returns the empty state subtitle */
    getEmptySubtitle: () => emptyState().getSubtitleText(),
    /** Clicks on try again button when error state visible */
    clickTryAgain: (theme = 'card') => theme === 'card' ? cardContainer().getErrorState().getRetryButton().click() : (0, _unidriver3.TextButtonUniDriver)(body.$('[data-hook="retry-button"]'), body).click(),
    /** Gets try again button text */
    getTryAgainContent: (theme = 'card') => theme === 'card' ? cardContainer().getErrorState().getRetryButton().getButtonTextContent() : (0, _unidriver3.TextButtonUniDriver)(body.$('[data-hook="retry-button"]'), body).getButtonTextContent(),
    /** Returns custom fields side panel driver */
    sidePanel: () => (0, _CustomFieldPanelUni.CustomFieldPanelUniDriver)(body, body),
    /** Returns custom field modal driver */
    customFieldModal: () => (0, _CustomFieldModalUni.CustomFieldModalUniDriver)(base, body),
    /** Returns archive field modal driver */
    archiveFieldModal: () => (0, _ArchiveFieldModalUni.ArchiveFieldModalUniDriver)(base, body),
    /** Returns field driver by given ID */
    fieldById: (id, namespace) => getFormByNamespace(namespace).field(id),
    ...(0, _unidriver2.baseUniDriverFactory)(base)
  };
};
exports.default = _default;
//# sourceMappingURL=CustomFieldsWidget.uni.driver.js.map