import { useState } from "react"; import { useLocation } from "wouter"; import { Code, Play, Save, FileCode, ArrowLeft, CheckCircle, XCircle, Loader2, Copy, Zap, } from "lucide-react"; import { haptics } from "@/lib/haptics"; const EXAMPLE_CODE = `reality HelloWorld { platforms: all } journey Greet(name) { platform: all notify "Hello, " + name + "!" } journey Main() { platform: all Greet("World") }`; const PASSPORT_EXAMPLE = `import { Passport } from "@aethex.os/core" reality AuthSystem { platforms: [web, roblox] } journey Login(username) { platform: all let passport = Passport(username) when passport.verify() { sync passport across [web, roblox] notify "Welcome, " + username reveal passport } }`; export default function MobileAethexStudio() { const [, navigate] = useLocation(); const [code, setCode] = useState(EXAMPLE_CODE); const [compiledOutput, setCompiledOutput] = useState(""); const [target, setTarget] = useState("javascript"); const [isCompiling, setIsCompiling] = useState(false); const [compileStatus, setCompileStatus] = useState<"idle" | "success" | "error">("idle"); const [errorMessage, setErrorMessage] = useState(""); const [activeTab, setActiveTab] = useState<"editor" | "output" | "publish">("editor"); // Publishing fields const [appName, setAppName] = useState(""); const [appDescription, setAppDescription] = useState(""); const [isSaving, setIsSaving] = useState(false); const handleCompile = async () => { haptics.medium(); setIsCompiling(true); setCompileStatus("idle"); setErrorMessage(""); try { const response = await fetch("/api/aethex/compile", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code, target }), credentials: "include", }); const data = await response.json(); if (data.success) { setCompiledOutput(data.output); setCompileStatus("success"); haptics.success(); } else { setErrorMessage(data.details || data.error || "Compilation failed"); setCompileStatus("error"); haptics.error(); } } catch (error) { console.error("Compilation error:", error); setErrorMessage("Failed to connect to compiler"); setCompileStatus("error"); haptics.error(); } finally { setIsCompiling(false); } }; const handleSaveApp = async () => { if (!appName.trim()) { alert("Please enter an app name"); return; } haptics.medium(); setIsSaving(true); try { const response = await fetch("/api/aethex/apps", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: appName, description: appDescription, source_code: code, category: "utility", is_public: true, targets: [target], tags: ["mobile-created"], }), credentials: "include", }); const data = await response.json(); if (data.success) { haptics.success(); alert("App published! Check the App Store."); setAppName(""); setAppDescription(""); } else { haptics.error(); alert(data.error || "Failed to publish app"); } } catch (error) { console.error("Save error:", error); haptics.error(); alert("Failed to publish app"); } finally { setIsSaving(false); } }; const handleRunCode = () => { if (!compiledOutput) { alert("Please compile the code first"); return; } haptics.light(); try { const sandbox = { console: { log: (...args: any[]) => { const output = args.map((a) => String(a)).join(" "); alert(`Output: ${output}`); }, }, }; new Function("console", compiledOutput)(sandbox.console); haptics.success(); } catch (error) { console.error("Runtime error:", error); alert(`Runtime error: ${error}`); haptics.error(); } }; const loadExample = (example: string) => { haptics.light(); if (example === "hello") { setCode(EXAMPLE_CODE); } else if (example === "passport") { setCode(PASSPORT_EXAMPLE); } setCompiledOutput(""); setCompileStatus("idle"); }; const copyToClipboard = (text: string) => { navigator.clipboard.writeText(text); haptics.success(); alert("Copied to clipboard!"); }; return (
{/* Animated background */}
{/* Header */}

AeThex Studio

{compileStatus === "success" && (

Compiled

)} {compileStatus === "error" && (

Error

)}
{/* Tab Navigation */}
{/* Content */}
{activeTab === "editor" && ( <> {/* Target Selection */}
{/* Examples */}
{/* Code Editor */}