"use strict";

exports.__esModule = true;
exports.linearProgressBarDriverFactory = void 0;
var _DataHooks = require("./DataHooks");
// @ts-ignore
var linearProgressBarDriverFactory = _ref => {
  var {
    element
  } = _ref;
  var getElement = dataHook => element == null ? void 0 : element.querySelector("[data-hook=\"".concat(dataHook, "\"]"));
  var getValue = () => {
    var _getElement;
    return !element ? null : (_getElement = getElement(_DataHooks.ProgressBarDataHooks.progressPercentage)) == null || (_getElement = _getElement.querySelector('span')) == null ? void 0 : _getElement.innerHTML;
  };
  var getDataAttribute = (key, parsingFunction) => {
    if (!element || !element.getAttribute(key)) {
      return null;
    }
    var value = element.getAttribute(key);
    return !!parsingFunction && parsingFunction instanceof Function ? parsingFunction(value) : value;
  };
  return {
    exists: () => !!element,
    getWidth: () => {
      var el = getElement(_DataHooks.ProgressBarDataHooks.foreground);
      return el ? el.style.width : '0';
    },
    isSuccessIconDisplayed: () => !!getElement(_DataHooks.ProgressBarDataHooks.successIcon),
    isErrorIconDisplayed: () => !!getElement(_DataHooks.ProgressBarDataHooks.errorIcon),
    isPercentagesProgressDisplayed: () => !!getElement(_DataHooks.ProgressBarDataHooks.progressPercentage),
    getValue: function (_getValue) {
      function getValue() {
        return _getValue.apply(this, arguments);
      }
      getValue.toString = function () {
        return _getValue.toString();
      };
      return getValue;
    }(() => getValue()),
    isCompleted: () =>
    // @ts-ignore
    getValue() >= getDataAttribute(_DataHooks.ProgressBarDataKeys.max),
    hasError: () => !!(element != null && element.querySelector("[data-hook='error-icon']")),
    getNumericValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.value, Number),
    getMinValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.min, Number),
    getMaxValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.max, Number),
    getAriaValueNow: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuenow, Number),
    getAriaValueMax: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuemax, Number),
    getAriaValueMin: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuemin, Number),
    getRoleAttribute: () => getDataAttribute('role'),
    getAriaValueText: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuetext),
    hasPrefixIndication: () => !!getElement(_DataHooks.ProgressBarDataHooks.prefixIndicator),
    hasSuffixIndication: () => !!getElement(_DataHooks.ProgressBarDataHooks.suffixIndicator),
    getSuffixIndicationText: () => {
      var _getElement2;
      return (_getElement2 = getElement(_DataHooks.ProgressBarDataHooks.suffixIndicator)) == null ? void 0 : _getElement2.textContent;
    },
    hasPrefixAriaHidden: () => {
      var _getElement3;
      return (_getElement3 = getElement(_DataHooks.ProgressBarDataHooks.prefixIndicator)) == null ? void 0 : _getElement3.hasAttribute(_DataHooks.ProgressBarInnerAriaKeys.hidden);
    },
    hasProgressIndicatorAriaHidden: () => {
      var _getElement4;
      return (_getElement4 = getElement(_DataHooks.ProgressBarDataHooks.progressIndicator)) == null ? void 0 : _getElement4.hasAttribute(_DataHooks.ProgressBarInnerAriaKeys.hidden);
    },
    getAriaLabel: () => {
      var _getElement5;
      return (_getElement5 = getElement(_DataHooks.ProgressBarDataHooks.container)) == null ? void 0 : _getElement5.getAttribute(_DataHooks.ProgressBarInnerAriaKeys.label);
    },
    click: () => {
      var el = getElement(_DataHooks.ProgressBarDataHooks.container);
      el.click();
    }
  };
};
exports.linearProgressBarDriverFactory = linearProgressBarDriverFactory;
//# sourceMappingURL=LinearProgressBarCore.driver.js.map