import React, { useMemo, useEffect, useState, useCallback } from 'react';
import { Tabs } from '../tabs';
import { AdvancedScheduler } from './advanced-scheduler';
import { SimpleScheduler } from './simple-scheduler';
import { TAB_KEYS } from './constants';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export function WithTabsSwitcherSchedulerContainer({
  onUpdateSchedule,
  isDisabled,
  validationTexts,
  initialSchedule,
  schedulerKey,
  validateArrayOfRangedNumbersOrAll,
  advancedSchedulerInfoTexts,
  labelTexts,
  frequencyOptions,
  daysOfWeek,
  months,
  selectedTabKey,
  onUseSimpleScheduler,
  tabTexts
}) {
  const [currTabKey, setCurrTabKey] = useState(selectedTabKey || TAB_KEYS.SIMPLE);
  const tabOptions = useMemo(() => {
    return [{
      key: TAB_KEYS.SIMPLE,
      label: tabTexts.simpleScheduleLabel,
      tooltip: currTabKey === TAB_KEYS.ADVANCED && tabTexts.simpleScheduleTooltip,
      testId: TAB_KEYS.SIMPLE
    }, {
      key: TAB_KEYS.ADVANCED,
      label: tabTexts.advancedScheduleLabel,
      tooltip: currTabKey === TAB_KEYS.SIMPLE && tabTexts.advancedScheduleTooltip,
      testId: TAB_KEYS.ADVANCED
    }];
  }, [tabTexts]);
  const onSelect = useCallback(({
    key
  }) => {
    if (key === TAB_KEYS.SIMPLE) {
      onUseSimpleScheduler();
    }
    setCurrTabKey(key);
  }, [onUseSimpleScheduler]);
  useEffect(() => {
    if (selectedTabKey) {
      setCurrTabKey(selectedTabKey);
    }
  }, [selectedTabKey]);
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsx(Tabs, {
      options: tabOptions,
      selectedKey: currTabKey,
      onSelect: onSelect,
      testId: "scheduler-tabs",
      isDisabled: isDisabled
    }), currTabKey === TAB_KEYS.SIMPLE && /*#__PURE__*/_jsx(SimpleScheduler, {
      onUpdateSchedule: onUpdateSchedule,
      initialSchedule: initialSchedule,
      frequencyOptions: frequencyOptions,
      validateArrayOfRangedNumbersOrAll: validateArrayOfRangedNumbersOrAll,
      daysOfWeek: daysOfWeek,
      months: months,
      labelTexts: labelTexts,
      validationTexts: validationTexts,
      isDisabled: isDisabled
    }, schedulerKey), currTabKey === TAB_KEYS.ADVANCED && /*#__PURE__*/_jsx(AdvancedScheduler, {
      onUpdateSchedule: onUpdateSchedule,
      initialSchedule: initialSchedule,
      validateArrayOfRangedNumbersOrAll: validateArrayOfRangedNumbersOrAll,
      labelTexts: labelTexts,
      infoTexts: advancedSchedulerInfoTexts,
      isDisabled: isDisabled
    }, schedulerKey)]
  });
}