import services from '@/services';
import { useRequest } from '@umijs/max';
import { useMemo } from 'react';
import CustomCard from '../../components/CustomCard';
import styles from './index.less';
import IndustryWiget from './IndustryWiget';
import WarnWiget from './WarnWiget';
const IndustryWarn = ({ data }: { data: any }) => {

  //环卫固废
  const { data: hwgf } = useRequest(services.CityRiskApi.catalogData, {
    defaultParams: [
      {
        typeCode: 'aq-hwgf',
        id: '1864283207541977090',
      },
    ],
  });

  //道路桥梁
  const dlql = useMemo(() => {
    // return data?.find((item: any) => item?.typeCode === 'dlql');
    return {
      typeCode: 'dlql',
      typeName: '道路桥梁',
      parentCode: null,
      total: '50',
      children: [
        {
          typeCode: 'dl',
          typeName: '道路',
          parentCode: 'dlql',
          total: '0',
          children: [
            {
              typeCode: '342',
              typeName: '涵洞',
              parentCode: 'dl',
              total: '1',
              children: [],
            },
          ],
        },
        {
          typeCode: 'ql',
          typeName: '桥梁',
          parentCode: 'dlql',
          total: '50',
          children: [
            {
              typeCode: '338',
              typeName: '跨河桥 ',
              parentCode: 'ql',
              total: '--',
              children: [],
            },
            {
              typeCode: '339',
              typeName: ' 跨线桥',
              parentCode: 'ql',
              total: '--',
              children: [],
            },
            {
              typeCode: '340',
              typeName: '互通式立交桥',
              parentCode: 'ql',
              total: '--',
              children: [],
            },
            {
              typeCode: '341',
              typeName: '人行天桥',
              parentCode: 'ql',
              total: '--',
              children: [],
            },
          ],
        },
        {
          typeCode: 'rwhw',
          typeName: '损坏管控点',
          parentCode: 'dlql',
          total: '0',
          children: [],
        },
        {
          typeCode: 'whzz',
          typeName: '维护作业',
          parentCode: 'dlql',
          total: '0',
          children: [],
        },
      ],
    };
  }, [data]);
  //城市环卫
  const hw = useMemo(() => {
    // return data?.find((item: any) => item?.typeCode === 'hw');
    return {
      typeCode: 'hw',
      typeName: '环卫',
      parentCode: null,
      total: hwgf?.data?.records?.[0]?.fxys ?? '--',
      children: [
        {
          typeCode: 'dl',
          typeName: '环卫设施',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.hwss ?? '--',
        },
        {
          typeCode: 'dl',
          typeName: '环卫公厕',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.hwgc ?? '--',
        },
        {
          typeCode: 'dl',
          typeName: '环卫车辆',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.hwcl ?? '--',
        },
        {
          typeCode: 'dl',
          typeName: '环卫车辆',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.hwzl ?? '--',
        },
      ],
    };
  }, [data, hwgf]);
  //固废
  const gf = useMemo(() => {
    // return data?.find((item: any) => item?.typeCode === 'gf');
    return {
      typeCode: 'gf',
      typeName: '固废',
      parentCode: null,
      total: '--',
      children: [
        {
          typeCode: 'dl',
          typeName: '固废设备',
          parentCode: 'dlql',
          total: '--',
        },
        {
          typeCode: 'dl',
          typeName: '生产作业',
          parentCode: 'dlql',
          total: '--',
        },
      ],
    };
  }, [data]);

 

 
  const { data:dlqlTotal } = useRequest(() => {
    return services.CityRiskApi.getstatisticalEvent({
      parentTypeCode: 'dlql',
    });
  });
  
  const { data:hwTotal } = useRequest(() => {
    return services.CityRiskApi.getstatisticalEvent({
      parentTypeCode: 'hw',
    });
  });

  
  return (
    <div className={styles.container}>
      <CustomCard
        title="道路桥梁"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={
          <div className={styles.riskCount}>风险源数&nbsp;{dlql?.total}</div>
        }
      >
        <div className={styles.content}>
          <div className={styles.warp}>
            {dlql?.children?.map((item: any) => {
              return (
                <IndustryWiget
                  data={{
                    ...item,
                    icon: require('@/assets/images/SecurityServiceOverview/qiaoliang.png'),
                    typeCode: dlql?.typeCode,
                    parentData: dlql,
                  }}
                  style={{ width: 170 }}
                />
              );
            })}
          </div>
          <div>
            <WarnWiget typeCode={dlql?.typeCode} yj={dlqlTotal?.monthEventTotal} cy={dlqlTotal?.yxcEventTotal} />
          </div>
        </div>
      </CustomCard>
      <CustomCard
        title="城市环卫"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={
          <div className={styles.riskCount}>风险源数&nbsp;{hw?.total}</div>
        }
      >
        <div className={styles.content}>
          <div className={styles.warp}>
            {hw?.children?.map((item: any) => {
              return (
                <IndustryWiget
                  data={{
                    ...item,
                    icon: require('@/assets/images/SecurityServiceOverview/huweiIcon.png'),
                    typeCode: hw?.typeCode,
                    parentData: hw,
                  }}
                  style={{ width: 100 }}
                />
              );
            })}
          </div>
          <div>
            <WarnWiget
              typeCode={hw?.typeCode}
              // yj={hwgf?.data?.records?.[0]?.yj}
              // cy={hwgf?.data?.records?.[0]?.ycz}
              yj={hwTotal?.monthEventTotal} cy={hwTotal?.yxcEventTotal}
            />
          </div>
        </div>
      </CustomCard>
      <CustomCard
        title="固废处置"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={
          <div className={styles.riskCount}>风险源数&nbsp;{gf?.total}</div>
        }
      >
        <div className={styles.content}>
          <div className={styles.warp}>
            {gf?.children?.map((item: any) => {
              return (
                <IndustryWiget
                  data={{
                    ...item,
                    icon: require('@/assets/images/SecurityServiceOverview/feigu.png'),
                    typeCode: gf?.typeCode,
                    parentData: gf,
                  }}
                  style={{ width: 100 }}
                />
              );
            })}
          </div>
          <div>
            <WarnWiget typeCode={gf?.typeCode} />
          </div>
        </div>
      </CustomCard>
    </div>
  );
};
export default IndustryWarn;
