import { BannerRep } from "@/api/home";
import Empty from "@/components/Empty";
import { server } from "@/utils/server";

import Popup from "@/app/[locale]/(TabBar)/(entire)/promo/Popup";
import Box from "@/components/Box";
const getPromotionApi = async () => {
    return server
        .request<BannerRep[]>({
            url: "/v1/api/front/activity_promotion",
            method: "post",
        })
        .then((res) => {
            if (res.code === 200) return res.data;
            return [];
        });
};
const Promo = async () => {
    const promotion = await getPromotionApi();
    if (!promotion.length) return <Empty />;
    return (
        <>
            {promotion.map((item, index) => (
                <Box key={item.id} action={item.action_type} actionData={item.action_params}>
                    <img
                        width={0}
                        height={0}
                        src={item.content!}
                        alt={"Image"}
                        className={"h-[1.16rem] w-[100%] rounded-[0.0833rem]"}
                    />
                </Box>
            ))}
            <Popup />
        </>
    );
};

export default Promo;
