// ───────────────────────────────────────────────────────────
// Huio Control Panel — UI Components (cp-components.jsx)
// ───────────────────────────────────────────────────────────
const { useState, useEffect, useContext, createContext } = React;
// ───── Translation Context ─────
window.TranslationContext = createContext({
lang: 'vi',
setLang: () => {},
t: (key) => key
});
// Helper: identify internal bot, system, superadmin, or test accounts
window.isExcludedAccount = function(idOrUser) {
if (!idOrUser) return false;
if (typeof idOrUser === 'object') {
if (idOrUser.isTester || idOrUser.isDemo || idOrUser.deletedAt) return true;
return window.isExcludedAccount(idOrUser.id);
}
const str = String(idOrUser).toLowerCase();
return str.startsWith('a0000000') ||
str === '0ef8985e-a4df-4b87-9bc5-8368ec96668e' ||
str === '53524201-43e8-43ab-adc1-47f9ef9adc0d' ||
str.startsWith('4b6ad40d') ||
str === 'ccd2c647-1503-4bf5-908e-5f23533291ba';
};
// Helper hook for translations
window.useTranslation = () => useContext(window.TranslationContext);
// ───── Theme Helper Hook ─────
window.useThemeColors = () => {
const [theme, setTheme] = useState(document.documentElement.getAttribute('data-theme') || 'candy');
useEffect(() => {
const observer = new MutationObserver(() => {
setTheme(document.documentElement.getAttribute('data-theme') || 'candy');
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
return () => observer.disconnect();
}, []);
return theme;
};
// ───── Inline SVG Icons ─────
const Icons = {
Dashboard: () => (
),
Users: () => (
),
Groups: () => (
),
CCCD: () => (
),
Clock: () => (
),
Bank: () => (
),
Payments: () => (
),
Gift: () => (
),
Database: () => (
),
Settings: () => (
),
Logout: () => (
),
Check: ({ size = 16, className = "" }) => (
),
X: ({ size = 16 }) => (
),
TrendingUp: () => (
),
TrendingDown: () => (
),
Close: () => (
),
Info: () => (
),
Shield: () => (
),
Analytics: () => (
),
AlertTriangle: () => (
),
Risk: () => (
),
Disputes: () => (
),
Support: () => (
),
Errors: () => (
),
Broadcast: () => (
),
Roadmap: () => (
),
Changelog: () => (
),
Activity: () => (
),
ChatBot: () => (
),
ChatLogs: () => (
),
Feedback: () => (
),
ChevronDown: ({ size = 16, style = {} }) => (
),
Search: ({ size = 16, style = {} }) => (
),
ZoomIn: ({ size = 16, style = {} }) => (
),
RotateCw: ({ size = 16, style = {} }) => (
),
Spinner: ({ size = 16, style = {}, className = "" }) => (
),
Menu: ({ size = 20, style = {} }) => (
),
Calendar: ({ size = 16, style = {} }) => (
),
MoreVertical: ({ size = 16, style = {} }) => (
),
FileText: ({ size = 16, style = {} }) => (
)
};
window.Icons = Icons;
// ───── Sidebar Component ─────
window.CpSidebar = function CpSidebar({ activeTab, setActiveTab, adminRole = 'super_admin', isOpen = false, onClose = () => {} }) {
const { lang, t } = useTranslation();
const theme = useThemeColors();
const navRef = React.useRef(null);
const [highlightStyle, setHighlightStyle] = React.useState({ top: 0, height: 46, opacity: 0 });
const isSuperAdmin = adminRole === 'super_admin';
const isManager = adminRole === 'manager';
const rawMenuGroups = [
{
label: null,
items: [
{ id: 'dashboard', label: t('nav.dashboard'), icon: Icons.Dashboard },
]
},
{
label: lang === 'vi' ? 'Quản lý' : 'Management',
items: [
{ id: 'users', label: t('nav.users'), icon: Icons.Users },
{ id: 'bank', label: t('nav.bank'), icon: Icons.Bank },
{ id: 'payments', label: t('nav.payments'), icon: Icons.Payments },
{ id: 'referral', label: t('nav.referral'), icon: Icons.Gift },
{ id: 'groups', label: t('nav.groups'), icon: Icons.Groups },
{ id: 'waitlist', label: t('nav.waitlist'), icon: Icons.Clock },
{ id: 'broadcast', label: t('nav.broadcast'), icon: Icons.Broadcast },
]
},
{
label: lang === 'vi' ? 'Kiểm duyệt' : 'Moderation',
items: [
{ id: 'cccd', label: t('nav.cccd'), icon: Icons.CCCD },
{ id: 'risk', label: t('nav.risk'), icon: Icons.Risk },
{ id: 'disputes', label: t('nav.disputes'), icon: Icons.Disputes },
{ id: 'feedback', label: t('nav.feedback'), icon: Icons.Feedback },
{ id: 'support', label: t('nav.support'), icon: Icons.Support },
]
},
{
label: lang === 'vi' ? 'Giám sát' : 'Monitoring',
items: [
{ id: 'activity_logs', label: t('nav.activity_logs'), icon: Icons.Activity },
{ id: 'errors', label: t('nav.errors'), icon: Icons.Errors },
{ id: 'bot_logs', label: t('nav.bot_logs'), icon: Icons.ChatBot },
{ id: 'chat_logs', label: t('nav.chat_logs'), icon: Icons.ChatLogs },
]
},
{
label: lang === 'vi' ? 'Hệ thống' : 'System',
items: [
{ id: 'analytics', label: t('nav.analytics'), icon: Icons.Analytics },
{ id: 'system', label: t('nav.system'), icon: Icons.Database },
...(isSuperAdmin ? [{ id: 'admins', label: t('nav.admins') || 'Đội ngũ & Phân quyền', icon: Icons.Users }] : []),
]
},
{
label: lang === 'vi' ? 'Tài liệu' : 'Docs',
items: [
{ id: 'roadmap', label: t('nav.roadmap'), icon: Icons.Roadmap },
{ id: 'changelog', label: t('nav.changelog'), icon: Icons.Changelog },
]
}
];
// RBAC Filtering: Manager only sees allowed operational sections
const managerForbiddenTabs = ['bank', 'referral', 'broadcast', 'activity_logs', 'errors', 'bot_logs', 'chat_logs', 'system', 'admins', 'analytics', 'risk'];
const menuGroups = rawMenuGroups.map(group => ({
...group,
items: group.items.filter(item => {
if (isManager && managerForbiddenTabs.includes(item.id)) return false;
if (!isSuperAdmin && item.id === 'admins') return false;
return true;
})
})).filter(group => group.items.length > 0);
// Dynamic calculation of active tab position for smooth highlight animation
React.useLayoutEffect(() => {
if (!navRef.current) return;
const effectiveTab = (activeTab === 'user_detail' || activeTab === 'user') ? 'users' : activeTab;
const activeEl = navRef.current.querySelector(`#nav-tab-${effectiveTab}`);
if (activeEl) {
setHighlightStyle({
top: activeEl.offsetTop,
height: activeEl.offsetHeight || 46,
opacity: 1
});
} else {
setHighlightStyle(prev => ({ ...prev, opacity: 0 }));
}
}, [activeTab, lang]);
return (
{isOpen && (
)}
);
};
// ───── Header Component ─────
window.CpHeader = function CpHeader({ onLogout, isSupabaseConnected, openSettings, currentUser, adminRole = 'super_admin', onToggleSidebar = () => {} }) {
const { lang, setLang, t } = useTranslation();
const theme = useThemeColors();
// Helper to switch theme attribute
const toggleTheme = (newTheme) => {
document.documentElement.setAttribute('data-theme', newTheme === 'editorial' ? 'light' : newTheme);
localStorage.setItem('huio-cp-theme', newTheme);
};
const initials = currentUser?.email
? currentUser.email.split('@')[0].substring(0, 2).toUpperCase()
: 'AD';
const displayName = currentUser?.user_metadata?.full_name || currentUser?.email || 'Admin';
const isDemo = currentUser?.email === 'demo-admin@huio.app';
const roleLabel = isDemo
? 'Demo Mode'
: adminRole === 'super_admin'
? '👑 Super Admin'
: adminRole === 'admin'
? '🛡️ Admin'
: '🎧 Manager';
const roleBadgeStyle = {
display: 'inline-flex',
alignItems: 'center',
gap: '3px',
padding: '1px 7px',
borderRadius: '6px',
fontSize: '11px',
fontWeight: '700',
marginTop: '2px',
background: adminRole === 'super_admin'
? 'rgba(193, 148, 51, 0.15)'
: adminRole === 'admin'
? 'rgba(74, 144, 226, 0.15)'
: 'rgba(79, 107, 61, 0.15)',
color: adminRole === 'super_admin'
? 'var(--hu-ochre, #C19433)'
: adminRole === 'admin'
? '#4a90e2'
: 'var(--hu-forest, #4F6B3D)',
border: `1px solid ${
adminRole === 'super_admin'
? 'rgba(193, 148, 51, 0.3)'
: adminRole === 'admin'
? 'rgba(74, 144, 226, 0.3)'
: 'rgba(79, 107, 61, 0.3)'
}`
};
return (
);
};
// ───── Metric Card Component ─────
window.CpMetricCard = function CpMetricCard({ title, value, trend, isPositive, iconKind, onClick, clickableHint }) {
const theme = useThemeColors();
// Decide icon container colors depending on type
let tileClass = "hu-icon-tile";
if (iconKind === 'users') tileClass += " hu-icon-tile-forest";
else if (iconKind === 'money') tileClass += " hu-icon-tile-terra";
else if (iconKind === 'cccd') tileClass += " hu-icon-tile-ochre";
else if (iconKind === 'db') tileClass += " hu-icon-tile-rust";
const renderIcon = () => {
switch (iconKind) {
case 'users': return ;
case 'money': return ;
case 'cccd': return ;
case 'db': return ;
default: return ;
}
};
return (
{ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick(); } } : undefined}
>
{value}
{trend && (
{isPositive ? : }
{trend}
)}
{clickableHint && (
{clickableHint}
)}
);
};
// ───── Custom Modal Component ─────
window.CpModal = function CpModal({ isOpen, onClose, title, children }) {
if (!isOpen) return null;
const theme = useThemeColors();
return (
e.stopPropagation()}
>
{title}
{children}
);
};
// ───── Unified Date Picker Component ─────
window.CpDatePicker = function CpDatePicker({
value = '',
onChange = () => {},
placeholder = '',
lang = 'vi',
style = {},
className = '',
disabled = false,
}) {
const [isOpen, setIsOpen] = React.useState(false);
const containerRef = React.useRef(null);
const selectedDate = value ? new Date(value + 'T00:00:00') : null;
const [viewYear, setViewYear] = React.useState(() => selectedDate && !isNaN(selectedDate.getTime()) ? selectedDate.getFullYear() : new Date().getFullYear());
const [viewMonth, setViewMonth] = React.useState(() => selectedDate && !isNaN(selectedDate.getTime()) ? selectedDate.getMonth() : new Date().getMonth());
React.useEffect(() => {
if (value) {
const d = new Date(value + 'T00:00:00');
if (!isNaN(d.getTime())) {
setViewYear(d.getFullYear());
setViewMonth(d.getMonth());
}
}
}, [value]);
React.useEffect(() => {
const handleClickOutside = (e) => {
if (containerRef.current && !containerRef.current.contains(e.target)) {
setIsOpen(false);
}
};
if (isOpen) {
document.addEventListener('mousedown', handleClickOutside);
}
return () => document.removeEventListener('mousedown', handleClickOutside);
}, [isOpen]);
const monthNames = {
vi: ['Tháng 1', 'Tháng 2', 'Tháng 3', 'Tháng 4', 'Tháng 5', 'Tháng 6', 'Tháng 7', 'Tháng 8', 'Tháng 9', 'Tháng 10', 'Tháng 11', 'Tháng 12'],
en: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
};
const dayHeaders = {
vi: ['T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
en: ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
};
const currentLang = monthNames[lang] ? lang : 'en';
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
const firstDayIndex = (new Date(viewYear, viewMonth, 1).getDay() + 6) % 7; // Monday = 0
const handleSelectDay = (day) => {
const mm = String(viewMonth + 1).padStart(2, '0');
const dd = String(day).padStart(2, '0');
const iso = `${viewYear}-${mm}-${dd}`;
onChange(iso);
setIsOpen(false);
};
const handlePrevMonth = (e) => {
e.stopPropagation();
if (viewMonth === 0) {
setViewMonth(11);
setViewYear(y => y - 1);
} else {
setViewMonth(m => m - 1);
}
};
const handleNextMonth = (e) => {
e.stopPropagation();
if (viewMonth === 11) {
setViewMonth(0);
setViewYear(y => y + 1);
} else {
setViewMonth(m => m + 1);
}
};
const displayFormatted = value ? (() => {
const parts = value.split('-');
if (parts.length === 3) return `${parts[2]}/${parts[1]}/${parts[0]}`;
return value;
})() : '';
return (
!disabled && setIsOpen(prev => !prev)}
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: '8px',
height: '36px',
padding: '0 10px',
borderRadius: 'var(--hu-r-sm)',
border: '1.5px solid var(--hu-border)',
background: 'var(--hu-bg-elev)',
color: value ? 'var(--hu-fg)' : 'var(--hu-fg-3)',
fontSize: '12px',
cursor: disabled ? 'not-allowed' : 'pointer',
minWidth: '125px',
userSelect: 'none',
boxSizing: 'border-box'
}}
className={className}
>
{displayFormatted || placeholder || (lang === 'vi' ? 'Chọn ngày' : 'Select date')}
{value && (
)}
{isOpen && (
{/* Calendar Header */}
{monthNames[currentLang][viewMonth]} {viewYear}
{/* Days of week header */}
{dayHeaders[currentLang].map((d, i) => (
{d}
))}
{/* Days Grid */}
{Array.from({ length: firstDayIndex }).map((_, i) => (
))}
{Array.from({ length: daysInMonth }).map((_, i) => {
const day = i + 1;
const mm = String(viewMonth + 1).padStart(2, '0');
const dd = String(day).padStart(2, '0');
const iso = `${viewYear}-${mm}-${dd}`;
const isSelected = value === iso;
const isToday = new Date().toISOString().slice(0, 10) === iso;
return (
);
})}
{/* Quick Today Button */}
{value && (
)}
)}
);
};
// ───── Unified Date Range Picker Component ─────
window.CpDateRangePicker = function CpDateRangePicker({
startDate = '',
endDate = '',
onChange = () => {},
lang = 'vi',
style = {}
}) {
const applyPreset = (preset) => {
const now = new Date();
const todayIso = now.toISOString().slice(0, 10);
if (preset === 'today') {
onChange({ startDate: todayIso, endDate: todayIso });
} else if (preset === '7d') {
const past = new Date();
past.setDate(past.getDate() - 7);
onChange({ startDate: past.toISOString().slice(0, 10), endDate: todayIso });
} else if (preset === '30d') {
const past = new Date();
past.setDate(past.getDate() - 30);
onChange({ startDate: past.toISOString().slice(0, 10), endDate: todayIso });
} else if (preset === 'month') {
const y = now.getFullYear();
const m = String(now.getMonth() + 1).padStart(2, '0');
const startOfMonth = `${y}-${m}-01`;
onChange({ startDate: startOfMonth, endDate: todayIso });
} else if (preset === 'all') {
onChange({ startDate: '', endDate: '' });
}
};
const presets = [
{ id: 'today', label: lang === 'vi' ? 'Hôm nay' : 'Today' },
{ id: '7d', label: lang === 'vi' ? '7 ngày' : '7 days' },
{ id: '30d', label: lang === 'vi' ? '30 ngày' : '30 days' },
{ id: 'month', label: lang === 'vi' ? 'Tháng này' : 'This month' },
];
return (
{lang === 'vi' ? 'Từ:' : 'From:'}
onChange({ startDate: val, endDate })}
placeholder={lang === 'vi' ? 'Từ ngày' : 'From date'}
lang={lang}
/>
{lang === 'vi' ? 'Đến:' : 'To:'}
onChange({ startDate, endDate: val })}
placeholder={lang === 'vi' ? 'Đến ngày' : 'To date'}
lang={lang}
/>
{/* Preset Chips */}
{presets.map(p => (
))}
{(startDate || endDate) && (
)}
);
};
// ───── Formatting Helpers ─────
window.vnd = (amount) => {
if (amount === undefined || amount === null) return "0 ₫";
return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' })
.format(amount)
.replace('₫', '₫');
};
window.vndShort = (amount) => {
if (amount === undefined || amount === null) return "0 ₫";
if (amount >= 1e9) return (amount / 1e9).toFixed(1) + "B ₫";
if (amount >= 1e6) return (amount / 1e6).toFixed(1) + "M ₫";
if (amount >= 1e3) return (amount / 1e3).toFixed(0) + "k ₫";
return amount + " ₫";
};
window.formatPhone = (phone) => {
if (!phone || (typeof phone === 'string' && phone.startsWith('no-phone-'))) return "—";
// Clean all except digits and "+"
let cleaned = ('' + phone).replace(/[^\d+]/g, '');
if (!cleaned.startsWith('+')) {
if (cleaned.startsWith('0')) {
cleaned = '+84' + cleaned.slice(1);
} else if (cleaned.startsWith('84')) {
cleaned = '+' + cleaned;
} else if (cleaned) {
cleaned = '+84' + cleaned;
}
}
if (cleaned.startsWith('+84')) {
const rest = cleaned.slice(3);
if (rest.length === 0) return '+84';
if (rest.length <= 3) return `+84 ${rest}`;
if (rest.length <= 6) return `+84 ${rest.slice(0, 3)} ${rest.slice(3)}`;
return `+84 ${rest.slice(0, 3)} ${rest.slice(3, 6)} ${rest.slice(6)}`;
}
return cleaned;
};
window.formatDateTime = (isoStr) => {
if (!isoStr) return "—";
try {
const d = new Date(isoStr);
if (isNaN(d.getTime())) return "—";
const day = String(d.getDate()).padStart(2, '0');
const month = String(d.getMonth() + 1).padStart(2, '0');
const year = d.getFullYear();
const hours = String(d.getHours()).padStart(2, '0');
const minutes = String(d.getMinutes()).padStart(2, '0');
const seconds = String(d.getSeconds()).padStart(2, '0');
return `${day}.${month}.${year}, ${hours}:${minutes}:${seconds}`;
} catch (e) {
return isoStr;
}
};
window.formatRelativeTime = (isoStr, lang = 'en') => {
if (!isoStr) return "—";
try {
const d = new Date(isoStr);
if (isNaN(d.getTime())) return "—";
const now = Date.now();
const diffMs = now - d.getTime();
const diffSec = Math.floor(diffMs / 1000);
const diffMin = Math.floor(diffSec / 60);
const diffHour = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHour / 24);
if (diffSec < 60) {
if (lang === 'vi') return 'Vừa xong';
return 'Just now';
}
if (diffMin < 60) {
if (lang === 'vi') return `${diffMin} phút trước`;
return `${diffMin}m ago`;
}
if (diffHour < 24) {
if (lang === 'vi') return `${diffHour} giờ trước`;
return `${diffHour}h ago`;
}
if (diffDay === 1) {
if (lang === 'vi') return 'Hôm qua';
return 'Yesterday';
}
if (diffDay < 30) {
if (lang === 'vi') return `${diffDay} ngày trước`;
return `${diffDay}d ago`;
}
const day = String(d.getDate()).padStart(2, '0');
const month = String(d.getMonth() + 1).padStart(2, '0');
const year = d.getFullYear();
return `${day}.${month}.${year}`;
} catch (e) {
return isoStr;
}
};
window.getInitials = (name) => {
if (!name) return '?';
const parts = String(name).trim().split(/\s+/);
if (parts.length === 0 || !parts[0]) return '?';
const first = parts[0][0];
const second = parts.length > 1 ? parts[1][0] : '';
return (first + second).toUpperCase();
};
window.AVATAR_COLORS = [
['#B85C38', '#FBF5EC'], // terracotta
['#4F6B3D', '#F4EFE6'], // forest
['#C19433', '#1C1A15'], // ochre
['#8B6F47', '#F4EFE6'], // walnut
['#6B7B5C', '#F4EFE6'], // sage
['#A8412A', '#FBF5EC'], // rust
['#7A5C6F', '#F4EFE6'], // plum
['#A89684', '#1C1A15'], // dust
];
window.getAvatarColorIndex = (name, fallbackIndex = 0) => {
const str = (name != null ? String(name) : '').trim();
if (!str) return fallbackIndex >= 0 ? fallbackIndex : 0;
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (str.charCodeAt(i) + ((hash << 5) - hash)) | 0;
}
return Math.abs(hash);
};
window.getAvatarColor = (name) => {
const idx = window.getAvatarColorIndex(name);
return window.AVATAR_COLORS[idx % window.AVATAR_COLORS.length][0];
};
window.getAvatarFgColor = (name) => {
const idx = window.getAvatarColorIndex(name);
return window.AVATAR_COLORS[idx % window.AVATAR_COLORS.length][1];
};
window.PRESETS = [
{ bg: '#B85C38', layers: [{ shape: 'circle', color: '#FBF5EC', alpha: 0.22, x: -0.2, y: -0.2, w: 0.85, h: 0.85 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.12, x: 0.35, y: 0.35, w: 0.65, h: 0.65 }] },
{ bg: '#4F6B3D', layers: [{ shape: 'circle', color: '#F4EFE6', alpha: 0.20, x: 0.08, y: 0.08, w: 0.80, h: 0.80 }, { shape: 'rect', color: '#F4EFE6', alpha: 0.30, x: 0.60, y: -0.10, w: 0.35, h: 0.35, rotate: 30 }] },
{ bg: '#C19433', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.15, x: 0, y: 0.25, w: 1.0, h: 0.18 }, { shape: 'rect', color: '#1C1A15', alpha: 0.10, x: 0, y: 0.57, w: 1.0, h: 0.18 }] },
{ bg: '#3D4B8B', layers: [{ shape: 'circle', color: '#B8C4F8', alpha: 0.25, x: 0.30, y: -0.15, w: 0.90, h: 0.90 }, { shape: 'rect', color: '#B8C4F8', alpha: 0.12, x: -0.10, y: 0.65, w: 0.55, h: 0.55, rotate: 45 }] },
{ bg: '#7A5C6F', layers: [{ shape: 'rect', color: '#F4EFE6', alpha: 0.20, x: 0.15, y: 0.15, w: 0.70, h: 0.70, rotate: 45 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.12, x: 0.30, y: 0.30, w: 0.40, h: 0.40 }] },
{ bg: '#A8412A', layers: [{ shape: 'rect', color: '#FBF5EC', alpha: 0.22, x: -0.20, y: 0.30, w: 1.40, h: 0.35, rotate: -35 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.10, x: 0.55, y: -0.10, w: 0.50, h: 0.50 }] },
{ bg: '#6B7B5C', layers: [{ shape: 'circle', color: '#F4EFE6', alpha: 0.30, x: 0.12, y: 0.12, w: 0.33, h: 0.33 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.30, x: 0.55, y: 0.12, w: 0.33, h: 0.33 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.18, x: 0.12, y: 0.55, w: 0.33, h: 0.33 }] },
{ bg: '#8B6F47', layers: [{ shape: 'circle', color: '#F4EFE6', alpha: 0.18, x: 0.05, y: 0.05, w: 0.90, h: 0.90 }, { shape: 'circle', color: '#8B6F47', alpha: 1.00, x: 0.22, y: 0.22, w: 0.56, h: 0.56 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.14, x: 0.34, y: 0.34, w: 0.32, h: 0.32 }] },
{ bg: '#3A7D7D', layers: [{ shape: 'circle', color: '#B8EDE8', alpha: 0.25, x: -0.40, y: 0.20, w: 1.10, h: 1.10 }, { shape: 'rect', color: '#B8EDE8', alpha: 0.15, x: 0.55, y: 0.05, w: 0.30, h: 0.60, rotate: 20 }] },
{ bg: '#2B2D4F', layers: [{ shape: 'rect', color: '#A8ADE8', alpha: 0.22, x: 0.38, y: 0.05, w: 0.24, h: 0.90 }, { shape: 'rect', color: '#A8ADE8', alpha: 0.22, x: 0.05, y: 0.38, w: 0.90, h: 0.24 }] },
{ bg: '#C4A97D', layers: [{ shape: 'circle', color: '#FBF5EC', alpha: 0.28, x: -0.05, y: -0.05, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#C4A97D', alpha: 1.00, x: 0.10, y: -0.10, w: 0.75, h: 0.75 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.12, x: 0.55, y: 0.55, w: 0.40, h: 0.40 }] },
{ bg: '#D4614E', layers: [{ shape: 'rect', color: '#FBF5EC', alpha: 0.20, x: -0.15, y: 0.20, w: 0.80, h: 0.30, rotate: -20 }, { shape: 'rect', color: '#FBF5EC', alpha: 0.15, x: 0.35, y: 0.50, w: 0.80, h: 0.30, rotate: -20 }] },
{ bg: '#5B3F6B', layers: [{ shape: 'rect', color: '#E8C8F8', alpha: 0.25, x: 0.38, y: 0.00, w: 0.24, h: 0.50, rotate: 0 }, { shape: 'rect', color: '#E8C8F8', alpha: 0.25, x: 0.38, y: 0.00, w: 0.24, h: 0.50, rotate: 90 }, { shape: 'rect', color: '#E8C8F8', alpha: 0.15, x: 0.38, y: 0.00, w: 0.24, h: 0.50, rotate: 45 }] },
{ bg: '#2D6A4F', layers: [{ shape: 'circle', color: '#A8E6CF', alpha: 0.22, x: 0.20, y: 0.20, w: 0.90, h: 0.90 }, { shape: 'rect', color: '#A8E6CF', alpha: 0.28, x: 0.42, y: -0.05, w: 0.16, h: 0.55 }] },
{ bg: '#8B1A1A', layers: [{ shape: 'circle', color: '#FFC0B5', alpha: 0.28, x: -0.15, y: 0.10, w: 0.65, h: 0.65 }, { shape: 'circle', color: '#FFC0B5', alpha: 0.18, x: 0.50, y: 0.25, w: 0.65, h: 0.65 }] },
{ bg: '#1D3461', layers: [{ shape: 'rect', color: '#93B4E8', alpha: 0.28, x: -0.10, y: -0.10, w: 0.48, h: 0.48, rotate: 15 }, { shape: 'rect', color: '#93B4E8', alpha: 0.20, x: 0.62, y: 0.62, w: 0.48, h: 0.48, rotate: 15 }, { shape: 'circle', color: '#93B4E8', alpha: 0.15, x: 0.25, y: 0.25, w: 0.50, h: 0.50 }] },
{ bg: '#7B5E3A', layers: [{ shape: 'rect', color: '#F5DEB3', alpha: 0.28, x: 0.35, y: -0.05, w: 0.28, h: 1.10 }, { shape: 'circle', color: '#F5DEB3', alpha: 0.22, x: 0.10, y: 0.12, w: 0.22, h: 0.22 }, { shape: 'circle', color: '#F5DEB3', alpha: 0.22, x: 0.10, y: 0.40, w: 0.22, h: 0.22 }] },
{ bg: '#C44569', layers: [{ shape: 'circle', color: '#FFB8CE', alpha: 0.25, x: 0.05, y: -0.35, w: 0.90, h: 0.90 }, { shape: 'rect', color: '#FFB8CE', alpha: 0.18, x: 0.55, y: 0.55, w: 0.38, h: 0.38, rotate: 30 }] },
{ bg: '#2D4A22', layers: [{ shape: 'rect', color: '#B5D5A0', alpha: 0.22, x: 0.08, y: 0.08, w: 0.84, h: 0.84 }, { shape: 'rect', color: '#2D4A22', alpha: 1.00, x: 0.20, y: 0.20, w: 0.60, h: 0.60 }, { shape: 'rect', color: '#B5D5A0', alpha: 0.18, x: 0.32, y: 0.32, w: 0.36, h: 0.36 }] },
{ bg: '#4A3728', layers: [{ shape: 'rect', color: '#D4B896', alpha: 0.28, x: -0.10, y: 0.25, w: 1.20, h: 0.40, rotate: -50 }, { shape: 'circle', color: '#D4B896', alpha: 0.20, x: 0.55, y: 0.55, w: 0.38, h: 0.38 }] },
{ bg: '#4A5C8A', layers: [{ shape: 'circle', color: '#C8D8F8', alpha: 0.22, x: 0.00, y: 0.45, w: 1.00, h: 1.00 }, { shape: 'circle', color: '#4A5C8A', alpha: 1.00, x: 0.12, y: 0.62, w: 0.76, h: 0.76 }, { shape: 'circle', color: '#C8D8F8', alpha: 0.16, x: 0.28, y: 0.75, w: 0.50, h: 0.50 }] },
{ bg: '#5C6B2D', layers: [{ shape: 'rect', color: '#E8F0A0', alpha: 0.26, x: 0.40, y: -0.05, w: 0.20, h: 1.10, rotate: 45 }, { shape: 'rect', color: '#E8F0A0', alpha: 0.18, x: 0.40, y: -0.05, w: 0.20, h: 1.10, rotate: -45 }] },
{ bg: '#B07080', layers: [{ shape: 'circle', color: '#FAE0E8', alpha: 0.26, x: -0.25, y: 0.05, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FAE0E8', alpha: 0.20, x: 0.62, y: 0.14, w: 0.26, h: 0.26 }, { shape: 'circle', color: '#FAE0E8', alpha: 0.14, x: 0.58, y: 0.58, w: 0.40, h: 0.40 }] },
{ bg: '#3A3A3A', layers: [{ shape: 'rect', color: '#D0D0D0', alpha: 0.28, x: 0.08, y: 0.18, w: 0.84, h: 0.14 }, { shape: 'rect', color: '#D0D0D0', alpha: 0.20, x: 0.18, y: 0.43, w: 0.64, h: 0.14 }, { shape: 'rect', color: '#D0D0D0', alpha: 0.14, x: 0.30, y: 0.68, w: 0.40, h: 0.14 }] },
{ bg: '#6B2737', layers: [{ shape: 'circle', color: '#F0AABB', alpha: 0.24, x: -0.30, y: -0.30, w: 1.10, h: 1.10 }, { shape: 'circle', color: '#6B2737', alpha: 1.00, x: 0.08, y: 0.08, w: 0.84, h: 0.84 }, { shape: 'circle', color: '#F0AABB', alpha: 0.22, x: 0.55, y: 0.55, w: 0.34, h: 0.34 }] },
];
window.USER_PRESETS = [
{ bg: '#B85C38', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.25, x: 0.26, y: 0.15, w: 0.48, h: 0.18 }, { shape: 'circle', color: '#1C1A15', alpha: 0.40, x: 0.33, y: 0.34, w: 0.13, h: 0.13 }, { shape: 'circle', color: '#1C1A15', alpha: 0.40, x: 0.54, y: 0.34, w: 0.13, h: 0.13 }] },
{ bg: '#4F6B3D', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#1C1A15', alpha: 0.28, x: 0.22, y: 0.24, w: 0.18, h: 0.42 }, { shape: 'circle', color: '#1C1A15', alpha: 0.28, x: 0.60, y: 0.24, w: 0.18, h: 0.42 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.32, x: 0.28, y: 0.14, w: 0.44, h: 0.16 }] },
{ bg: '#C19433', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.20, x: 0.43, y: 0.48, w: 0.14, h: 0.20 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.22, x: 0.12, y: 0.66, w: 0.76, h: 0.80 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.35, x: 0.29, y: 0.18, w: 0.42, h: 0.42 }, { shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.25, y: 0.12, w: 0.50, h: 0.18 }, { shape: 'circle', color: '#1C1A15', alpha: 0.15, x: 0.34, y: 0.60, w: 0.32, h: 0.08 }] },
{ bg: '#3D4B8B', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.24, y: 0.22, w: 0.52, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#B8C4F8', alpha: 0.24, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#B8C4F8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.35, x: 0.22, y: 0.20, w: 0.10, h: 0.32 }, { shape: 'rect', color: '#1C1A15', alpha: 0.35, x: 0.68, y: 0.20, w: 0.10, h: 0.32 }] },
{ bg: '#7A5C6F', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.35, x: 0.28, y: 0.22, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.35, x: 0.26, y: 0.16, w: 0.48, h: 0.20 }, { shape: 'rect', color: '#1C1A15', alpha: 0.45, x: 0.22, y: 0.22, w: 0.36, h: 0.08, rotate: -15 }] },
{ bg: '#A8412A', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.30, x: 0.28, y: 0.16, w: 0.44, h: 0.10 }] },
{ bg: '#6B7B5C', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.28, x: 0.26, y: 0.14, w: 0.48, h: 0.15 }, { shape: 'circle', color: '#1C1A15', alpha: 0.45, x: 0.31, y: 0.32, w: 0.16, h: 0.16 }, { shape: 'circle', color: '#1C1A15', alpha: 0.45, x: 0.53, y: 0.32, w: 0.16, h: 0.16 }] },
{ bg: '#8B6F47', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#F4EFE6', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#3A7D7D', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#B8EDE8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#B8EDE8', alpha: 0.35, x: 0.28, y: 0.22, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.35, x: 0.27, y: 0.16, w: 0.46, h: 0.14, rotate: -5 }, { shape: 'circle', color: '#1C1A15', alpha: 0.35, x: 0.30, y: 0.10, w: 0.40, h: 0.14 }] },
{ bg: '#2B2D4F', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.42, y: 0.12, w: 0.16, h: 0.16 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#A8ADE8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#A8ADE8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.45, x: 0.33, y: 0.34, w: 0.13, h: 0.13 }, { shape: 'circle', color: '#1C1A15', alpha: 0.45, x: 0.54, y: 0.34, w: 0.13, h: 0.13 }] },
{ bg: '#C4A97D', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#1C1A15', alpha: 0.25, x: 0.22, y: 0.20, w: 0.20, h: 0.38 }, { shape: 'circle', color: '#1C1A15', alpha: 0.25, x: 0.58, y: 0.20, w: 0.20, h: 0.38 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#D4614E', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FBF5EC', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.30, x: 0.24, y: 0.14, w: 0.52, h: 0.16, rotate: 10 }] },
{ bg: '#5B3F6B', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#E8C8F8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#E8C8F8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.26, y: 0.14, w: 0.48, h: 0.15 }, { shape: 'rect', color: '#1C1A15', alpha: 0.85, x: 0.30, y: 0.33, w: 0.17, h: 0.11, rotate: 5 }, { shape: 'rect', color: '#1C1A15', alpha: 0.85, x: 0.53, y: 0.33, w: 0.17, h: 0.11, rotate: 5 }] },
{ bg: '#2D6A4F', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.43, y: 0.10, w: 0.14, h: 0.14 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#A8E6CF', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#A8E6CF', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#8B1A1A', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FFC0B5', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FFC0B5', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.35, x: 0.32, y: 0.48, w: 0.36, h: 0.18 }] },
{ bg: '#1D3461', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#93B4E8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#93B4E8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.30, x: 0.32, y: 0.15, w: 0.36, h: 0.10 }] },
{ bg: '#7B5E3A', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F5DEB3', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#F5DEB3', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.25, x: 0.48, y: 0.64, w: 0.04, h: 0.16 }] },
{ bg: '#C44569', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FFB8CE', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FFB8CE', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'circle', color: '#1C1A15', alpha: 0.35, x: 0.25, y: 0.18, w: 0.50, h: 0.50 }, { shape: 'circle', color: '#C44569', alpha: 1.00, x: 0.28, y: 0.23, w: 0.44, h: 0.44 }] },
{ bg: '#2D4A22', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#B5D5A0', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#B5D5A0', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#4A3728', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#D4B896', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#D4B896', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.30, x: 0.24, y: 0.15, w: 0.42, h: 0.12, rotate: -25 }] },
{ bg: '#4A5C8A', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.24, y: 0.28, w: 0.20, h: 0.20 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#C8D8F8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#C8D8F8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#5C6B2D', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#E8F0A0', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#E8F0A0', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }, { shape: 'rect', color: '#1C1A15', alpha: 0.45, x: 0.33, y: 0.34, w: 0.13, h: 0.13 }, { shape: 'rect', color: '#1C1A15', alpha: 0.45, x: 0.54, y: 0.34, w: 0.13, h: 0.13 }] },
{ bg: '#B07080', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.26, y: 0.14, w: 0.14, h: 0.14 }, { shape: 'circle', color: '#1C1A15', alpha: 0.30, x: 0.60, y: 0.14, w: 0.14, h: 0.14 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#FAE0E8', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#FAE0E8', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#3A3A3A', layers: [{ shape: 'rect', color: '#1C1A15', alpha: 0.35, x: 0.40, y: 0.48, w: 0.20, h: 0.20 }, { shape: 'circle', color: '#D0D0D0', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#D0D0D0', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
{ bg: '#6B2737', layers: [{ shape: 'circle', color: '#1C1A15', alpha: 0.25, x: 0.15, y: 0.22, w: 0.26, h: 0.50, rotate: 10 }, { shape: 'rect', color: '#1C1A15', alpha: 0.18, x: 0.44, y: 0.48, w: 0.12, h: 0.18 }, { shape: 'circle', color: '#F0AABB', alpha: 0.22, x: 0.10, y: 0.64, w: 0.80, h: 0.80 }, { shape: 'circle', color: '#F0AABB', alpha: 0.35, x: 0.28, y: 0.20, w: 0.44, h: 0.44 }] },
];
window.CpAvatar = function CpAvatar({ name, uri, size = 36, style = {}, className = '' }) {
const [imgError, setImgError] = React.useState(false);
React.useEffect(() => { setImgError(false); }, [uri]);
// Mascot branding for Huio bots
if (name === 'Huio AI' || name === 'Huio' || name === 'Huio Support') {
return (

{ e.currentTarget.style.display = 'none'; }}
/>
);
}
// Geometric Presets (preset:1..25)
if (uri && uri.startsWith('preset:') && window.PRESETS) {
const id = parseInt(uri.split(':')[1], 10);
const def = window.PRESETS[(id - 1) % window.PRESETS.length];
if (def) {
return (
{def.layers.map((layer, i) => (
))}
);
}
}
// Geometric User Presets (userpreset:1..25)
if (uri && uri.startsWith('userpreset:') && window.USER_PRESETS) {
const id = parseInt(uri.split(':')[1], 10);
const def = window.USER_PRESETS[(id - 1) % window.USER_PRESETS.length];
if (def) {
return (
{def.layers.map((layer, i) => (
))}
);
}
}
// Remote image URL
if (uri && !imgError && (uri.startsWith('http://') || uri.startsWith('https://') || uri.startsWith('data:'))) {
return (
setImgError(true)}
/>
);
}
// Deterministic Initial Avatar with AVATAR_COLORS (1:1 with mobile app)
const rawKey = (name != null && String(name).trim()) ? String(name).trim() : '';
const colorIndex = window.getAvatarColorIndex(rawKey);
const colorPair = window.AVATAR_COLORS[colorIndex % window.AVATAR_COLORS.length] || window.AVATAR_COLORS[0];
const bg = colorPair[0];
const fg = colorPair[1];
const label = window.getInitials(name);
const fontSize = Math.max(10, Math.round(size * 0.36));
return (
{label}
);
};
// ───── Inline CSS Styles (Theming-friendly) ─────
const styles = {
sidebar: {
width: '260px',
height: '100vh',
position: 'fixed',
top: 0,
left: 0,
background: 'var(--hu-bg-card)',
borderRight: '1px solid var(--hu-border)',
display: 'flex',
flexDirection: 'column',
padding: '24px 16px',
boxShadow: 'var(--hu-shadow-sm)',
zIndex: 10,
boxSizing: 'border-box'
},
sidebarLogoContainer: {
display: 'flex',
alignItems: 'baseline',
justifyContent: 'space-between',
padding: '8px 12px 24px 12px',
borderBottom: '1px solid var(--hu-border)'
},
logoText: {
fontSize: '32px',
fontWeight: '600',
color: 'var(--hu-fg)',
letterSpacing: '-0.03em'
},
logoSub: {
fontFamily: 'var(--hu-mono)',
fontSize: '14px',
fontWeight: '500',
background: 'var(--hu-terra)',
color: 'var(--hu-fg-inverse)',
padding: '2px 6px',
borderRadius: '4px',
marginLeft: '6px',
verticalAlign: 'middle',
letterSpacing: '0.05em'
},
logoStar: {
display: 'inline-block'
},
navMenu: {
display: 'flex',
flexDirection: 'column',
gap: '6px',
position: 'relative',
zIndex: 1
},
navItem: {
display: 'flex',
alignItems: 'center',
gap: '12px',
height: '46px',
padding: '0 16px',
border: '1.5px solid transparent',
borderRadius: 'var(--hu-r-md)',
background: 'transparent',
color: 'var(--hu-fg-2)',
fontSize: '14px',
textAlign: 'left',
cursor: 'pointer',
position: 'relative',
transition: 'all 150ms ease-out',
boxSizing: 'border-box',
width: '100%',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis'
},
navItemHover: {
':hover': {
background: 'rgba(28, 26, 21, 0.04)',
color: 'var(--hu-fg)'
}
},
navItemActive: (theme) => ({
background: 'transparent',
color: 'var(--hu-fg)',
border: '1.5px solid transparent'
}),
iconInactive: {
color: 'var(--hu-fg-3)',
display: 'inline-flex'
},
iconActive: (theme) => ({
color: 'var(--hu-terra)',
display: 'inline-flex'
}),
activeIndicator: (theme) => ({
position: 'absolute',
left: '0',
top: '25%',
height: '50%',
width: '4px',
background: 'var(--hu-terra)',
borderRadius: '0 var(--hu-r-pill) var(--hu-r-pill) 0'
}),
sidebarFooter: {
padding: '12px 12px 0 12px',
borderTop: '1px solid var(--hu-border)',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
},
footerVersion: {
fontFamily: 'var(--hu-mono)',
fontSize: '11px',
color: 'var(--hu-fg-3)',
textTransform: 'uppercase',
letterSpacing: '0.05em'
},
header: {
height: '70px',
marginLeft: 0,
padding: '0 32px',
background: 'var(--hu-bg-card)',
borderBottom: '1px solid var(--hu-border)',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
zIndex: 9,
boxSizing: 'border-box'
},
headerLeft: {
display: 'flex',
alignItems: 'center'
},
statusBadge: {
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
padding: '6px 12px',
background: 'var(--hu-bg-elev)',
borderRadius: 'var(--hu-r-pill)',
border: '1px solid var(--hu-border)',
fontSize: '12px',
fontWeight: '500'
},
statusText: {
fontFamily: 'var(--hu-mono)',
color: 'var(--hu-fg-2)'
},
headerRight: {
display: 'flex',
alignItems: 'center',
gap: '16px'
},
languageToggle: {
display: 'flex',
background: 'var(--hu-bg-elev)',
border: '1px solid var(--hu-border)',
borderRadius: 'var(--hu-r-pill)',
padding: '3px',
gap: '2px'
},
langBtnActive: (theme) => ({
background: 'var(--hu-bg-inverse)',
color: 'var(--hu-fg-inverse)',
border: 'none',
borderRadius: 'var(--hu-r-pill)',
fontSize: '10px',
fontWeight: '700',
padding: '4px 10px',
cursor: 'pointer'
}),
langBtnInactive: {
background: 'transparent',
color: 'var(--hu-fg-3)',
border: 'none',
borderRadius: 'var(--hu-r-pill)',
fontSize: '10px',
fontWeight: '600',
padding: '4px 10px',
cursor: 'pointer'
},
themeToggle: {
display: 'flex',
alignItems: 'center',
gap: '8px',
padding: '4px 8px',
background: 'var(--hu-bg-elev)',
borderRadius: 'var(--hu-r-pill)',
border: '1px solid var(--hu-border)'
},
themeDot: {
width: '16px',
height: '16px',
borderRadius: '50%',
cursor: 'pointer',
border: '1px solid var(--hu-border-strong)',
padding: '0',
transition: 'transform 100ms ease'
},
headerDivider: {
width: '1px',
height: '24px',
background: 'var(--hu-border)'
},
settingsBtn: {
minHeight: '36px',
width: '36px',
height: '36px',
padding: '0',
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'var(--hu-fg-2)'
},
adminProfile: {
display: 'flex',
alignItems: 'center',
gap: '10px'
},
adminAvatar: (theme) => ({
background: theme === 'candy' ? 'var(--hu-bg-2)' : 'var(--hu-bg-elev)',
color: 'var(--hu-fg)',
border: '1.5px solid var(--hu-border-strong)',
fontWeight: 'bold'
}),
adminText: {
display: 'flex',
flexDirection: 'column'
},
adminName: {
fontSize: '13px',
fontWeight: '600',
color: 'var(--hu-fg)'
},
adminRole: {
fontSize: '11px',
color: 'var(--hu-fg-3)'
},
logoutBtn: {
minHeight: '36px',
width: '36px',
height: '36px',
padding: '0',
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'var(--hu-rust)',
borderColor: 'rgba(168,65,42,0.22)'
},
metricCard: {
flex: '1 1 200px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
minHeight: '120px',
padding: '20px',
transition: 'transform 150ms ease-out, box-shadow 150ms ease-out',
cursor: 'default',
boxSizing: 'border-box'
},
metricCardHeader: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'flex-start',
width: '100%'
},
metricValueContainer: {
display: 'flex',
alignItems: 'baseline',
justifyContent: 'space-between',
marginTop: '16px',
width: '100%'
},
metricValue: {
fontSize: '28px',
fontWeight: '600',
color: 'var(--hu-fg)',
letterSpacing: '-0.02em',
lineHeight: '1.1'
},
trendPillUp: (theme) => ({
display: 'inline-flex',
alignItems: 'center',
padding: '3px 8px',
background: theme === 'candy' ? 'rgba(79, 163, 98, 0.12)' : 'rgba(79,107,61,0.1)',
border: theme === 'candy' ? '1px solid var(--hu-border-strong)' : '1px solid rgba(79,107,61,0.25)',
borderRadius: 'var(--hu-r-pill)',
color: 'var(--hu-forest)',
fontSize: '11px'
}),
trendPillDown: (theme) => ({
display: 'inline-flex',
alignItems: 'center',
padding: '3px 8px',
background: theme === 'candy' ? 'rgba(220, 75, 54, 0.12)' : 'rgba(168,65,42,0.08)',
border: theme === 'candy' ? '1px solid var(--hu-border-strong)' : '1px solid rgba(168,65,42,0.22)',
borderRadius: 'var(--hu-r-pill)',
color: 'var(--hu-rust)',
fontSize: '11px'
}),
modalOverlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(28, 26, 21, 0.5)',
backdropFilter: 'blur(4px)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 100,
padding: '24px'
},
modalContent: (theme) => ({
width: '100%',
maxWidth: '650px',
background: 'var(--hu-bg-card)',
display: 'flex',
flexDirection: 'column',
boxShadow: 'var(--hu-shadow-lg)',
overflow: 'hidden',
border: theme === 'candy' ? '2px solid var(--hu-border-strong)' : '1px solid var(--hu-border-strong)'
}),
modalHeader: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '20px 24px',
borderBottom: '1px solid var(--hu-border)'
},
modalCloseBtn: {
border: '0',
background: 'transparent',
color: 'var(--hu-fg-2)',
cursor: 'pointer',
padding: '4px',
display: 'inline-flex',
borderRadius: '50%'
},
modalBody: {
padding: '24px',
overflowY: 'auto',
maxHeight: 'calc(80vh - 100px)'
}
};
// ───── Live Support Chat Modal Shell ─────
// Inject skeleton animation once on script load (avoids per-render