import CooglMap from '@/components/CooglMap';
import services from '@/services';
import { useModel, useRequest } from '@umijs/max';
import { memo, useMemo } from 'react';

const IndustryInode = ({ typeCode }: { typeCode?: string }) => {
  const { selectAreaId, industryModalData, setIndustryModalData } =
    useModel('safetyAreaId');
  //桥梁点位
  const { data: facility } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-qlmxlb',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  //道路点位
  const { data: dlInode } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-dllxfz',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  //垃圾转运站点位
  const { data: ljzyzInode } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-ljzymx',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  //环卫公厕点位
  const { data: hwgcInode } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-hwgcmx',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  //填埋厂点位
  const { data: tmcInode } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-hwgf-fylb',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
          factorytypecode: 'TMC',
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  //填埋厂点位
  const { data: cccInode } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-aq-hwgf-fylb',
        params: {
          regionCode: selectAreaId,
          pageNo: 1,
          pageSize: 50,
          factorytypecode: 'CCC',
        },
      }),
    {
      refreshDeps: [selectAreaId],
    },
  );
  const list = useMemo(() => {
    if (!typeCode) {
      return [
        ...facility?.data?.records,
        ...dlInode?.data?.records,
        ...ljzyzInode?.data?.records,
        ...hwgcInode?.data?.records,
        ...tmcInode?.data?.records,
        ...cccInode?.data?.records,
      ]?.filter((item) => !!item);
    }
    if (typeCode == 'dlql') {
      return [...facility?.data?.records, ...dlInode?.data?.records]?.filter(
        (item) => !!item,
      );
    }
    if (typeCode == 'hw') {
      return [
        ...ljzyzInode?.data?.records,
        ...hwgcInode?.data?.records,
      ]?.filter((item) => !!item);
    }
    if (typeCode == 'gf') {
      return [...tmcInode?.data?.records, ...cccInode?.data?.records]?.filter(
        (item) => !!item,
      );
    }
  }, [typeCode, facility, dlInode, ljzyzInode, hwgcInode, tmcInode, cccInode]);
  return (
    <>
      {facility?.data?.records?.map((item: any, index: number) => {
        const point = [Number(item?.longitude), Number(item?.latitude)];
        return (
          <CooglMap.Marker
            key={index}
            onClick={() => {
              try {
                console.log(item);

                setIndustryModalData({
                  open: true,
                  title: item?.parentData?.typeName,
                  parentCode: item?.parentTypeCode,
                  typeCode: item?.parentTypeCode,
                  ...item,
                });
              } catch (error) {
                console.log(error);
              }
            }}
            position={point}
            icon={require('@/assets/images/SecurityServiceOverview/mapGroup/icon1.png')}
          ></CooglMap.Marker>
        );
        // return (
        //   <CooglMap.CustomOverlay
        //     key={index}
        //     position={point}
        //     onSet1={() => {
        //       try {
        //         console.log(item);

        //         setIndustryModalData({
        //           open: true,
        //           title: item?.parentData?.typeName,
        //           parentCode: item?.parentTypeCode,
        //           typeCode: item?.parentTypeCode,
        //           ...item,
        //         });
        //         // getqlJcDet({
        //         //   typeCode: 'zzcc-aq-qljcxx',
        //         //   data: {
        //         //     id: item.id,
        //         //     pageNo: 1,
        //         //     pageSize: 10,
        //         //   },
        //         // });
        //         // getqlDet({
        //         //   typeCode: 'zzcc-aq-qlxx',
        //         //   params: {
        //         //     id: item.id,
        //         //   },
        //         // });
        //         // run({ id: item?.id });
        //       } catch (error) {
        //         console.log(error);
        //       }
        //     }}
        //   >
        //     <img
        //       data-event-key="set1"
        //       src={
        //         items?.find(
        //           (it) => it.typeCode === searchParams.parentTypeCode,
        //         )?.icon ??
        //         require('@/assets/images/SecurityServiceOverview/mapGroup/icon1.png')
        //       }
        //       alt=""
        //       style={{ width: 52, height: 52, zIndex: 999 }}
        //     />
        //   </CooglMap.CustomOverlay>
        // );
      })}
    </>
  );
};
export default memo(IndustryInode);
