import React, { useState, useEffect, useRef } from 'react' import { FaChevronLeft, FaChevronRight, FaMapMarkerAlt, FaCalendarAlt, FaUsers, FaExpand, FaCommentAlt, FaPaperPlane, } from 'react-icons/fa' import { Button, Dialog } from '@/components/ui' import { useDialogContext } from '@/components/ui/Dialog/Dialog' import { EventCommentDto, EventDto } from '@/proxy/intranet/models' import useLocale from '@/utils/hooks/useLocale' import { currentLocalDate } from '@/utils/dateUtils' import Avatar from '@/components/ui/Avatar/Avatar' import { AVATAR_URL } from '@/constants/app.constant' import { intranetService } from '@/services/intranet.service' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import { useLocalization } from '@/utils/hooks/useLocalization' import ImageLightbox from './ImageLightbox' import LikeButton from './LikeButton' import { imageSrc } from './widgetUtils' dayjs.extend(relativeTime) interface EventModalProps { event: EventDto onClose: () => void onLikeChange?: (event: EventDto) => void } function EventModalContent({ event, onClose, onLikeChange }: EventModalProps) { const currentLocale = useLocale() const photos = (event.photos || '').split('|').filter(Boolean) const { translate } = useLocalization() const { isMaximized } = useDialogContext() // Photo slider state const [activePhoto, setActivePhoto] = useState(0) const [lightboxOpen, setLightboxOpen] = useState(false) const [lightboxIndex, setLightboxIndex] = useState(0) // Comments state const [comments, setComments] = useState(event.comments || []) const [commentText, setCommentText] = useState('') const [submitting, setSubmitting] = useState(false) const commentInputRef = useRef(null) const commentsEndRef = useRef(null) // Likes state const [likes, setLikes] = useState(event.likes) const [isLiked, setIsLiked] = useState(event.isLiked) const [liking, setLiking] = useState(false) useEffect(() => { // Refresh comments from API on open intranetService.getEventComments(event.id).then((res) => { if (res.data) setComments(res.data) }) }, [event.id]) const scrollToBottom = () => { commentsEndRef.current?.scrollIntoView({ behavior: 'smooth' }) } const handleSubmitComment = async () => { if (!commentText.trim() || submitting) return setSubmitting(true) try { const res = await intranetService.createEventComment(event.id, commentText.trim()) if (res.data) { setComments((prev) => [...prev, res.data!]) setCommentText('') setTimeout(scrollToBottom, 100) } } finally { setSubmitting(false) } } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() handleSubmitComment() } } const handleLike = async () => { if (liking) return setLiking(true) // Optimistic update setIsLiked((prev) => !prev) setLikes((prev) => (isLiked ? Math.max(0, prev - 1) : prev + 1)) try { const res = await intranetService.likeEvent(event.id) if (res.data) { const updatedEvent = { ...event, likes: res.data.likes, isLiked: res.data.isLiked, } setLikes(updatedEvent.likes) setIsLiked(updatedEvent.isLiked) onLikeChange?.(updatedEvent) } } catch { // Revert on error setIsLiked((prev) => !prev) setLikes((prev) => (isLiked ? prev + 1 : Math.max(0, prev - 1))) } finally { setLiking(false) } } const openLightbox = (idx: number) => { setLightboxIndex(idx) setLightboxOpen(true) } const closeLightbox = () => setLightboxOpen(false) return ( <> {/* Header */}

{event.name}

{currentLocalDate(event.date, currentLocale || 'tr')} {event.place && ( {event.place} )} {event.participantsCount > 0 && ( {event.participantsCount} )}
{event.user && (
{event.user.fullName}
)}
{/* Scrollable body */}
{/* Photo Gallery */} {photos.length > 0 && (
{/* Main photo */}
{`${event.name} openLightbox(activePhoto)} />
{/* Thumbnail strip */} {photos.length > 1 && (
{photos.map((photo, idx) => ( ))}
)}
)} {/* Description */} {event.description && (

{event.description}

)} {/* Comments Section */}

{translate('::App.Intranet.Events.Comments')} ({comments.length})

{/* Comment List */}
{comments.length === 0 ? (

{translate('::App.Intranet.Events.NoComment')}

) : ( comments.map((comment) => (
{comment.user && ( )}

{comment.user?.fullName ?? 'Kullanıcı'}

{comment.content}

{dayjs(comment.creationTime).fromNow()}

)) )}