import './index.scss'
import Taro from '@tarojs/taro';
import {useEffect, useState} from "react";
import {getSiteInfo} from "@/api/layout";
import Login from "./Login";
import Banner from "./Banner";
import Menu from "./Menu";
import Image from "./Image";
import SimpleH5TabBar from "@/components/SimpleH5TabBar";

function Home() {
    const [loading, setLoading] = useState<boolean>(false)
    const [IsLogin, setIsLogin] = useState<boolean>(true)
    const [search, setSearch] = useState(false)

    // 登录成功后回调
    const handleLogin = () => {
        setIsLogin(true)
        Taro.showTabBar()
        reload();
    }

    const reload = async () => {
        setLoading(true)
        if (!Taro.getStorageSync('access_token')) {
            return false;
        }
        console.log(loading)
    };

    useEffect(() => {
        Taro.hideTabBar()
        // 获取站点信息
        getSiteInfo().then((data) => {
            console.log(data, 'siteInfo')
            if (data.search) {
                setSearch(false);
            }
        })
    }, []);

    return (
        <div className="mobile-container">
            {!IsLogin && search ? (<Login done={handleLogin}/>) : (<>
                <Image/>
                <Menu/>
                <Banner/>
            </>)}
            {/* H5模式下显示自定义TabBar */}
            {process.env.TARO_ENV === 'h5' && <SimpleH5TabBar current={0} />}
        </div>
    )
}

export default Home
