import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { Toggle } from './toggle';
import React from 'react';

describe('Toggle', () => {
  it('renders correctly', () => {
    render(<Toggle>Toggle Me</Toggle>);
    expect(screen.getByText('Toggle Me')).toBeInTheDocument();
  });

  it('toggles state on click', () => {
    const onPressedChange = vi.fn();
    render(<Toggle onPressedChange={onPressedChange}>Toggle</Toggle>);
    const toggle = screen.getByRole('button');

    fireEvent.click(toggle);
    expect(onPressedChange).toHaveBeenCalledWith(true);
  });

  it('reflects pressed state', () => {
    render(<Toggle pressed={true}>Pressed</Toggle>);
    const toggle = screen.getByRole('button');
    expect(toggle).toHaveAttribute('data-state', 'on');
  });

  it('is disabled when disabled prop is true', () => {
    render(<Toggle disabled>Disabled</Toggle>);
    const toggle = screen.getByRole('button');
    expect(toggle).toBeDisabled();
  });
});
