import { Button } from "@mui/material";
import { Dispatch, FC, SetStateAction } from "react";

import { eventHeaderContextMenu } from "shared/lib/slickgrid";

import { getHideableColumns, hideColumns } from "../../lib";

export const ButtonUncheckAll: FC<IProps> = ({ setHidden }) => {
	function onClick() {
		const table = eventHeaderContextMenu.table;
		if (!table) return;
		const columns = getHideableColumns(table);
		const columnIds = columns.map(({ id }) => id as string);
		setHidden(columnIds);
		hideColumns(columnIds);
	}

	return (
		<Button
			onClick={onClick}
			size={"small"}
			sx={{ textTransform: "none" }}
			variant={"contained"}
		>
			Uncheck all
		</Button>
	);
};

interface IProps {
	setHidden: Dispatch<SetStateAction<string[]>>;
}
