import { UserInfoRep, UserVipInfo, Wallet } from "@/api/user";
import { server } from "@/utils/server";
import { FC } from "react";
import ItemCom from "./component/ItemCom";
import ModalCom from "./component/ModalCom";
import "./page.scss";
import { ProfileHeader } from "./ProfileHeader";

const getUserInfo = async () => {
    return server
        .request<UserInfoRep>({
            url: "/v1/api/user/user_info",
            method: "POST",
        })
        .then((res) => {
            console.log(`🚀🚀🚀🚀🚀-> in page.tsx on 16`, res);
            if (res.code === 200) return res.data;
            return {};
        });
};

const getMoneyApi = async () => {
    return server
        .request<Wallet>({
            url: "/v1/api/user/user_money",
            method: "POST",
        })
        .then((res) => {
            if (res.code === 200) return res.data;
            return {};
        });
};

/**
 * @description  前台用户VIP信息 接口地址：https://app.apifox.com/link/project/4790544/apis/api-201160713
 */
const getVipApi = async () => {
    return server
        .request<UserVipInfo>({
            url: "/v1/api/user/user_vip_info",
            method: "POST",
        })
        .then((res) => {
            if (res.code === 200) return res.data;
        });
};
interface Props {}
const Profile: FC<Props> = async () => {
    const userInfo = await getUserInfo();
    const userMoney = await getMoneyApi();
    const userVip = await getVipApi();
    return (
        <div className="profile-box">
            <ProfileHeader userInfo={userInfo} userMoney={userMoney} userVip={userVip!} />
            <ItemCom />
            <ModalCom />
        </div>
    );
};

export default Profile;
