import React, { useCallback } from "react";

import { VirtualGridList } from "@enact/sandstone/VirtualList";

import { scaleH, scaleW } from "../../../../utils/helperMethods";
import UpComingCard from "./UpComingCard/UpComingCard";
import css from "./UpComingList.module.less";

const LIST_ITEM_CONF = {
  ITEM_WIDTH: 480,
  ITEM_HEIGHT: 344,
  SAPCING: 18,
};

export default function UpComingList({ brandLiveChannelUpcoming }) {
  const renderItem = useCallback(
    ({ index, ...rest }) => {
      const {
        hstNm: hostName,
        showNm: showName,
        strtDt: startTime,
      } = brandLiveChannelUpcoming[index];
      return (
        <UpComingCard
          {...rest}
          hostName={hostName}
          showName={showName}
          startTime={startTime}
        />
      );
    },
    [brandLiveChannelUpcoming]
  );

  return (
    <div className={css.container}>
      {brandLiveChannelUpcoming && (
        <VirtualGridList
          className={css.virtualGridList}
          dataSize={brandLiveChannelUpcoming.length}
          direction="horizontal"
          itemRenderer={renderItem}
          itemSize={{
            minWidth: scaleW(LIST_ITEM_CONF.ITEM_WIDTH),
            minHeight: scaleH(LIST_ITEM_CONF.ITEM_HEIGHT),
          }}
          noScrollByWheel
          scrollMode="translate"
          spacing={scaleW(LIST_ITEM_CONF.SAPCING)}
          verticalScrollbar="hidden"
        />
      )}
    </div>
  );
}
