// ** React Imports import { useState, SyntheticEvent, Fragment, ReactNode } from 'react' // ** MUI Imports import Box from '@mui/material/Box' import Badge from '@mui/material/Badge' import Button from '@mui/material/Button' import IconButton from '@mui/material/IconButton' import { styled, Theme } from '@mui/material/styles' import useMediaQuery from '@mui/material/useMediaQuery' import MuiMenu, { MenuProps } from '@mui/material/Menu' import MuiMenuItem, { MenuItemProps } from '@mui/material/MenuItem' import Typography, { TypographyProps } from '@mui/material/Typography' // ** Icon Imports import Icon from 'src/@core/components/icon' // ** Third Party Components import PerfectScrollbarComponent from 'react-perfect-scrollbar' // ** Type Imports import { ThemeColor } from 'src/@core/layouts/types' import { Settings } from 'src/@core/context/settingsContext' import { CustomAvatarProps } from 'src/@core/components/mui/avatar/types' // ** Custom Components Imports import CustomChip from 'src/@core/components/mui/chip' import CustomAvatar from 'src/@core/components/mui/avatar' // ** Util Import import { getInitials } from 'src/@core/utils/get-initials' export type NotificationsType = { meta: string title: string subtitle: string } & ( | { avatarAlt: string; avatarImg: string; avatarText?: never; avatarColor?: never; avatarIcon?: never } | { avatarAlt?: never avatarImg?: never avatarText: string avatarIcon?: never avatarColor?: ThemeColor } | { avatarAlt?: never avatarImg?: never avatarText?: never avatarIcon: ReactNode avatarColor?: ThemeColor } ) interface Props { settings: Settings notifications: NotificationsType[] } // ** Styled Menu component const Menu = styled(MuiMenu)(({ theme }) => ({ '& .MuiMenu-paper': { width: 380, overflow: 'hidden', marginTop: theme.spacing(4), [theme.breakpoints.down('sm')]: { width: '100%' } }, '& .MuiMenu-list': { padding: 0 } })) // ** Styled MenuItem component const MenuItem = styled(MuiMenuItem)(({ theme }) => ({ paddingTop: theme.spacing(3), paddingBottom: theme.spacing(3), '&:not(:last-of-type)': { borderBottom: `1px solid ${theme.palette.divider}` } })) // ** Styled PerfectScrollbar component const PerfectScrollbar = styled(PerfectScrollbarComponent)({ maxHeight: 344 }) // ** Styled Avatar component const Avatar = styled(CustomAvatar)({ width: 38, height: 38, fontSize: '1.125rem' }) // ** Styled component for the title in MenuItems const MenuItemTitle = styled(Typography)(({ theme }) => ({ fontWeight: 600, flex: '1 1 100%', overflow: 'hidden', fontSize: '0.875rem', whiteSpace: 'nowrap', textOverflow: 'ellipsis', marginBottom: theme.spacing(0.75) })) // ** Styled component for the subtitle in MenuItems const MenuItemSubtitle = styled(Typography)({ flex: '1 1 100%', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }) const ScrollWrapper = ({ children, hidden }: { children: ReactNode; hidden: boolean }) => { if (hidden) { return {children} } else { return {children} } } const NotificationDropdown = (props: Props) => { // ** Props const { settings, notifications } = props // ** States const [anchorEl, setAnchorEl] = useState<(EventTarget & Element) | null>(null) // ** Hook const hidden = useMediaQuery((theme: Theme) => theme.breakpoints.down('lg')) // ** Vars const { direction } = settings const handleDropdownOpen = (event: SyntheticEvent) => { setAnchorEl(event.currentTarget) } const handleDropdownClose = () => { setAnchorEl(null) } const RenderAvatar = ({ notification }: { notification: NotificationsType }) => { const { avatarAlt, avatarImg, avatarIcon, avatarText, avatarColor } = notification if (avatarImg) { return } else if (avatarIcon) { return ( {avatarIcon} ) } else { return ( {getInitials(avatarText as string)} ) } } return ( `0 0 0 2px ${theme.palette.background.paper}` } }} > Notifications `1px solid ${theme.palette.divider}` }} > ) } export default NotificationDropdown