'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, }: 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' ? 'Нужен перевозчик' : 'Могу перевезти' return ( <> {/* десктоп */}
{`User
{username}
|
{userRequest}
Тип посылки:{' '} {formatted_cargo_type}
{comment && (
{comment}
)}
Объявление № {id}
{userRequest === 'Нужен перевозчик' ? ( Забрать из: ) : ( Выезжаю из: )}
{from_country_name.substring(0, {from_country_name.substring(0, 3).toUpperCase()} {from_city_name} / {from_country_name}
{userRequest === 'Могу перевезти' && (
Отправление:{' '} {formatDateTime(formatted_departure)}
)}
{formatted_transport} route vector
route vector
{userRequest === 'Нужен перевозчик' && (
Дата доставки:{' '} {formatDateTime(formatted_arrival)}
)}
{userRequest === 'Нужен перевозчик' ? (
Доставить в:
) : (
Прибываю в:
)}
{to_country_name.substring(0, {to_country_name.substring(0, 3).toUpperCase()} {to_city_name} / {to_country_name}
{userRequest === 'Могу перевезти' && (
Прибытие:{' '} {formatDateTime(formatted_arrival)}
)}
{/* мобилка */}
{userRequest}
{formatted_cargo_type}
{`User
{comment}
Объявление № {id}
{userRequest === 'Нужен перевозчик' ? ( Забрать из: ) : ( Выезжаю из: )}
route vector
{from_country_name.substring(0, {from_country_name.substring(0, 3).toUpperCase()} {from_city_name} / {from_country_name}
{formatted_transport} route vector
Дата доставки: {formatDateTime(formatted_arrival)}
{userRequest === 'Нужен перевозчик' ? (
Доставить в:
) : (
Прибываю в:
)}
{to_country_name.substring(0, {to_country_name.substring(0, 3).toUpperCase()} {to_city_name} / {to_country_name}
{userRequest === 'Могу перевезти' && (
Прибытие:{' '} {formatDateTime(formatted_arrival)}
)}
setIsLeadPopupOpen(false)} onSuccess={() => { setIsLeadPopupOpen(false) }} /> ) } export default SearchCard