'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

require('../../assets/styles/widgets/meetingCalenderViews/meetingCalenderViews.scss');

var _reactRefetch = require('react-refetch');

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _react3 = require('@momentum-ui/react');

var _Loading = require('../common/component/Loading');

var _Loading2 = _interopRequireDefault(_Loading);

var _MeetingAction = require('./MeetingAction');

var _MeetingAction2 = _interopRequireDefault(_MeetingAction);

var _MeetingHost = require('./MeetingHost');

var _MeetingHost2 = _interopRequireDefault(_MeetingHost);

var _PmrMoreInfo = require('../pmr/PmrMoreInfo');

var _PmrMoreInfo2 = _interopRequireDefault(_PmrMoreInfo);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var MeetingDetail = function (_React$Component) {
  _inherits(MeetingDetail, _React$Component);

  function MeetingDetail(props) {
    _classCallCheck(this, MeetingDetail);

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    _this.state = {
      showDialog: false,
      items: []
    };
    return _this;
  }

  MeetingDetail.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        meetingDetailFetch = _props.meetingDetailFetch,
        meetingAttendeeFetch = _props.meetingAttendeeFetch;

    var meetingDetail = _reactRefetch.PromiseState.all([meetingDetailFetch, meetingAttendeeFetch]);

    if (meetingDetail.pending) {
      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting_detail' },
        _react2.default.createElement(_Loading2.default, null)
      );
    } else if (meetingDetail.rejected) {
      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting_detail' },
        meetingDetail.reason
      );
    } else if (meetingDetail.fulfilled) {
      // decompose the PromiseState back into individual
      var _meetingDetail$value = meetingDetail.value,
          myMeetingInfo = _meetingDetail$value[0],
          myMeetingAttendee = _meetingDetail$value[1];
      // this.setState(state => ({ items: myMeetingInfo.items}));
      // + {item.meetingNumber}
      // console.log(this.state)
      // console.log("sdfsdf" + this.props.meetingID);

      console.log("sdfsdf" + myMeetingInfo.items);
      // console.log(myMeetingAttendee.items);

      var myMeetingInfoDetail = myMeetingInfo;

      //   function a() {
      //   for(var k in myMeetingInfo.items ){//遍历packJson 对象的每个key/value对,k为key
      //     if (myMeetingInfo.items.id == this.props.meetingID) {
      //       return myMeetingInfo.items;
      //     }
      //   }
      // };

      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting_detail' },
        _react2.default.createElement(
          'div',
          { className: 'wg_m_title' },
          myMeetingInfoDetail.title
        ),
        _react2.default.createElement(
          'div',
          { className: 'wg_m_info' },
          _react2.default.createElement(
            'div',
            { className: 'wg_m_info_time' },
            _react2.default.createElement(
              'span',
              null,
              (0, _moment2.default)(myMeetingInfoDetail.start).format('MMM D, YYYY')
            ),
            _react2.default.createElement(
              'span',
              null,
              ' ',
              (0, _moment2.default)(myMeetingInfoDetail.start).format('HH:mm a')
            ),
            _react2.default.createElement(
              'span',
              null,
              ' - ',
              (0, _moment2.default)(myMeetingInfoDetail.end).format('HH:mm a')
            )
          ),
          _react2.default.createElement('div', { className: 'wg_m_info_place' }),
          _react2.default.createElement(
            'div',
            { className: 'wg_m_action' },
            _react2.default.createElement(_MeetingAction2.default, {
              hostName: this.props.hostUserId,
              userName: this.props.userName,
              webLink: this.props.webLink
            })
          ),
          _react2.default.createElement(
            _react3.Accordion,
            { initialActive: [2], focus: [2] },
            _react2.default.createElement(
              _react3.AccordionGroup,
              null,
              _react2.default.createElement(
                _react3.AccordionHeader,
                null,
                _react2.default.createElement(
                  'div',
                  null,
                  'Meeting information'
                )
              ),
              _react2.default.createElement(
                _react3.AccordionContent,
                null,
                _react2.default.createElement(
                  'div',
                  { className: 'wg_m_detail' },
                  _react2.default.createElement(
                    'dl',
                    null,
                    _react2.default.createElement(
                      'dt',
                      { title: 'Meeting link:' },
                      'Meeting link:'
                    ),
                    _react2.default.createElement(
                      'dd',
                      null,
                      _react2.default.createElement(
                        'span',
                        { tabIndex: '0', 'aria-label': 'Using command C or Ctrl C to copy the information', role: 'Note',
                          title: myMeetingInfoDetail.webLink },
                        myMeetingInfoDetail.webLink
                      )
                    ),
                    _react2.default.createElement(
                      'dt',
                      { title: 'Meeting number:' },
                      'Meeting number:'
                    ),
                    _react2.default.createElement(
                      'dd',
                      null,
                      _react2.default.createElement(
                        'span',
                        { tabIndex: '0', 'aria-label': 'Using command C or Ctrl C to copy the information', role: 'Note',
                          title: myMeetingInfoDetail.meetingNumber },
                        myMeetingInfoDetail.meetingNumber
                      )
                    ),
                    _react2.default.createElement(
                      'dt',
                      { title: 'Password:' },
                      'Password:'
                    ),
                    _react2.default.createElement(
                      'dd',
                      null,
                      _react2.default.createElement(
                        'span',
                        { tabIndex: '0', 'aria-label': 'Using command C or Ctrl C to copy the information', role: 'Note',
                          title: myMeetingInfoDetail.password },
                        myMeetingInfoDetail.password
                      )
                    )
                  )
                )
              )
            ),
            _react2.default.createElement(
              _react3.AccordionGroup,
              null,
              _react2.default.createElement(
                _react3.AccordionHeader,
                null,
                _react2.default.createElement(
                  'div',
                  null,
                  'More ways to join'
                )
              ),
              _react2.default.createElement(
                _react3.AccordionContent,
                null,
                _react2.default.createElement(
                  'dl',
                  null,
                  _react2.default.createElement(
                    'dt',
                    { title: 'Access code:' },
                    'Access code:'
                  ),
                  _react2.default.createElement(
                    'dd',
                    null,
                    _react2.default.createElement(
                      'span',
                      { tabIndex: '0', 'aria-label': 'Using command C or Ctrl C to copy the information', role: 'Note',
                        title: myMeetingInfoDetail.telephony.accessCode },
                      myMeetingInfoDetail.telephony.accessCode
                    )
                  ),
                  _react2.default.createElement(
                    'dt',
                    { title: 'SIP Address:' },
                    'SIP Address:'
                  ),
                  _react2.default.createElement(
                    'dd',
                    null,
                    _react2.default.createElement(
                      'span',
                      { tabIndex: '0', 'aria-label': 'Using command C or Ctrl C to copy the information', role: 'Note',
                        title: myMeetingInfoDetail.sipAddress },
                      myMeetingInfoDetail.sipAddress
                    )
                  )
                ),
                _react2.default.createElement(
                  'a',
                  { 'aria-label': 'Open Modal', className: 'wg_m_callLink', onClick: function onClick() {
                      return _this2.setState({ showDialog: true });
                    }, href: '#' },
                  'Global call-in numbers'
                ),
                _react2.default.createElement(
                  _react3.Modal,
                  {
                    icon: _react2.default.createElement(_react3.Icon, { name: 'warning_72', color: '$md-yellow-50' }),
                    applicationId: 'app',
                    onHide: function onHide() {
                      return _this2.setState({ showDialog: false });
                    },
                    show: this.state.showDialog,
                    ref: function ref(modalDialog) {
                      return _this2.modalDialog = modalDialog;
                    },
                    size: 'dialog',
                    htmlId: 'modalDialog'
                  },
                  _react2.default.createElement(_react3.ModalHeader, {
                    headerLabel: 'Global call-in numbers'
                  }),
                  _react2.default.createElement(
                    _react3.ModalBody,
                    null,
                    _react2.default.createElement(
                      'div',
                      { className: 'md-data-table', style: { width: '100%' } },
                      _react2.default.createElement(
                        'div',
                        { className: 'md-data-table__wrapper' },
                        _react2.default.createElement(
                          'table',
                          { className: 'testTableClass' },
                          _react2.default.createElement(
                            'thead',
                            { className: 'md-data-table__thead' },
                            _react2.default.createElement(
                              'tr',
                              null,
                              _react2.default.createElement(
                                'th',
                                { style: { width: '8rem' } },
                                'Country'
                              ),
                              _react2.default.createElement(
                                'th',
                                { style: { width: '5rem' } },
                                'Toll Type'
                              ),
                              _react2.default.createElement(
                                'th',
                                { style: { width: '10rem' } },
                                'Call Number'
                              )
                            )
                          ),
                          _react2.default.createElement(
                            'tbody',
                            {
                              className: 'md-data-table__tbody' },
                            myMeetingInfoDetail.telephony.callInNumbers.map(function (item, index) {
                              return _react2.default.createElement(
                                'tr',
                                null,
                                _react2.default.createElement(
                                  'td',
                                  null,
                                  ' ',
                                  item.label,
                                  ' '
                                ),
                                _react2.default.createElement(
                                  'td',
                                  null,
                                  ' ',
                                  item.tollType,
                                  ' '
                                ),
                                _react2.default.createElement(
                                  'td',
                                  null,
                                  ' ',
                                  item.callInNumber,
                                  ' '
                                )
                              );
                            })
                          )
                        )
                      )
                    )
                  ),
                  _react2.default.createElement(
                    _react3.ModalFooter,
                    null,
                    _react2.default.createElement(_react3.Button, {
                      children: 'Cancel',
                      onClick: function onClick() {
                        return _this2.modalDialog.closeModal();
                      },
                      ariaLabel: 'Close Modal',
                      color: 'default'
                    }),
                    _react2.default.createElement(_react3.Button, {
                      children: 'OK',
                      onClick: function onClick() {
                        return _this2.modalDialog.closeModal();
                      },
                      ariaLabel: 'Submit Form',
                      color: 'blue'
                    })
                  )
                )
              )
            ),
            _react2.default.createElement(
              _react3.AccordionGroup,
              null,
              _react2.default.createElement(
                _react3.AccordionHeader,
                null,
                _react2.default.createElement(
                  'div',
                  null,
                  'People (',
                  myMeetingAttendee.items.length,
                  ')'
                )
              ),
              _react2.default.createElement(
                _react3.AccordionContent,
                null,
                myMeetingAttendee.items.map(function (item, index) {
                  return _react2.default.createElement(
                    'div',
                    { className: 'wg_m_attendees', key: index.toString() },
                    _react2.default.createElement(_MeetingHost2.default, {
                      token: _this2.props.token,
                      meetingID: myMeetingInfoDetail.meetingSeriesId,
                      userEmail: item.email,
                      endPoint: _this2.props.endPoint
                    }),
                    _react2.default.createElement(
                      'span',
                      { className: 'wg_m_attendees_name' },
                      item.displayName
                    ),
                    _react2.default.createElement(
                      'span',
                      { className: 'wg_m_attendees_status' },
                      item.coHost ? "Alternate Host" : "Attendee"
                    )
                  );
                })
              )
            )
          )
        )
      );
    }
  };

  return MeetingDetail;
}(_react2.default.Component);

exports.default = (0, _reactRefetch.connect)(function (props) {
  return {
    // simple GET from a URL injected as `userFetch` prop
    // if `userId` changes, data will be refetched

    // similar to `userFetch`, but using object syntax
    // specifies a refresh interval to poll for new data
    meetingDetailFetch: {
      url: props.endPoint + '/meetings/' + props.meetingID,
      headers: {
        Authorization: 'Bearer ' + props.token
      }
    },
    meetingAttendeeFetch: {
      url: props.endPoint + '/meetingInvitees?meetingId=' + props.meetingID + "&max=50",
      headers: {
        Authorization: 'Bearer ' + props.token
      }
    }
  };
})(MeetingDetail);
module.exports = exports['default'];