import { useState, useEffect, useCallback } from "react"; import InstanceLogsPanel from "./InstanceLogsPanel"; import ProfileMetaInfoPanel from "./ProfileMetaInfoPanel"; import ProfileBasicInfoPanel from "./ProfileBasicInfoPanel"; import ProfileLiveViewPanel from "./ProfileLiveViewPanel"; import ProfileToolbar from "./ProfileToolbar"; import { InstanceTabsPanel } from "../tabs"; import { TabsLayout, EmptyView } from "../molecules"; import type { Profile, Instance, InstanceTab } from "../../generated/types"; import * as api from "../../services/api"; interface Props { profile: Profile | null; instance?: Instance; onLaunch: () => void; onStop?: () => void; onSave?: (name: string, useWhen: string) => void; onDelete?: () => void; } type TabId = "profile" | "live" | "tabs" | "logs"; export default function ProfileDetailsPanel({ profile, instance, onLaunch, onStop, onSave, onDelete, }: Props) { const [activeTab, setActiveTab] = useState("profile"); const [tabs, setTabs] = useState([]); const [formValues, setFormValues] = useState({ name: "", useWhen: "" }); const isRunning = instance?.status === "running"; useEffect(() => { if (profile) { setFormValues({ name: profile.name, useWhen: profile.useWhen || "" }); } else { setTabs([]); setFormValues({ name: "", useWhen: "" }); } }, [profile]); const handleProfileChange = useCallback((name: string, useWhen: string) => { setFormValues({ name, useWhen }); }, []); const loadTabs = useCallback(async () => { if (!instance?.id) { setTabs([]); return; } try { const instanceTabs = await api .fetchInstanceTabs(instance.id) .catch(() => []); setTabs(instanceTabs); } catch (e) { console.error("Failed to load tabs", e); } }, [instance]); useEffect(() => { if (activeTab === "live" || activeTab === "tabs" || activeTab === "logs") { loadTabs(); } }, [activeTab, loadTabs]); const handleSave = () => { onSave?.(formValues.name, formValues.useWhen); }; if (!profile) { return (
); } const hasChanges = formValues.name.trim() !== profile.name || formValues.useWhen !== (profile.useWhen || ""); const profileTabs: { id: TabId; label: string; badge?: string | number }[] = [ { id: "profile", label: "Profile" }, { id: "live", label: "Live" }, { id: "tabs", label: "Tabs", badge: tabs.length }, { id: "logs", label: "Logs" }, ]; return (
{})} onSave={handleSave} onDelete={onDelete || (() => {})} isSaveDisabled={!formValues.name.trim() || !hasChanges} />
setActiveTab(id)} > {activeTab === "profile" && (
)} {activeTab === "live" && ( )} {activeTab === "tabs" && (
)} {activeTab === "logs" && ( )}
); }