"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.thumbnailDriverFactory = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../utils/test-utils/unidriver");
var _TextUni = require("../Text/Text.uni.driver");
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 thumbnailDriverFactory = base => {
  var byHook = hook => base.$("[data-hook*=\"".concat(hook, "\"]"));
  var getThumbnailWrapper = () => byHook(_constants.dataHooks.thumbnailWrapper);
  var getStyle = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (element, rule) {
      var style = yield element.attr('style');
      var match = style == null ? void 0 : style.match(new RegExp("".concat(rule, ": (.*?);")));
      return match ? match[1] : '';
    });
    return function getStyle(_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }();
  var _getTitle = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* () {
      if (yield byHook(_constants.dataHooks.thumbnailTitle).exists()) {
        return (0, _TextUni.textUniDriverFactory)(byHook(_constants.dataHooks.thumbnailTitle));
      }
      if (yield byHook(_constants.dataHooks.thumbnailBottomTitle).exists()) {
        return (0, _TextUni.textUniDriverFactory)(byHook(_constants.dataHooks.thumbnailBottomTitle));
      }
      return null;
    });
    return function getTitle() {
      return _ref2.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** Gets thumbnail title */
    getTitle: function () {
      var _getTitle2 = (0, _asyncToGenerator2.default)(function* () {
        var title = yield _getTitle();
        return title ? title.getText() : '';
      });
      function getTitle() {
        return _getTitle2.apply(this, arguments);
      }
      return getTitle;
    }(),
    /** Gets thumbnail description */
    getDescription: () => byHook(_constants.dataHooks.thumbnailDescription).text(),
    /** Gets selected icon driver */
    getSelectedIcon: () => byHook(_constants.dataHooks.thumbnailSelectedIcon),
    /** Gets background image driver */
    getBackgroundImage: () => byHook(_constants.dataHooks.thumbnailBackgroundImage),
    /** Checks whether Thumbnail is selected */
    isSelected: function () {
      var _isSelected = (0, _asyncToGenerator2.default)(function* () {
        return (yield getThumbnailWrapper().attr('data-selected')) === 'true';
      });
      function isSelected() {
        return _isSelected.apply(this, arguments);
      }
      return isSelected;
    }(),
    /** Checks whether Thumbnail is disabled */
    isDisabled: function () {
      var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
        return (yield getThumbnailWrapper().attr('data-disabled')) === 'true';
      });
      function isDisabled() {
        return _isDisabled.apply(this, arguments);
      }
      return isDisabled;
    }(),
    /** Gets thumbnail image driver */
    getImage: () => byHook(_constants.dataHooks.thumbnailImage),
    /** Gets thumbnail width, if it's set through `width` prop */
    getWidth: function () {
      var _getWidth = (0, _asyncToGenerator2.default)(function* () {
        return yield getStyle(base, 'width');
      });
      function getWidth() {
        return _getWidth.apply(this, arguments);
      }
      return getWidth;
    }(),
    /** Gets thumbnail height, if it's set through `height` prop */
    getHeight: function () {
      var _getHeight = (0, _asyncToGenerator2.default)(function* () {
        return yield getStyle(yield getThumbnailWrapper(), 'height');
      });
      function getHeight() {
        return _getHeight.apply(this, arguments);
      }
      return getHeight;
    }(),
    /** Gets aria-label attribute */
    getAriaLabel: () => base.attr('aria-label')
  });
};
exports.thumbnailDriverFactory = thumbnailDriverFactory;
//# sourceMappingURL=Thumbnail.uni.driver.js.map