'use client' import React, { useState } from 'react' import Image from 'next/image' import Button from '@/components/ui/Button' import { SearchCardProps } from '@/app/types' import noPhoto from '../../../../public/images/noPhoto.png' import LeadPopup from '@/components/popups/LeadPopup' import useUserStore from '@/app/store/userStore' import { useRouter } from 'next/navigation' const formatDateTime = (dateTimeString: string): string => { const date = new Date(dateTimeString) const formatter = new Intl.DateTimeFormat('ru-RU', { day: 'numeric', month: 'long', year: 'numeric', }) const timeFormatter = new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit', }) const dateStr = formatter.format(date).replace(' г.', '') const timeStr = timeFormatter.format(date) return `${dateStr}, ${timeStr}` } const SearchCard = ({ id, username, owner_type, from_city_name, from_country_name, to_city_name, to_country_name, formatted_cargo_type, formatted_transport, type_transport, userImg, comment, formatted_departure, formatted_arrival, country_from_icon, country_to_icon, is_highlighted, }: SearchCardProps) => { const [isLeadPopupOpen, setIsLeadPopupOpen] = useState(false) const { isAuthenticated } = useUserStore() const router = useRouter() const handleLeadClick = () => { if (!isAuthenticated) { router.push('/login') return } setIsLeadPopupOpen(true) } const getUserRequestStyles = () => { if (owner_type === 'customer') { return 'text-[#065bff]' } return 'text-[#45c226]' } const setMovingTypeIcon = () => { if (type_transport === 'avia') { return '/images/airplane.png' } return '/images/car.png' } const userRequest = owner_type === 'customer' ? 'Нужен перевозчик' : 'Могу перевезти' const getBorderColor = () => { if (is_highlighted) { return 'border-yellow-500 border-3' } return null } return ( <> {/* десктоп */}