"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const react_2 = require("@testing-library/react");
const TailwindCheckbox_1 = require("../components/modern/TailwindCheckbox");
describe('TailwindCheckbox', () => {
    test('renders correctly with default props', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox" }));
        const checkbox = react_2.screen.getByRole('checkbox');
        expect(checkbox).toBeInTheDocument();
        expect(checkbox).toHaveAttribute('name', 'test-checkbox');
        expect(checkbox).not.toBeChecked();
    });
    test('renders with label and required indicator', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", label: "Test Label", isRequired: true }));
        const label = react_2.screen.getByText('Test Label');
        expect(label).toBeInTheDocument();
        const requiredIndicator = react_2.screen.getByText('*');
        expect(requiredIndicator).toBeInTheDocument();
        expect(requiredIndicator).toHaveClass('text-red-500');
    });
    test('renders checked state when defaultChecked is true', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", defaultChecked: true }));
        const checkbox = react_2.screen.getByRole('checkbox');
        expect(checkbox).toBeChecked();
    });
    test('renders helper text when provided', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", helperText: "This is a helper text" }));
        const helperText = react_2.screen.getByText('This is a helper text');
        expect(helperText).toBeInTheDocument();
        expect(helperText).toHaveClass('text-gray-500');
    });
    test('renders error message when provided', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", error: "This field is required" }));
        const errorMessage = react_2.screen.getByText('This field is required');
        expect(errorMessage).toBeInTheDocument();
        expect(errorMessage).toHaveClass('text-red-500');
        const checkbox = react_2.screen.getByRole('checkbox');
        expect(checkbox).toHaveAttribute('aria-invalid', 'true');
    });
    test('handles click correctly', () => {
        const handleChange = jest.fn();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", onChange: handleChange }));
        const checkbox = react_2.screen.getByRole('checkbox');
        react_2.fireEvent.click(checkbox);
        expect(handleChange).toHaveBeenCalledTimes(1);
        expect(checkbox).toBeChecked();
    });
    test('applies disabled state correctly', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", isDisabled: true }));
        const checkbox = react_2.screen.getByRole('checkbox');
        expect(checkbox).toBeDisabled();
    });
    test('applies indeterminate state correctly', () => {
        const { container } = (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", isIndeterminate: true }));
        const checkbox = react_2.screen.getByRole('checkbox');
        expect(checkbox).toHaveProperty('indeterminate', true);
        // Check for the presence of the indeterminate icon
        const svg = container.querySelector('svg');
        expect(svg).toBeInTheDocument();
        // Check for the presence of the horizontal line path which represents indeterminate state
        const path = svg?.querySelector('path');
        expect(path).toHaveAttribute('d', expect.stringContaining('h-8.5'));
    });
    test('applies different sizes correctly', () => {
        const { rerender } = (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", size: "sm", "data-testid": "test-checkbox-container" }));
        let checkboxContainer = react_2.screen.getByTestId('test-checkbox-container')
            .nextElementSibling?.querySelector('div');
        expect(checkboxContainer).toHaveClass('h-3.5');
        rerender((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", size: "md", "data-testid": "test-checkbox-container" }));
        checkboxContainer = react_2.screen.getByTestId('test-checkbox-container')
            .nextElementSibling?.querySelector('div');
        expect(checkboxContainer).toHaveClass('h-4');
        rerender((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", size: "lg", "data-testid": "test-checkbox-container" }));
        checkboxContainer = react_2.screen.getByTestId('test-checkbox-container')
            .nextElementSibling?.querySelector('div');
        expect(checkboxContainer).toHaveClass('h-5');
    });
    test('renders with custom icon', () => {
        const iconTestId = 'custom-icon';
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", defaultChecked: true, icon: (0, jsx_runtime_1.jsx)("div", { "data-testid": iconTestId, children: "\u2713" }) }));
        const icon = react_2.screen.getByTestId(iconTestId);
        expect(icon).toBeInTheDocument();
    });
    test('renders with label on the left', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", label: "Left Label", labelPosition: "left" }));
        const container = react_2.screen.getByRole('checkbox').closest('div')?.parentElement;
        expect(container).toHaveClass('flex-row-reverse');
        const label = react_2.screen.getByText('Left Label');
        expect(label).toHaveClass('mr-2');
    });
    test('applies additional class names correctly', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", containerClassName: "test-container-class", checkboxClassName: "test-checkbox-class", labelClassName: "test-label-class", label: "Test Label" }));
        const container = react_2.screen.getByRole('checkbox').closest('div')?.parentElement;
        expect(container).toHaveClass('test-container-class');
        const checkboxContainer = react_2.screen.getByRole('checkbox')
            .nextElementSibling?.querySelector('div');
        expect(checkboxContainer).toHaveClass('test-checkbox-class');
        const label = react_2.screen.getByText('Test Label');
        expect(label).toHaveClass('test-label-class');
    });
    test('forwards ref to checkbox element', () => {
        const ref = react_1.default.createRef();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(TailwindCheckbox_1.TailwindCheckbox, { name: "test-checkbox", ref: ref }));
        expect(ref.current).not.toBeNull();
        expect(ref.current?.tagName).toBe('INPUT');
    });
});
//# sourceMappingURL=TailwindCheckbox.test.js.map