import services from '@/services';
import { useRequest } from 'ahooks';
import { useState } from 'react';

/**
 * 地区指数
 * @module TheOperationOfTheDistrictCityAndCounty
 * @description 地区列表的管理
 *
 */
const useRegionalIndex = () => {
  const [areaListDto, setAreaListDto] = useState<
    DistrictAPI.RealtimeIndexDTO[]
  >([]);

  /** 当前选择的区市县 */
  const [selectDistrict, setSelectDistrict] =
    useState<DistrictAPI.RealtimeIndexDTO>();

  /** 列表加载状态 */
  const [loading, setLoading] = useState(false);

  /** 获取地区列表 */
  const getAreaListDto = async (params:any) => {
    setLoading(true);

    services.districtController
      .getDistrictIndexList(params)
      .then((res) => {
        setAreaListDto(res.data);
      })
      .finally(() => {
        setLoading(false);
      });
  };
  /**区县指数 */
  const { data: indexs, run: getIndexs } = useRequest(
    services.Physicalsign.getComparisonIndexInstance,
    {
      manual: true,
    },
  );

  return {
    areaListDto,
    loading,
    getAreaListDto,
    selectDistrict,
    setSelectDistrict,
    indexs: indexs?.data?.currentIndex,
    getIndexs,
  };
};

export default useRegionalIndex;
