import React, { useMemo, useState } from 'react'; import { useAppStore } from '../store/useAppStore'; import { RefreshCw, Download, Trash2, Zap, SearchCode, ArrowUpDown, Package, } from 'lucide-react'; import { api } from '../lib/tauri'; type SortKey = 'name' | 'size' | 'publisher' | 'date'; export const AppsView: React.FC = () => { const { apps, isLoadingApps, searchQuery, selectedAppIds, toggleSelectApp, selectAllApps, clearSelectedApps, loadApps, uninstallSingleApp, bulkUninstall, isUninstalling, startLeftoverScan, addToast, } = useAppStore(); const [sortKey, setSortKey] = useState('name'); const [sortAsc, setSortAsc] = useState(true); const [filterKind, setFilterKind] = useState('all'); const filteredApps = useMemo(() => { let result = apps.filter((app) => { const matchSearch = searchQuery.trim() === '' || app.display_name.toLowerCase().includes(searchQuery.toLowerCase()) || app.publisher.toLowerCase().includes(searchQuery.toLowerCase()); const matchKind = filterKind === 'all' || (filterKind === 'steam' && app.kind === 'Steam') || (filterKind === 'store' && app.kind === 'StoreApp') || (filterKind === 'registry' && app.kind === 'Registry'); return matchSearch && matchKind; }); result.sort((a, b) => { let cmp = 0; switch (sortKey) { case 'name': cmp = a.display_name.localeCompare(b.display_name); break; case 'size': cmp = a.estimated_size_kb - b.estimated_size_kb; break; case 'publisher': cmp = a.publisher.localeCompare(b.publisher); break; case 'date': cmp = a.install_date.localeCompare(b.install_date); break; } return sortAsc ? cmp : -cmp; }); return result; }, [apps, searchQuery, filterKind, sortKey, sortAsc]); const totalSizeMB = useMemo(() => { const totalKB = apps.reduce((acc, a) => acc + a.estimated_size_kb, 0); return (totalKB / 1024).toFixed(1); }, [apps]); const toggleSort = (key: SortKey) => { if (sortKey === key) { setSortAsc(!sortAsc); } else { setSortKey(key); setSortAsc(true); } }; const formatSize = (kb: number) => { if (kb >= 1024 * 1024) return `${(kb / 1024 / 1024).toFixed(2)} GB`; if (kb >= 1024) return `${(kb / 1024).toFixed(1)} MB`; if (kb > 0) return `${kb} KB`; return '-'; }; const handleExportCsv = async () => { try { const savedPath = await api.exportAppsCsv(''); addToast('Dışa Aktarıldı', `Uygulama listesi kaydedildi: ${savedPath}`, 'success'); } catch (e: any) { addToast('Hata', String(e), 'error'); } }; return (
{/* Üst İşlem Çubuğu */}
{/* Seçim İşlemleri */}
{selectedAppIds.length > 0 && ( <> )}
{/* Tablo Başlığı */}
0 && selectedAppIds.length === apps.length} onChange={(e) => (e.target.checked ? selectAllApps() : clearSelectedApps())} className="rounded border-slate-700 bg-slate-900 text-sky-500 focus:ring-0 cursor-pointer" />
toggleSort('name')} className="col-span-5 flex items-center gap-1 cursor-pointer hover:text-slate-200" > Uygulama Adı
toggleSort('publisher')} className="col-span-2 flex items-center gap-1 cursor-pointer hover:text-slate-200" > Yayımcı
toggleSort('size')} className="col-span-2 flex items-center justify-end gap-1 cursor-pointer hover:text-slate-200 pr-2" > Boyut
İşlemler
{/* Uygulama Listesi */}
{isLoadingApps ? (

Kayıt defteri ve mağaza uygulamaları taranıyor...

) : filteredApps.length === 0 ? (

Uygulama bulunamadı

Arama filtrenizi değiştirmeyi deneyin.

) : ( filteredApps.map((app) => { const isSelected = selectedAppIds.includes(app.id); return (
toggleSelectApp(app.id)} className={`grid grid-cols-12 px-4 py-2.5 items-center text-xs transition-colors cursor-pointer select-none ${ isSelected ? 'bg-sky-500/10 hover:bg-sky-500/15' : 'hover:bg-white/[0.03]' }`} >
e.stopPropagation()}> toggleSelectApp(app.id)} className="rounded border-slate-700 bg-slate-900 text-sky-500 focus:ring-0 cursor-pointer" />

{app.display_name}

{app.display_version || 'v1.0'} {app.kind === 'Steam' && ( Steam )} {app.kind === 'StoreApp' && ( Store )}
{app.publisher || 'Bilinmiyor'}
{formatSize(app.estimated_size_kb)}
e.stopPropagation()}> {/* Sessiz Kaldır */} {/* Kalıntı Tara */} {/* Normal Kaldır */}
); }) )}
{/* Alt Bilgi Çubuğu */}
Toplam: {apps.length} uygulama • Tahmini Alan: {totalSizeMB} MB {selectedAppIds.length > 0 && ( <> • {selectedAppIds.length} seçili )}
İpucu: Birden fazla uygulamayı seçip tek tıkla toplu kaldırabilirsiniz.
); };