// Art 3D Screen — Upload ảnh nhân vật, đặt tên, gen Art 3D const artStyles = { page: { minHeight: '100vh', display: 'flex', flexDirection: 'column', background: 'var(--bg)' }, topbar: { height: '64px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', padding: '0 32px', gap: '16px', background: 'var(--bg-2)' }, backBtn: { display: 'flex', alignItems: 'center', gap: '6px', color: 'var(--text-mute)', fontSize: '13px', fontWeight: 500, padding: '6px 12px', borderRadius: '8px', transition: 'all 0.15s' }, title: { fontSize: '15px', fontWeight: 600, letterSpacing: '-0.01em' }, main: { flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', padding: '48px 32px 64px', maxWidth: '960px', margin: '0 auto', width: '100%' }, heading: { fontSize: '32px', fontWeight: 600, letterSpacing: '-0.025em', margin: '0 0 8px 0', textAlign: 'center' }, subtitle: { fontSize: '14px', color: 'var(--text-dim)', margin: '0 0 40px 0', textAlign: 'center', maxWidth: '520px' }, dropzone: { width: '100%', minHeight: '200px', border: '2px dashed var(--border)', borderRadius: '16px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '16px', padding: '40px 20px', cursor: 'pointer', transition: 'all 0.2s', background: 'var(--surface)' }, dropzoneActive: { borderColor: 'var(--accent)', background: 'var(--accent-soft)' }, dropIcon: { width: '56px', height: '56px', borderRadius: '14px', background: 'var(--accent-soft)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--accent-2)', border: '1px solid rgba(76,141,255,0.25)' }, dropText: { fontSize: '14px', color: 'var(--text-dim)', textAlign: 'center' }, dropHint: { fontSize: '12px', color: 'var(--text-mute)', fontFamily: 'JetBrains Mono, monospace' }, grid: { width: '100%', display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))', gap: '16px', marginTop: '24px' }, card: { position: 'relative', background: 'var(--surface)', border: '1px solid var(--border)', borderRadius: '14px', overflow: 'hidden', transition: 'all 0.2s' }, cardThumb: { aspectRatio: '3/4', background: '#0a0f1a', position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }, cardImg: { width: '100%', height: '100%', objectFit: 'contain' }, cardRemove: { position: 'absolute', top: '8px', right: '8px', width: '28px', height: '28px', borderRadius: '50%', background: 'rgba(11,18,32,0.7)', backdropFilter: 'blur(4px)', border: '1px solid var(--border)', color: 'var(--text-mute)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', transition: 'all 0.15s', zIndex: 2 }, cardBody: { padding: '12px 14px' }, cardLabel: { fontSize: '11px', color: 'var(--text-mute)', fontFamily: 'JetBrains Mono, monospace', marginBottom: '6px', textTransform: 'uppercase', letterSpacing: '0.05em' }, cardInput: { width: '100%', padding: '8px 10px', fontSize: '13px', background: 'var(--bg)', border: '1px solid var(--border)', borderRadius: '8px', color: 'var(--text)', outline: 'none', fontFamily: 'inherit', transition: 'border-color 0.15s' }, footer: { width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: '32px', paddingTop: '20px', borderTop: '1px solid var(--border)' }, footerInfo: { fontSize: '12px', color: 'var(--text-mute)', fontFamily: 'JetBrains Mono, monospace' }, genBtn: { display: 'flex', alignItems: 'center', gap: '8px', padding: '12px 28px', fontSize: '14px', fontWeight: 600, background: 'linear-gradient(135deg, #7aa7ff, #4c8dff)', color: '#fff', borderRadius: '10px', cursor: 'pointer', transition: 'all 0.2s', border: 'none', boxShadow: '0 4px 20px rgba(76,141,255,0.3)' }, genBtnDisabled: { opacity: 0.5, cursor: 'not-allowed', boxShadow: 'none' }, // Processing overlay processing: { width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px', marginTop: '40px' }, processingCard: { width: '100%', maxWidth: '600px', background: 'var(--surface)', border: '1px solid var(--border)', borderRadius: '16px', padding: '32px', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '20px' }, processingTitle: { fontSize: '18px', fontWeight: 600, letterSpacing: '-0.01em' }, progressBar: { width: '100%', height: '6px', background: 'var(--border)', borderRadius: '3px', overflow: 'hidden' }, progressFill: (pct) => ({ height: '100%', width: `${pct}%`, background: 'linear-gradient(90deg, #4c8dff, #7aa7ff)', borderRadius: '3px', transition: 'width 0.5s ease' }), processingStatus: { fontSize: '13px', color: 'var(--text-dim)', fontFamily: 'JetBrains Mono, monospace' }, }; function ArtScreen({ user, onBack, onDone }) { const [files, setFiles] = React.useState([]); // [{ file, url, name }] const [isDragOver, setIsDragOver] = React.useState(false); const [isProcessing, setIsProcessing] = React.useState(false); const [jobId, setJobId] = React.useState(null); const [status, setStatus] = React.useState(null); const has3D = user?.role === 'admin' || (user?.allowed_tools || []).includes('art_3d'); const has2D = user?.role === 'admin' || (user?.allowed_tools || []).includes('art_2d'); const [artType, setArtType] = React.useState(has3D ? "3d" : "2d"); const [stylesList, setStylesList] = React.useState([]); const [selectedStyleId, setSelectedStyleId] = React.useState(null); const fileInputRef = React.useRef(null); // Fetch styles React.useEffect(() => { let active = true; const fetchStyles = async () => { try { const res = await API.getPublicArtStyles(artType); if (active) { setStylesList(res.styles || []); // Auto select default or first const defaultStyle = (res.styles || []).find(s => s.is_default); if (defaultStyle) { setSelectedStyleId(defaultStyle.id); } else if (res.styles?.length > 0) { setSelectedStyleId(res.styles[0].id); } else { setSelectedStyleId(null); } } } catch (err) { console.error("Lỗi fetch styles:", err); } }; fetchStyles(); return () => { active = false; }; }, [artType]); // Handle file selection const addFiles = (newFiles) => { const validFiles = Array.from(newFiles).filter(f => f.type.startsWith('image/') && f.size <= 15 * 1024 * 1024 ); if (files.length + validFiles.length > 10) { alert('Tối đa 10 ảnh mỗi lần'); return; } const newItems = validFiles.map(f => ({ file: f, url: URL.createObjectURL(f), name: f.name.replace(/\.[^.]+$/, '').replace(/[_-]/g, ' '), })); setFiles(prev => [...prev, ...newItems]); }; const removeFile = (idx) => { setFiles(prev => { const updated = [...prev]; URL.revokeObjectURL(updated[idx].url); updated.splice(idx, 1); return updated; }); }; const updateName = (idx, name) => { setFiles(prev => { const updated = [...prev]; updated[idx] = { ...updated[idx], name }; return updated; }); }; // Handle drag & drop const handleDrop = (e) => { e.preventDefault(); setIsDragOver(false); addFiles(e.dataTransfer.files); }; // Submit job const handleSubmit = async () => { if (files.length === 0 || isProcessing) return; setIsProcessing(true); try { const result = await API.createArtJob( files.map(f => f.file), files.map(f => f.name), artType, selectedStyleId ); setJobId(result.jobId); setStatus({ status: 'waiting', items: [] }); // We don't need to poll indefinitely anymore, as it's a background job. // But we can just set status to indicate it's submitted. } catch (err) { alert('Lỗi tạo Art job: ' + err.message); setIsProcessing(false); } }; // Poll status const pollStatus = async (jid) => { try { const data = await API.getArtStatus(jid); setStatus(data); if (data.status === 'processing' || data.status === 'waiting') { setTimeout(() => pollStatus(jid), 3000); } else { // Done, partial, or failed if (onDone) { onDone({ jobId: jid, items: data.items, status: data.status, doneCount: data.doneCount, totalCount: data.totalCount, }); } } } catch (err) { console.error('Poll error:', err); setTimeout(() => pollStatus(jid), 5000); } }; // Cleanup URLs on unmount React.useEffect(() => { return () => { files.forEach(f => URL.revokeObjectURL(f.url)); }; }, []); const doneCount = status ? status.doneCount : 0; const totalCount = status ? status.totalCount : files.length; const progressPct = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0; return (
Upload ảnh nhân vật, đặt tên cho từng nhân vật. AI sẽ tạo lại thành Art 2D phong cách Manhua hoặc CGI 3D chất lượng AAA theo lựa chọn của bạn.