import { useState } from "react"; import { useNavigate, useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Trash2, Pencil } from "lucide-react"; import { useLoanOrderMobileById, useDeleteLoanOrderMobile, } from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles"; import { CreditCardVisual } from "@/components/creditCardVisual"; import { Skeleton } from "@/components/ui/skeleton"; import type { LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; import { StatusBadge, type StatusBadgeVariant, } from "@/components/ui/statusBadge"; import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; import { InfoRow, PassportImage, AuditLog, type AuditRowProps, } from "@/components/viewPageComponents"; import { ConfirmDialog } from "@/components/confirmDialog"; // ─── Status config ──────────────────────────────────────────────────────────── const STATUS_CONFIG = { GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, KANAGATLANDYRYLAN: { label: "Tassyklandy", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, RED_EDILDI: { label: "Ýatyryldy", variant: "error" as StatusBadgeVariant, icon: XCircle }, IŞLENÝÄR: { label: "Işlenýär", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, } satisfies Record function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { const cfg = STATUS_CONFIG[status] if (!cfg) return {String(status)} return } // ─── Bento primitives ───────────────────────────────────────────────────────── function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { const colClass = { 1: "grid-cols-1", 2: "grid-cols-1 sm:grid-cols-2", 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", }[cols] return
{children}
} function BentoCard({ title, span, children, noPadding, }: { title?: string span?: "full" | 2 | 3 children: React.ReactNode noPadding?: boolean }) { const spanClass = span === "full" ? "sm:col-span-full" : span === 2 ? "sm:col-span-2" : span === 3 ? "sm:col-span-3" : "" return (
{title && (

{title}

)}
{children}
) } // ─── Skeleton ───────────────────────────────────────────────────────────────── function LoanOrderMobilesViewSkeleton() { return (
{[...Array(6)].map((_, i) => (
{[...Array(3)].map((_, j) => ( ))}
))}
) } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderMobilesViewPage() { const { t } = useTranslation() const navigate = useNavigate() const { id } = useParams<{ id: string }>() const deleteMutation = useDeleteLoanOrderMobile() const [showDeleteDialog, setShowDeleteDialog] = useState(false) const { data: order, isLoading } = useLoanOrderMobileById(id!) const handleDelete = () => { setShowDeleteDialog(true) } const confirmDelete = () => { deleteMutation.mutate(id!, { onSuccess: () => navigate("/loan-order-mobiles"), }) } if (isLoading) return if (!order) { return (
{t("common.notFound", "Tapylmady")}
) } const auditLogs: AuditRowProps[] = [ { id: "44548", action: t("audit.actions.view", "Görmek"), by: order.createdBy ?? "", target: `${t("loanOrderMobiles.title", "Karz sargyt")}: ${order.id}`, status: "FINISHED", date: order.createdAt ?? "", }, ] const hasCard = !!(order.cardNumber || order.cardName) const hasGuarantor = !!(order.guarantor1Name || order.guarantor1CardNumber) return (
{/* ── Page header ──────────────────────────────────────────────────── */}

{t("loanOrderMobiles.view.title", "Karz sargyt giriş")}: {order.id}

{/* ── Row 1: Meta + Loan + Location ───────────────────────────────── */} {/* ── Row 2: Card visual (conditional) ────────────────────────────── */} {hasCard && (
{/* Guarantor card — shown side-by-side with main card when both exist */} {hasGuarantor && ( {order.guarantor1CardNumber && (
)}
)}
)} {/* ── Row 3: Personal + Contacts ──────────────────────────────────── */} {/* ── Row 4: Employment + Passport info ───────────────────────────── */} {/* ── Row 5: Passport images ───────────────────────────────────────── */} {/* ── Guarantor (standalone — only when no card to pair with) ─────── */} {hasGuarantor && !hasCard && ( {order.guarantor1CardNumber && (
)}
)} {/* ── Audit log ────────────────────────────────────────────────────── */}
) }