import {useEffect, useState} from 'react'
import {CmsAd} from "@/api/cms/cmsAd/model";
import {pageCmsAd} from "@/api/cms/cmsAd";

const MyPage = () => {
    const [item, setItem] = useState<CmsAd>()
    const [image, setImage] = useState()
    const [height, setHeight] = useState<string>()
    const [width, setWidth] = useState<string>()

    const reload = () => {
        pageCmsAd({keywords: 'TopBanner'}).then(data => {
            if (data && data?.count > 0) {
                const cmsAd = data.list[0];
                setItem(cmsAd)
                console.log(item,'ad')
                setHeight(cmsAd.height)
                setWidth(cmsAd.width)
                if (cmsAd.imageList && cmsAd.imageList.length > 0) {
                    setImage(cmsAd.imageList[0].url)
                }
            }
        })
    }

    useEffect(() => {
        reload()
    }, [])

    return (
        <>
            <img src={image} alt="" style={{width: width + 'px', height: height + 'px'}}/>
        </>
    )
}
export default MyPage
