'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

require('./style.css');

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

var UnorderedList = function UnorderedList(props) {
  return subList(props);
};

UnorderedList.propTypes = {
  /** The text displayed. */
  sublist: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    text: _propTypes2.default.string.required,
    sublist: _propTypes2.default.arrayOf(_propTypes2.default.shape({
      text: _propTypes2.default.string.required
    }))
  }))
};

UnorderedList.defaultProps = {
  sublist: [{
    text: 'This is a list item in an unordered list'
  }, {
    text: 'An unordered list is a list in which the sequence of items is not important. Sometimes, an unordered list is a bulleted list. And this is a long list item in an unordered list that can wrap onto a new line.'
  }, {
    text: 'Lists can be nested inside of each other',
    sublist: [{
      text: 'This is a nested list item'
    }, {
      text: 'This is another nested list item in an unordered list'
    }]
  }, {
    text: 'This is the last list item'
  }]
};

var listItem = function listItem(props, itemIndex, ulIndex) {
  var raw = {
    __html: props.text
  };
  var key = 'li.' + ulIndex + '.' + itemIndex;
  /* eslint-disable-next-line react/no-danger */
  return _react2.default.createElement('li', { key: key, dangerouslySetInnerHTML: raw });
};

listItem.propTypes = process.env.NODE_ENV !== "production" ? {
  text: _propTypes2.default.string
} : {};

var subList = function subList(props) {
  var newProps = Object.assign({}, props);
  if (!Object.prototype.hasOwnProperty.call(newProps, 'ulIndex')) {
    newProps.ulIndex = 0;
  }
  var ulId = 'ul.' + newProps.ulIndex;
  newProps.ulIndex += 1;
  var list = newProps.sublist;
  return _react2.default.createElement(
    'ul',
    { key: ulId },
    list && list.map(function (item, itemIndex) {
      if (item.sublist) {
        var subitem = [listItem(item, itemIndex, ulId)];
        subitem.push(subList(item));
        return subitem;
      }
      return listItem(item, itemIndex, ulId);
    })
  );
};

exports.default = UnorderedList;
module.exports = exports['default'];