"use client" import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Card } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { Building2, Phone, Mail, MapPin, Calendar, FileText, Users, CreditCard, Hash, User, Briefcase } from 'lucide-react' import { OrganizationAvatar } from './organization-avatar' interface User { id: string avatar?: string | null phone: string createdAt: string } interface ApiKey { id: string marketplace: string isActive: boolean createdAt: string } interface Organization { id: string inn: string kpp?: string | null name?: string | null fullName?: string | null type: 'FULFILLMENT' | 'SELLER' | 'LOGIST' | 'WHOLESALE' address?: string | null addressFull?: string | null ogrn?: string | null ogrnDate?: string | null status?: string | null actualityDate?: string | null registrationDate?: string | null liquidationDate?: string | null managementName?: string | null managementPost?: string | null opfCode?: string | null opfFull?: string | null opfShort?: string | null okato?: string | null oktmo?: string | null okpo?: string | null okved?: string | null employeeCount?: number | null revenue?: string | null taxSystem?: string | null phones?: Array<{ value: string }> | null emails?: Array<{ value: string }> | null users?: User[] apiKeys?: ApiKey[] createdAt: string } interface OrganizationDetailsModalProps { organization: Organization | null open: boolean onOpenChange: (open: boolean) => void } function formatDate(dateString?: string | null): 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 (error) { return 'Не указана' } } function getTypeLabel(type: string): string { switch (type) { case 'FULFILLMENT': return 'Фулфилмент' case 'SELLER': return 'Селлер' case 'LOGIST': return 'Логистика' case 'WHOLESALE': return 'Оптовик' default: return type } } function getTypeColor(type: string): 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' } } export function OrganizationDetailsModal({ organization, open, onOpenChange }: OrganizationDetailsModalProps) { if (!organization) return null const displayName = organization.name || organization.fullName || 'Неизвестная организация' return (

{displayName}

{getTypeLabel(organization.type)}
{/* Основная информация */}

Основная информация

ИНН: {organization.inn}
{organization.kpp && (
КПП: {organization.kpp}
)} {organization.ogrn && (
ОГРН: {organization.ogrn}
)} {organization.status && (
Статус: {organization.status}
)}
Дата регистрации: {formatDate(organization.registrationDate)}
{/* Контактная информация */}

Контакты

{organization.phones && organization.phones.length > 0 && (
Телефоны:
{organization.phones.map((phone, index) => (
{phone.value}
))}
)} {organization.emails && organization.emails.length > 0 && (
Email:
{organization.emails.map((email, index) => (
{email.value}
))}
)} {organization.address && (
Адрес:
{organization.addressFull || organization.address}
)}
{/* Руководство */} {organization.managementName && (

Руководство

Руководитель: {organization.managementName}
{organization.managementPost && (
Должность: {organization.managementPost}
)}
)} {/* Организационно-правовая форма */} {organization.opfFull && (

ОПФ

Полное название: {organization.opfFull}
{organization.opfShort && (
Краткое название: {organization.opfShort}
)} {organization.opfCode && (
Код ОКОПФ: {organization.opfCode}
)}
)} {/* Коды статистики */} {(organization.okato || organization.oktmo || organization.okpo || organization.okved) && (

Коды статистики

{organization.okato && (
ОКАТО: {organization.okato}
)} {organization.oktmo && (
ОКТМО: {organization.oktmo}
)} {organization.okpo && (
ОКПО: {organization.okpo}
)} {organization.okved && (
Основной ОКВЭД: {organization.okved}
)}
)} {/* Финансовая информация */} {(organization.employeeCount || organization.revenue || organization.taxSystem) && (

Финансовая информация

{organization.employeeCount && (
Сотрудников: {organization.employeeCount}
)} {organization.revenue && (
Выручка: {organization.revenue}
)} {organization.taxSystem && (
Налоговая система: {organization.taxSystem}
)}
)} {/* Пользователи */} {organization.users && organization.users.length > 0 && (

Пользователи ({organization.users.length})

{organization.users.map((user, index) => (
{user.phone}
{formatDate(user.createdAt)}
))}
)} {/* API ключи */} {organization.apiKeys && organization.apiKeys.length > 0 && (

API ключи маркетплейсов

{organization.apiKeys.map((apiKey, index) => (
{apiKey.marketplace} {apiKey.isActive ? 'Активен' : 'Неактивен'}
{formatDate(apiKey.createdAt)}
))}
)}
) }