import moment from 'moment';
import { DateAndTimeFormat } from 'components/DashboardTable/constants';
import { TRotationSettingSubmit } from './types';

export const prepareDataBeforeSubmit = (
  values: TRotationSettingSubmit,
): {
  rotation_type: number;
  size_rotation?: number;
  schedule?: {
    period?: string;
    time?: string;
    week_day?: string[];
    month?: string[];
  };
} => {
  const prepareData = {
    ...values,
    rotation_type: +values.rotation_type,
  };

  if (
    prepareData &&
    prepareData.schedule &&
    values.schedule &&
    values.schedule.time
  ) {
    prepareData.schedule.time = moment(
      values.schedule.time,
      DateAndTimeFormat.HM,
    ).format(DateAndTimeFormat.HM);
  }

  return prepareData;
};
