import { useState, useEffect, useRef, useCallback } from 'react'; import { api, S } from '../lib.js'; import { useConfirm } from '../confirm.jsx'; import { UploadIcon, DownloadIcon, TrashIcon, SearchIcon, ChevronIcon } from '../icons.jsx'; const fmtSize = b => b<1024?`${b} B`:b<1024*1024?`${(b/1024).toFixed(1)} KB`:`${(b/(1024*1024)).toFixed(1)} MB`; const fmtDate = s => { if (!s) return ''; const d = new Date(String(s).replace(' ','T')); return isNaN(d)?'':d.toLocaleDateString('de-DE',{day:'2-digit',month:'2-digit',year:'numeric'}); }; const extIcon = name => { const e = name.split('.').pop().toLowerCase(); if (['jpg','jpeg','png','gif','webp'].includes(e)) return 'πΌ'; if (e==='pdf') return 'π'; if (['zip','rar','7z'].includes(e)) return 'π¦'; if (['mp4','mov','avi'].includes(e)) return 'π¬'; if (['mp3','wav'].includes(e)) return 'π΅'; if (['stl','3mf'].includes(e)) return 'π¨'; if (['txt','md'].includes(e)) return 'π'; if (['xlsx','csv'].includes(e)) return 'π'; if (['docx','doc'].includes(e)) return 'π'; return 'π'; }; const IconBtn = ({ onClick, color, title, children, stop }) => ( ); // ββ Share Modal βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function ShareModal({ item, type, onClose, toast }) { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [shares, setShares] = useState([]); const base = type==='folder' ? `/tools/dateien/folders/${item.id}` : `/tools/dateien/${item.id}`; useEffect(() => { api(`${base}/shares`).then(setShares).catch(()=>{}); }, [base]); const share = async () => { if (!username.trim()) return; try { await api(`${base}/share`, { body: { username: username.trim(), password: password.trim() || undefined } }); toast('Geteilt β'); setUsername(''); setPassword(''); api(`${base}/shares`).then(setShares); } catch(e) { toast(e.message,'error'); } }; const unshare = async uid => { try { await api(`${base}/share/${uid}`,{method:'DELETE'}); setShares(p=>p.filter(s=>s.id!==uid)); toast('Freigabe entfernt'); } catch(e) { toast(e.message,'error'); } }; const isMobile = window.innerWidth<768; return (