// Banner Generation Screen
const bannerStyles = {
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' },
// v6 layout: sidebar + canvas panel
wrap: { flex: 1, display: 'grid', gridTemplateColumns: '360px 1fr', overflow: 'hidden', background: 'var(--bg)' },
// Left sidebar
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 },
// Right canvas panel
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 },
// Kept styles (adapted for sidebar context)
heading: { fontSize: '32px', fontWeight: 600, letterSpacing: '-0.025em', margin: '0 0 8px 0', textAlign: 'center' },
sectionTitle: { fontSize: '12px', fontWeight: 600, marginBottom: '10px', color: 'var(--text-dim)', textTransform: 'uppercase', letterSpacing: '0.05em' },
dropzone: { width: '100%', minHeight: '100px', border: '2px dashed var(--border)', borderRadius: '10px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '8px', padding: '16px 12px', cursor: 'pointer', transition: 'all 0.2s', background: 'var(--surface)' },
dropzoneActive: { borderColor: 'var(--accent)', background: 'var(--accent-soft)' },
dropIcon: { width: '36px', height: '36px', borderRadius: '10px', background: 'var(--accent-soft)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--accent-2)', border: '1px solid rgba(76,141,255,0.25)' },
preview: { width: '100%', maxWidth: '100%', borderRadius: '8px', overflow: 'hidden', border: '1px solid var(--border)', background: '#0a0f1a', position: 'relative', marginTop: '8px' },
previewImg: { width: '100%', display: 'block', objectFit: 'contain', maxHeight: '200px' },
previewRemove: { position: 'absolute', top: '6px', right: '6px', width: '24px', height: '24px', borderRadius: '50%', background: 'rgba(11,18,32,0.7)', border: '1px solid var(--border)', color: 'var(--text-mute)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' },
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: '60px', resize: 'vertical', fontFamily: 'inherit' },
styleCard: (sel) => ({ padding: '10px 12px', background: sel ? 'var(--accent-soft)' : 'var(--surface)', border: `1.5px solid ${sel ? 'var(--accent)' : 'var(--border)'}`, borderRadius: '8px', cursor: 'pointer', transition: 'all 0.2s' }),
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' },
footer: { width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: '32px', paddingTop: '20px', borderTop: '1px solid var(--border)' },
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' },
layoutToggle: (active) => ({ padding: '7px 14px', fontSize: '12px', fontWeight: 500, borderRadius: '8px', cursor: 'pointer', border: `1px solid ${active ? 'var(--accent)' : 'var(--border)'}`, background: active ? 'var(--accent-soft)' : 'var(--surface)', color: active ? 'var(--accent-2)' : 'var(--text-dim)', transition: 'all 0.15s' }),
};
const getPlaceholder = (key) => {
const map = {
'main_text': 'VD: Siêu Phẩm Mới Ra Mắt',
'sub_text': 'VD: Nhận x10 kim cương miễn phí',
'cta': 'VD: TẢI NGAY',
'character_name': 'VD: Đông Phương Bất Bại',
'character_rank': 'VD: SSR, UR, 5 Sao...',
'rank': 'VD: SSR+',
'skill_name': 'VD: Hỏa Long Hống, Băng Giá...',
'skill_description': 'VD: Gây 500% sát thương diện rộng',
'giftcode': 'VD: VIP999, TANTHU888',
'reward_list': 'VD: x100 Kim Cương, x1 Tướng SSR',
'event_name': 'VD: Sự Kiện Mùa Hè',
'event_title': 'VD: Khai Mở Server Mới',
'event_date': 'VD: 01/06 - 30/06',
'expiry_date': 'VD: 30/06/2026',
'text_group_1': 'VD: ĐẾM NGƯỢC RA MẮT',
'text_group_2': 'VD: 3',
'text_group_3': 'VD: NGÀY',
'gameplay_highlight': 'VD: PvP 5v5 thời gian thực',
};
return map[key] || `Nhập ${key.replace(/_/g, ' ')}...`;
};
const getFieldLabel = (key) => {
const map = {
'main_text': 'Tiêu đề chính',
'sub_text': 'Phụ đề',
'cta': 'Nút CTA',
'character_name': 'Tên nhân vật',
'character_rank': 'Hạng nhân vật',
'rank': 'Hạng (Rank)',
'skill_name': 'Tên kỹ năng',
'skill_description': 'Mô tả kỹ năng',
'giftcode': 'Mã Giftcode',
'reward_list': 'Danh sách quà',
'event_name': 'Tên sự kiện',
'event_title': 'Tiêu đề sự kiện',
'event_date': 'Thời gian sự kiện',
'expiry_date': 'Hạn nhận quà',
'text_group_1': 'Nhóm chữ 1',
'text_group_2': 'Nhóm chữ 2',
'text_group_3': 'Nhóm chữ 3',
'gameplay_highlight': 'Điểm nhấn gameplay',
};
return map[key] || key.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
};
function CustomLayoutEditor({ elements, value, onChange, bgImageUrl, bgImageUrl2, fieldValues, bgImageUrls }) {
// Map zone element names → user input field keys
const zoneToFieldKey = {
'main_text_zone': 'main_text', 'sub_text_zone': 'sub_text', 'cta_zone': 'cta',
'character_name_zone': 'character_name', 'rank_zone': 'rank', 'character_rank_zone': 'character_rank',
'skill_effect_zone': 'skill_name', 'skill_name_zone': 'skill_name', 'skill_description_zone': 'skill_description',
'giftcode_zone': 'giftcode', 'reward_zone': 'reward_list', 'reward_list_zone': 'reward_list',
'event_text_zone': 'event_name', 'event_name_zone': 'event_name', 'event_title_zone': 'event_title',
'event_date_zone': 'event_date', 'expiry_date_zone': 'expiry_date',
'text_group_1_zone': 'text_group_1', 'text_group_2_zone': 'text_group_2', 'text_group_3_zone': 'text_group_3',
'gameplay_highlight_zone': 'gameplay_highlight',
};
const [activeEl, setActiveEl] = React.useState(elements[0] || null);
const [drawing, setDrawing] = React.useState(null);
const overlayRef = React.useRef(null);
React.useEffect(() => {
if (elements.length > 0 && !elements.includes(activeEl)) {
setActiveEl(elements[0]);
}
}, [elements, activeEl]);
const parseRect = (str) => {
if (!str) return null;
const mTop = str.match(/top:(\d+)%/);
const mLeft = str.match(/left:(\d+)%/);
const mW = str.match(/w:(\d+)%/);
const mH = str.match(/h:(\d+)%/);
if (mTop && mLeft && mW && mH) {
return { y: parseInt(mTop[1]) / 100, x: parseInt(mLeft[1]) / 100, w: parseInt(mW[1]) / 100, h: parseInt(mH[1]) / 100 };
}
return null;
};
const toRectString = (rect) => {
return `top:${Math.round(rect.y * 100)}% left:${Math.round(rect.x * 100)}% w:${Math.round(rect.w * 100)}% h:${Math.round(rect.h * 100)}%`;
};
const onPointerDown = (e) => {
if (!activeEl) return;
const rect = overlayRef.current.getBoundingClientRect();
const x = (e.clientX - rect.left) / rect.width;
const y = (e.clientY - rect.top) / rect.height;
setDrawing({ x0: x, y0: y, x, y });
e.currentTarget.setPointerCapture(e.pointerId);
};
const onPointerMove = (e) => {
if (!drawing) return;
const rect = overlayRef.current.getBoundingClientRect();
const x = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
const y = Math.min(1, Math.max(0, (e.clientY - rect.top) / rect.height));
setDrawing({ ...drawing, x, y });
};
const onPointerUp = (e) => {
if (!drawing) return;
const { x0, y0, x, y } = drawing;
const nx = Math.min(x0, x), ny = Math.min(y0, y);
const nw = Math.abs(x - x0), nh = Math.abs(y - y0);
setDrawing(null);
if (nw < 0.02 || nh < 0.02) return; // ignore tiny clicks
onChange({ ...value, [activeEl]: toRectString({ x: nx, y: ny, w: nw, h: nh }) });
};
const clearElement = (el) => {
const newVal = { ...value };
delete newVal[el];
onChange(newVal);
};
const colors = ['#4c8dff', '#ffb547', '#3dd68c', '#e371ff', '#ff6a6a'];
return (
{/* Canvas — 4:5 aspect ratio (1088×1360) */}
1088 × 1360
{elements.map((el, i) => {
const rect = parseRect(value[el]);
if (!rect) return null;
const color = colors[i % colors.length];
const isActive = el === activeEl;
const isCharZone = el.startsWith('character_zone');
const isScreenshotZone = el === 'screenshot_zone';
const isLogoZone = el === 'logo_safe_area';
// Determine zone inner content
let zoneInner = null;
if (isCharZone) {
let charIdx = 0;
if (el !== 'character_zone') {
charIdx = parseInt(el.split('_').pop()) - 1;
}
const currentBg = bgImageUrls && bgImageUrls[charIdx] ? bgImageUrls[charIdx] : (charIdx === 0 ? bgImageUrl : null);
if (currentBg) {
zoneInner =

;
}
} else if (isScreenshotZone && bgImageUrl2) {
zoneInner =

;
} else if (isLogoZone) {
zoneInner =
LOGO
;
} else {
const fieldKey = zoneToFieldKey[el];
const text = fieldKey && (fieldValues || {})[fieldKey];
if (text) {
zoneInner =
{text}
;
}
}
return (
{el.replace(/_/g, ' ')}
{zoneInner}
);
})}
{drawing && (() => {
const { x0, y0, x, y } = drawing;
const nx = Math.min(x0, x), ny = Math.min(y0, y);
const nw = Math.abs(x - x0), nh = Math.abs(y - y0);
const color = colors[elements.indexOf(activeEl) % colors.length];
return
;
})()}
{/* Controls */}
Chọn vùng và kéo thả trên khung canvas (tỷ lệ 4:5) bên trái:
{elements.map((el, i) => {
const isActive = el === activeEl;
const hasValue = !!value[el];
const color = colors[i % colors.length];
return (
{hasValue && (
)}
);
})}
);
}
function BannerScreen({ user, onBack, onDone, initData }) {
const [characterFiles, setCharacterFiles] = React.useState([]);
const [characterUrls, setCharacterUrls] = React.useState([]);
const [isDragOver, setIsDragOver] = React.useState(false);
const [stylesList, setStylesList] = React.useState([]);
const [selectedStyleId, setSelectedStyleId] = React.useState(null);
const [layoutMode, setLayoutMode] = React.useState('AUTO');
const [isProcessing, setIsProcessing] = React.useState(false);
const [jobId, setJobId] = React.useState(null);
const [error, setError] = React.useState('');
const [showStyleModal, setShowStyleModal] = React.useState(false);
// Dynamic content fields — single object for all inputs
const [allFields, setAllFields] = React.useState({});
// Multi-skill entries
const [skills, setSkills] = React.useState([{ name: '', description: '' }]);
// Logos
const [logos, setLogos] = React.useState([]);
const [useLogo, setUseLogo] = React.useState(false);
const [selectedLogoUrl, setSelectedLogoUrl] = React.useState('');
// Custom Layout
const [customLayout, setCustomLayout] = React.useState({});
const fileInputRef = React.useRef(null);
// Screenshot (Multi-upload)
const [screenshotFiles, setScreenshotFiles] = React.useState([]);
const [screenshotUrls, setScreenshotUrls] = React.useState([]);
const [isScreenshotDragOver, setIsScreenshotDragOver] = React.useState(false);
const screenshotInputRef = React.useRef(null);
// Fetch styles & logos
React.useEffect(() => {
let active = true;
Promise.all([API.getPublicBannerStyles(), API.getPublicLogos()]).then(([stylesRes, logosRes]) => {
if (!active) return;
const styles = stylesRes.styles || [];
setStylesList(styles);
const def = styles.find(s => s.is_default) || styles[0];
if (def) setSelectedStyleId(def.id);
const lg = logosRes.logos || [];
setLogos(lg);
if (lg.length > 0) setSelectedLogoUrl(lg[0].url);
}).catch(err => console.error('Fetch data:', err));
return () => { active = false; };
}, []);
React.useEffect(() => {
if (initData && stylesList.length > 0 && characterFiles.length === 0) { // init once
// Multi-art: initData.characters[] (new) hoặc initData.character (backward compat)
if (initData.characters && initData.characters.length > 0) {
setCharacterFiles(initData.characters.map(c => c.file));
setCharacterUrls(initData.characters.map(c => c.url));
} else if (initData.character) {
setCharacterFiles([initData.character.file]);
setCharacterUrls([initData.character.url]);
}
// Multi-screenshot: initData.screenshots[] (new) hoặc initData.screenshot (backward compat)
if (initData.screenshots && initData.screenshots.length > 0) {
setScreenshotFiles(initData.screenshots.map(s => s.file));
setScreenshotUrls(initData.screenshots.map(s => s.url));
console.log('[BannerInit] Set screenshotFiles from initData.screenshots:', initData.screenshots.length,
initData.screenshots.map(s => ({ name: s.file.name, size: s.file.size, type: s.file.type })));
} else if (initData.screenshot) {
setScreenshotFiles([initData.screenshot.file]);
setScreenshotUrls([initData.screenshot.url]);
console.log('[BannerInit] Set screenshotFiles from initData.screenshot (single):', { name: initData.screenshot.file.name, size: initData.screenshot.file.size });
} else {
console.warn('[BannerInit] No screenshots in initData!', { screenshots: initData.screenshots, screenshot: initData.screenshot });
}
if (initData.meta) {
if (initData.meta.style_id) setSelectedStyleId(initData.meta.style_id);
console.log('[BannerInit] style_id from meta:', initData.meta.style_id);
if (initData.meta.layout_mode) setLayoutMode(initData.meta.layout_mode);
if (initData.meta.custom_layout) setCustomLayout(initData.meta.custom_layout);
if (initData.meta.content) {
const { skills: initSkills, ...restContent } = initData.meta.content;
setAllFields(restContent);
if (Array.isArray(initSkills) && initSkills.length > 0) setSkills(initSkills);
}
if (initData.meta.logo_url) {
setUseLogo(true);
setSelectedLogoUrl(initData.meta.logo_url);
}
}
}
}, [initData, stylesList]);
const selectedStyle = stylesList.find(s => s.id === selectedStyleId);
const maxCharacterArts = 10; // giới hạn an toàn, không phụ thuộc cấu hình style
const maxScreenshots = selectedStyle?.max_screenshots || 1;
const handleFileSelect = (file) => {
if (!file || !file.type.startsWith('image/')) return;
if (file.size > 15 * 1024 * 1024) { alert('File quá lớn (max 15MB)'); return; }
if (characterFiles.length >= maxCharacterArts) {
alert(`Style này chỉ cho phép tối đa ${maxCharacterArts} ảnh nhân vật`);
return;
}
setCharacterFiles(prev => [...prev, file]);
setCharacterUrls(prev => [...prev, URL.createObjectURL(file)]);
};
const handleMultiFileSelect = (files) => {
for (const file of files) {
handleFileSelect(file);
}
};
const handleDrop = (e) => {
e.preventDefault(); setIsDragOver(false);
const files = Array.from(e.dataTransfer.files).filter(f => f.type.startsWith('image/'));
if (files.length > 0) handleMultiFileSelect(files);
};
const removeFile = (index) => {
setCharacterUrls(prev => { URL.revokeObjectURL(prev[index]); return prev.filter((_, i) => i !== index); });
setCharacterFiles(prev => prev.filter((_, i) => i !== index));
};
const handleScreenshotSelect = (file) => {
if (!file || !file.type.startsWith('image/')) return;
if (file.size > 15 * 1024 * 1024) { alert('File quá lớn (max 15MB)'); return; }
if (screenshotFiles.length >= maxScreenshots) {
alert(`Style này chỉ cho phép tối đa ${maxScreenshots} ảnh screenshot`);
return;
}
setScreenshotFiles(prev => [...prev, file]);
setScreenshotUrls(prev => [...prev, URL.createObjectURL(file)]);
};
const removeScreenshot = (index) => {
setScreenshotUrls(prev => { URL.revokeObjectURL(prev[index]); return prev.filter((_, i) => i !== index); });
setScreenshotFiles(prev => prev.filter((_, i) => i !== index));
};
const handleSubmit = async () => {
if (characterFiles.length === 0 || isProcessing) return;
setError(''); setIsProcessing(true);
try {
// Build content from allFields
const content = {};
const reqInputs = selectedStyle?.required_inputs || ['main_text', 'sub_text', 'cta'];
const optInputs = selectedStyle?.optional_inputs || [];
[...reqInputs, ...optInputs].forEach(key => {
if (key === 'skill_name' || key === 'skill_description') return; // handled via skills array
if (allFields[key]) content[key] = allFields[key];
});
// Include skills array if style uses skill fields
const allInputs = [...reqInputs, ...optInputs];
if (allInputs.includes('skill_name') || allInputs.includes('skill_description')) {
const validSkills = skills.filter(s => s.name.trim() || s.description.trim());
if (validSkills.length > 0) content.skills = validSkills;
}
// Backward compat: if style uses main_text/sub_text/cta, also set them
if (!content.main_text && allFields.main_text) content.main_text = allFields.main_text;
const payload = {
style_id: selectedStyleId,
layout_mode: layoutMode,
content,
render_mode: 'FULL_TEXT_IN_IMAGE',
logo_url: useLogo ? selectedLogoUrl : null,
};
if (layoutMode === 'CUSTOM') {
payload.custom_layout = customLayout;
}
console.log('[BannerSubmit] Sending:', {
characterFiles: characterFiles.length,
screenshotFiles: screenshotFiles.length,
screenshotDetails: screenshotFiles.map(f => ({ name: f.name, size: f.size, type: f.type })),
style_id: payload.style_id,
layout_mode: payload.layout_mode,
});
const result = await API.createBannerJob(characterFiles, payload, screenshotFiles);
setJobId(result.jobId);
} catch (err) {
setError(err.message);
setIsProcessing(false);
}
};
const requiredInputs = selectedStyle?.required_inputs || ['main_text', 'sub_text', 'cta'];
const canSubmit = characterFiles.length > 0 && requiredInputs.every(k => (allFields[k] || '').trim()) && (!(selectedStyle?.required_images || []).includes('ingame_screenshot') || screenshotFiles.length >= maxScreenshots);
// Cleanup
React.useEffect(() => () => {
characterUrls.forEach(u => URL.revokeObjectURL(u));
screenshotUrls.forEach(u => URL.revokeObjectURL(u));
}, []);
// Count elements for canvas header
const elementCount = characterFiles.length + screenshotFiles.length + (useLogo ? 1 : 0);
// Compute layout elements for custom layout editor
const layoutElements = (() => {
if (!selectedStyle?.layout_elements) return [];
const baseElements = selectedStyle.layout_elements || [];
const finalElements = [];
for (const el of baseElements) {
if (el === 'character_zone') {
if (characterUrls.length > 1) {
finalElements.push('character_zone');
for (let idx = 2; idx <= characterUrls.length; idx++) {
finalElements.push(`character_zone_${idx}`);
}
} else {
finalElements.push('character_zone');
}
} else {
finalElements.push(el);
}
}
if (useLogo && !finalElements.includes('logo_safe_area')) {
finalElements.push('logo_safe_area');
}
return finalElements;
})();
return (
Tạo Banner
{!isProcessing ? (
{/* ── LEFT SIDEBAR ── */}
{/* ① Phong Cách Banner */}
{stylesList.length > 0 && (
1 Phong cách banner
{selectedStyle ? (
<>
{selectedStyle.name}
{selectedStyle.is_default && Mặc định}
{!selectedStyle.is_enabled && (
Đang tắt
)}
{selectedStyle.description || 'Không có mô tả'}
{!selectedStyle.is_enabled && (
⚠️ Style này đang tắt cho tất cả user
)}
>
) : (
Chưa chọn phong cách
)}
)}
{/* ② Ảnh Nhân Vật */}
2 Ảnh nhân vật
{characterFiles.length}/{maxCharacterArts}
{characterFiles.length === 0 && characterFiles.length < maxCharacterArts && (
{ e.preventDefault(); setIsDragOver(true); }}
onDragLeave={() => setIsDragOver(false)}
onDrop={handleDrop}
onClick={() => fileInputRef.current?.click()}>
Kéo thả hoặc nhấn để chọn
PNG / JPG / WEBP • Max 15MB
{ Array.from(e.target.files).forEach(f => handleFileSelect(f)); e.target.value = ''; }} />
)}
{characterFiles.length > 0 && (
{characterFiles.map((file, idx) => (
{idx === 0 ? 'Main Art' : `Art phụ ${idx}`}
{file.name}
))}
)}
{characterFiles.length > 0 && characterFiles.length < maxCharacterArts && (
)}
{characterFiles.length > 0 && (
{ Array.from(e.target.files).forEach(f => handleFileSelect(f)); e.target.value = ''; }} />
)}
{/* ③ Screenshot (conditional) */}
{(selectedStyle?.required_images || []).includes('ingame_screenshot') && (
3 Screenshot
{maxScreenshots > 1 && Cần {maxScreenshots}}
= maxScreenshots ? 'var(--accent-2)' : 'var(--text-mute)', fontFamily: 'JetBrains Mono, monospace' }}>{screenshotFiles.length}/{maxScreenshots}
{screenshotFiles.length < maxScreenshots && (
0 ? '60px' : '100px' }}
onDragOver={e => { e.preventDefault(); setIsScreenshotDragOver(true); }}
onDragLeave={() => setIsScreenshotDragOver(false)}
onDrop={e => {
e.preventDefault(); setIsScreenshotDragOver(false);
Array.from(e.dataTransfer.files).filter(f => f.type.startsWith('image/')).forEach(f => handleScreenshotSelect(f));
}}
onClick={() => screenshotInputRef.current?.click()}>
Kéo thả hoặc nhấn để chọn
PNG / JPG / WEBP • Max 15MB
1} style={{ display: 'none' }}
onChange={e => { Array.from(e.target.files).forEach(f => handleScreenshotSelect(f)); e.target.value = ''; }} />
)}
{screenshotFiles.length > 0 && (
{screenshotFiles.map((file, idx) => (
Screenshot {idx + 1}
{file.name}
))}
)}
)}
{/* ④ Nội Dung Banner */}
{(selectedStyle?.required_images || []).includes('ingame_screenshot') ? '4' : '3'} Nội dung banner
{selectedStyle && (
Style {selectedStyle.name} — gõ nội dung bạn muốn in lên ảnh. Ô (tuỳ chọn) để trống sẽ bị bỏ qua.
)}
{/* Dynamic required inputs (skip skill fields) */}
{(selectedStyle?.required_inputs || ['main_text', 'sub_text', 'cta']).filter(k => k !== 'skill_name' && k !== 'skill_description').map(key => (
setAllFields(prev => ({ ...prev, [key]: e.target.value }))}
placeholder={getPlaceholder(key)}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--border)'} />
))}
{/* Dynamic optional inputs (skip skill fields) */}
{selectedStyle?.optional_inputs?.filter(k => k !== 'skill_name' && k !== 'skill_description').map(key => (
setAllFields(prev => ({ ...prev, [key]: e.target.value }))}
placeholder={getPlaceholder(key)}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--border)'} />
))}
{/* Multi-Skill Section */}
{(() => {
const allInputs = [...(selectedStyle?.required_inputs || []), ...(selectedStyle?.optional_inputs || [])];
const hasSkillFields = allInputs.includes('skill_name') || allInputs.includes('skill_description');
if (!hasSkillFields) return null;
const isRequired = (selectedStyle?.required_inputs || []).includes('skill_name');
return (
{skills.map((skill, i) => (
{ const ns = [...skills]; ns[i] = { ...ns[i], name: e.target.value }; setSkills(ns); }}
placeholder={`Kỹ năng ${i + 1}`}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--border)'} />
{ const ns = [...skills]; ns[i] = { ...ns[i], description: e.target.value }; setSkills(ns); }}
placeholder="Mô tả kỹ năng"
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--border)'} />
{skills.length > 1 && (
)}
))}
);
})()}
{/* ⑤ Logo Game */}
{logos.length > 0 && (
{(selectedStyle?.required_images || []).includes('ingame_screenshot') ? '5' : '4'} Logo game
{useLogo && (
{logos.map(l => (
setSelectedLogoUrl(l.url)}
style={{
border: `1.5px solid ${selectedLogoUrl === l.url ? 'var(--accent)' : 'transparent'}`,
background: selectedLogoUrl === l.url ? 'var(--accent-soft)' : 'var(--surface)',
borderRadius: '6px', padding: '6px', cursor: 'pointer', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '4px', transition: 'all 0.15s'
}}
>
{l.name}
))}
)}
)}
{/* ⑥ Chế Độ Layout */}
{(selectedStyle?.required_images || []).includes('ingame_screenshot') ? (logos.length > 0 ? '6' : '5') : (logos.length > 0 ? '5' : '4')} Chế độ layout
{/* ── RIGHT CANVAS PANEL ── */}
{/* Canvas Header */}
{layoutMode === 'CUSTOM' ? 'Bố cục — ' : 'Preview — '}
{selectedStyle?.name || 'Chọn style'}
{elementCount} element{elementCount !== 1 ? 's' : ''}
{/* Canvas Body */}
{error &&
{error}
}
{layoutMode === 'CUSTOM' && selectedStyle?.layout_elements ? (
) : (
/* AUTO mode — show style example image or placeholder */
{selectedStyle?.example_image ? (
{selectedStyle.name}
{selectedStyle.description || 'Không có mô tả cho phong cách này.'}
) : (
🖼️
Chưa có ảnh mẫu
Chọn phong cách bên trái để xem preview
)}
)}
{/* Canvas Footer */}
1 lượt quota • ~60s xử lý
{!canSubmit && characterFiles.length === 0 && (
Cần upload ảnh nhân vật
)}
{showStyleModal && (
setShowStyleModal(false)}>
e.stopPropagation()}>
{/* Modal Header */}
Chọn phong cách banner
{/* Modal Body */}
{stylesList.map(s => (
{ setSelectedStyleId(s.id); setShowStyleModal(false); }} style={bannerStyles.styleCard(selectedStyleId === s.id)}
onMouseEnter={e => { if (selectedStyleId !== s.id) e.currentTarget.style.borderColor = 'rgba(255,107,157,0.4)'; }}
onMouseLeave={e => { if (selectedStyleId !== s.id) e.currentTarget.style.borderColor = 'var(--border)'; }}>
{s.name}
{s.is_default && Mặc định}
{!s.is_enabled && (
Đang tắt
)}
{s.description || 'Không có mô tả'}
{!s.is_enabled && (
⚠️ Style này đang tắt cho tất cả user
)}
))}
)}
) : (
/* Processing State */
Đã gửi yêu cầu tạo Banner
🎨
Job đang được xử lý!
AI đang phân tích artwork và tạo banner. Quá trình mất khoảng 60 giây. Kết quả sẽ hiển thị ở Banner gần đây trên Dashboard.
)}
);
}
window.BannerScreen = BannerScreen;