"use strict";

exports.__esModule = true;
exports.DateRangePickerUniDriver = DateRangePickerUniDriver;
var _unidriver = require("@wix/design-system/dist/testkit/unidriver");
var _unidriver2 = require("../../unidriver");
var _DatePickerUni = require("../../unidriver/DatePicker.uni.driver");
function DateRangePickerUniDriver(base, body) {
  const getDatePickersContainer = () => base.$(`[data-hook="date-range-picker"]`);
  const getDatePickerBase = picker => base.$(`[data-hook="date-range-picker-${picker}"]`);
  const getTimeInputBase = picker => base.$(`[data-hook="date-range-picker-time-${picker}"]`);
  const getDatePickerSync = picker => (0, _unidriver.DatePickerUniDriver)(getDatePickerBase(picker), body, {
    dataHook: `date-range-picker-${picker}`
  });
  const getDatePicker = async picker => (0, _DatePickerUni.DatePickerUniDriver)(getDatePickerBase(picker), body);
  const getTimeInput = picker => (0, _unidriver.TimeInputUniDriver)(getTimeInputBase(picker), body);
  const getRadioGroup = () => (0, _unidriver.RadioGroupUniDriver)(base.$(`[data-hook="date-range-filter-group"]`), body);
  const getRadioItem = preset => (0, _unidriver.RadioUniDriver)(base.$(`[data-hook="date-range-filter-option-${preset}"]`), body);
  const openDatePicker = async datePicker => {
    !(await datePicker.calendarDriver.exists()) && (await datePicker.driver.open());
  };
  const chooseRandomDates = async () => {
    const dateFrom = await getDatePicker('from');
    const dateTo = await getDatePicker('to');
    await openDatePicker(dateFrom);
    await dateFrom.calendarDriver.clickOnNthDay(1);
    await dateTo.calendarDriver.clickOnNthDay(2);
    return {
      from: dateFrom,
      to: dateTo
    };
  };
  const chooseDate = async (picker, date) => {
    const datePicker = await getDatePicker(picker);
    await openDatePicker(datePicker);
    await datePicker.calendarDriver.clickDay(date);
    return datePicker;
  };
  const choosePresetOption = async option => {
    const datesRadioGroup = getRadioGroup();
    await datesRadioGroup.selectByValue(option);
  };
  const getPresetOptions = async () => {
    const presetOptions = [];
    try {
      const datesRadioGroup = getRadioGroup();
      const numberOfRadios = await datesRadioGroup.getNumberOfRadios();
      for (let i = 0; i < numberOfRadios; i++) {
        presetOptions.push(await datesRadioGroup.getRadioValueAt(i));
      }
    } catch {}
    return presetOptions;
  };
  const getSelectedPresetTitle = async () => {
    const selectedRaido = await getRadioItem(await getSelectedPreset());
    return selectedRaido.getLabel();
  };
  const getSelectedPreset = () => {
    const datesRadioGroup = getRadioGroup();
    return datesRadioGroup.getSelectedValue();
  };
  const getTimeInputDriver = picker => (0, _unidriver.InputUniDriver)(getTimeInputBase(picker).$(`[data-hook="TimeInput-input"]`), body);
  return {
    ...(0, _unidriver2.baseUniDriverFactory)(base),
    _getRadioGroup: getRadioGroup,
    getDatePicker: getDatePickerSync,
    getDatePickersContainer,
    getTimeInput,
    isTimeSelected: async picker => {
      return !!(await getTimeInputDriver(picker).getValue());
    },
    openTimeDropdown: async picker => {
      await getTimeInputDriver(picker).click();
    },
    getTimeDropdown: picker => (0, _unidriver.DropdownBaseUniDriver)(getTimeInputBase(picker).$(`[data-hook="TimeInput-dropdown"]`), body),
    chooseRandomDates,
    chooseDate,
    choosePresetOption,
    getPresetOptions,
    getSelectedPreset,
    getSelectedPresetTitle,
    openDatePicker
  };
}
//# sourceMappingURL=DateRangeFilter.uni.driver.js.map