"use strict";

exports.__esModule = true;
exports.ReferenceEditUniDriver = ReferenceEditUniDriver;
var _unidriver = require("../../../../unidriver");
var _unidriver2 = require("@wix/design-system/dist/testkit/unidriver");
const {
  fireEvent = null
} = process.env.NODE_ENV === 'test' ? (() => {
  try {
    return require('@testing-library/react');
  } catch {}
  return {};
})() : {};
function ReferenceEditUniDriver(base, body) {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const getNativeInput = () => base.$('input').getNative();
  const getAutoCompleteBase = () => base.$('[data-hook="reference-input-autocomplete"]');
  const getAutoComplete = () => (0, _unidriver2.AutoCompleteUniDriver)(getAutoCompleteBase(), body);
  const getDropdownLayoutBase = () => body.$('[data-hook="reference-input-autocomplete-content"]');
  return {
    ...(0, _unidriver.baseUniDriverFactory)(base),
    hasInput: () => base.$('input').exists(),
    getInputValue: () => base.$('input').value(),
    getAutoComplete,
    getLoader: async () => getDropdownLayoutBase().$('[data-hook="initial-loader"]'),
    typeInInput: async value => {
      fireEvent.change(await getNativeInput(), {
        target: {
          value
        }
      });
    },
    pressKeyOnInput: async key => {
      fireEvent.keyDown(await getNativeInput(), {
        key
      });
    },
    hasDropdown: () => base.$('[data-hook="dropdown-layout-wrapper"]').exists(),
    hasClearButton: () => base.$('[data-hook="input-clear-button"]').exists(),
    clickClearButton: async () => {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      const el = base.$('[data-hook="input-clear-button"]').getNative();
      fireEvent.click(await el);
    },
    hasAvatarPrefix: () => base.$('[data-hook="reference-input-avatar-prefix"]').exists(),
    hasInitialLoader: () => body.$('[data-hook="initial-loader"]').exists(),
    // Dropdown is portal-mounted to document.body, so search in body, not base.
    getOptionCount: async () => body.$$('[data-hook="list-item-select"]').count(),
    getOptionTitleByIndex: async index => {
      const option = await body.$$('[data-hook="list-item-select"]').get(index);
      return option.$('[data-hook="list-item-select-title"]').text();
    },
    clickOptionByIndex: async index => {
      const option = await body.$$('[data-hook="list-item-select"]').get(index);
      return option.click();
    },
    // Open-collection action is rendered inside the portal-mounted dropdown footer.
    hasOpenCollectionButton: () => body.$('[data-hook="reference-open-collection"]').exists(),
    clickOpenCollection: async () => {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      const el = body.$('[data-hook="reference-open-collection"]').getNative();
      fireEvent.click(await el);
    }
  };
}
//# sourceMappingURL=Edit.uni.driver.js.map