"use client";
import Box from "@/components/Box";
import Header from "@/components/Header";
import { usePathname } from "@/i18n";
import { FC, PropsWithChildren, ReactNode, useEffect } from "react";

type Props = {
    swiperWidget: ReactNode;
    popupWidget: ReactNode;
    cardWidget: ReactNode;
    noticeWidget: ReactNode;
    searchWidget: ReactNode;
    prizeWidget: ReactNode;
    actionWidget: ReactNode;
};
const Layout: FC<PropsWithChildren<Props>> = (props) => {
    const {
        children,
        swiperWidget,
        popupWidget,
        cardWidget,
        noticeWidget,
        searchWidget,
        prizeWidget,
        actionWidget,
    } = props;

    // 获取分享id
    const pathname = usePathname();
    useEffect(() => {
        const [, shareId] = pathname.split("/");
        if (!shareId || shareId === "xxxxxx") return;
        sessionStorage.setItem("shareId", shareId);
    }, []);
    return (
        <>
            <Header></Header>
            <main id="maincontainer" className={"main-footer-header"}>
                {/*弹窗*/}
                {popupWidget}
                <Box>
                    {/* swiper */}
                    {swiperWidget}
                    {/* swiper下的活动 */}
                    {cardWidget}
                    {/* 跑马灯 */}
                    {noticeWidget}
                    {/* 搜索组件 */}
                    {searchWidget}
                    {/* 搜索下面的大奖展示 */}
                    {prizeWidget}
                </Box>
                {/* tabs 和 游戏列表 */}
                {children}
                {/*底部信息*/}
                {actionWidget}
            </main>
        </>
    );
};

export default Layout;
