import ImageList from '@mui/material/ImageList';
import { makeStyles } from '@material-ui/core'

import MediaListItem from './MediaListItem';
import AlertInfo from '../../../../reusableComponents/AlertInfo';
import { TAllMessages } from '../../../../../typescript/redux/allMessages/types'

const useStyles = makeStyles({
  container: {
    width: '100%',
    maxHeight: '840px',
    overflowY: 'scroll',
  '&::-webkit-scrollbar': {
    width: '0.4em'
  },
  '&::-webkit-scrollbar-track': {
    boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
    webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
    backgroundColor: '#eceeec',
  },
  '&::-webkit-scrollbar-thumb': {
    backgroundColor: '#ccc8c8',
    },
  "&::-webkit-scrollbar-thumb:focus": {
    backgroundColor: "#959595",
          },
  "&::-webkit-scrollbar-thumb:active": {
    backgroundColor: "#959595",
    },
  },  
})

const MediaList = ({ allMessagesMemo,value }: { allMessagesMemo: TAllMessages,value:string }) => {
  const classes = useStyles()
  const filteredMessagesMemo =  allMessagesMemo.filter(({ type }) => type === 'image')
  return (
    <>
      <ImageList className={classes.container} cols={3} rowHeight={164}>
        {filteredMessagesMemo.map(({message,createdAt,fullType,updatedAt}) => 
          <MediaListItem key={createdAt} message={message} fullType={fullType} updatedAt={updatedAt}/>)}
      </ImageList>
      {value &&  filteredMessagesMemo.length === 0 && <AlertInfo name={`Can not find Media by request: ${value}`} />}
      {!value && filteredMessagesMemo.length === 0 && <AlertInfo name='You do not have Media yet!'/>}
     </>
   )
}

export default MediaList