import { screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../utils/testHelpers";
import { ImportICSModal } from "./ImportICSModal";

// Mock hooks
vi.mock("../hooks/tablos", () => ({
  useTablosList: () => ({
    data: [{ id: "tablo-1", name: "Tablo 1" }],
    isLoading: false,
  }),
  useCreateTablo: () => ({ mutate: vi.fn() }),
}));

vi.mock("../hooks/events", () => ({
  useCreateEvents: () => vi.fn(),
}));

describe("ImportICSModal", () => {
  const mockOnClose = vi.fn();

  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("renders without crashing", () => {
    const { container } = renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(container).toBeInTheDocument();
  });

  it("displays title", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Import an ICS file")).toBeInTheDocument();
  });

  it("displays file label", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("ICS File *")).toBeInTheDocument();
  });

  it("displays destination label", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Destination")).toBeInTheDocument();
  });

  it("displays choose file button", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Choose a file")).toBeInTheDocument();
  });

  it("displays cancel button", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Cancel")).toBeInTheDocument();
  });

  it("displays import button", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText(/Import \d+ event\(s\)/)).toBeInTheDocument();
  });

  it("renders select component for tablo selection", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Destination")).toBeInTheDocument();
  });

  it("displays create new tablo checkbox", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    expect(screen.getByText("Create a new project")).toBeInTheDocument();
  });

  it("disables import button initially", () => {
    renderWithProviders(<ImportICSModal onClose={mockOnClose} />);
    const importButton = screen.getByText(/Import \d+ event\(s\)/);
    expect(importButton).toBeDisabled();
  });
});
