// @@@ 포커스 처리 남음
import React, { useEffect } from 'react';

import classNames from 'classnames';

import Spotlight from '@enact/spotlight';
import SpotlightContainerDecorator
  from '@enact/spotlight/SpotlightContainerDecorator';
import Spottable from '@enact/spotlight/Spottable';

import css from './TCFI_4.module.less';

const SpottableComponent = Spottable("li");

const Container = SpotlightContainerDecorator(
  { enterTo: "last-focused", preserveId: true },
  "ul"
);
export default function TCFI_4({ className, data }) {
  useEffect(() => {
    if (data) {
      const productInfos = data[0].productInfos[0].prdtId;
      Spotlight.focus("spotlight" + productInfos);
    }
  }, [data]);
  return (
    <>
      {data &&
        data.map(({ bgImgPath, curationNm, tmpltCd, productInfos }) => {
          return (
            <div key={tmpltCd} className={classNames(className && className)}>
              <div className={css.fullImg}>
                <img src={bgImgPath} alt={curationNm} />
              </div>
              <Container className={css.itemList}>
                {productInfos &&
                  productInfos.slice(0, 4).map(({ imgUrl, prdtNm, prdtId }) => {
                    return (
                      <SpottableComponent
                        key={prdtId}
                        spotlightId={"spotlight" + prdtId}
                      >
                        <img src={imgUrl} alt={prdtNm} />
                      </SpottableComponent>
                    );
                  })}
              </Container>
            </div>
          );
        })}
    </>
  );
}
