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; }

import React from 'react';
import '../../assets/styles/widgets/meetingCalenderViews/meetingCalenderViews.scss';
import { connect, PromiseState } from "react-refetch";
import moment from 'moment';
import { Accordion, AccordionContent, AccordionGroup, AccordionHeader, Modal, ModalBody, ModalFooter, ModalHeader, Icon, Button } from '@momentum-ui/react';
import Loading from "../common/component/Loading";
import MeetingAction from "./MeetingAction";
import MeetingHost from "./MeetingHost";
import PmrMoreInfo from "../pmr/PmrMoreInfo";

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 = PromiseState.all([meetingDetailFetch, meetingAttendeeFetch]);

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

  return MeetingDetail;
}(React.Component);

export default 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);