import React, { useCallback } from "react";

import VirtualGridList from "@enact/sandstone/VirtualList";
import SpotlightContainerDecorator from "@enact/spotlight/SpotlightContainerDecorator";
import ri from "@enact/ui/resolution";

import SearchShowCard from "./SearchShowCard/SearchShowCard";
import css from "./SearchShowResults.module.less";

const LIST_ITEM_CONF = {
  ITEM_WIDTH: 344 * 2,
  ITEM_HEIGHT: 281 * 2,
  SPACING: 0,
};

const Container = SpotlightContainerDecorator(
  { leaveFor: { right: "" }, enterTo: "last-focused" },
  "div"
);

export default function SearchShowResults({ showDatas, showCount, ...rest }) {
  const renderItem = useCallback(
    ({ index, ...rest }) => {
      const showData = showDatas[index];

      return (
        <SearchShowCard {...rest} key={showData.contentId} {...showData} />
      );
    },
    [showDatas]
  );

  return (
    <Container className={css.container}>
      {showDatas && (
        <VirtualGridList
          className={css.grid}
          dataSize={showDatas.length}
          direction="horizontal"
          itemRenderer={renderItem}
          itemSize={{
            minWidth: ri.scale(LIST_ITEM_CONF.ITEM_WIDTH),
            minHeight: ri.scale(LIST_ITEM_CONF.ITEM_HEIGHT),
          }}
          spacing={ri.scale(LIST_ITEM_CONF.SPACING)}
          scrollMode="translate"
          horizontalScrollbar="hidden"
          noScrollByWheel
        />
      )}
    </Container>
  );
}
