import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import ListItemAvatar from '@mui/material/ListItemAvatar';
import LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
import Divider from '@mui/material/Divider';
import { makeStyles } from '@material-ui/core'

import AlertInfo from '../../../../../../../reusableComponents/AlertInfo';
import { timeStampEU,handleDownload } from '../../../../../../../../helpers'
import { TMessages } from '../../../../../../../../typescript/redux/messages/types'

const useStyles = makeStyles({
    folderIcon: {
      color: '#54b0fc',
      cursor: 'pointer',
      '&:hover': {
        color: '#016cc3'
      },
  },
  listItem: {
    '&:hover': {
      backgroundColor: '#f0f0f0',
    }
  },  
})
const AudioList = ({ messagesMemo }: { messagesMemo: TMessages }) => {
  const classes = useStyles()
    const filteredMessagesMemo =  messagesMemo.filter(({type}) => type === 'audio')
    return filteredMessagesMemo.length > 0 ?(
      <List>
        {filteredMessagesMemo.map(({ message, createdAt, fullType }) =>
          <div key={createdAt}>
            <ListItem alignItems="flex-start" className={classes.listItem}>
              <ListItemAvatar>
                <LibraryMusicIcon onClick={() =>
                  handleDownload(`http://localhost:3000/${message}`, fullType)}
                  className={classes.folderIcon} fontSize='large' />
              </ListItemAvatar>
              <ListItemText
                primary={fullType}
                secondary={timeStampEU(createdAt)}
               />
            </ListItem>
            <Divider variant="inset"/>
        </div>)}
    </List>
   ): <AlertInfo name='You do not have Audio yet!'/>  
}

export default AudioList