import "@testing-library/jest-dom/vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

import { WorkspaceToolsPanel } from "./workspace-tools-panel";
import type { Workspace } from "../../../types/workspace";

vi.mock("../../../hooks/use-workspace-instances", () => ({
  useWorkspaceInstances: () => ({
    instances: [],
    loading: false,
    refresh: vi.fn(),
  }),
}));

vi.mock("../tool/tool-starter", () => ({
  ToolStarter: () => <div data-testid="tool-starter" />,
}));

const workspace: Workspace = {
  id: "workspace-1",
  name: "Main",
  repo_id: "repo-1",
  repo_name: "repository",
  repo_ssh_key_id: null,
  project_id: "project-1",
  project_name: "Project",
  user_id: "user-1",
  branch: "main",
  path: "/workspace",
  status: "ready",
  last_sync_at: null,
  created_at: "2026-01-01T00:00:00Z",
  updated_at: "2026-01-01T00:00:00Z",
  instance_count: 0,
};

describe("WorkspaceToolsPanel", () => {
  it("places the tool launcher inside the shared scrollable dialog body", () => {
    const { container } = render(<WorkspaceToolsPanel workspace={workspace} />);

    fireEvent.click(screen.getByRole("button", { name: "Start Tool" }));

    const dialogBody = container.querySelector(".dialog-body");
    expect(dialogBody).toContainElement(screen.getByTestId("tool-starter"));
  });
});
