import { makeStyles } from "@material-ui/core/styles";
import { IconButton } from "@material-ui/core";
import VideoFileIcon from '@mui/icons-material/VideoFile';
import FileDownloadIcon from '@mui/icons-material/FileDownload';
import { timeStampMessage,handleDownload } from '../../../../../../helpers'

const { Player } = require('video-react')

const useStyles = makeStyles({
  container: {
      display: "flex",
      justifyContent: "flex-end",
      width:'auto',
      maxWidth: '80%',
      marginBottom:15
  },
  wrapper: {
    position: 'relative',
    display: 'flex',
    justifyContent: 'space-between',
    alignContent: 'center',
    alignItems: 'center',
    width: 400,
    padding: '12px 5px 12px 5px',
    backgroundColor: '#deffa9',
    borderRadius: 7,
      "&:after": {
        content: "''",
        position: "absolute",
        width: "0",
        height: "0",
        borderBottom: "15px solid #deffa9",
        borderLeft: "15px solid transparent",
        borderRight: "15px solid transparent",
        bottom: "0",
        right: "-15px"
      },
      "&:before": {
        content: "''",
        position: "absolute",
        width: "0",
        height: "0",
        borderBottom: "17px solid #deffa9",
        borderLeft: "16px solid transparent",
        borderRight: "16px solid transparent",
        bottom: "0px",
        right: "-17px"
      }    
  },
  bntDownload: {
    backgroundColor: '#deffa9',
    color: '#54b0fc',
    width: 30,
    height: 30,
    marginLeft:5,
    '&:hover': {
      backgroundColor: '#54b0fc',
      color:'#ffffff'
    }
  },
  time: {
      position: "absolute",
      fontSize: ".65em",
      fontWeight:600,
      bottom: 0,
      right: 6,
      color: '#414141',
      padding: 3,
      borderRadius: 5,
  },
  player: {
    backgroundColor: '#deffa9',
  }
});

interface IMessageRightVideo {
  url:string,
  updatedAt: string,
  fullType:string
}

const MessageRightVideo = ({ url,updatedAt,fullType }:IMessageRightVideo) => {
  const classes = useStyles();
 
  return (
    <div className={classes.container}>
      <div className={classes.wrapper}>
        <VideoFileIcon fontSize='large' style={{ color:'#03b003'}}/>         
        <Player className={classes.player}  playsInline  src={url}/>
        <IconButton onClick={() => handleDownload(url, fullType)} className={classes.bntDownload}  >
            <FileDownloadIcon fontSize='medium'/>
        </IconButton>
        <div className={classes.time}>{timeStampMessage(updatedAt)}</div>
      </div>
    </div>    
)};

export  default  MessageRightVideo
