import React from 'react'; import { FormControlLabel, Checkbox, Box, useTheme } from '@material-ui/core'; import { useTranslation } from 'react-i18next'; import { ICertificateViewItem } from '@energyweb/origin-ui-core'; import { CertificateGroup } from './CertificateGroup'; import { IOriginTypography } from '../../types/typography'; import { MyDevice } from '../../types'; interface IOwnProps { groups: { [key: string]: ICertificateViewItem[] }; selected: ICertificateViewItem[]; setSelected: (certs: ICertificateViewItem[]) => void; devices: MyDevice[]; } export const GroupedCertificateList = (props: IOwnProps) => { const { groups, selected, setSelected, devices } = props; const certificates = Array.from( Object.values(groups).reduce((total, certs) => total.concat(certs), []) ); const fontSizeMd = ((useTheme().typography as unknown) as IOriginTypography)?.fontSizeMd; const { t } = useTranslation(); const isAllSelected = (): boolean => { if (certificates.length === 0) { return false; } for (const cert of certificates) { if (!selected.find((s) => s.id === cert.id)) { return false; } } return true; }; const toggleSelectAll = () => { if (isAllSelected()) { return setSelected([]); } return setSelected([...certificates]); }; return ( } label={ {t('certificate.actions.selectAll')} } /> {Object.keys(groups).map((facility, index, arr) => ( ))} ); };