import { useState, useEffect } from 'react'
import { getChannelStatReport } from '@/services/agent'
import { fillTime } from '../utils'

const now = new Date()

export default function useReport() {
  const [reportDateRange, setReportDateRange] = useState([now.toJSON().substring(0, 10), now.toJSON().substring(0, 10)])
  const [reportInfo, setReportInfo] = useState({})

  useEffect(() => {
    const [startDate, endDate] = reportDateRange
    getChannelStatReport({
      startDate: fillTime(startDate, true),
      endDate: fillTime(endDate, false),
    }).then((res) => {
      setReportInfo(res || {})
    })
  }, [reportDateRange])

  return [reportDateRange, setReportDateRange, reportInfo]
}
