import { BannerRep } from "@/api/home";
import Empty from "@/components/Empty";
import { server } from "@/utils/server";
import PromoClient from "./PromoClient"; // 引入客户端组件

const getPromotionApi = async () => {
    return server
        .request<BannerRep[]>({
            url: "/v1/api/front/activity_promotion",
            method: "post",
            data: {},
        })
        .then((res) => {
            console.log('getPromotionApi', res);
            if (res.code === 200) return res.data;
            return [];
        });
};

const Promo = async () => {
    const promotion = await getPromotionApi();
    
    if (!promotion.length) return <Empty />;
    
    // 将促销数据传递给客户端组件
    return <PromoClient promotion={promotion} />;
};

export default Promo;
