import React, { useEffect, useState } from 'react'; import { Film, Mic, FolderOpen, Layers, Palette, Cpu, Cloud, Trash2, CheckCircle2, RefreshCw, Sparkles, Plus, ShieldCheck, Lock, Unlock, Users, LogOut, LogIn, FileSpreadsheet, } from 'lucide-react'; import { api } from './api'; import type { Project, AIProviderProfile, AIRoleRoutingEntry, AssetItem, BrandKit, FrozenRecipe, } from '@olokaflow/shared'; import { StudioWorkspaceView } from './components/StudioWorkspaceView'; import { BatchStudioView } from './components/BatchStudioView'; import { AIProfileHubView } from './components/AIProfileHubView'; import { AssetLibraryView } from './components/AssetLibraryView'; import { CatalogBrowserView } from './components/CatalogBrowserView'; import { Button, Badge } from './components/ui/primitives'; type MainTab = | 'studio' | 'batch' | 'voices' | 'assets' | 'catalog' | 'brands' | 'ai_profiles' | 'vault'; export const App: React.FC = () => { const [activeTab, setActiveTab] = useState('studio'); const [projects, setProjects] = useState([]); const [activeProjectId, setActiveProjectId] = useState(''); const [catalog, setCatalog] = useState(null); const [profiles, setProfiles] = useState([]); const [routings, setRoutings] = useState([]); const [assets, setAssets] = useState([]); const [brands, setBrands] = useState([]); const [recipes, setRecipes] = useState([]); const [vaultStatus, setVaultStatus] = useState(null); const [syncingVault, setSyncingVault] = useState(false); // Auth Login Gate & Team Governance State const [authChecked, setAuthChecked] = useState(false); const [requireAuthGate, setRequireAuthGate] = useState(false); const [currentUser, setCurrentUser] = useState(null); const [showLoginModal, setShowLoginModal] = useState(false); const [loginEmail, setLoginEmail] = useState('admin@olokaflow.ai'); const [loginPassword, setLoginPassword] = useState('admin123'); const [loginError, setLoginError] = useState(''); const [loginBusy, setLoginBusy] = useState(false); const [teamUsers, setTeamUsers] = useState([]); const [newUserEmail, setNewUserEmail] = useState(''); const [newUserName, setNewUserName] = useState(''); const [newUserPassword, setNewUserPassword] = useState(''); const [newUserRole, setNewUserRole] = useState<'creator' | 'admin'>('creator'); const [newUserQuota, setNewUserQuota] = useState(5000000); // Brand Kit quick form state const [newBrandName, setNewBrandName] = useState(''); const [newBrandTagline, setNewBrandTagline] = useState(''); const [newBrandPrimary, setNewBrandPrimary] = useState('#E11D48'); const [newBrandAccent, setNewBrandAccent] = useState('#18181B'); useEffect(() => { void loadAllState(); }, []); async function loadAllState() { try { const [authRes, projRes, catRes, aiRes, astRes, brdRes, vltRes, usrRes] = await Promise.all([ api.getAuthMe().catch(() => ({ authenticated: false, requireAuthGate: false, user: null, })), api.getProjects(), api.getCatalog(), api.getAIProfiles(), api.getAssets(), api.getBrandsAndRecipes(), api.getVaultStatus(), api.getUsers().catch(() => ({ users: [] })), ]); setRequireAuthGate(Boolean(authRes.requireAuthGate)); setCurrentUser(authRes.user || null); setAuthChecked(true); const pList = projRes.projects || []; setProjects(pList); if (!activeProjectId && pList.length > 0) { setActiveProjectId(pList[0].id); } setCatalog(catRes); setProfiles(aiRes.profiles || []); setRoutings(aiRes.routings || []); setAssets(astRes.assets || []); setBrands(brdRes.brands || []); setRecipes(brdRes.recipes || []); setVaultStatus(vltRes); setTeamUsers(usrRes.users || []); } catch (err) { console.error('Load state error:', err); setAuthChecked(true); } } async function handleLoginSubmit(e: React.FormEvent) { e.preventDefault(); setLoginBusy(true); setLoginError(''); try { const res = await api.login(loginEmail.trim(), loginPassword); setCurrentUser(res.user); setShowLoginModal(false); await loadAllState(); } catch (err: any) { setLoginError(err.message || 'Đăng nhập thất bại'); } finally { setLoginBusy(false); } } async function handleToggleAuthGate(nextVal: boolean) { try { const res = await api.setAuthGate(nextVal); setRequireAuthGate(res.requireAuthGate); if (nextVal && !currentUser) { setShowLoginModal(true); } } catch (err: any) { alert(`Lỗi cập nhật Auth Gate: ${err.message}`); } } async function handleCreateTeamUser(e: React.FormEvent) { e.preventDefault(); if (!newUserEmail.trim()) return; try { await api.createUser({ email: newUserEmail.trim(), name: newUserName.trim() || 'Creator', password: newUserPassword || 'oloka123', role: newUserRole, tokenQuota: Number(newUserQuota) || 5000000, }); setNewUserEmail(''); setNewUserName(''); setNewUserPassword(''); await loadAllState(); } catch (err: any) { alert(`Lỗi tạo tài khoản: ${err.message}`); } } const activeProject = projects.find((p) => p.id === activeProjectId) || projects[0] || null; const navItems: Array<{ id: MainTab; label: string; icon: React.ComponentType<{ className?: string }>; badge?: string | number; }> = [ { id: 'studio', label: 'Fliki Video Studio', icon: Film, badge: projects.length, }, { id: 'batch', label: 'Sản Xuất Hàng Loạt', icon: FileSpreadsheet, badge: 'Batch', }, { id: 'voices', label: 'Giọng Đọc & Clone', icon: Mic, badge: catalog?.voices?.length || 25, }, { id: 'assets', label: 'Kho Media & Cào URL', icon: FolderOpen, badge: assets.length, }, { id: 'catalog', label: 'HyperFrames Catalog', icon: Layers, badge: '4-Tier', }, { id: 'brands', label: 'Brand Kits & Recipes', icon: Palette, badge: brands.length + recipes.length, }, { id: 'ai_profiles', label: 'Cấu Hình AI & Test API', icon: Cpu, badge: profiles.length, }, { id: 'vault', label: 'HF Vault & Quản Trị Team', icon: Cloud, badge: teamUsers.length, }, ]; async function handleCreateBrand(e: React.FormEvent) { e.preventDefault(); if (!newBrandName.trim()) return; await api.saveBrand({ name: `Bộ nhận diện ${newBrandName}`, brandName: newBrandName.trim(), tagline: newBrandTagline.trim() || 'Sáng tạo video tự động chuẩn thương hiệu', primaryColor: newBrandPrimary, accentColor: newBrandAccent, }); setNewBrandName(''); setNewBrandTagline(''); await loadAllState(); } // Full-Screen Login Gate when requireAuthGate is enabled and user is not logged in if (authChecked && requireAuthGate && !currentUser) { return (
OlokaFlow Studio AUTH GATE

Đăng nhập để truy cập hệ thống tạo video HyperFrames 60fps

{loginError && (
{loginError}
)}
setLoginEmail(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2.5 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" required />
setLoginPassword(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2.5 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" required />
); } return (
{/* ===================================================================== LEFT EDITORIAL NAVIGATION RAIL (DESIGN.MD + TASTE-DESIGN + SHADCN) ===================================================================== */} {/* ===================================================================== MAIN WORKSPACE CANVAS ===================================================================== */}
{activeTab === 'studio' && ( setActiveProjectId(id)} onRefreshAll={loadAllState} /> )} {activeTab === 'batch' && ( { setActiveProjectId(id); setActiveTab('studio'); }} onRefreshAll={loadAllState} /> )} {activeTab === 'voices' && ( )} {activeTab === 'assets' && ( )} {activeTab === 'catalog' && ( )} {activeTab === 'ai_profiles' && ( )} {/* BRAND KITS & FROZEN RECIPES TAB */} {activeTab === 'brands' && (
Brand Governance & Frozen Recipes

Quản Trị Bộ Nhận Diện Thương Hiệu & Công Thức Dựng Video

Đồng bộ màu sắc thương hiệu, phông chữ, giọng đọc mặc định và công thức chuyển động xuyên suốt mọi video.

{/* Create Brand Form */}

Thêm Bộ Nhận Diện Thương Hiệu (Brand Kit)

setNewBrandName(e.target.value)} placeholder="VD: Oloka Cloud AI..." className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" required />
setNewBrandTagline(e.target.value)} placeholder="VD: Giải pháp tự động hóa doanh nghiệp..." className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" />
setNewBrandPrimary(e.target.value)} className="w-full h-9 rounded-lg border border-zinc-200 cursor-pointer" />
setNewBrandAccent(e.target.value)} className="w-full h-9 rounded-lg border border-zinc-200 cursor-pointer" />
{/* Existing Brand Kits & Recipes */}
{brands.map((b: any) => (
{b.name}

{b.tagline || b.defaultCtaText}

Voice: {b.defaultVoiceId} • Font:{' '} {b.headingFont || 'Plus Jakarta Sans'}
))}

Công Thức Dựng Video Đóng Băng (Frozen Recipes)

{recipes.map((r: any) => (
{r.name}

{r.description}

Preset: {r.framePresetId} •{' '} {r.defaultAspectRatio || r.aspectRatio}
))}
)} {/* HF CLOUD VAULT, TEAM GOVERNANCE & PROJECT MANAGEMENT TAB */} {activeTab === 'vault' && (
Hugging Face Private Dataset Vault + Team Auth Gate

Đồng Bộ Lưu Trữ Đám Mây Vĩnh Viễn, Bảo Mật Đăng Nhập & Quản Trị Team

Tự động sao lưu SQLite WAL, cấu hình AI đã mã hóa và toàn bộ dự án HyperFrames lên Private Dataset{' '} {vaultStatus?.vaultRepo || 'phucsd/olokaflow-vault'} .

{/* Team Governance Grid */}

Cấp Tài Khoản Thành Viên Mới (Team Member)

setNewUserEmail(e.target.value)} placeholder="editor@olokaflow.ai" className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900" required />
setNewUserName(e.target.value)} placeholder="Video Editor" className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs text-zinc-900" />
setNewUserPassword(e.target.value)} placeholder="oloka123" className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-mono text-zinc-900" />
setNewUserQuota(Number(e.target.value))} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-mono tabular-nums text-zinc-900" />

Danh Sách Thành Viên & Hạn Mức Sử Dụng ({teamUsers.length})

Default Admin: admin@olokaflow.ai / admin123
{teamUsers.map((u) => (
{u.name} {u.role.toUpperCase()}
{u.email} • Đã dùng:{' '} {Number(u.tokensUsed || 0).toLocaleString()} /{' '} {Number(u.tokenQuota || 0).toLocaleString()} tokens
{u.id !== 'usr-admin' && ( )}
))}

Danh Sách Toàn Bộ Dự Án Video

{projects.length} dự án
{projects.map((p) => (
{p.title} {p.aspectRatio} • {Math.round(p.totalDurationSec || 0)}s {p.status}

{p.prompt}

))}
)}
{/* LOGIN MODAL (WHEN CLICKING LOGIN FROM SIDEBAR) */} {showLoginModal && (

Đăng nhập Tài khoản OlokaFlow

{loginError && (
{loginError}
)}
setLoginEmail(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900" required />
setLoginPassword(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900" required />
)}
); }; export default App;