import { ProgressBarDataHooks, ProgressBarDataKeys, ProgressBarAriaKeys, ProgressBarInnerAriaKeys, } from './DataHooks';
// @ts-ignore
export const linearProgressBarDriverFactory = ({ element }) => {
    const getElement = (dataHook) => element?.querySelector(`[data-hook="${dataHook}"]`);
    const getValue = () => !element
        ? null
        : getElement(ProgressBarDataHooks.progressPercentage)?.querySelector('span')?.innerHTML;
    const getDataAttribute = (key, parsingFunction) => {
        if (!element || !element.getAttribute(key)) {
            return null;
        }
        const value = element.getAttribute(key);
        return !!parsingFunction && parsingFunction instanceof Function
            ? parsingFunction(value)
            : value;
    };
    return {
        exists: () => !!element,
        getWidth: () => {
            const el = getElement(ProgressBarDataHooks.foreground);
            return el ? el.style.width : '0';
        },
        isSuccessIconDisplayed: () => !!getElement(ProgressBarDataHooks.successIcon),
        isErrorIconDisplayed: () => !!getElement(ProgressBarDataHooks.errorIcon),
        isPercentagesProgressDisplayed: () => !!getElement(ProgressBarDataHooks.progressPercentage),
        getValue: () => getValue(),
        isCompleted: () => 
        // @ts-ignore
        getValue() >= getDataAttribute(ProgressBarDataKeys.max),
        hasError: () => !!element?.querySelector("[data-hook='error-icon']"),
        getNumericValue: () => getDataAttribute(ProgressBarDataKeys.value, Number),
        getMinValue: () => getDataAttribute(ProgressBarDataKeys.min, Number),
        getMaxValue: () => getDataAttribute(ProgressBarDataKeys.max, Number),
        getAriaValueNow: () => getDataAttribute(ProgressBarAriaKeys.valuenow, Number),
        getAriaValueMax: () => getDataAttribute(ProgressBarAriaKeys.valuemax, Number),
        getAriaValueMin: () => getDataAttribute(ProgressBarAriaKeys.valuemin, Number),
        getRoleAttribute: () => getDataAttribute('role'),
        getAriaValueText: () => getDataAttribute(ProgressBarAriaKeys.valuetext),
        hasPrefixIndication: () => !!getElement(ProgressBarDataHooks.prefixIndicator),
        hasSuffixIndication: () => !!getElement(ProgressBarDataHooks.suffixIndicator),
        getSuffixIndicationText: () => getElement(ProgressBarDataHooks.suffixIndicator)?.textContent,
        hasPrefixAriaHidden: () => getElement(ProgressBarDataHooks.prefixIndicator)?.hasAttribute(ProgressBarInnerAriaKeys.hidden),
        hasProgressIndicatorAriaHidden: () => getElement(ProgressBarDataHooks.progressIndicator)?.hasAttribute(ProgressBarInnerAriaKeys.hidden),
        getAriaLabel: () => getElement(ProgressBarDataHooks.container)?.getAttribute(ProgressBarInnerAriaKeys.label),
        click: () => {
            const el = getElement(ProgressBarDataHooks.container);
            el.click();
        },
    };
};
//# sourceMappingURL=LinearProgressBarCore.driver.js.map