"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.WithTabsSwitcherSchedulerContainer = WithTabsSwitcherSchedulerContainer;
var _react = _interopRequireWildcard(require("react"));
var _tabs = require("../tabs");
var _advancedScheduler = require("./advanced-scheduler");
var _simpleScheduler = require("./simple-scheduler");
var _constants = require("./constants");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function WithTabsSwitcherSchedulerContainer({
  onUpdateSchedule,
  isDisabled,
  validationTexts,
  initialSchedule,
  schedulerKey,
  validateArrayOfRangedNumbersOrAll,
  advancedSchedulerInfoTexts,
  labelTexts,
  frequencyOptions,
  daysOfWeek,
  months,
  selectedTabKey,
  onUseSimpleScheduler,
  tabTexts
}) {
  const [currTabKey, setCurrTabKey] = (0, _react.useState)(selectedTabKey || _constants.TAB_KEYS.SIMPLE);
  const tabOptions = (0, _react.useMemo)(() => {
    return [{
      key: _constants.TAB_KEYS.SIMPLE,
      label: tabTexts.simpleScheduleLabel,
      tooltip: currTabKey === _constants.TAB_KEYS.ADVANCED && tabTexts.simpleScheduleTooltip,
      testId: _constants.TAB_KEYS.SIMPLE
    }, {
      key: _constants.TAB_KEYS.ADVANCED,
      label: tabTexts.advancedScheduleLabel,
      tooltip: currTabKey === _constants.TAB_KEYS.SIMPLE && tabTexts.advancedScheduleTooltip,
      testId: _constants.TAB_KEYS.ADVANCED
    }];
  }, [tabTexts]);
  const onSelect = (0, _react.useCallback)(({
    key
  }) => {
    if (key === _constants.TAB_KEYS.SIMPLE) {
      onUseSimpleScheduler();
    }
    setCurrTabKey(key);
  }, [onUseSimpleScheduler]);
  (0, _react.useEffect)(() => {
    if (selectedTabKey) {
      setCurrTabKey(selectedTabKey);
    }
  }, [selectedTabKey]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_tabs.Tabs, {
      options: tabOptions,
      selectedKey: currTabKey,
      onSelect: onSelect,
      testId: "scheduler-tabs",
      isDisabled: isDisabled
    }), currTabKey === _constants.TAB_KEYS.SIMPLE && /*#__PURE__*/(0, _jsxRuntime.jsx)(_simpleScheduler.SimpleScheduler, {
      onUpdateSchedule: onUpdateSchedule,
      initialSchedule: initialSchedule,
      frequencyOptions: frequencyOptions,
      validateArrayOfRangedNumbersOrAll: validateArrayOfRangedNumbersOrAll,
      daysOfWeek: daysOfWeek,
      months: months,
      labelTexts: labelTexts,
      validationTexts: validationTexts,
      isDisabled: isDisabled
    }, schedulerKey), currTabKey === _constants.TAB_KEYS.ADVANCED && /*#__PURE__*/(0, _jsxRuntime.jsx)(_advancedScheduler.AdvancedScheduler, {
      onUpdateSchedule: onUpdateSchedule,
      initialSchedule: initialSchedule,
      validateArrayOfRangedNumbersOrAll: validateArrayOfRangedNumbersOrAll,
      labelTexts: labelTexts,
      infoTexts: advancedSchedulerInfoTexts,
      isDisabled: isDisabled
    }, schedulerKey)]
  });
}