"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.toggleButtonDriverFactory = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _TooltipUni = require("../Tooltip/Tooltip.uni.driver");
var _ButtonCoreUni = require("../Button/ButtonCore/ButtonCore.uni.driver");
var _unidriver = require("../utils/test-utils/unidriver");
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var toggleButtonDriverFactory = (base, body) => {
  var buttonBaseElement = (0, _unidriver.findByHook)(base, _constants.dataHooks.button);
  var tooltipBaseElement = base;
  var tooltipDriver = (0, _TooltipUni.tooltipDriverFactory)(tooltipBaseElement, body);
  var buttonDriver = (0, _ButtonCoreUni.buttonCoreDriverFactory)(buttonBaseElement);
  function getLabelPlacement() {
    return _getLabelPlacement.apply(this, arguments);
  }
  function _getLabelPlacement() {
    _getLabelPlacement = (0, _asyncToGenerator2.default)(function* () {
      return (0, _unidriver.getDataAttributeValue)(buttonBaseElement, _constants.dataAttr.placement);
    });
    return _getLabelPlacement.apply(this, arguments);
  }
  function getTooltipText() {
    return tooltipDriver.getTooltipText();
  }
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(buttonBaseElement)), {}, {
    /**
     * Checks whether ToggleButton is disabled
     */
    isButtonDisabled: buttonDriver.isButtonDisabled,
    /**
     * Gets the ToggleButton skin
     */
    getSkin: function () {
      var _getSkin = (0, _asyncToGenerator2.default)(function* () {
        return yield (0, _unidriver.getDataAttributeValue)(buttonBaseElement, _constants.dataAttr.skin);
      });
      function getSkin() {
        return _getSkin.apply(this, arguments);
      }
      return getSkin;
    }(),
    /**
     * Checks whether ToggleButton is selected
     */
    isButtonSelected: function () {
      var _isButtonSelected = (0, _asyncToGenerator2.default)(function* () {
        return (yield (0, _unidriver.getDataAttributeValue)(buttonBaseElement, _constants.dataAttr.selected)) === 'true';
      });
      function isButtonSelected() {
        return _isButtonSelected.apply(this, arguments);
      }
      return isButtonSelected;
    }(),
    /**
     * Gets the ToggleButton label placement
     */
    getLabelPlacement,
    /**
     * Gets the ToggleButton label placement value
     */
    getLabelValue: function () {
      var _getLabelValue = (0, _asyncToGenerator2.default)(function* () {
        var placement = yield getLabelPlacement();
        if (placement === 'tooltip') {
          return getTooltipText();
        }
        return (0, _unidriver.findByHook)(buttonBaseElement, _constants.dataHooks.label).text();
      });
      function getLabelValue() {
        return _getLabelValue.apply(this, arguments);
      }
      return getLabelValue;
    }(),
    /**
     * Gets the ToggleButton shape
     */
    getShape: function () {
      var _getShape = (0, _asyncToGenerator2.default)(function* () {
        return yield (0, _unidriver.getDataAttributeValue)(buttonBaseElement, _constants.dataAttr.shape);
      });
      function getShape() {
        return _getShape.apply(this, arguments);
      }
      return getShape;
    }()
  });
};
exports.toggleButtonDriverFactory = toggleButtonDriverFactory;
//# sourceMappingURL=ToggleButton.uni.driver.js.map