import services from '@/services';
import { useRequest } from 'ahooks';
import { csxq, jqxc, zxcq } from '../../../AdministPunish/NumTop5';

const useRoadBridgeData = () => {
  //桥梁总数
  const { data: bridgeTotal } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-qsqlzszmj',
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0];
      }
      throw new Error('获取数据失败');
    }),
  );
  //道路总数
  const { data: roadTotal } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-qsdlzs',
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0];
      }
      throw new Error('获取数据失败');
    }),
  );
  //道路新城城面积
  const { data: newCityRoadTotal=0 } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-qycxdlmj',
      params: {
        regionName: csxq.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0]?.mj;
      }
      throw new Error('获取数据失败');
    }),
  );
  //道路中心城区面积
  const { data: coreRoadTotal=0 } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-qycxdlmj',
      params: {
        regionName: zxcq.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0]?.mj;
      }
      throw new Error('获取数据失败');
    }),
  );
  //郊区道路面积
  const { data: suburbRoadTotal=0 } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-qycxdlmj',
      params: {
        regionName: jqxc.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0]?.mj;
      }
      throw new Error('获取数据失败');
    }),
  );

   //桥梁新城面积
   const { data: newCityBridgeTotal=0 } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-aqycxqlsl',
      params: {
        regionName: csxq.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        console.log(res);
        
        return res?.data?.data?.records?.[0]?.num;
      }
      throw new Error('获取数据失败');
    }),
  );

  //桥梁中心城区面积
  const { data: centerBridgeTotal =0} = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-aqycxqlsl',
      params: {
        regionName: zxcq.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0]?.num;
      }
      throw new Error('获取数据失败');
    }),
  );
   //桥梁郊区面积
   const { data:  suburbBridgeTotal=0 } = useRequest(() =>
    services.DataBase.getSjdzInfoData({
      typeCode: 'zzcc-dq-aqycxqlsl',
      params: {
        regionName: jqxc.join(','),
      },
    }).then((res) => {
      if (res.code === 200) {
        return res?.data?.data?.records?.[0]?.num;
      }
      throw new Error('获取数据失败');
    }),
  );
  return {
    bridgeTotal,
    roadTotal,
    newCityRoadTotal,
    coreRoadTotal,
    suburbRoadTotal,
    newCityBridgeTotal,
    centerBridgeTotal,
    suburbBridgeTotal
  };
};
export default useRoadBridgeData;
