'use strict';

var slicedToArray = require('./slicedToArray-5d1bc3b3.js');
var React = require('react');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var AuthorComponent = function AuthorComponent(_ref) {
  var authors = _ref.authors,
      index = _ref.index;

  var renderAuthor = function renderAuthor(authorDetail, index, length) {
    if (authorDetail) {
      var _id = authorDetail._id,
          displayName = authorDetail.displayName,
          url = authorDetail.url;


      if (displayName && url && url.current) {
        return React__default['default'].createElement(
          'span',
          { key: _id },
          index === 0 && React__default['default'].createElement(
            'span',
            { className: 'pr-1' },
            'By'
          ),
          React__default['default'].createElement(
            'a',
            { href: '/authors/' + url.current, className: 'author-name', style: { color: '#000', fontWeight: 'bold' } },
            displayName
          ),
          length !== index + 1 && ', '
        );
      } else if (displayName) {
        return React__default['default'].createElement(
          'span',
          { key: _id },
          index === 0 && React__default['default'].createElement(
            'span',
            { className: 'pr-1' },
            'By'
          ),
          React__default['default'].createElement(
            'span',
            { className: 'author-name', style: { color: '#000', fontWeight: 'bold' } },
            displayName,
            length !== index + 1 && ', '
          )
        );
      }
    } else return null;
  };

  var onOverlayClick = function onOverlayClick() {
    if (authorRef && authorRef.current) {
      authorRef.current.classList.remove('hide-content');
      sethideContent(false);
    }
  };

  React.useEffect(function () {
    if (authorRef && authorRef.current.clientHeight && authorRef.current.clientHeight > 50) {
      authorRef.current.classList.add('hide-content');
      sethideContent(true);
    }
  }, []);

  var _useState = React.useState(''),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      hideContent = _useState2[0],
      sethideContent = _useState2[1];

  var overlayRef = React.useRef(null);
  var authorRef = React.useRef(null);

  return React__default['default'].createElement(
    'div',
    { id: 'author-sec' + index, ref: authorRef },
    hideContent && React__default['default'].createElement('div', { onClick: function onClick() {
        return onOverlayClick();
      }, ref: overlayRef, id: 'overlay-content' + index }),
    authors.map(function (authorDetail, index) {
      return renderAuthor(authorDetail, index, authors.length);
    }),
    React__default['default'].createElement(
      'style',
      { jsx: true },
      '\n          #author-sec' + index + ' {\n            line-height: 25px;\n            position: relative;\n            height: auto;\n            // max-height: 50px;\n          }\n          .hide-content {\n            display: -webkit-box;\n            -webkit-line-clamp: 2;\n            -webkit-box-orient: vertical;\n            overflow: hidden;\n          }\n          #overlay-content' + index + ' {\n            position: absolute;\n            cursor: pointer;\n            width: 100%;\n            height: 100%;\n            top: 0;\n            left: 0;\n            z-index: 1000;\n          }\n        '
    )
  );
};

exports.AuthorComponent = AuthorComponent;
