import { ListSubheader, Typography } from '@mui/material'; import type React from 'react'; import type { HTMLAttributes, ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import { Button } from '../../../../components/Button'; import { labelElementsFound, labelSelectAll, labelUnSelectAll } from '../../../translatedLabels'; import type { SelectEntry } from '../..'; import { useListboxStyles } from './Multi.styles'; interface CustomListboxProps extends HTMLAttributes { children?: ReactNode; label: string; labelTotal: string; handleSelectAllToggle: () => void; } const CustomListbox = ({ children, label, labelTotal, handleSelectAllToggle, ...props }: CustomListboxProps) => { const { classes } = useListboxStyles(); return ( ); }; interface ListboxProps { disableSelectAll?: boolean; options: Array; isOptionSelected: (opt: SelectEntry) => boolean; onChange?: ( event: React.SyntheticEvent, value: Array, reason: string ) => void; total?: number; value?: Array; } const ListboxComponent = ({ disableSelectAll, options, isOptionSelected, onChange, total, value = [] }: ListboxProps) => { const { t } = useTranslation(); if (disableSelectAll) { return; } return ( listboxProps: HTMLAttributes ): JSX.Element | undefined => { const allSelected = options.length > 0 && options.every((opt) => isOptionSelected(opt)); const handleSelectAllToggle = (): void => { const syntheticEvent = {} as React.SyntheticEvent; if (allSelected) { const remaining = value.filter( (v) => !options.some((opt) => opt.id === v.id) ); onChange?.(syntheticEvent, remaining, 'selectOption'); return; } const merged = [ ...value, ...options.filter((opt) => !isOptionSelected(opt)) ]; onChange?.(syntheticEvent, merged, 'selectOption'); }; return ( ); }; }; export default ListboxComponent;