"use strict";

exports.__esModule = true;
exports.CollectionViewsDropdownUniDriver = void 0;
var _unidriver = require("@wix/design-system/dist/testkit/unidriver");
var _unidriver2 = require("../../unidriver");
var _ViewsDropdownListItemUni = require("./ViewsDropdownListItem.uni.driver");
var _ManageViewPopoverUni = require("./ManageViewPopover.uni.driver");
var _CollectionSaveViewModalUni = require("./modals/SaveView/CollectionSaveViewModal.uni.driver");
var _CollectionRenameViewModalUni = require("./modals/RenameView/CollectionRenameViewModal.uni.driver");
const CollectionViewsDropdownUniDriver = (base, body) => {
  const viewsDropdownDriverBase = () => base.$('[data-hook="collection-views-dropdown"]');
  const manageViewPopover = () => (0, _ManageViewPopoverUni.ManageViewPopoverUniDriver)(base, body);
  const getSaveViewModal = () => (0, _CollectionSaveViewModalUni.CollectionSaveViewModalUniDriver)(base, body);
  const getRenameViewModal = () => (0, _CollectionRenameViewModalUni.CollectionRenameViewModalUniDriver)(base, body);
  const getDropdownLayoutBase = async () => {
    const contentDataHook = await viewsDropdownDriverBase().attr('data-content-hook');
    if (contentDataHook) {
      return body.$(`[data-content-element="${contentDataHook}"]`);
    }
    const baseDataHook = await viewsDropdownDriverBase().attr('data-hook');
    return body.$(`[data-hook="${baseDataHook}-content"]`);
  };
  const viewsDropdownDriver = () => (0, _unidriver.DropdownUniDriver)(viewsDropdownDriverBase(), body);
  const getViewListItemById = id => {
    return (0, _ViewsDropdownListItemUni.ViewsDropdownListItemUniDriver)(viewsDropdownDriverBase().$(`[data-hook="dropdown-item-${id}"]`), body);
  };
  const getViewListItemAt = index => {
    return (0, _ViewsDropdownListItemUni.ViewsDropdownListItemUniDriver)(viewsDropdownDriverBase().$$('[data-hook="view-item"]').get(index), body);
  };
  const getCategoryListItemById = id => {
    return (0, _unidriver.ListItemSectionUniDriver)(viewsDropdownDriverBase().$(`[data-hook="dropdown-item-${id}"]`), body);
  };
  const getCategoryListItemAt = index => {
    return (0, _unidriver.ListItemSectionUniDriver)(viewsDropdownDriverBase().$$('[data-hook="view-category"]').get(index), body);
  };
  const openManageViewPopover = () => manageViewPopover().open();
  const saveNewViewActionClick = () => manageViewPopover().clickSaveNewView();
  const deleteViewActionClick = () => manageViewPopover().clickDeleteView();
  const saveViewChangesActionClick = () => manageViewPopover().clickSaveChanges();
  const renameViewActionClick = () => manageViewPopover().clickRenameView();
  const setAsDefaultViewActionClick = () => manageViewPopover().clickSetAsDefaultView();
  return {
    ...(0, _unidriver2.baseUniDriverFactory)(base),
    _input: () => viewsDropdownDriverBase().$('input'),
    exists: () => viewsDropdownDriver().exists(),
    initialLoaderExists: async () => (await getDropdownLayoutBase()).$('[data-hook="initial-loader"]').exists(),
    /** Get the currently selected view name */
    getSelected: () => viewsDropdownDriver().inputDriver.getValue(),
    /** Get the dropdown input text */
    getInputValue: () => viewsDropdownDriver().inputDriver.getValue(),
    /** Indicates input is ready-only */
    getInputReadOnly: () => viewsDropdownDriver().inputDriver.getReadOnly(),
    /** Indicates input is focused */
    isInputFocused: () => viewsDropdownDriver().inputDriver.isFocus(),
    /** Get the currently selected view id */
    getSelectedId: () => viewsDropdownDriver().dropdownLayoutDriver.getSelectedOptionId(),
    /** Checks if total is shown */
    hasTotal: () => viewsDropdownDriver().inputDriver.suffixComponentExists('.total-count'),
    /** Opens views dropdown */
    open: () => viewsDropdownDriver().inputDriver.click(),
    /** Enter dropdown input text */
    enterText: value => viewsDropdownDriver().inputDriver.enterText(value),
    /** Click dropdown input clear button */
    clickInputClearButton: () => viewsDropdownDriver().inputDriver.clickClear(),
    /** Indicates input clear button exists  */
    inputClearButtonExists: () => viewsDropdownDriver().inputDriver.hasClearButton(),
    /** Get number of views */
    getViewsCount: async () => viewsDropdownDriverBase().$$('[data-hook="view-item"]').count(),
    /** Get array of all view names in the dropdown */
    getViewsContent: async () => viewsDropdownDriverBase().$$('[data-hook="view-item"]').text(),
    /** Get array popover content , like empty state */
    getViewsPopoverContent: async () => viewsDropdownDriver().dropdownLayoutDriver.optionsContent(),
    /** Indicates whether the dropdown is open */
    isOpen: () => viewsDropdownDriver().dropdownLayoutDriver.isShown(),
    /** Get the placeholder test of the dropdown */
    getPlaceholderText: () => viewsDropdownDriver().inputDriver.getPlaceholder(),
    /** Get modal driver for "Save View" */
    getSaveViewModal,
    /** Get modal driver for "Rename View" */
    getRenameViewModal,
    /** Get view list item driver by view id */
    getViewListItemById,
    /** Get view list item driver by view index */
    getViewListItemAt,
    /** Get category list item driver by category id */
    getCategoryListItemById,
    /** Get category list item driver by category index */
    getCategoryListItemAt,
    /** Get "all items" view list item */
    getAllItemsView: () => getCategoryListItemById('all-items-view'),
    /** Get number of categories */
    getCategoriesCount: async () => viewsDropdownDriverBase().$$('[data-hook="view-category"]').count(),
    /** Get array of all category names in the dropdown */
    getCategoriesContent: async () => viewsDropdownDriverBase().$$('[data-hook="view-category"]').text(),
    /** Check if view pending changes */
    isViewPendingChanges: async () => viewsDropdownDriver().inputDriver.prefixComponentExists('[data-hook="view-pending-changes"]'),
    isDefaultView: async () => viewsDropdownDriver().inputDriver.prefixComponentExists('[data-hook="view-default"]'),
    /** Indicates whether the Manage View popover exists */
    manageViewPopoverExists: () => manageViewPopover().exists(),
    /** Indicates whether the Manage View popover opened */
    isManageViewPopoverOpen: () => manageViewPopover().isOpen(),
    /** Opens the Manage View popover */
    openManageViewPopover,
    /** Clicks the Save Changes action in the Manage View popover */
    saveViewChangesActionClick,
    /** Clicks the Save as New View action in the Manage View popover */
    saveNewViewActionClick,
    /** Clicks the Rename action in the Manage View popover */
    renameViewActionClick,
    /** Clicks the Set as Default View action in the Manage View popover */
    setAsDefaultViewActionClick,
    /** Clicks the Delete action in the Manage View popover */
    deleteViewActionClick,
    /** Get DropdownLayoutOptionUniDriver of a Save Changes option */
    getSaveViewChangesBtn: () => manageViewPopover().getSaveChangesBtn(),
    /** Get DropdownLayoutOptionUniDriver of a Save as New View option */
    getSaveNewViewBtn: () => manageViewPopover().getSaveNewViewBtn(),
    /** Get DropdownLayoutOptionUniDriver of a Delete View option */
    getDeleteViewBtn: () => manageViewPopover().getDeleteViewBtn(),
    /** Get DropdownLayoutOptionUniDriver of a Rename option */
    getRenameViewBtn: () => manageViewPopover().getRenameViewBtn(),
    /** Get DropdownLayoutOptionUniDriver of a Set as Default View option */
    getSetAsDefaultViewBtn: () => manageViewPopover().getSetAsDefaultViewBtn(),
    /** Saves new view with a defined name and current filters / sort / columns */
    saveNewView: async name => {
      await openManageViewPopover();
      await saveNewViewActionClick();
      const saveViewModal = getSaveViewModal();
      await saveViewModal.fillViewNameInput(name);
      await saveViewModal.clickSaveButton();
    },
    /** Deletes the view with a given index */
    deleteView: async ind => {
      await open();
      await getViewListItemAt(ind).select();
      await openManageViewPopover();
      await deleteViewActionClick();
    },
    /** Saves changes to the current view */
    saveViewChanges: async () => {
      await openManageViewPopover();
      await saveViewChangesActionClick();
    },
    /** Renames the current view with a given name */
    renameView: async name => {
      await openManageViewPopover();
      await renameViewActionClick();
      const renameViewModal = getRenameViewModal();
      await renameViewModal.fillViewNameInput(name);
      await renameViewModal.clickSaveButton();
    },
    /** Sets a default view with a given index */
    setAsDefaultView: async ind => {
      await open();
      await getViewListItemAt(ind).select();
      await openManageViewPopover();
      await setAsDefaultViewActionClick();
    }
  };
};
exports.CollectionViewsDropdownUniDriver = CollectionViewsDropdownUniDriver;
//# sourceMappingURL=CollectionViewsDropdown.uni.driver.js.map