import services from '@/services';
import { useRequest } from '@umijs/max';
import { useMemo } from 'react';
import CustomCard from '../../components/CustomCard';
import DisposeFlow from './DisposeFlow';
import styles from './index.less';
import IndustryWiget from './IndustryWiget';
import StatusWiget from './StatusWiget';
const IndustryWarn = ({
  warnLevel,
  setWarnLevel,
}: {
  warnLevel: number;
  setWarnLevel: (val: number) => void;
}) => {
  //道路桥梁
  const { data: dq } = useRequest(services.DataBase.getSjdzInfoData, {
    defaultParams: [
      {
        typeCode: 'zzcc-aq-qldlsl',
      },
    ],
  });
  //环卫
  const { data: hwgf } = useRequest(services.DataBase.getSjdzInfoData, {
    defaultParams: [
      {
        typeCode: 'zzcc-aq-hwgcsl',
      },
    ],
  });
  //固废处置
  const { data: gfcz } = useRequest(services.DataBase.getSjdzInfoData, {
    defaultParams: [
      {
        typeCode: 'zzcc-aq-tmcfssl',
      },
    ],
  });
  //道路桥梁
  const dlql = useMemo(() => {
    // return data?.find((item: any) => item?.typeCode === 'dlql');
    return {
      typeCode: 'dlql',
      typeName: '道路桥梁',
      parentCode: null,
      total: '50',
      children: [
        {
          typeCode: 'zzcc-aq-dllxfz',
          typeName: '道路',
          parentCode: 'dlql',
          typeField: 'lb',
          total: dq?.data?.records?.[0]?.dl ?? '--',
          listTypeCode: 'zzcc-aq-dlmx',
          columnsFields: {
            name: 'roadname',
            type: 'jishuguanlifenlei',
            descgldw: 'guanlidanwei',
            address: 'region_name',
            status: 'objstate',
          },
        },
        {
          listTypeCode: 'zzcc-aq-qlmxlb',
          typeName: '桥梁',
          typeField: 'lx',
          parentCode: 'dlql',
          typeCode: 'zzcc-aq-qllxfz',
          total: dq?.data?.records?.[0]?.ql ?? '--',
        },
      ],
    };
  }, []);
  //城市环卫
  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',
          listTypeCode: 'zzcc-aq-ljzymx',
          typeName: '垃圾转运站',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.zyz ?? '--',
          columnsFields: {
            name: 'objcode',
            type: 'industry_name',
            descgldw: 'deptname1',
            address: 'region_name',
            status: 'objstate',
          },
        },
        {
          typeCode: 'dl',
          listTypeCode: 'zzcc-aq-hwgcmx',
          typeName: '环卫公厕',
          parentCode: 'dlql',
          columnsFields: {
            address: 'address',
            descgldw: 'yydw_name',
          },
          total: hwgf?.data?.records?.[0]?.hwgc ?? '--',
        },
        {
          typeCode: '',
          listTypeCode: 'zzcc-aq-qlmxlb',
          typeName: '环卫车辆',
          parentCode: 'dlql',
          total: hwgf?.data?.records?.[0]?.hwcl ?? '--',
        },
      ],
    };
  }, [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: gfcz?.data?.records?.[0]?.tmc ?? '--',
        },
        {
          typeCode: 'dl',
          typeName: '焚烧发电厂',
          parentCode: 'dlql',
          total: gfcz?.data?.records?.[0]?.fsfdc ?? '--',
        },
        {
          listTypeCode: 'zzcc-aq-cccmx',
          typeCode: 'dl',
          typeName: '餐厨厂',
          parentCode: 'dlql',
          total: gfcz?.data?.records?.[0]?.canchu ?? '--',
        },
      ],
    };
  }, []);

  return (
    <div className={styles.container}>
      <CustomCard
        title="道路桥梁"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={<StatusWiget industryCode="0401" />}
      >
        <div className={styles.content}>
          <div
            className={styles.warp}
            style={{
              display: 'flex',
              alignItems: 'flex-start',
              paddingTop: 38,
            }}
          >
            {dlql?.children?.map((item: any) => {
              return (
                <IndustryWiget
                  data={{
                    ...item,
                    icon: require('@/assets/images/SecurityServiceOverview/qiaoliang.png'),
                    // typeCode: dlql?.typeCode,
                    parentData: dlql,
                    warn: 33,
                  }}
                  // style={{ width: 170 }}
                />
              );
            })}
          </div>
          <div className={styles.flow}>
            <DisposeFlow industryCode="0401" />
          </div>
        </div>
      </CustomCard>
      <CustomCard
        title="环卫作业"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={<StatusWiget industryCode="0401" />}
      >
        <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: 150 }}
                />
              );
            })}
          </div>
          <div className={styles.flow}>
            <DisposeFlow industryCode="0401" />
          </div>
        </div>
      </CustomCard>
      <CustomCard
        title="固废处置"
        width={353}
        height={380}
        style={{
          paddingTop: 16,
          paddingRight: 18,
          backgroundColor: 'rgba(63, 149, 229, 0.1)',
        }}
        extra={<StatusWiget industryCode="0401" />}
      >
        <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 className={styles.flow}>
            <DisposeFlow industryCode="0401" />
          </div>
        </div>
      </CustomCard>
    </div>
  );
};
export default IndustryWarn;
