import React, { useCallback } from "react";
import classes from "./classes.module.scss";
import Typography, { ITypo } from "../Typography";
import ChevronIcon from "@Assets/Icons/chevron.svg";
import Image from "next/image";

export type IBlock = {
	name: string;
	id: string;
};

type IProps = {
	blocks: IBlock[];
	onSelectedBlock: (block: IBlock) => void;
};
export default function BlockList({ blocks, onSelectedBlock }: IProps) {
	const selectBlock = useCallback(
		(e: React.MouseEvent<HTMLDivElement>) => {
			onSelectedBlock && onSelectedBlock(blocks.find((block) => block.id === e.currentTarget.id)!);
		},
		[blocks, onSelectedBlock],
	);
	return (
		<div>
			{blocks.map((block) => {
				return (
					<div onClick={selectBlock} key={block.id} id={block.id}>
						<div className={classes["root"]}>
							<div className={classes["left-side"]}>
								<Typography typo={ITypo.P_16}>{block.name}</Typography>
							</div>
							<Image alt="chevron" src={ChevronIcon} />
						</div>
					</div>
				);
			})}
		</div>
	);
}
