import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["avatar", "className", "lineItems"],
    _excluded2 = ["icon"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import theme from './theme.css';
import Avatar from '../avatar';
import Box from '../box';
import Icon from '../icon';
import Link from '../link';
import Popover from '../popover';
import { Heading3, TextBody } from '../typography';
/** @type {React.ComponentType<any>} */

var Passport = /*#__PURE__*/function (_PureComponent) {
  _inherits(Passport, _PureComponent);

  var _super = _createSuper(Passport);

  function Passport() {
    var _this;

    _classCallCheck(this, Passport);

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

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "renderDescription", function () {
      var description = _this.props.description;

      if (!description) {
        return null;
      }

      if (Array.isArray(description)) {
        return /*#__PURE__*/React.createElement(React.Fragment, null, description.map(function (child, index) {
          return /*#__PURE__*/React.createElement(TextBody, {
            color: "teal",
            key: index
          }, child);
        }));
      } else {
        return /*#__PURE__*/React.createElement(TextBody, {
          color: "teal"
        }, description);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "renderTitle", function () {
      var title = _this.props.title;
      return /*#__PURE__*/React.createElement(Heading3, {
        className: cx(theme['prevent-overflow'], theme['prevent-wrap'], theme['show-ellipsis']),
        color: "teal"
      }, typeof title === 'string' ? title : /*#__PURE__*/React.createElement(Link, _extends({}, title, {
        inherit: false
      })));
    });

    return _this;
  }

  _createClass(Passport, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          avatar = _this$props.avatar,
          className = _this$props.className,
          lineItems = _this$props.lineItems,
          others = _objectWithoutProperties(_this$props, _excluded);

      return /*#__PURE__*/React.createElement(Popover, _extends({}, others, {
        backdrop: "transparent",
        className: cx(theme['passport'], className)
      }), /*#__PURE__*/React.createElement(Box, {
        padding: 3
      }, /*#__PURE__*/React.createElement(Box, {
        display: "flex"
      }, /*#__PURE__*/React.createElement(Box, {
        flex: "48px 0 0",
        paddingRight: 3
      }, /*#__PURE__*/React.createElement(Avatar, _extends({}, avatar, {
        size: "small"
      }))), /*#__PURE__*/React.createElement(Box, {
        className: theme['prevent-overflow']
      }, this.renderTitle(), this.renderDescription())), lineItems && /*#__PURE__*/React.createElement(Box, {
        marginTop: 3
      }, lineItems.map(function (_ref, index) {
        var icon = _ref.icon,
            lineItem = _objectWithoutProperties(_ref, _excluded2);

        return /*#__PURE__*/React.createElement(Box, {
          alignItems: "flex-start",
          display: "flex",
          key: index
        }, /*#__PURE__*/React.createElement(Box, {
          display: "flex",
          flex: "48px 0 0",
          justifyContent: "center",
          paddingRight: 3
        }, icon && /*#__PURE__*/React.createElement(Icon, {
          color: lineItem.href || lineItem.onClick ? 'aqua' : 'teal',
          tint: lineItem.href || lineItem.onClick ? 'dark' : 'darkest',
          marginTop: 1
        }, icon)), /*#__PURE__*/React.createElement(TextBody, {
          className: cx(theme['prevent-overflow'], theme['prevent-wrap'], theme['show-ellipsis']),
          color: "teal"
        }, lineItem.href || lineItem.onClick ? /*#__PURE__*/React.createElement(Link, _extends({}, lineItem, {
          inherit: false
        })) : lineItem.children));
      }))));
    }
  }]);

  return Passport;
}(PureComponent);

export default Passport;