import { useMemo, useState } from "react"; import { Download, Eye, ChevronDown, Inbox, Pencil, Trash2 } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { Link } from "react-router-dom"; // ─── BentoGrid ──────────────────────────────────────────────────────────────── export 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}
; } // ─── BentoCard ──────────────────────────────────────────────────────────────── interface BentoCardProps { title?: string; span?: "full" | 2 | 3; children: React.ReactNode; noPadding?: boolean; } export function BentoCard({ title, span, children, noPadding }: BentoCardProps) { const spanClass = span === "full" ? "sm:col-span-full" : span === 2 ? "sm:col-span-2" : span === 3 ? "sm:col-span-3" : ""; return (
{title && (

{title}

)} {noPadding ?
{children}
: children}
); } // ─── InfoRow ────────────────────────────────────────────────────────────────── export interface InfoRowProps { label: string; value?: string | number | null; children?: React.ReactNode; isLink?: boolean; href?: string; } export function InfoRow({ label, value, children, isLink, href }: InfoRowProps) { const content = children ?? (value != null ? String(value) : null); return (
{label} {content != null && content !== "" ? ( typeof content === "string" ? ( isLink && href ? ( href.startsWith("http") ? ( {content} ) : ( {content} ) ) : ( {content} ) ) : (
{content}
) ) : ( — )}
); } // ─── MultiLangRow ───────────────────────────────────────────────────────────── export interface MultiLangRowProps { label: string; value?: { tm?: string; tk?: string; ru?: string; en?: string } | string | null; } export function MultiLangRow({ label, value }: MultiLangRowProps) { if (!value) return ; if (typeof value === "string") return ; const langs = [ { code: "TK", val: value.tm ?? value.tk }, { code: "RU", val: value.ru }, { code: "EN", val: value.en }, ]; const hasAny = langs.some((l) => l.val); return (
{label}
{langs.map((l) => l.val ? (
{l.code} {l.val}
) : null, )} {!hasAny && —}
); } // ─── Section ────────────────────────────────────────────────────────────────── export interface SectionProps { title?: string; children: React.ReactNode; } export function Section({ title, children }: SectionProps) { return (
{title ?

{title}

: null}
{children}
); } // ─── CollapsibleSection ──────────────────────────────────────────────────────── export interface CollapsibleSectionProps { title: string; children: React.ReactNode; } export function CollapsibleSection({ title, children }: CollapsibleSectionProps) { const [open, setOpen] = useState(true); return (
setOpen((v) => !v)}>

{title}

{open &&
{children}
}
); } // ─── PassportImage ──────────────────────────────────────────────────────────── export interface PassportImageProps { label: string; src?: string | null; url?: string | null; } export function PassportImage({ label, src, url }: PassportImageProps) { const { t } = useTranslation(); const imageSrc = src ?? url ?? null; return (
{imageSrc ? ( {label} ) : (
—
)} {imageSrc && ( {t("common.download", "Göçürip al")} )}
); } // ─── AuditRowProps ──────────────────────────────────────────────────────────── export interface AuditRowProps { id: string; action: string; by: string; target: string; status: string; date: string; } // ─── StatusBadge ────────────────────────────────────────────────────────────── export function StatusBadge({ status }: { status: string }) { const normalized = status.toLowerCase(); const variant = normalized === "success" || normalized === "completed" ? "default" : normalized === "failed" || normalized === "error" ? "destructive" : normalized === "pending" ? "secondary" : "outline"; return {status}; } // ─── useAuditColumns ────────────────────────────────────────────────────────── export function useAuditColumns(onView?: (log: AuditRowProps) => void): ColumnDef[] { const { t } = useTranslation(); return useMemo( () => [ { accessorKey: "id", header: t("audit.columns.id", "ID"), cell: ({ row }) => {row.original.id}, size: 130, }, { accessorKey: "action", header: t("audit.columns.action", "AMALYŇ ADY"), cell: ({ row }) => {row.original.action}, }, { accessorKey: "by", header: t("audit.columns.by", "KIM TARAPYNDAN"), cell: ({ row }) => {row.original.by}, }, { accessorKey: "target", header: t("audit.columns.target", "AMALYŇ NYŞANY"), cell: ({ row }) => {row.original.target}, }, { accessorKey: "status", header: t("audit.columns.status", "AMALYŇ STATUSY"), cell: ({ row }) => , size: 160, }, { accessorKey: "date", header: t("audit.columns.date", "SENE"), cell: ({ row }) => {row.original.date}, size: 160, }, { id: "actions", header: "", enableHiding: false, size: 60, cell: ({ row }) => onView ? (
) : null, }, ], [t, onView], ); } // ─── AuditLog ───────────────────────────────────────────────────────────────── export interface AuditLogProps { logs: AuditRowProps[]; currentPage?: number; totalPages?: number; totalCount?: number; onPageChange?: (page: number) => void; isLoading?: boolean; onView?: (log: AuditRowProps) => void; } // ─── EmptyState ──────────────────────────────────────────────────────────────── export interface EmptyStateProps { label: string; } export function EmptyState({ label }: EmptyStateProps) { return (

{label}

); } // ─── ViewActions ────────────────────────────────────────────────────────────── // Standard edit (→ `/edit` route) + delete (with confirmation AlertDialog) // action buttons rendered in a view page header. Delete validation and the // destructive mutation itself live in the caller's `onDelete`; this component // only handles the dialog flow (open → confirm → close). export interface ViewActionsProps { editTo?: string; onDelete?: () => void | Promise; deleteTitle?: string; deleteDescription?: string; deleting?: boolean; deleteConfirmLabel?: string; editDisabled?: boolean; deleteDisabled?: boolean; } export function ViewActions({ editTo, onDelete, deleteTitle, deleteDescription, deleting, deleteConfirmLabel, editDisabled, deleteDisabled, }: ViewActionsProps) { const { t } = useTranslation(); const [deleteOpen, setDeleteOpen] = useState(false); const handleConfirm = async () => { await onDelete?.(); setDeleteOpen(false); }; return (
{editTo && ( )} {onDelete && ( )} {deleteTitle ?? t("Are you sure?", "Eminsiňizmi?")} {deleteDescription ?? t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz.")} {t("Cancel", "Ýatyr")} {deleting ? t("Deleting...", "Öçürilýär...") : (deleteConfirmLabel ?? t("Delete", "Öçür"))}
); } // ─── AuditLog ───────────────────────────────────────────────────────────────── export function AuditLog({ logs, currentPage, totalPages, totalCount, onPageChange, isLoading, onView }: AuditLogProps) { const columns = useAuditColumns(onView); return (
row.id} />
); }