import { baseUniDriverFactory } from '../utils/test-utils/unidriver';
import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver';
import { dataHooks } from './constants';
export const sliderUniDriverFactory = (base, body) => {
    const $sliderHandles = () => base.$$(`[data-hook="${dataHooks.sliderHandle}"]`);
    const $sliderDots = () => base.$$('.wsr-slider-dot');
    const $sliderMarks = () => base.$$(`[data-hook="${dataHooks.sliderMarkLabel}"]`);
    const getTooltipDriver = async (index) => {
        const sliderDataHook = await base.attr('data-hook');
        const tooltipDataHook = sliderDataHook
            ? `${sliderDataHook}-${dataHooks.sliderTooltip}-${index}`
            : `${dataHooks.sliderTooltip}-${index}`;
        return tooltipDriverFactory(base.$(`[data-hook="${tooltipDataHook}"]`), body);
    };
    return {
        ...baseUniDriverFactory(base),
        /** returns true if slider grade is selected */
        isDotSelected: number => $sliderDots()
            .get(number - 1)
            .hasClass('wsr-slider-dot-active'),
        /** returns number of slider grades */
        numOfSliderDots: () => $sliderDots().count(),
        /** returns number of slider handles */
        numOfSliderHandles: () => $sliderHandles().count(),
        /** returns number of slider marks labels */
        numOfSliderMarksLabels: () => $sliderMarks().count(),
        /** returns slider value */
        getValue: async () => {
            const el = await base.$(`[data-hook="${dataHooks.sliderHandle}"]`);
            return el.attr('aria-valuenow');
        },
        /** decreases value of the slider once */
        decreaseValueOnce: async () => {
            const el = await base.$(`[data-hook="${dataHooks.sliderHandle}"]`);
            return el.pressKey('ArrowLeft');
        },
        /** increases value of the slider once */
        increaseValueOnce: async () => {
            const el = await base.$(`[data-hook="${dataHooks.sliderHandle}"]`);
            return el.pressKey('ArrowRight');
        },
        /** returns slider tooltip value */
        getToolTipValue: async (index) => {
            const tooltipDriver = await getTooltipDriver(index);
            let text = null;
            try {
                text = await tooltipDriver.getTooltipText();
            }
            catch { }
            return text;
        },
        /** returns if the slider is disabled */
        isDisabled: async () => {
            return !!(await base.$('.wsr-slider-disabled').exists());
        },
        /** returns direction either horizontal or vertical */
        getDirection: async () => base.attr('data-direction'),
    };
};
//# sourceMappingURL=Slider.uni.driver.js.map