import {useState, useEffect, useRef} from 'react' import {styled} from '@mui/material/styles' import PropTypes from 'prop-types' import {useSession} from 'next-auth/client' import { IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography, Tooltip, Zoom } from '@mui/material' import AddCommentIcon from '@mui/icons-material/AddComment' import {useRouter} from 'next/router' import Koneksyon from '../sesyon/koneksyon' import KomanteList from './komante-list' import EkriKomante from './ekri-komante' const PREFIX = 'vwe-komante' const classes = { tooltip: `${PREFIX}-tooltip`, margin: `${PREFIX}-margin`, extendedIcon: `${PREFIX}-extendedIcon` } const Root = styled('div')(( { theme } ) => ({ [`& .${classes.margin}`]: { margin: theme.spacing(1) }, [`& .${classes.extendedIcon}`]: { marginRight: theme.spacing(1) } })) const KomanteTooltip = Tooltip export default function VweKomante({komante, teks}) { const [esOuve, meteEsOuve] = useState(false) const [esKoneksyonOuve, meteEsKoneksyonOuve] = useState(false) const [esKomenteOuve, meteEsKomanteOuve] = useState(false) const [session] = useSession() const router = useRouter() const handleClick = () => { meteEsOuve(true) } const handleClose = () => { meteEsOuve(false) } const descriptionElementRef = useRef(null) useEffect(() => { if (esOuve) { const {current: descriptionElement} = descriptionElementRef if (descriptionElement !== null) { descriptionElement.focus() } } }, [esOuve]) return ( Kòmantè {komante.length > 0 ? ( ) : ( Aucun )} {session && session.user && !esKomenteOuve && ( )} {!session && !esKoneksyonOuve && ( )} {!session && esKoneksyonOuve && ( )} {!session && esKoneksyonOuve && ( )} {session && session.user && esKomenteOuve && ( <> )} ) } VweKomante.defaultProps = { komante: null } VweKomante.propTypes = { komante: PropTypes.array, teks: PropTypes.object.isRequired }