/*eslint no-unused-vars:0*/
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Body = undefined;

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Common = {
  "inner-block": "Common__inner-block___2cOrF",
  "disable-inner-block": "Common__disable-inner-block___1MLd0",
  "components": "Common__components___2fQuj",
  "component": "Common__component___3bwMg",
  "hide": "Common__hide___2HyoH",
  "desc-text-color": "Common__desc-text-color___2fV3l",
  "desc-text-block": "Common__desc-text-block___1Z4b-",
  "text-link": "Common__text-link___1jaLy",
  "image": "Common__image___AKB6W",
  "imagediff": "Common__imagediff___2j7tX",
  "slideshow": "Common__slideshow___1Fz23",
  "embeddedcode": "Common__embeddedcode___3Avmp",
  "youtube": "Common__youtube___2oq1n",
  "topic-box": "Common__topic-box___2Q-kN"
};

var _Common2 = _interopRequireDefault(_Common);

var _getArticleComponent = require('./getArticleComponent');

var _getArticleComponent2 = _interopRequireDefault(_getArticleComponent);

var _Body = {
  "anchor": "Body__anchor___21zrU"
};

var _Body2 = _interopRequireDefault(_Body);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

var Body = exports.Body = function (_Component) {
  _inherits(Body, _Component);

  function Body(props) {
    _classCallCheck(this, Body);

    return _possibleConstructorReturn(this, (Body.__proto__ || Object.getPrototypeOf(Body)).call(this, props));
  }

  _createClass(Body, [{
    key: 'render',
    value: function render() {
      var data = this.props.data;

      var sectionCnt = 0;

      if (Array.isArray(data)) {
        var Blocks = data.map(function (ele) {
          var anchor = null;
          var styles = {};
          var type = ele.type;
          var Component = (0, _getArticleComponent2.default)(type);

          if (type === 'header-one') {
            sectionCnt++;
            anchor = _react2.default.createElement('div', { id: 'section-' + sectionCnt, className: styles['anchor'] });
          } else if (type === 'embeddedcode') {
            var embeddedContent = _lodash2.default.get(ele, ['content', 0], {});
            var width = _lodash2.default.get(embeddedContent, 'width');
            var height = _lodash2.default.get(embeddedContent, 'height');
            if (width) {
              styles.maxWidth = width;
            }
            if (height) {
              styles.minHeight = height;
            }
          }

          if (!Component) {
            return null;
          }

          return _react2.default.createElement(
            'div',
            {
              key: ele.id,
              className: (0, _classnames2.default)(_Common2.default['component'], _Common2.default[type]),
              style: styles
            },
            anchor,
            _react2.default.createElement(Component, {
              alignment: ele.alignment,
              content: ele.content,
              id: ele.id,
              styles: ele.styles
            })
          );
        });
        return _react2.default.createElement(
          'div',
          {
            className: _Common2.default['components']
          },
          Blocks
        );
      }
    }
  }]);

  return Body;
}(_react.Component);