'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _CompHeading = require('../../atoms/headings/CompHeading');

var _CompHeading2 = _interopRequireDefault(_CompHeading);

var _Paragraph = require('../../atoms/text/Paragraph');

var _Paragraph2 = _interopRequireDefault(_Paragraph);

var _DecorativeLink = require('../../atoms/links/DecorativeLink');

var _DecorativeLink2 = _interopRequireDefault(_DecorativeLink);

require('./style.css');

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

// import child components
var LinkList = function LinkList(props) {
  var compHeading = props.compHeading,
      description = props.description,
      stacked = props.stacked,
      hideBullets = props.hideBullets,
      links = props.links,
      more = props.more;

  var bulletClass = hideBullets ? 'ma__link-list__items--no-bullets' : '';
  var length = links.length;
  var halfLength = Math.ceil(length / 2);
  return _react2.default.createElement(
    'section',
    { className: 'ma__link-list' },
    compHeading && _react2.default.createElement(_CompHeading2.default, compHeading),
    description && _react2.default.createElement(_Paragraph2.default, description),
    _react2.default.createElement(
      'div',
      { className: 'ma__link-list__container' },
      stacked || length < 4 ? _react2.default.createElement(
        'ul',
        { className: 'ma__link-list__items ' + bulletClass },
        links.map(function (link, index) {
          return (
            /* eslint-disable-next-line react/no-array-index-key */
            _react2.default.createElement(
              'li',
              { className: 'ma__link-list__item', key: index },
              _react2.default.createElement(_DecorativeLink2.default, link)
            )
          );
        })
      ) : _react2.default.createElement(
        _react2.default.Fragment,
        null,
        _react2.default.createElement(
          'ul',
          { className: 'ma__link-list__items ' + bulletClass },
          links.slice(0, halfLength).map(function (link, index) {
            return (
              /* eslint-disable-next-line react/no-array-index-key */
              _react2.default.createElement(
                'li',
                { className: 'ma__link-list__item', key: index },
                _react2.default.createElement(_DecorativeLink2.default, link)
              )
            );
          })
        ),
        _react2.default.createElement(
          'ul',
          { className: 'ma__link-list__items ' + bulletClass },
          links.slice(halfLength, length).map(function (link, index) {
            return (
              /* eslint-disable-next-line react/no-array-index-key */
              _react2.default.createElement(
                'li',
                { className: 'ma__link-list__item', key: index + halfLength },
                _react2.default.createElement(_DecorativeLink2.default, link)
              )
            );
          })
        )
      )
    ),
    _react2.default.createElement(
      'div',
      { className: 'ma__link-list__see-all' },
      more && _react2.default.createElement(_DecorativeLink2.default, more)
    )
  );
};

LinkList.propTypes = process.env.NODE_ENV !== "production" ? {
  /** @atoms/headings/CompHeading */
  compHeading: _propTypes2.default.shape(_CompHeading2.default.PropTypes),
  /** short description rendered below the heading, note that this version renders @atoms/text/Paragraph instead of rich text */
  description: _propTypes2.default.shape(_Paragraph2.default.PropTypes),
  /** Render links as a stacked list instead of two columns */
  stacked: _propTypes2.default.bool,
  /** Hide bullets for the list of links */
  hideBullets: _propTypes2.default.bool,
  /** List of links rendered */
  links: _propTypes2.default.arrayOf(_propTypes2.default.shape(_DecorativeLink2.default.PropTypes)).isRequired,
  /** @atoms/DecorativeLink as see all link */
  more: _propTypes2.default.shape(_DecorativeLink2.default.PropTypes)
} : {};

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