"use client" import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Phone, Mail, MapPin, Calendar, Plus, Send, Trash2, User } from 'lucide-react' import { OrganizationAvatar } from './organization-avatar' import { useState } from 'react' interface Organization { id: string inn: string name?: string fullName?: string type: 'FULFILLMENT' | 'SELLER' | 'LOGIST' | 'WHOLESALE' address?: string phones?: Array<{ value: string }> emails?: Array<{ value: string }> createdAt: string users?: Array<{ id: string, avatar?: string }> isCounterparty?: boolean isCurrentUser?: boolean hasOutgoingRequest?: boolean hasIncomingRequest?: boolean } interface OrganizationCardProps { organization: Organization onSendRequest?: (organizationId: string, message: string) => void onRemove?: (organizationId: string) => void showRemoveButton?: boolean actionButtonText?: string actionButtonColor?: string requestSending?: boolean } export function OrganizationCard({ organization, onSendRequest, onRemove, showRemoveButton = false, actionButtonText = "Добавить", actionButtonColor = "green", requestSending = false }: OrganizationCardProps) { const [requestMessage, setRequestMessage] = useState('') const [isDialogOpen, setIsDialogOpen] = useState(false) const formatDate = (dateString: string) => { if (!dateString) return '' try { let date: Date // Проверяем, является ли строка числом (Unix timestamp) if (/^\d+$/.test(dateString)) { // Если это Unix timestamp в миллисекундах const timestamp = parseInt(dateString, 10) date = new Date(timestamp) } else { // Обычная строка даты date = new Date(dateString) } if (isNaN(date.getTime())) { return 'Неверная дата' } return date.toLocaleDateString('ru-RU', { year: 'numeric', month: 'long', day: 'numeric' }) } catch { return 'Ошибка даты' } } const getTypeLabel = (type: string) => { switch (type) { case 'FULFILLMENT': return 'Фулфилмент' case 'SELLER': return 'Селлер' case 'LOGIST': return 'Логистика' case 'WHOLESALE': return 'Поставщик' default: return type } } const getTypeColor = (type: string) => { switch (type) { case 'FULFILLMENT': return 'bg-blue-500/20 text-blue-300 border-blue-500/30' case 'SELLER': return 'bg-green-500/20 text-green-300 border-green-500/30' case 'LOGIST': return 'bg-orange-500/20 text-orange-300 border-orange-500/30' case 'WHOLESALE': return 'bg-purple-500/20 text-purple-300 border-purple-500/30' default: return 'bg-gray-500/20 text-gray-300 border-gray-500/30' } } const getActionButtonColor = (color: string, isDisabled: boolean) => { if (isDisabled) { return "bg-gray-500/20 text-gray-400 border-gray-500/30 cursor-not-allowed" } switch (color) { case 'green': return 'bg-green-500/20 hover:bg-green-500/30 text-green-300 border-green-500/30' case 'orange': return 'bg-orange-500/20 hover:bg-orange-500/30 text-orange-300 border-orange-500/30' case 'yellow': return 'bg-yellow-500/20 hover:bg-yellow-500/30 text-yellow-300 border-yellow-500/30' case 'red': return 'bg-red-500/20 hover:bg-red-500/30 text-red-300 border-red-500/30' case 'blue': return 'bg-blue-500/20 hover:bg-blue-500/30 text-blue-300 border-blue-500/30' default: return 'bg-gray-500/20 hover:bg-gray-500/30 text-gray-300 border-gray-500/30' } } const handleSendRequest = () => { if (onSendRequest) { onSendRequest(organization.id, requestMessage) setRequestMessage('') setIsDialogOpen(false) } } const handleRemove = () => { if (onRemove) { onRemove(organization.id) } } return (

{organization.name || organization.fullName}

{getTypeLabel(organization.type)} {organization.isCurrentUser && ( Это вы )} {organization.isCounterparty && !organization.isCurrentUser && ( Уже добавлен )}

ИНН: {organization.inn}

{organization.address && (
{organization.address}
)} {organization.phones && organization.phones.length > 0 && (
{organization.phones[0].value}
)} {organization.emails && organization.emails.length > 0 && (
{organization.emails[0].value}
)}
{showRemoveButton ? 'Добавлен' : 'Зарегистрирован'} {formatDate(organization.createdAt)}
{showRemoveButton ? ( ) : organization.isCurrentUser ? ( ) : ( Отправить заявку в контрагенты

{organization.name || organization.fullName}

ИНН: {organization.inn}

setRequestMessage(e.target.value)} className="glass-input text-white placeholder:text-white/40" />
)}
) }