import React, {
  useEffect,
  useState,
} from 'react';

import HomeTodayDeal from '../HomeTodayDeal/HomeTodayDeal';

export default function RandomUnit({ bannerData, imageType }) {
  const bannerDetailInfos = bannerData.bannerDetailInfos;
  const [randomData, setRandomData] = useState([]);

  useEffect(() => {
    if (bannerData) {
      const leng = bannerDetailInfos.length;
      const num = Math.floor(Math.random() * leng);
      setRandomData(bannerDetailInfos[num]);
    }
  }, [bannerData]);
  // 추후 변경
  return (
    <>
      {randomData.shptmBanrTpNm == "Image Banner" ? (
        <p>TEST</p>
      ) : randomData.shptmBanrTpNm == "LIVE" ||
        randomData.shptmBanrTpNm == "VOD" ? (
        <p>비디오</p>
      ) : randomData.shptmBanrTpNm == "Today's Deals" ||
        randomData.shptmBanrTpNm == "" ? (
        <HomeTodayDeal
          imgAlt={randomData.imgAlt}
          imageName={randomData.tmnlImgNm}
          imgPath={randomData.tmnlImgPath}
          priceInfo={randomData.priceInfo}
          productId={randomData.prdtId}
          productName={randomData.prdtNm}
          soldoutFlag={randomData.soldoutFlag}
          isHorizontal={imageType}
        />
      ) : null}
    </>
  );
}
