"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var React = _interopRequireWildcard(require("react"));

var _lowcodeSetterBehavior = _interopRequireDefault(require("@ali/lowcode-setter-behavior"));

var _excluded = ["url", "responseFormatter", "extraBehaviorActions"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var defaultExtraBehaviorActions = [];

var LocalBehaviorSetter = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(LocalBehaviorSetter, _React$Component);

  function LocalBehaviorSetter() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = LocalBehaviorSetter.prototype;

  _proto.render = function render() {
    // ignore url && responseFormatter props, use default ones
    var _this$props = this.props,
        propsUrl = _this$props.url,
        propsFormatter = _this$props.responseFormatter,
        _this$props$extraBeha = _this$props.extraBehaviorActions,
        propsExtraBehaviorActions = _this$props$extraBeha === void 0 ? [] : _this$props$extraBeha,
        otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
    var url = 'https://hn.algolia.com/api/v1/search?query';

    var responseFormatter = function responseFormatter(response) {
      return response.hits.map(function (item) {
        return {
          label: item.title,
          value: item.author
        };
      });
    };

    var extraBehaviorActions = propsExtraBehaviorActions.concat(defaultExtraBehaviorActions);
    return /*#__PURE__*/React.createElement(_lowcodeSetterBehavior["default"], (0, _extends2["default"])({}, otherProps, {
      url: url,
      responseFormatter: responseFormatter,
      extraBehaviorActions: extraBehaviorActions
    }));
  };

  return LocalBehaviorSetter;
}(React.Component);

var _default = LocalBehaviorSetter;
exports["default"] = _default;