import services from '@/services';
import dayjs from 'dayjs';
import React, { useEffect, useState } from 'react';
import styles from './index.less';
import LineCharts from './LineCharts';

const ComplaintTrend: React.FC = () => {
  const [statisticRecent, setStatisticRecent] = useState<any>([]);

  const getDate = () => {
    const oneMonthAgo = dayjs().subtract(1, 'month');
    return {
      startTime: oneMonthAgo.format('YYYY-MM-DD'),
      endTime: dayjs().format('YYYY-MM-DD'),
    };
  };

  const getData = async () => {
    const resp = await services.DataBase.getSjdzInfoData({
      typeCode: 'quhs-jqqs',
      params: {
        ...getDate(),
      },
    });
    if (resp.code === 200) {
      setStatisticRecent(resp.data?.data?.records);
    }
  };

  useEffect(() => {
    getData();
  }, []);

  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <span className={styles.title}>投诉趋势</span>
      </div>
      <div className={styles.content}>
        <LineCharts dataSource={statisticRecent} />
      </div>
    </div>
  );
};

export default ComplaintTrend;
