"use strict";

exports.__esModule = true;
exports.default = void 0;

require("core-js/modules/web.dom.iterable");

require("core-js/modules/es6.array.iterator");

require("core-js/modules/es6.object.keys");

require("core-js/modules/es6.object.assign");

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _ = require("./..");

var _lodash = require("lodash");

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category containers
 * @component list-item
 * @variations collab-ui-react
 */
var SpaceListMeeting =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(SpaceListMeeting, _React$PureComponent);

  function SpaceListMeeting() {
    var _this;

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

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    _this.state = {
      id: _this.props.id || (0, _lodash.uniqueId)('cui-space-list-meeting-')
    };

    _this.handleButtonClick = function (e) {
      var buttonOnClick = _this.props.buttonOnClick;
      buttonOnClick && buttonOnClick(e);
      e.stopPropagation();
    };

    return _this;
  }

  var _proto = SpaceListMeeting.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        attendees = _this$props.attendees,
        buttonLabel = _this$props.buttonLabel,
        childrenLeft = _this$props.childrenLeft,
        childrenRight = _this$props.childrenRight,
        className = _this$props.className,
        header = _this$props.header,
        isBold = _this$props.isBold,
        meetingType = _this$props.meetingType,
        subheader = _this$props.subheader,
        title = _this$props.title,
        props = _objectWithoutPropertiesLoose(_this$props, ["attendees", "buttonLabel", "childrenLeft", "childrenRight", "className", "header", "isBold", "meetingType", "subheader", "title"]);

    var id = this.state.id;
    var otherProps = (0, _lodash.omit)(Object.assign({}, props), ['buttonOnClick']);
    var getTitle = !title && typeof header === 'string' ? header : title;

    var getLeftSection = function getLeftSection() {
      switch (meetingType) {
        case 'group':
          return _react.default.createElement(_.Avatar, {
            title: getTitle,
            alt: getTitle,
            type: "group"
          });

        case 'number':
          return _react.default.createElement(_.Avatar, {
            title: "#",
            alt: getTitle
          });

        case 'device':
          return _react.default.createElement(_.Avatar, {
            icon: _react.default.createElement(_.Icon, {
              name: "spark-board_16"
            }),
            alt: getTitle
          });

        default:
          return _react.default.createElement(_.Avatar, {
            title: getTitle,
            alt: getTitle
          });
      }
    };

    var getPopoverContent = _react.default.createElement(_.List, null, attendees.map(function (ele, idx) {
      return _react.default.createElement(_.ListItem, {
        key: "attendee-" + idx
      }, _react.default.createElement(_.ListItemSection, {
        position: "left"
      }, ele.node ? ele.node : _react.default.createElement(_.Avatar, {
        size: "small",
        title: ele.title,
        alt: ele.alt || ele.title,
        src: ele.src || '',
        type: "group"
      })), _react.default.createElement(_.ListItemSection, {
        position: "center"
      }, _react.default.createElement("div", {
        className: "cui-list-item__header"
      }, ele.title)));
    }));

    var children = [_react.default.createElement(_.ListItemSection, {
      key: "child-0",
      position: "left"
    }, childrenLeft || getLeftSection()), _react.default.createElement(_.ListItemSection, {
      key: "child-1",
      position: "center"
    }, _react.default.createElement("div", {
      className: "cui-list-item__header"
    }, header), _react.default.createElement("div", {
      className: "cui-list-item__subheader"
    }, subheader)), _react.default.createElement(_.ListItemSection, {
      key: "child-2",
      position: "right"
    }, childrenRight || attendees.length > 0 && _react.default.createElement(_.Popover, {
      content: getPopoverContent,
      direction: "bottom-center",
      targetOffset: {
        vertical: 3
      },
      isDynamic: true
    }, _react.default.createElement("span", {
      role: "button",
      tabIndex: 0,
      className: "cui-list-item--space-meeting--attendees"
    }, attendees.length, _react.default.createElement(_.Icon, {
      name: "people_12"
    }))), buttonLabel && _react.default.createElement(_.Button, {
      color: "green",
      ariaLabel: buttonLabel,
      children: buttonLabel,
      onClick: this.handleButtonClick,
      size: 28
    }))];
    return _react.default.createElement(_.ListItem, _extends({
      className: 'cui-list-item--space-meeting' + ("" + (isBold && " cui-list-item--unread" || '')) + ("" + (className && " " + className || '')),
      id: id,
      title: getTitle,
      type: "space"
    }, otherProps), children);
  };

  return SpaceListMeeting;
}(_react.default.PureComponent);

SpaceListMeeting.propTypes = {
  /** @prop Array of Attendee's Data | [] */
  attendees: _propTypes.default.arrayOf(_propTypes.default.shape({
    title: _propTypes.default.string.isRequired,
    alt: _propTypes.default.string,
    src: _propTypes.default.string,
    node: _propTypes.default.element
  })),

  /** @prop Label string for button | '' */
  buttonLabel: _propTypes.default.string,

  /** @prop Callback function invoked when user clicks on button | null */
  buttonOnClick: _propTypes.default.func,

  /** @prop Children nodes to render for left section | null */
  childrenLeft: _propTypes.default.node,

  /** @prop Children nodes to render for right section | null */
  childrenRight: _propTypes.default.node,

  /** @prop Optional HTML Class string | '' */
  className: _propTypes.default.string,

  /** @prop ListItem header text | '' */
  header: _propTypes.default.node.isRequired,

  /** @prop HTML ID for SpaceListMeeting | '' */
  id: _propTypes.default.string,

  /** @prop Determines if SpaceListMeeting is Bolded | false */
  isBold: _propTypes.default.bool,

  /** @prop Set the SpaceListMeeting type | '' */
  meetingType: _propTypes.default.oneOf(['', 'group', 'number', 'device']),

  /** @prop SpaceListMeeting sub header node | '' */
  subheader: _propTypes.default.node,

  /** @prop SpaceListMeeting title | '' */
  title: _propTypes.default.string
};
SpaceListMeeting.defaultProps = {
  attendees: [],
  buttonLabel: '',
  buttonOnClick: null,
  childrenLeft: null,
  childrenRight: null,
  className: '',
  id: '',
  isBold: false,
  meetingType: '',
  subheader: '',
  title: ''
};
SpaceListMeeting.displayName = 'SpaceListMeeting';
var _default = SpaceListMeeting;
/**
* @name Space List Meeting
*
* @category containers
* @component list-item
* @section space-meeting
*
* @js
*
import {
  Avatar,
  Icon,
  List,
  SpaceListMeeting,
} from '@collab-ui/react';
import { NavLink } from 'react-router-dom';

export default class SpaceListExamples extends React.PureComponent {

  render() {
    return(
      <div className="medium-5 columns">
        <List style={{backgroundColor: 'rgba(40,40,40,0.72)'}}>
          <SpaceListMeeting 
            buttonLabel='Now'
            attendees={[
              {title: 'Joe Bojangles'},
              {title: 'Joe Boe'},
              {title: 'Joe Coe'},
              {title: 'Joe Doe'},
              {title: 'Joe Foe'},
              {title: 'Joe Goe'},
              {title: 'Joe Joe'},
              {title: 'Joe Koe'},
              {title: 'Joe Loe'},
              {title: 'Joe Moe'},
              {title: 'Joe Noe'},
              {title: 'Joe Poe'},
              {title: 'Moe Moe'},
              {title: 'Toe Toe'}
            ]}
            header='Attendees Prop'
            subheader='must be very long long long long long message message' 
          />
          <SpaceListMeeting
            header='isBold(true)'
            subheader='subheader'
            isBold
          />
          <SpaceListMeeting
            buttonLabel='In 5 Min'
            header='MeetingType(group)'
            subheader='subheader'
            meetingType='group'
          />
          <SpaceListMeeting
            buttonLabel='2:25'
            header='MeetingType(number)'
            subheader='subheader'
            meetingType='number'
          />
          <SpaceListMeeting
            attendees={[
              {title: 'Joe Boe'},
              {title: 'Moe Moe'},
              {title: 'Toe Toe'}
            ]}
            buttonLabel='30:25'
            header='MeetingType(device)'
            meetingType='device'
          />
          <SpaceListMeeting
            attendees={[
              {title: 'Joe Boe'},
              {title: 'Moe Moe'},
              {title: 'Toe Toe'}
            ]}
            buttonLabel='30:25'
            header='ChildrenLeft Prop'
            childrenLeft={<Avatar icon={<Icon color='blue' name='mention_12' />} />}
          />
        </List>
      </div>
    );
  }
}
**/

exports.default = _default;