"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

require("core-js/modules/es.object.set-prototype-of.js");

require("core-js/modules/es.object.get-prototype-of.js");

require("core-js/modules/es.reflect.construct.js");

require("core-js/modules/es.object.create.js");

require("core-js/modules/es.reflect.get.js");

require("core-js/modules/es.object.get-own-property-descriptor.js");

require("core-js/modules/es.object.keys.js");

require("core-js/modules/es.symbol.js");

require("core-js/modules/es.array.filter.js");

require("core-js/modules/es.array.for-each.js");

require("core-js/modules/web.dom-collections.for-each.js");

require("core-js/modules/es.object.get-own-property-descriptors.js");

require("core-js/modules/es.object.define-properties.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.promise.js");

require("core-js/modules/es.symbol.description.js");

require("core-js/modules/es.symbol.iterator.js");

require("core-js/modules/es.array.iterator.js");

require("core-js/modules/es.string.iterator.js");

require("core-js/modules/web.dom-collections.iterator.js");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Article = void 0;

require("regenerator-runtime/runtime.js");

require("core-js/modules/es.array.map.js");

require("core-js/modules/es.array.concat.js");

require("core-js/modules/es.object.define-property.js");

var _common = require("../../common");

var _articleSummary = require("../article-summary");

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }

function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var Article = /*#__PURE__*/function (_BaseArticleSummary) {
  _inherits(Article, _BaseArticleSummary);

  var _super = _createSuper(Article);

  /**
   * Article sections.
   */

  /**
   * Related recommendations sections.
   */
  function Article(slug, title, summary, recomemndationTitle, disclaimer, metaDescription, genes, area, author, publishDate, content, recommendations) {
    var _this;

    _classCallCheck(this, Article);

    _this = _super.call(this, slug, title, summary, recomemndationTitle, disclaimer, metaDescription, genes, area, author, publishDate);

    _defineProperty(_assertThisInitialized(_this), "content", void 0);

    _defineProperty(_assertThisInitialized(_this), "recommendations", void 0);

    _this.content = content;
    _this.recommendations = recommendations;
    return _this;
  }

  _createClass(Article, [{
    key: "serializeRedux",
    value: function serializeRedux() {
      if (this.id === undefined) {
        throw new _common.ReduxSerializeError();
      }

      return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(Article.prototype), "serializeRedux", this).call(this)), {}, {
        content: this.content,
        recommendations: this.recommendations
      });
    }
  }], [{
    key: "resourceName",
    get: function get() {
      return "article";
    }
  }, {
    key: "articleSectionAPIFactory",
    value: function articleSectionAPIFactory(data) {
      return data;
    }
  }, {
    key: "recommendationSectionAPIFactory",
    value: function recommendationSectionAPIFactory(data) {
      return data;
    }
  }, {
    key: "apiFactory",
    value: function apiFactory(data) {
      var article = new Article(data.slug, data.title, data.summary, data.recommendation_title, data.disclaimer, data.meta_description, data.genes, data.area, data.author && _articleSummary.ArticleSummary.authorAPIFactory(data.author), data.publish_date, data.content.map(function (section) {
        return Article.articleSectionAPIFactory(section);
      }), data.recommendations.map(function (recommendation) {
        return Article.recommendationSectionAPIFactory(recommendation);
      }));
      article.id = data.id;
      return article;
    }
  }, {
    key: "reduxFactory",
    value: function reduxFactory(data) {
      var article = new Article(data.slug, data.title, data.summary, data.recommendationTitle, data.disclaimer, data.metaDescription, data.genes, data.area, data.author, data.publishDate, data.content, data.recommendations);
      article.id = data.id;
      return article;
    }
    /**
     * Fetch the article from the server.
     *
     * @param slug Article slug.
     */

  }, {
    key: "get",
    value: function () {
      var _get2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(slug) {
        var server, response;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                server = new _common.APIServer();
                _context.next = 3;
                return server.get(this.path, slug);

              case 3:
                response = _context.sent;

                if (!response.error) {
                  _context.next = 6;
                  break;
                }

                throw new _common.APIResponseError("RETRIEVE error in ".concat(this.resourceName, " for ").concat(slug), this.handleError(response));

              case 6:
                return _context.abrupt("return", this.apiFactory(response.data));

              case 7:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function get(_x) {
        return _get2.apply(this, arguments);
      }

      return get;
    }()
  }]);

  return Article;
}(_articleSummary.BaseArticleSummary);

exports.Article = Article;
//# sourceMappingURL=data:application/json;charset=utf-8;base64, 