'use client' import PropTypes from 'prop-types' import {useState} from 'react' import Box from '@mui/material/Box' import Paper from '@mui/material/Paper' import {styled} from '@mui/material/styles' import IconButton from '@mui/material/IconButton' import AddCommentIcon from '@mui/icons-material/AddComment' import CommentIcon from '@mui/icons-material/Comment' import Tooltip, {tooltipClasses} from '@mui/material/Tooltip' import AuthAlert from '../auth-form/auth-alert.js' import Titre from './edit/titre.js' import Article from './edit/article.js' import HandleCreate from './create/handle-create.js' import ListComments from './list-comments.js' import {formatKonstitisyon} from '@/lib/format.js' const LightTooltip = styled(({className, ...props}) => ( ))(({theme}) => ({ [`& .${tooltipClasses.tooltip}`]: { backgroundColor: theme.palette.common.white, color: 'rgba(0, 0, 0, 0.87)', boxShadow: theme.shadows[1], fontSize: 15, }, })) export default function Konstitisyon({session, titres, articles}) { const konstitisyon = formatKonstitisyon(titres, articles) const [isDialogOpen, setIsDialogOpen] = useState(false) const [operation, setOperation] = useState(null) const [isErrorAlertOpen, setIsErrorAlertOpen] = useState(false) const [isSuccessAlertOpen, setIsSuccessAlertOpen] = useState(false) const [selectedTitre, setSelectedTitre] = useState(null) const [error, setError] = useState('') const [success, setSuccess] = useState('') const handleCommentsDialog = (titreId, titre, action) => { setSelectedTitre({id: titreId, titre}) setOperation(action) setIsDialogOpen(true) } return ( <> {error && } {success && } {konstitisyon.map(({titreId, titre, articles}) => ( {articles.map(({id, numero, contenu}) => (
))} {session && ( handleCommentsDialog(titreId, titre, 'read')}> handleCommentsDialog(titreId, titre, 'create')}> )} ))} {selectedTitre && operation === 'create' && ( )} {selectedTitre && operation === 'read' && ( )} ) } Konstitisyon.propTypes = { session: PropTypes.object, titres: PropTypes.object.isRequired, articles: PropTypes.object.isRequired }