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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AlignedEmbedded = exports.EmbeddedCode = 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 _BlockAlignmentWrapper = require('./BlockAlignmentWrapper');

var _BlockAlignmentWrapper2 = _interopRequireDefault(_BlockAlignmentWrapper);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

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 _Embedded;

var _Embedded2 = _interopRequireDefault(_Embedded);

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; } // eslint-disable-next-line


var EmbeddedCode = exports.EmbeddedCode = function (_React$Component) {
  _inherits(EmbeddedCode, _React$Component);

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

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

  _createClass(EmbeddedCode, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      var node = _reactDom2.default.findDOMNode(this.refs.embedded);
      var scripts = _lodash2.default.get(this.props, ['content', 0, 'scripts']);
      if (node && Array.isArray(scripts)) {
        _lodash2.default.forEach(scripts, function (script) {
          var scriptEle = document.createElement('script');
          var attribs = script.attribs;
          _lodash2.default.merge(scriptEle, attribs);
          scriptEle.text = script.text || '';
          node.appendChild(scriptEle);
        });
      }
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      this.refs.embedded = null;
    }
  }, {
    key: 'render',
    value: function render() {
      var content = _lodash2.default.get(this.props, ['content', 0], {});

      return _react2.default.createElement(
        'div',
        { className: (0, _classnames2.default)(_Common2.default['inner-block']) },
        _react2.default.createElement('div', { ref: 'embedded', dangerouslySetInnerHTML: { __html: content.embeddedCodeWithoutScript } }),
        _react2.default.createElement(
          'div',
          { className: (0, _classnames2.default)(_Common2.default['desc-text-block'], 'text-justify') },
          content.caption
        )
      );
    }
  }]);

  return EmbeddedCode;
}(_react2.default.Component);

var AlignedEmbedded = exports.AlignedEmbedded = (0, _BlockAlignmentWrapper2.default)(EmbeddedCode);