"use client"; import { useEffect, useState } from "react"; import { DashboardLayout } from "@/components/dashboard/DashboardLayout"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Trash2, Eye, EyeOff, Copy, Save, Lock, Loader2 } from "lucide-react"; import { Env } from "@/lib/types"; import { getEnv, setEnv } from "@/core/application"; import { AddVariableDialog } from "@/components/dialogs/AddVariable"; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, } from "@/components/ui/dropdown-menu"; import { ChevronDown } from "lucide-react"; export default function EnvironmentPage() { const [selectedApp, setSelectedApp] = useState(""); const [showSecrets, setShowSecrets] = useState>({}); const [envGroups, setEnvGroups] = useState>({}); const [isSaving, setIsSaving] = useState(false); useEffect(() => { const fetch = async () => { const env = await getEnv(); setEnvGroups(env); const vars = Object.keys(env); if (vars.length > 0) setSelectedApp(vars[0]); }; fetch(); }, []); const currentGroup = envGroups[selectedApp]; const toggleSecret = (key: string) => { setShowSecrets((prev) => ({ ...prev, [key]: !prev[key] })); }; const maskValue = (value: string) => { return "•".repeat(Math.min(value.length, 24)); }; const handleSave = async () => { setIsSaving(true); try { await setEnv(selectedApp, currentGroup.variables); } catch (error) { console.error("Failed to save:", error); } finally { setIsSaving(false); } }; return (
{currentGroup?.name ?? selectedApp} {Object.entries(envGroups).map(([id, env]) => ( setSelectedApp(id)} className={selectedApp === id ? "font-medium" : ""} > {env.name} ))}

{currentGroup?.variables.length} variables •{" "} {currentGroup?.variables.filter((v) => v.secret).length} secrets

{/* Table header (desktop only) */}
Key
Value
Actions
{/* Rows */}
{currentGroup?.variables.map((variable, i) => (
{/* Key */}
{variable.secret && } {variable.key}
{/* Value */}
{/* Actions */}
{variable.secret && ( )}
))}
); }