// Banner Maker V2 Screen // Renders the interactive canvas editor with custom drag-and-resize bounding boxes for V2 creation. const bannerV2Styles = { page: { minHeight: '100vh', display: 'flex', flexDirection: 'column', background: 'var(--bg)' }, topbar: { height: '56px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', padding: '0 20px', gap: '12px', background: 'var(--bg-2)', flexShrink: 0 }, backBtn: { display: 'flex', alignItems: 'center', gap: '6px', color: 'var(--text-mute)', fontSize: '13px', fontWeight: 500, padding: '6px 12px', borderRadius: '8px', transition: 'all 0.15s', background: 'none', border: 'none', cursor: 'pointer' }, title: { fontSize: '15px', fontWeight: 600, letterSpacing: '-0.01em', display: 'flex', alignItems: 'center', gap: '8px' }, wrap: { flex: 1, display: 'grid', gridTemplateColumns: '360px 1fr', overflow: 'hidden', background: 'var(--bg)' }, sidebar: { borderRight: '1px solid var(--border)', display: 'flex', flexDirection: 'column', overflowY: 'auto', background: 'var(--bg)' }, section: { padding: '14px 16px', borderBottom: '1px solid var(--border)' }, sectionLast: { padding: '14px 16px', borderBottom: 'none' }, secLabel: { fontSize: '11px', fontWeight: 500, color: 'var(--text-dim)', textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '10px', display: 'flex', alignItems: 'center', gap: '7px' }, secNum: { width: '19px', height: '19px', borderRadius: '50%', background: 'var(--surface)', border: '1px solid var(--border)', fontSize: '10px', fontWeight: 600, color: 'var(--text-mute)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }, canvasPanel: { display: 'flex', flexDirection: 'column', background: 'var(--bg-2)' }, canvasHeader: { padding: '10px 16px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: 'var(--bg)', flexShrink: 0 }, canvasBody: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px', overflow: 'auto', minHeight: 0 }, canvasFooter: { padding: '14px 16px', borderTop: '1px solid var(--border)', background: 'var(--bg)', flexShrink: 0 }, dropzone: { width: '100%', minHeight: '80px', border: '2px dashed var(--border)', borderRadius: '10px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '6px', padding: '12px 10px', cursor: 'pointer', transition: 'all 0.2s', background: 'var(--surface)' }, dropIcon: { width: '30px', height: '30px', borderRadius: '8px', background: 'var(--accent-soft)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--accent-2)', border: '1px solid rgba(76,141,255,0.25)' }, inputGroup: { marginBottom: '10px' }, label: { fontSize: '11px', fontWeight: 500, color: 'var(--text-dim)', marginBottom: '5px', display: 'block' }, input: { width: '100%', padding: '8px 10px', background: 'var(--bg-2)', border: '1px solid var(--border)', borderRadius: '8px', color: 'var(--text)', fontSize: '13px', outline: 'none', transition: 'border-color 0.15s' }, textarea: { width: '100%', padding: '8px 10px', background: 'var(--bg-2)', border: '1px solid var(--border)', borderRadius: '8px', color: 'var(--text)', fontSize: '13px', outline: 'none', minHeight: '50px', resize: 'vertical', fontFamily: 'inherit' }, genBtn: { display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px', width: '100%', padding: '12px 24px', fontSize: '14px', fontWeight: 600, background: 'linear-gradient(135deg, #ff6b9d, #c850c0)', color: '#fff', borderRadius: '10px', cursor: 'pointer', transition: 'all 0.2s', border: 'none', boxShadow: '0 4px 20px rgba(255,107,157,0.3)' }, genBtnDisabled: { opacity: 0.5, cursor: 'not-allowed', boxShadow: 'none' }, 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' }, // Custom interactive canvas styles cf: { position: 'relative', background: '#101420', overflow: 'hidden', boxShadow: '0 8px 30px rgba(0,0,0,0.5)', border: '2px solid var(--border-strong)' }, cel: { position: 'absolute', cursor: 'move', userSelect: 'none' }, celInner: { width: '100%', height: '100%', position: 'relative', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '4px', borderRadius: '4px', overflow: 'hidden' }, h: { position: 'absolute', width: '9px', height: '9px', borderRadius: '1px', zIndex: 10, border: '1.5px solid', background: 'var(--bg)' }, h_tl: { top: '-5px', left: '-5px', cursor: 'nw-resize' }, h_tc: { top: '-5px', left: 'calc(50% - 4px)', cursor: 'n-resize' }, h_tr: { top: '-5px', right: '-5px', cursor: 'ne-resize' }, h_ml: { top: 'calc(50% - 4px)', left: '-5px', cursor: 'w-resize' }, h_mr: { top: 'calc(50% - 4px)', right: '-5px', cursor: 'e-resize' }, h_bl: { bottom: '-5px', left: '-5px', cursor: 'sw-resize' }, h_bc: { bottom: '-5px', left: 'calc(50% - 4px)', cursor: 's-resize' }, h_br: { bottom: '-5px', right: '-5px', cursor: 'se-resize' }, chip: (active) => ({ padding: '6px 12px', borderRadius: '20px', background: active ? 'var(--accent-soft)' : 'var(--surface)', border: `1px solid ${active ? 'var(--accent)' : 'var(--border)'}`, color: active ? 'var(--accent-2)' : 'var(--text-dim)', fontSize: '12px', fontWeight: 500, cursor: 'pointer', textAlign: 'center', transition: 'all 0.15s' }) }; const SIZE_PRESETS = [ { w: 1200, h: 1500, label: '1200×1500 (4:5)' }, { w: 1200, h: 1200, label: '1200×1200 (1:1)' }, { w: 1080, h: 1920, label: '1080×1920 (9:16)' }, { w: 1920, h: 1080, label: '1920×1080 (16:9)' }, ]; const MAX_TOTAL_ARTS = 10; // main + sub, giới hạn an toàn const MAX_FONTS = 5; const SUB_ART_COLORS = ['#3D7FD4', '#3DAA6E', '#C8A23D', '#8B5FBF', '#D4573D', '#3DC8B8', '#C83D8E', '#7A8C3D', '#3D5FC8']; const SUB_ART_DEFAULT_COORDS = [ { xp: 55, yp: 10, wp: 40, hp: 42 }, { xp: 20, yp: 20, wp: 35, hp: 35 }, { xp: 60, yp: 45, wp: 32, hp: 32 }, { xp: 5, yp: 45, wp: 30, hp: 30 }, { xp: 40, yp: 3, wp: 26, hp: 26 }, { xp: 68, yp: 3, wp: 26, hp: 26 }, { xp: 3, yp: 3, wp: 26, hp: 26 }, { xp: 35, yp: 55, wp: 26, hp: 26 }, { xp: 65, yp: 60, wp: 26, hp: 26 }, ]; const nextSubArtCoords = (i) => SUB_ART_DEFAULT_COORDS[i % SUB_ART_DEFAULT_COORDS.length]; function BannerV2Screen({ user, onBack, initialData }) { // Size Banner const [canvasSize, setCanvasSize] = React.useState({ width: 1200, height: 1500 }); const [customW, setCustomW] = React.useState(''); const [customH, setCustomH] = React.useState(''); // Art uploads const [mainArtFile, setMainArtFile] = React.useState(null); const [mainArtUrl, setMainArtUrl] = React.useState(''); const [subArts, setSubArts] = React.useState([]); // [{ localId, file, url, name, xp, yp, wp, hp }] const addSubArtFile = (file) => { if (!file || 1 + subArts.length >= MAX_TOTAL_ARTS) return; const localId = `art_sub_${Date.now()}_${subArts.length}`; const coords = nextSubArtCoords(subArts.length); setSubArts(prev => [...prev, { localId, file, url: URL.createObjectURL(file), name: file.name, ...coords }]); setSelectedElId(localId); }; const removeSubArt = (localId) => { setSubArts(prev => prev.filter(a => a.localId !== localId)); setSelectedElId(prev => prev === localId ? 'art_main' : prev); }; // Custom font uploads const [fontFiles, setFontFiles] = React.useState([]); // [{ localId, file, name }] const addFontFile = (file) => { if (!file || fontFiles.length >= MAX_FONTS) return; const localId = `font_${Date.now()}_${fontFiles.length}`; setFontFiles(prev => [...prev, { localId, file, name: file.name }]); }; const removeFontFile = (localId) => { setFontFiles(prev => { const removedIdx = prev.findIndex(f => f.localId === localId); if (removedIdx === -1) return prev; // Re-index font selections đang trỏ tới font bị xóa hoặc phía sau nó const remapIdx = (idx) => { if (idx === null || idx === undefined) return idx; if (idx === removedIdx) return null; if (idx > removedIdx) return idx - 1; return idx; }; setTexts(ts => ts.map(t => ({ ...t, fontIndex: remapIdx(t.fontIndex) }))); setCtaElement(c => ({ ...c, fontIndex: remapIdx(c.fontIndex) })); return prev.filter(f => f.localId !== localId); }); }; // Text Lines const [texts, setTexts] = React.useState([ { id: 'text_1', type: 'TEXT_REGION', content: 'KIM DUNG thuần CHẤT', xp: 10, yp: 65, wp: 80, hp: 7, fontIndex: null }, { id: 'text_2', type: 'TEXT_REGION', content: 'Khai mở 10h ngày 15/06', xp: 15, yp: 73, wp: 70, hp: 5, fontIndex: null } ]); // CTA Button const [hasCta, setHasCta] = React.useState(true); const [ctaLabel, setCtaLabel] = React.useState('TẢI NGAY'); const [ctaElement, setCtaElement] = React.useState({ id: 'cta', type: 'CTA_BUTTON', content: 'TẢI NGAY', xp: 25, yp: 81, wp: 50, hp: 8, fontIndex: null }); // Descriptions (Style / Extra) const [styleDesc, setStyleDesc] = React.useState('Thủy mặc cổ trang kiếm hiệp, tông màu tối u mặc huyền ảo'); const [extraDesc, setExtraDesc] = React.useState('Lá phong đỏ rơi nhẹ góc dưới, ánh hào quang nhẹ quanh kiếm'); const [sampleFile, setSampleFile] = React.useState(null); const [sampleUrl, setSampleUrl] = React.useState(''); // Editor states const [selectedElId, setSelectedElId] = React.useState('art_main'); const [hoveredElId, setHoveredElId] = React.useState(null); // Job status const [isProcessing, setIsProcessing] = React.useState(false); const [jobId, setJobId] = React.useState(null); const [progress, setProgress] = React.useState(0); const [progressMsg, setProgressMsg] = React.useState(''); const [outputUrl, setOutputUrl] = React.useState(null); const [error, setError] = React.useState(null); const [copied, setCopied] = React.useState(false); const handleCopy = async () => { try { await API.copyImageToClipboard(outputUrl); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch (err) { alert('Copy thất bại: ' + err.message); } }; // Handle CTA Toggle React.useEffect(() => { setCtaElement(prev => ({ ...prev, content: ctaLabel })); }, [ctaLabel]); // Aspect ratio and dynamic size calculation for preview container const maxW = 680; const maxH = 500; const aspectRatio = canvasSize.width / canvasSize.height; let containerW = maxW; let previewHeight = maxW / aspectRatio; if (previewHeight > maxH) { previewHeight = maxH; containerW = maxH * aspectRatio; } // Compile layout components for V2 const mainArtElement = { id: 'art_main', type: 'CHARACTER_ART', art_index: 0, name: 'Main Art', xp: 5, yp: 5, wp: 55, hp: 58, color: '#C84B31', thumbUrl: mainArtUrl, filename: mainArtFile ? mainArtFile.name : '' }; const subArtElements = subArts.map((a, i) => ({ id: a.localId, type: 'CHARACTER_ART', art_index: i + 1, name: `Art phụ ${i + 1}`, xp: a.xp, yp: a.yp, wp: a.wp, hp: a.hp, color: SUB_ART_COLORS[i % SUB_ART_COLORS.length], thumbUrl: a.url, filename: a.name, })); // Compile active elements const getActiveElements = () => { const list = [mainArtElement, ...subArtElements]; texts.forEach(t => list.push(t)); if (hasCta) list.push(ctaElement); return list; }; const activeElements = getActiveElements(); // Pointer drag and resize handlers const handleStartDrag = (e, elId) => { if (e.target.classList.contains('cel-h')) return; // let resize handles work setSelectedElId(elId); const el = activeElements.find(item => item.id === elId); if (!el) return; const cf = document.getElementById('cf-frame'); const cfRect = cf.getBoundingClientRect(); const startX = e.clientX; const startY = e.clientY; const startXp = el.xp; const startYp = el.yp; const handleMouseMove = (moveEvent) => { const dx = ((moveEvent.clientX - startX) / cfRect.width) * 100; const dy = ((moveEvent.clientY - startY) / cfRect.height) * 100; const newXp = Math.min(100 - el.wp, Math.max(0, startXp + dx)); const newYp = Math.min(100 - el.hp, Math.max(0, startYp + dy)); updateElementCoords(elId, { xp: newXp, yp: newYp }); }; const handleMouseUp = () => { document.removeEventListener('mousemove', handleMouseMove); document.removeEventListener('mouseup', handleMouseUp); }; document.addEventListener('mousemove', handleMouseMove); document.addEventListener('mouseup', handleMouseUp); e.preventDefault(); }; const handleStartResize = (e, elId, handleType) => { e.stopPropagation(); const el = activeElements.find(item => item.id === elId); if (!el) return; const cf = document.getElementById('cf-frame'); const cfRect = cf.getBoundingClientRect(); const startX = e.clientX; const startY = e.clientY; const startXp = el.xp; const startYp = el.yp; const startWp = el.wp; const startHp = el.hp; const handleMouseMove = (moveEvent) => { const dx = ((moveEvent.clientX - startX) / cfRect.width) * 100; const dy = ((moveEvent.clientY - startY) / cfRect.height) * 100; let nx = startXp; let ny = startYp; let nw = startWp; let nh = startHp; if (handleType.includes('r')) { nw = Math.max(5, startWp + dx); } if (handleType.includes('l')) { nx = Math.min(startXp + startWp - 5, Math.max(0, startXp + dx)); nw = startWp + (startXp - nx); } if (handleType.includes('b')) { nh = Math.max(4, startHp + dy); } if (handleType.includes('t')) { ny = Math.min(startYp + startHp - 4, Math.max(0, startYp + dy)); nh = startHp + (startYp - ny); } // Clamping inside canvas bounds if (nx + nw > 100) nw = 100 - nx; if (ny + nh > 100) nh = 100 - ny; updateElementCoords(elId, { xp: nx, yp: ny, wp: nw, hp: nh }); }; const handleMouseUp = () => { document.removeEventListener('mousemove', handleMouseMove); document.removeEventListener('mouseup', handleMouseUp); }; document.addEventListener('mousemove', handleMouseMove); document.addEventListener('mouseup', handleMouseUp); e.preventDefault(); }; const updateElementCoords = (elId, coords) => { if (elId === 'art_main') { setCoordsMap(prev => ({ ...prev, [elId]: { ...prev[elId], ...coords } })); } else if (elId.startsWith('art_sub_')) { setSubArts(prev => prev.map(a => a.localId === elId ? { ...a, ...coords } : a)); } else if (elId === 'cta') { setCtaElement(prev => ({ ...prev, ...coords })); } else { setTexts(prev => prev.map(t => t.id === elId ? { ...t, ...coords } : t)); } }; // Coords Cache Map cho Main Art (sub arts giữ coords ngay trong subArts[]) const [coordsMap, setCoordsMap] = React.useState({ art_main: { xp: 5, yp: 5, wp: 55, hp: 58 }, }); const loadedRef = React.useRef(false); // Load initialData when editing React.useEffect(() => { if (initialData && initialData.meta && !loadedRef.current) { loadedRef.current = true; const { meta, characters, sampleBanner } = initialData; // Canvas size if (meta.canvas_width && meta.canvas_height) { setCanvasSize({ width: meta.canvas_width, height: meta.canvas_height }); } const comps = (meta.layout_json && meta.layout_json.components) || []; const parseZone = (zoneStr) => { const result = { xp: 0, yp: 0, wp: 0, hp: 0 }; if (!zoneStr) return result; const topMatch = zoneStr.match(/top:\s*([\d.]+)/); const leftMatch = zoneStr.match(/left:\s*([\d.]+)/); const wMatch = zoneStr.match(/w:\s*([\d.]+)/); const hMatch = zoneStr.match(/h:\s*([\d.]+)/); if (leftMatch) result.xp = parseFloat(leftMatch[1]); if (topMatch) result.yp = parseFloat(topMatch[1]); if (wMatch) result.wp = parseFloat(wMatch[1]); if (hMatch) result.hp = parseFloat(hMatch[1]); return result; }; // Characters: đầu tiên là main art, còn lại là sub arts (dynamic, không giới hạn 2) if (characters && characters.length > 0) { setMainArtFile(characters[0].file); setMainArtUrl(characters[0].url); const subs = characters.slice(1).map((c, i) => { const artIdx = i + 1; const comp = comps.find(cc => cc.type === 'CHARACTER_ART' && cc.art_index === artIdx); const coords = comp ? parseZone(comp.zone) : nextSubArtCoords(i); return { localId: `art_sub_${Date.now()}_${i}`, file: c.file, url: c.url, name: c.file.name, ...coords }; }); setSubArts(subs); } else { setSubArts([]); } // Sample reference if (sampleBanner) { setSampleFile(sampleBanner.file); setSampleUrl(sampleBanner.url); } else { setSampleFile(null); setSampleUrl(''); } // Descriptions if (meta.style_description) setStyleDesc(meta.style_description); if (meta.extra_items_desc) setExtraDesc(meta.extra_items_desc); // Layout components (main art coords + texts + cta). Sub art coords đã xử lý ở trên cùng characters. if (comps.length > 0) { // Coords map for main art component const newCoords = { art_main: { xp: 5, yp: 5, wp: 55, hp: 58 } }; const artMain = comps.find(c => c.type === 'CHARACTER_ART' && c.art_index === 0); if (artMain) { const coords = parseZone(artMain.zone); newCoords.art_main = { xp: coords.xp, yp: coords.yp, wp: coords.wp, hp: coords.hp }; } setCoordsMap(newCoords); // Texts const textComponents = comps.filter(c => c.type === 'TEXT_REGION'); if (textComponents.length > 0) { setTexts(textComponents.map(c => { const coords = parseZone(c.zone); return { id: c.id, type: 'TEXT_REGION', content: c.content, xp: coords.xp, yp: coords.yp, wp: coords.wp, hp: coords.hp, fontIndex: (c.font_index === undefined) ? null : c.font_index }; })); } // CTA const ctaComponent = comps.find(c => c.type === 'CTA_BUTTON'); if (ctaComponent) { const coords = parseZone(ctaComponent.zone); setHasCta(true); setCtaLabel(ctaComponent.content || 'TẢI NGAY'); setCtaElement({ id: 'cta', type: 'CTA_BUTTON', content: ctaComponent.content || 'TẢI NGAY', xp: coords.xp, yp: coords.yp, wp: coords.wp, hp: coords.hp, fontIndex: (ctaComponent.font_index === undefined) ? null : ctaComponent.font_index }); } else { setHasCta(false); } } } }, [initialData]); // Apply cache coordinates cho main art (sub arts đã có coords sẵn trong subArts[]) mainArtElement.xp = coordsMap.art_main.xp; mainArtElement.yp = coordsMap.art_main.yp; mainArtElement.wp = coordsMap.art_main.wp; mainArtElement.hp = coordsMap.art_main.hp; // Add text line const handleAddText = () => { const nextId = `text_${Date.now()}`; const nextY = texts.length > 0 ? Math.min(90, texts[texts.length - 1].yp + 8) : 65; setTexts(prev => [...prev, { id: nextId, type: 'TEXT_REGION', content: 'Dòng chữ mới', xp: 15, yp: nextY, wp: 70, hp: 5, fontIndex: null }]); setSelectedElId(nextId); }; // Remove text line const handleRemoveText = (id) => { setTexts(prev => prev.filter(t => t.id !== id)); if (selectedElId === id) setSelectedElId('art_main'); }; // Assign font to a text line / CTA const handleTextFontChange = (id, fontIndex) => { setTexts(prev => prev.map(t => t.id === id ? { ...t, fontIndex } : t)); }; const handleCtaFontChange = (fontIndex) => { setCtaElement(prev => ({ ...prev, fontIndex })); }; // Handle Text Content Change const handleTextChange = (id, val) => { setTexts(prev => prev.map(t => t.id === id ? { ...t, content: val } : t)); }; // Submit banner generation job const handleGenerate = async () => { if (!mainArtFile) return; setIsProcessing(true); setError(null); setOutputUrl(null); setProgress(5); setProgressMsg('Phân tích art với Claude Vision…'); try { // Build components layout structure const components = []; // Main art components.push({ id: 'art_main', type: 'CHARACTER_ART', zone: `top:${mainArtElement.yp.toFixed(1)}% left:${mainArtElement.xp.toFixed(1)}% w:${mainArtElement.wp.toFixed(1)}% h:${mainArtElement.hp.toFixed(1)}%`, art_index: 0, lock_position: true }); // Sub arts (dynamic, tối đa MAX_TOTAL_ARTS - 1) subArtElements.forEach(el => { components.push({ id: el.id, type: 'CHARACTER_ART', zone: `top:${el.yp.toFixed(1)}% left:${el.xp.toFixed(1)}% w:${el.wp.toFixed(1)}% h:${el.hp.toFixed(1)}%`, art_index: el.art_index, lock_position: true }); }); // Text elements texts.forEach((t, i) => { components.push({ id: t.id, type: 'TEXT_REGION', zone: `top:${t.yp.toFixed(1)}% left:${t.xp.toFixed(1)}% w:${t.wp.toFixed(1)}% h:${t.hp.toFixed(1)}%`, content: t.content, font_index: (t.fontIndex === null || t.fontIndex === undefined) ? null : t.fontIndex, lock_position: true }); }); // CTA button if (hasCta) { components.push({ id: 'cta', type: 'CTA_BUTTON', zone: `top:${ctaElement.yp.toFixed(1)}% left:${ctaElement.xp.toFixed(1)}% w:${ctaElement.wp.toFixed(1)}% h:${ctaElement.hp.toFixed(1)}%`, content: ctaElement.content, font_index: (ctaElement.fontIndex === null || ctaElement.fontIndex === undefined) ? null : ctaElement.fontIndex, lock_position: true }); } const layoutJson = { coordinate_unit: 'PERCENT_OF_FINAL_CANVAS', canvas: { width: canvasSize.width, height: canvasSize.height }, components: components }; const payload = { style_description: styleDesc, extra_items_desc: extraDesc, canvas_width: canvasSize.width, canvas_height: canvasSize.height, layout_json: layoutJson }; const result = await API.createBannerV2Job( mainArtFile, subArts.map(a => a.file), sampleFile, payload, fontFiles.map(f => f.file) ); setJobId(result.jobId); pollJobStatus(result.jobId); } catch (err) { setError(err.message); setIsProcessing(false); } }; // Poll Job Status const pollJobStatus = (id) => { let steps = [ { pct: 15, msg: 'Trích xuất màu sắc & intent…', delay: 1500 }, { pct: 35, msg: 'Biến đổi toạ độ & protected zones…', delay: 3500 }, { pct: 55, msg: 'Build prompt cho GPT-image-2…', delay: 5500 }, { pct: 75, msg: 'Đang tạo banner với AI…', delay: 8500 }, { pct: 95, msg: 'Kiểm tra kích thước & lưu trữ…', delay: 18000 } ]; // Simulate progress while polling steps.forEach(s => { setTimeout(() => { setIsProcessing(active => { if (active) { setProgress(s.pct); setProgressMsg(s.msg); } return active; }); }, s.delay); }); const checkStatus = async () => { try { const res = await API.getBannerV2Status(id); if (res.status === 'done') { setProgress(100); setProgressMsg('Hoàn tất!'); setOutputUrl(res.outputUrl); setIsProcessing(false); } else if (res.status === 'failed') { setError(res.error_msg || 'Tạo banner thất bại.'); setIsProcessing(false); } else { // Poll again in 3 seconds setTimeout(checkStatus, 3000); } } catch (err) { setError(err.message); setIsProcessing(false); } }; setTimeout(checkStatus, 2000); }; // Reset page const handleReset = () => { setJobId(null); setOutputUrl(null); setError(null); setProgress(0); setProgressMsg(''); }; return (
Tải ảnh Art chính để định hình bố cục