import { GridColDef } from "@mui/x-data-grid";
import DataGrid from "@kitUI/datagrid";
import { Typography } from "@mui/material";
import { useCombinedPrivileges } from "@root/hooks/useCombinedPrivileges.hook";
import { addMergedPrivileges } from "@root/stores/mergedPrivileges";

const columns: GridColDef[] = [
  { field: "id", headerName: "id", width: 40 },
  { field: "name", headerName: "Привелегия", width: 150 },
  { field: "description", headerName: "Описание", width: 550 }, //инфо из гитлаба.
  { field: "type", headerName: "Тип", width: 150 },
  { field: "price", headerName: "Стоимость", width: 100 },
];

export default function Privileges() {
  const { mergedPrivileges, isError, errorMessage } = useCombinedPrivileges();
  const privilegesGridData = mergedPrivileges.map((privilege) => ({
    id: privilege.privilegeId,
    name: privilege.name,
    description: privilege.description,
    type: privilege.type,
    price: privilege.price,
  }));

  addMergedPrivileges(mergedPrivileges, isError, errorMessage);

  return (
    <>
      {isError ? (
        <Typography>{errorMessage}</Typography>
      ) : (
        <DataGrid
          // checkboxSelection={true}
          rows={privilegesGridData}
          columns={columns}
        />
      )}
    </>
  );
}
