import { screen } from "@testing-library/dom";
function getElements(slider) {
    const sliderInput = slider.nextElementSibling;
    const sliderTrack = slider.parentElement;
    const sliderContainer = sliderTrack?.parentElement;
    if (!(sliderInput instanceof HTMLInputElement)) {
        throw new Error("Unable to find the `Slider` input element");
    }
    if (!(sliderTrack instanceof HTMLSpanElement) || !sliderTrack.classList.contains("rmd-slider-track")) {
        throw new Error("Unable to find the `Slider` track element");
    }
    if (!(sliderContainer instanceof HTMLDivElement) || !sliderContainer.classList.contains("rmd-slider-container")) {
        throw new Error("Unable to find the `Slider` container element");
    }
    return {
        sliderInput,
        sliderTrack,
        sliderContainer
    };
}
/**
 * @example Simple Example
 * ```tsx
 * function Test(): ReactElement {
 *   const slider = useSlider({ defaultValue: 30 });
 *   return <Slider {...slider} aria-label="Example" />;
 * }
 *
 * rmdRender(<Test />);
 *
 * const { slider, sliderInput } = getSliderTestElements({ name: "Example" });
 *
 * expect(slider).toHaveValue(30);
 * expect(sliderInput).toHaveValue("30");
 *
 * fireEvent.change(sliderInput, { target: { value: "55" }});
 * expect(slider).toHaveValue(55);
 * expect(sliderInput).toHaveValue("55");
 * ```
 *
 * @since 6.0.0
 */ export function getSliderTestElements(options) {
    const { container = screen, ...byRoleOptions } = options;
    const slider = container.getByRole("slider", byRoleOptions);
    return {
        slider,
        ...getElements(slider)
    };
}
/**
 * @see {@link getSliderTestElements}
 * @since 6.0.0
 */ export async function findSliderTestElements(options) {
    const { container = screen, ...byRoleOptions } = options;
    const slider = await container.findByRole("slider", byRoleOptions);
    return {
        slider,
        ...getElements(slider)
    };
}
/**
 * @example Simple Example
 * ```tsx
 * function Test(): ReactElement {
 *   const slider = useRangeSlider({ defaultValue: [30, 60] });
 *   return <Slider {...slider} aria-label="Example" />;
 * }
 *
 * rmdRender(<Test />);
 *
 * const { slider, sliderInput } = getSliderTestElements();
 *
 * const { minSlider, minSliderInput, maxSlider, maxSliderInput } =
 *   getRangeSliderTestElements();
 * expect(minSlider).toHaveValue(30);
 * expect(minSliderInput).toHaveValue("30");
 * expect(maxSlider).toHaveAttribute(60);
 * expect(maxSliderInput).toHaveValue("60");
 *
 * fireEvent.change(minSliderInput, { target: { value: "55" }});
 * expect(minSlider).toHaveValue(55);
 * expect(minSliderInput).toHaveValue("55");
 * expect(maxSlider).toHaveAttribute(60);
 * expect(maxSliderInput).toHaveValue("60");
 *
 * fireEvent.change(maxSliderInput, { target: { value: "88" }});
 * expect(minSlider).toHaveValue(55);
 * expect(minSliderInput).toHaveValue("55");
 * expect(maxSlider).toHaveAttribute(88);
 * expect(maxSliderInput).toHaveValue("88");
 * ```
 *
 * @since 6.0.0
 */ export function getRangeSliderTestElements(options = {}) {
    const { container = screen, min, max } = options;
    const minSlider = container.getByRole("slider", min ?? {
        name: "Min"
    });
    const maxSlider = container.getByRole("slider", max ?? {
        name: "Max"
    });
    const { sliderInput: minSliderInput, sliderTrack, sliderContainer } = getElements(minSlider);
    const { sliderInput: maxSliderInput } = getElements(maxSlider);
    return {
        minSlider,
        minSliderInput,
        maxSlider,
        maxSliderInput,
        sliderTrack,
        sliderContainer
    };
}
/**
 * @see {@link getRangeSliderTestElements}
 * @since 6.0.0
 */ export async function findRangeSliderTestElements(options = {}) {
    const { container = screen, min, max } = options;
    const minSlider = await container.findByRole("slider", min ?? {
        name: "Min"
    });
    const maxSlider = await container.findByRole("slider", max ?? {
        name: "Max"
    });
    const { sliderInput: minSliderInput, sliderTrack, sliderContainer } = getElements(minSlider);
    const { sliderInput: maxSliderInput } = getElements(maxSlider);
    return {
        minSlider,
        minSliderInput,
        maxSlider,
        maxSliderInput,
        sliderTrack,
        sliderContainer
    };
}

//# sourceMappingURL=slider.js.map