import type {RangeValue} from '@components';
import type {Dayjs} from 'dayjs';
import {useState} from 'react';

export function useRangeDate(
  startTime: Dayjs | null = null,
  endTime: Dayjs | null = null,
) {
  const [dates, setDates] = useState<RangeValue<Dayjs>>([startTime, endTime]);

  const start = dates?.[0]?.format('YYYY-MM-DD') ?? '',
    end = dates?.[1]?.format('YYYY-MM-DD') ?? '';

  return [{dates, start, end}, setDates] as const;
}
