import { Dispatch, FC, SetStateAction } from "react";

import { eventContextMenu, eventSummary } from "shared/lib/slickgrid";

import Styled from "../ContextMenu.style";

export const ButtonSummary: FC<IProps> = ({ setIsOpened }) => {
	const table = eventContextMenu.table;
	const grid = table?.grid;
	const selectedRows = grid?.getSelectedRows();

	function openSummary() {
		if (!table) return;
		setIsOpened(false);
		eventSummary.table = table;
		eventSummary.open = true;
		eventSummary.x = eventContextMenu.x;
		eventSummary.y = eventContextMenu.y;
	}

	if (!table?.summaryColumnIds.length || Number(selectedRows?.length) < 2)
		return null;

	return (
		<Styled.Li onClick={openSummary}>
			<Styled.Icon
				className={"sgi sgi-checkbox-multiple-outline"}
			></Styled.Icon>
			Summary
		</Styled.Li>
	);
};

interface IProps {
	setIsOpened: Dispatch<SetStateAction<boolean>>;
}
