import { useState } from "react"; import { useParams, useNavigate, Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Download, Trash2, Pencil, ChevronDown } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { useCardBalance, useDeleteCardBalance, useDownloadCardBalance, } from "@/features/cardBalance/hooks/useCardBalance"; import { InfoRow } from "@/components/viewPageComponents"; // ─── Types for operations table ─────────────────────────────────────────────── interface Operation { id: number; action_name: string; performed_by: string; target: string; status: "FINISHED" | "PENDING" | "FAILED"; date: string; } // ─── Status badge ───────────────────────────────────────────────────────────── const STATUS_STYLES: Record = { FINISHED: "bg-emerald-500/20 text-emerald-400 border border-emerald-500/30", PENDING: "bg-yellow-500/20 text-yellow-400 border border-yellow-500/30", FAILED: "bg-red-500/20 text-red-400 border border-red-500/30", }; function OpStatusBadge({ status }: { status: string }) { return ( {status} ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardBalanceViewPage() { const { t } = useTranslation(); const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [deleteOpen, setDeleteOpen] = useState(false); const [opsExpanded, setOpsExpanded] = useState(true); const [opsPage, setOpsPage] = useState(1); const numericId = Number(id); const { data, isLoading } = useCardBalance(numericId); const deleteMutation = useDeleteCardBalance(); const downloadMutation = useDownloadCardBalance(); // Placeholder operations — in real app fetch from API using numericId const operations: Operation[] = []; const opsTotal = operations.length; const handleDelete = async () => { await deleteMutation.mutateAsync(numericId); navigate("/card-balances"); }; if (isLoading) { return (
); } if (!data) { return (
{t("Not found", "Tapylmady")}
); } return (
{/* Header */}

{t("Card balance detail", "Kart galyndysy giňişleýin")}:

{/* Detail card */}
{/* Ammallar (Operations) collapsible section */}
{/* Section toggle header */} {opsExpanded && ( <>
{[ t("ID", "ID"), t("Action name", "AMALYŇ ADY"), t("Performed by", "KIM TARAPYNDAN"), t("Target", "AMALYŇ NYŞANY (TARGEDI)"), t("Status", "AMALYŇ STATUSY"), t("Date", "SENE"), ].map((h) => ( ))} {operations.length === 0 ? ( ) : ( operations.map((op) => ( )) )}
{h}
{t("No operations found", "Amal tapylmady")}
{op.id} {op.action_name} {op.performed_by} {op.target} {op.date}
{/* Ops pagination */}
{opsTotal === 0 ? "0" : `1–${opsTotal}`} {t("of", "of")}{" "} {opsTotal}
)}
{/* Delete dialog */} {t("Are you sure?", "Eminsiňizmi?")} {t( "This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.", )} {t("Cancel", "Ýatyr")} {deleteMutation.isPending ? t("Deleting...", "Öçürilýär...") : t("Delete", "Öçür")}
); }