import * as React from 'react';
import Request from '../utils/request';
interface basicHooksStateprops {
  loading: boolean;
}

export const useEnvironmentalMonitoring = () => {
  const [state, setState] = React.useState<{
    loading: boolean;
    dataSource: {
      b03: number;
      date: number;
      h01: number;
      p01: number;
      pm10: number;
      pm25: number;
      r01: number;
      t01: number;
      tsp: number;
      w01: number;
      w02: number;
    };
  }>({
    loading: false,
    dataSource: {
      b03: 0,
      date: 0,
      h01: 0,
      p01: 0,
      pm10: 0,
      pm25: 0,
      r01: 0,
      tsp: 0,
      w01: 0,
      t01: 0,
      w02: 0,
    },
  });
  const request = () => {
    setState((preState) => ({ ...preState, loading: true }));
    Request.sendRequest({
      url: '/v1/dust/last',
    })
      .then((data: any) => {
        setState((preState) => ({
          ...preState,
          loading: false,
        }));
      })
      .catch((error) => {
        setState((preState) => ({ ...preState, loading: false }));
      });
  };
  return [state, request] as const;
};
