'use client'; import React from 'react'; import { Download, CreditCard, Eye } from 'lucide-react'; import { useMutation } from '@tanstack/react-query'; import { useSiHistory } from '../../lib/hooks/useSiHistory'; import { formatDate } from '@/widgets/history/lib/utils'; import { apiRequest } from '@/shared/request/apiRequest'; import { links } from '@/shared/request/links'; import { toast } from 'react-toastify'; import type { SiDocument } from '../../lib/types'; import { SiButton } from '@/features/modals/siModal/page'; import { useRouter, useParams } from 'next/navigation'; // ─── State badge ─────────────────────────────────────────────────────────────── const StateBadge: React.FC<{ state: 'paid' | 'unpaid' }> = ({ state }) => { const isPaid = state === 'paid'; return ( {isPaid ? "To'langan" : "To'lanmagan"} ); }; // ─── SI% badge ───────────────────────────────────────────────────────────────── const SiPercentBadge: React.FC<{ value: number }> = ({ value }) => { const cls = value < 20 ? 'text-emerald-700 bg-emerald-50' : value < 40 ? 'text-amber-700 bg-amber-50' : 'text-red-700 bg-red-50'; return ( {value}% ); }; // ─── Skeleton ────────────────────────────────────────────────────────────────── const SkeletonRow = () => ( {Array.from({ length: 7 }).map((_, i) => (
))} ); // ─── Empty / Error states ────────────────────────────────────────────────────── const EmptyState = () => ( Hozircha SI tekshiruvlar yo'q ); const ErrorState = () => ( Ma'lumotlarni yuklashda xatolik yuz berdi ); // ─── Row ─────────────────────────────────────────────────────────────────────── const SiRow: React.FC<{ item: SiDocument; index: number }> = ({ item, index, }) => { const router = useRouter(); const { locale } = useParams() as { locale: string }; const pay = useMutation({ mutationKey: ['si-payment', item.id], mutationFn: () => apiRequest<{ payment_link: string }>('POST', links.demo_pay(item.id)), onSuccess: (res) => { window.open(res.data.payment_link, '_self'); }, onError: (err) => { toast.error(err instanceof Error ? err.message : 'Xatolik yuz berdi'); }, }); return ( {/* # */} {String(index).padStart(2, '0')} {/* Sarlavha */} {item.title || '—'} {/* Fayl */} {item.file ? ( Fayl ) : ( )} {/* So'z */} {item.total_words > 0 ? item.total_words.toLocaleString() : '—'} {/* SI% */} {item.si_percantage != null && item.result != null ? ( ) : ( )} {/* Sana */} {formatDate(item.created_at)} {/* Holat */} {/* Amal */} {item.state === 'unpaid' ? ( ) : ( )} ); }; // ─── SiTable ─────────────────────────────────────────────────────────────────── export const SiTable: React.FC = () => { const { items, isLoading, isError } = useSiHistory(); return (

SI detektor

{isLoading ? '...' : `${items.length} ta tekshiruv`}

{[ '#', 'Sarlavha', 'Fayl', "So'z", 'SI%', 'Sana', 'Holat', 'Amal', ].map((h) => ( ))} {isLoading && Array.from({ length: 5 }).map((_, i) => ( ))} {isError && } {!isLoading && !isError && items.length === 0 && } {!isLoading && !isError && items.map((item, i) => ( ))}
{h}
); };