import React, { useCallback, useEffect, useState } from "react";
import styles from "./index.module.scss";
import { A1_APIgetCover } from "@/store/action/A1Home";
import { addVisitFu } from "@/utils/storage";
import history from "@/utils/history";
import ImgLoding from "@/components/ImgLoding";
import { baseURL } from "@/utils/http";
import { imgLodingFu } from "@/pages/A0Map/data";
function HomeM() {
  const [cover, setCover] = useState("");

  const A1_APIgetCoverFu = useCallback(async () => {
    const res = await A1_APIgetCover('app');
    if (res.code === 0) {
      const urlObj = res.data.find((v: any) => v.isIndex === 1);
      setCover(urlObj.thumb || res.data[0].thumb);
    }
  }, []);

  useEffect(() => {
    A1_APIgetCoverFu();
  }, [A1_APIgetCoverFu]);

  useEffect(() => {
    // 进来页面 线上访客  访问量+1（23小时内）
    addVisitFu();
  }, []);

  return (
    <div className={styles.HomeM} onClick={() => history.push("/main")}>
      {/* 大图片加载中 */}
      <ImgLoding id={-1} />

      {cover ? (
        <img
          className="HomeBac"
          onLoad={() => imgLodingFu(-1)}
          src={baseURL + cover}
          alt=""
        />
      ) : null}

    </div>
  );
}

const MemoHomeM = React.memo(HomeM);

export default MemoHomeM;
