import type { PluginTheme } from "@getpaseo/plugin";
import type {
AgentRef,
PluginHostSummary,
ProjectRef,
WorkspaceRef,
} from "@getpaseo/plugin/client";
import { useProject } from "@getpaseo/plugin/client";
import { Icon } from "@getpaseo/plugin/client/ui";
import { useState } from "react";
import { Pressable, Text, View } from "react-native";
import type { ContextMenuRequest } from "./context-menu";
import { getHostStatusColor, getHostStatusLabel } from "./grouping";
import { WorkspaceRow } from "./workspace-row";
interface ProjectItemProps {
projectRef: ProjectRef;
theme: PluginTheme;
onOpenProject(ref: ProjectRef): void;
}
function ProjectItem({ projectRef, theme, onOpenProject }: ProjectItemProps) {
const project = useProject(projectRef);
if (!project) return null;
return (
onOpenProject(project.ref)}
style={({ pressed }) => ({
flexDirection: "row",
alignItems: "center",
gap: 7,
paddingVertical: 5,
paddingHorizontal: 8,
borderRadius: 6,
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
})}
>
{project.displayName}
);
}
export interface HostGroupProps {
hostId: string;
hostLabel: string;
hostStatus: PluginHostSummary["status"];
workspaceRefs: readonly WorkspaceRef[];
projectRefs: readonly ProjectRef[];
agentsByWorkspace: ReadonlyMap;
collapsed: boolean;
onToggleCollapsed(hostId: string): void;
theme: PluginTheme;
compact: boolean;
platform: "ios" | "android" | "web";
showAgents: boolean;
activeWorkspaceKey: string | null;
activeAgentKey: string | null;
activeMenuKey: string | null;
hasActiveWorkspaceInHost: boolean;
onToggleMenu(key: string): void;
onCloseMenu(): void;
onOpenContextMenu(request: ContextMenuRequest): void;
onOpenWorkspace(ref: WorkspaceRef): void;
onOpenAgent(ref: AgentRef): void;
onOpenProject(ref: ProjectRef): void;
}
export function HostGroup({
hostId,
hostLabel,
hostStatus,
workspaceRefs,
projectRefs,
agentsByWorkspace,
collapsed,
onToggleCollapsed,
theme,
compact,
platform,
showAgents,
activeWorkspaceKey,
activeAgentKey,
activeMenuKey,
hasActiveWorkspaceInHost,
onToggleMenu,
onCloseMenu,
onOpenContextMenu,
onOpenWorkspace,
onOpenAgent,
onOpenProject,
}: HostGroupProps) {
const [projectsOpen, setProjectsOpen] = useState(false);
const statusColor = getHostStatusColor(hostStatus, theme);
const statusLabel = getHostStatusLabel(hostStatus);
const hasProjects = projectRefs.length > 0;
return (
onToggleCollapsed(hostId)}
style={({ pressed }) => ({
flex: 1,
minWidth: 0,
flexDirection: "row",
alignItems: "center",
gap: 8,
paddingVertical: compact ? 9 : 7,
paddingLeft: 10,
paddingRight: 6,
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
})}
>
{hostLabel}
{statusLabel ? (
{statusLabel}
) : null}
{workspaceRefs.length}
{hasProjects ? (
{
if (collapsed) {
onToggleCollapsed(hostId);
setProjectsOpen(true);
} else {
setProjectsOpen((prev) => !prev);
}
}}
style={({ pressed }) => ({
padding: 6,
borderRadius: 6,
backgroundColor:
projectsOpen || pressed ? theme.colors.surface2 : "transparent",
})}
>
) : null}
{!collapsed ? (
{projectsOpen && hasProjects ? (
New workspace from project
{projectRefs.map((projectRef) => (
{
setProjectsOpen(false);
onOpenProject(ref);
}}
/>
))}
) : null}
{workspaceRefs.length > 0 ? (
{workspaceRefs.map((workspaceRef) => (
))}
) : (
{hostStatus === "offline" || hostStatus === "error"
? "Host unavailable."
: "No workspaces on this host."}
)}
) : null}
);
}