'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 _MeetingDetail = require('./MeetingDetail');

var _MeetingDetail2 = _interopRequireDefault(_MeetingDetail);

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

var _MeetingAction2 = _interopRequireDefault(_MeetingAction);

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

var _MeetingHost2 = _interopRequireDefault(_MeetingHost);

var _MeetingSearchBar = require('./MeetingSearchBar');

var _MeetingSearchBar2 = _interopRequireDefault(_MeetingSearchBar);

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

var _Loading2 = _interopRequireDefault(_Loading);

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 MeetingCalenderViews = function (_React$Component) {
  _inherits(MeetingCalenderViews, _React$Component);

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

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

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

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

    var meetingFetch = this.props.meetingFetch;

    var myMeeting = _reactRefetch.PromiseState.all([meetingFetch]);

    if (myMeeting.pending) {
      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting' },
        _react2.default.createElement(_Loading2.default, null)
      );
    } else if (myMeeting.rejected) {
      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting' },
        myMeeting.reason
      );
    } else if (myMeeting.fulfilled) {
      // decompose the PromiseState back into individual
      var _myMeeting$value = myMeeting.value,
          myMeetingInfo = _myMeeting$value[0];

      console.log("myMeetingInfo:" + myMeetingInfo);

      var listItems = myMeetingInfo.items.map(function (item, index) {
        return _react2.default.createElement(
          _react3.Popover,
          {
            isContained: true,
            content: _react2.default.createElement(_MeetingDetail2.default, {
              key: index.toString(),
              token: _this2.props.token,
              meetingID: item.id,
              hostName: item.hostUserId,
              userName: 'Y2lzY29zcGFyazovL3VzL1BFT1BMRS83MjljOTcxMi1kZTQyLTRiNDAtODFjZS05MWZkNzZiMGM1OTk',
              webLink: item.webLink,
              endPoint: _this2.props.endPoint
            }),
            direction: 'right-center',
            popoverTrigger: 'Click'
            // startOpen={true}
          },
          _react2.default.createElement(
            'div',
            { className: 'wg_m_item', key: index.toString() },
            _react2.default.createElement(
              'div',
              { className: 'col col_2' },
              _react2.default.createElement(
                'div',
                { className: 'wg_m_time' },
                (0, _moment2.default)(item.start).format('HH:mm a'),
                _react2.default.createElement('br', null),
                (0, _moment2.default)(item.end).format('HH:mm a')
              )
            ),
            _react2.default.createElement(
              'div',
              { className: 'col col_3' },
              _react2.default.createElement(
                'div',
                { className: 'wg_m_title' },
                _react2.default.createElement(
                  'span',
                  null,
                  item.title
                ),
                item.recurrenceType == "recurring" ? _react2.default.createElement('i', { className: 'icon icon-recurring_16' }) : ""
              )
            ),
            _react2.default.createElement(
              'div',
              { className: 'col col_4' },
              _react2.default.createElement(_MeetingAction2.default, {
                hostName: item.hostUserId,
                userName: 'Y2lzY29zcGFyazovL3VzL1BFT1BMRS84MmM4YjQ5Yi00ZDI1LTQ0NjQtODY2MS05ZDU3YzhjMzY1OWU',
                webLink: item.webLink,
                endPoint: _this2.props.endPoint
              })
            ),
            _react2.default.createElement(
              'div',
              { className: 'col col_1' },
              _react2.default.createElement(_MeetingHost2.default, {
                token: _this2.props.token,
                meetingID: item.meetingSeriesId,
                userEmail: item.hostEmail,
                endPoint: _this2.props.endPoint
              })
            )
          )
        );
      });

      return _react2.default.createElement(
        'div',
        { className: 'wg_meeting' },
        this.props.noTitle ? "" : _react2.default.createElement(
          'h3',
          null,
          'My Calendar'
        ),
        this.props.searchBar ? _react2.default.createElement(_MeetingSearchBar2.default, null) : "",
        _react2.default.createElement(
          'div',
          { className: 'wg_m_list' },
          listItems
        )
      );
    }
  };

  return MeetingCalenderViews;
}(_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
    meetingFetch: {
      url: props.endPoint + '/meetingCalendarView',
      headers: {
        Authorization: 'Bearer ' + props.token
      }
    }
  };
})(MeetingCalenderViews);
module.exports = exports['default'];