import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { connect } from "../redux";
import { getActiveElementId, getElement, getElementWithChildren } from "../selectors";
export function withActiveElement() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      _ref$propName = _ref.propName,
      propName = _ref$propName === void 0 ? "element" : _ref$propName,
      _ref$shallow = _ref.shallow,
      shallow = _ref$shallow === void 0 ? false : _ref$shallow,
      _ref$keys = _ref.keys,
      keys = _ref$keys === void 0 ? [] : _ref$keys;

  return function decorator(Component) {
    return connect(function (state) {
      var elementId = getActiveElementId(state);

      if (!elementId) {
        return _defineProperty({}, propName, null);
      }

      var element = shallow ? getElement(state, elementId) : getElementWithChildren(state, elementId);

      if (keys.length > 0) {
        return _defineProperty({}, propName, keys.reduce(function (el, key) {
          el[key] = element[key];
          return el;
        }, {}));
      }

      return _defineProperty({}, propName, element);
    })(Component);
  };
}
//# sourceMappingURL=withActiveElement.js.map