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

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

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

  it("renders when open", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Add an exception")).toBeInTheDocument();
  });

  it("does not render when closed", () => {
    render(<ExceptionModal isOpen={false} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.queryByText("Add an exception")).not.toBeInTheDocument();
  });

  it("displays title", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Add an exception")).toBeInTheDocument();
  });

  it("displays description", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText(/Define an exception for a specific date/)).toBeInTheDocument();
  });

  it("displays exception type label", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Exception type")).toBeInTheDocument();
  });

  it("displays exception type buttons", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Unavailable all day")).toBeInTheDocument();
    expect(screen.getByText("Custom hours")).toBeInTheDocument();
  });

  it("displays date picker", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Exception date")).toBeInTheDocument();
  });

  it("renders button group for exception types", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Unavailable all day")).toBeInTheDocument();
  });

  it("displays cancel button", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Cancel")).toBeInTheDocument();
  });

  it("displays add button", () => {
    render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
    expect(screen.getByText("Add exception")).toBeInTheDocument();
  });
});
