'use strict';

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

var _leaf = require('./leaf');

var _leaf2 = _interopRequireDefault(_leaf);

var _mark = require('../models/mark');

var _mark2 = _interopRequireDefault(_mark);

var _offsetKey = require('../utils/offset-key');

var _offsetKey2 = _interopRequireDefault(_offsetKey);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactDom2 = _interopRequireDefault(_reactDom);

var _keycode = require('keycode');

var _keycode2 = _interopRequireDefault(_keycode);

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

/**
 * Void.
 */

var Void = function (_React$Component) {
  _inherits(Void, _React$Component);

  function Void() {
    var _Object$getPrototypeO;

    var _temp, _this, _ret;

    _classCallCheck(this, Void);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Void)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.render = function () {
      var _this$props = _this.props;
      var children = _this$props.children;
      var node = _this$props.node;

      var Tag = node.kind == 'block' ? 'div' : 'span';
      var style = {
        position: 'relative'
      };

      return _react2.default.createElement(
        Tag,
        { style: style },
        _this.renderSpacer(),
        _react2.default.createElement(
          'div',
          { contentEditable: false },
          children
        )
      );
    }, _this.renderSpacer = function () {
      var style = {
        position: 'absolute',
        top: '0px',
        right: '0px',
        bottom: '0px',
        left: '0px',
        textIndent: '-9999px'
      };

      return _react2.default.createElement(
        'span',
        { style: style },
        _this.renderLeaf()
      );
    }, _this.renderLeaf = function () {
      var _this$props2 = _this.props;
      var node = _this$props2.node;
      var state = _this$props2.state;

      var child = node.getTextNodes().first();
      var text = '';
      var marks = _mark2.default.createSet();
      var start = 0;
      var end = 0;
      var offsetKey = _offsetKey2.default.stringify({
        key: child.key,
        start: start,
        end: end
      });

      return _react2.default.createElement(_leaf2.default, {
        ref: _this.renderLeafRefs,
        renderMark: _this.renderLeafMark,
        key: offsetKey,
        state: state,
        node: child,
        start: start,
        end: end,
        text: text,
        marks: marks
      });
    }, _this.renderLeafMark = function (mark) {
      return {};
    }, _this.renderLeafRefs = function (el) {
      _this.leaf = el;
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

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

/**
 * Export.
 */

Void.propTypes = {
  children: _react2.default.PropTypes.any.isRequired,
  editor: _react2.default.PropTypes.object.isRequired,
  node: _react2.default.PropTypes.object.isRequired,
  state: _react2.default.PropTypes.object.isRequired
};
exports.default = Void;