/**
 * `ViewPanelBody` — renders the body of a single View panel from its id and a
 * project context, reusing the existing feature panels as-is.
 *
 * Shared (ticket #23) between the in-window placements of {@link ProjectsView}
 * (docked/floating) and the detached {@link ViewWindow} (its own OS window), so
 * a view looks and behaves the same wherever it is placed. The `"projects"`
 * panel is intentionally **not** handled here — the projects manager is
 * main-window chrome, never a detachable view.
 */

import type { ReactNode } from "react";

import { AgentsPanel } from "@/features/agents";
import { TemplatesPanel } from "@/features/templates";
import { SkillsPanel } from "@/features/skills";
import { MemoryPanel } from "@/features/memory";
import { EmbedderSettings } from "@/features/embedder";
import { PermissionsPanel } from "@/features/permissions";
import { ProjectWorkStatePanel } from "@/features/workstate";
import { TicketsView } from "@/features/tickets";
import { GitPanel } from "@/features/git";
import { ProjectContextPanel } from "./ProjectContextPanel";
import type { PanelId } from "./viewPlacement";

/** Panels that render a project-scoped view (everything except "projects"). */
export type ViewPanelId = Exclude<PanelId, "projects">;

export interface ViewPanelBodyProps {
  panel: ViewPanelId;
  projectId: string;
  /** Project root — required by the agents panel (its cwd base). */
  projectRoot: string;
  /** Optional: open a conversation viewer (only wired inside the main window). */
  onOpenConversation?: (conversationId: string) => void;
}

/** Renders the requested view panel for the given project. */
export function ViewPanelBody({
  panel,
  projectId,
  projectRoot,
  onOpenConversation,
}: ViewPanelBodyProps): ReactNode {
  switch (panel) {
    case "context":
      return <ProjectContextPanel projectId={projectId} />;
    case "work":
      return (
        <ProjectWorkStatePanel
          projectId={projectId}
          onOpenConversation={onOpenConversation}
        />
      );
    case "tickets":
      return <TicketsView projectId={projectId} />;
    case "agents":
      return <AgentsPanel projectId={projectId} projectRoot={projectRoot} />;
    case "templates":
      return <TemplatesPanel projectId={projectId} />;
    case "skills":
      return <SkillsPanel projectId={projectId} />;
    case "permissions":
      return <PermissionsPanel projectId={projectId} />;
    case "memory":
      return (
        <div className="flex flex-col gap-4">
          <MemoryPanel projectId={projectId} />
          <EmbedderSettings />
        </div>
      );
    case "git":
      return <GitPanel projectId={projectId} />;
  }
}
