"use client";

import React, { useEffect, useState } from "react";
import { Toast, Image } from "antd-mobile";
import { useRouter } from "next/navigation";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft } from "@fortawesome/free-solid-svg-icons";
import requireAPI from "@/utils/requireAPI";
import LoadingMask from "@/components/LoadingMask";
import { get, clear } from "@/utils/storeInfo";
export default function JoinEntrance() {
  const router = useRouter();
  const [guildState, setGuildState] = useState(null);
  const [isLoading, setIsLoading] = useState(true);
  const [account, setAccount] = useState(null);

  useEffect(() => {
    const getAccount = async () => {
      const account = await get("account");
      if (account) {
        setAccount(account);
        checkGuildState();
      }
    };
    getAccount();
  }, []);
  const checkGuildState = async () => {
    setIsLoading(true);
    //上传表单
    try {
      const streamerData = await requireAPI(
        "POST",
        "/api/guild_registration/list",
        null,
        true
      );
      if (streamerData.ret === -1) {
        Toast.show({
          icon: "fail",
          content: streamerData.msg,
          position: 60,
        });
        return;
      }
      setGuildState(streamerData.data.list[0]?.status);
    } catch (error) {
      console.error(error);
    } finally {
      setIsLoading(false);
    }
  };
  return (
    <div>
      {/* 头部标题 */}
      <div className="p-4 fixed top-0 z-10 w-full bg-black flex justify-between items-center">
        <div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full">
          <FontAwesomeIcon
            icon={faAngleLeft}
            style={{ maxWidth: "12px" }}
            size="xl"
            onClick={() => {
              router.back();
            }}
          />
        </div>
        <p className="text-base text-center leading-9">申请入驻</p>
        <div></div>
      </div>
      {/* 内容 */}
      <div className="h-screen relative">
        <div className="absolute inset-x-0 bottom-24 top-24 flex flex-col items-center justify-center gap-12">
          <div
            className="max-w-80"
            onClick={() => account?.role !== 3 && router.push("joinStreamer")}
          >
            <Image
              src={
                process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
                `/images/${
                  account?.role === 3 ? "streamerJoined" : "streamerJoin"
                }.png`
              }
              placeholder=""
            />
          </div>
          <div className="max-w-80" onClick={() => router.push("joinGuild")}>
            <Image
              src={
                process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
                `/images/${guildState === 0 ? "guildJoined" : "guildJoin"}.png`
              }
              placeholder=""
            />
          </div>
          {/* <Button
            size="middle"
            shape="rounded"
            block
            style={{
              backgroundImage: "url(../../../../images/streamerJoin.png)",
              paddingLeft: "32px",
              paddingRight: "32px",
            }}
            disabled={guildState === 0}
            onClick={() => router.push("joinGuild")}
          >
            {guildState === 0 ? "已提交，资料审核中..." : "我是公会"}
          </Button> */}
        </div>
        <LoadingMask isLoading={isLoading} />
      </div>
    </div>
  );
}
