import {useRef, useState, useEffect} from "react"; import PinIcon from "../components/icons/PinIcon"; import CalendarIcon from "../components/icons/CalendarIcon"; import PhoneIcon from "../components/icons/PhoneIcon"; import HeartIcon from "../components/icons/HeartIcon"; import TrashIcon from "../components/icons/TrashIcon"; import {useContactSeller} from "../hooks/useContactSeller"; import {useAuthContext} from "../context/AuthContext"; import {getImageUrl} from "../config/authConstants"; import DateCalendarPopup from "../components/DateCalendarPopup"; import Toast from "../components/Toast"; import {useTranslation} from 'react-i18next'; export default function PostOnFeed({ ad, liked, likeCountAdj, onLike, onEdit, onDelete, onMarkFound, isOwner, onImageClick, onLocationClick, onAuthRequired }) { const { t } = useTranslation(); const [showCalendar, setShowCalendar] = useState(false); const [descExpanded, setDescExpanded] = useState(false); const [descTruncated, setDescTruncated] = useState(false); const dateAnchorRef = useRef(null); const descRef = useRef(null); const { isAuthenticated } = useAuthContext(); const { contactSeller, error: contactError, clearError } = useContactSeller(ad); useEffect(() => { const check = () => { if (!descExpanded && descRef.current) { setDescTruncated(descRef.current.scrollHeight > descRef.current.clientHeight + 1); } }; check(); window.addEventListener("resize", check); return () => window.removeEventListener("resize", check); }, [descExpanded]); const handleContact = (e) => { e.stopPropagation(); if (!isAuthenticated) { if (onAuthRequired) onAuthRequired(); return; } contactSeller(); }; const imageUrl = getImageUrl(ad.images?.[0]); const address = ad.city; const createdAt = ad.createdAt ? new Date(ad.createdAt).toLocaleDateString("ru-RU") : null; const isClosed = ad.status === 'CLOSED'; const headAccentClass = ad.type === "found" ? " f-head-found" : " f-head-loss"; const typeBadge = (