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 { Button, Icon, ListItemSection, Menu, MenuItem, MenuOverlay, Popover } from "@momentum-ui/react";
import MeetingDetail from "./MeetingDetail";
import MeetingAction from "./MeetingAction";
import MeetingHost from "./MeetingHost";
import MeetingSearchBar from "./MeetingSearchBar";

import Loading from "../common/component/Loading";

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

    if (myMeeting.pending) {
      return React.createElement(
        'div',
        { className: 'wg_meeting' },
        React.createElement(Loading, null)
      );
    } else if (myMeeting.rejected) {
      return React.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 React.createElement(
          Popover,
          {
            isContained: true,
            content: React.createElement(MeetingDetail, {
              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}
          },
          React.createElement(
            'div',
            { className: 'wg_m_item', key: index.toString() },
            React.createElement(
              'div',
              { className: 'col col_2' },
              React.createElement(
                'div',
                { className: 'wg_m_time' },
                moment(item.start).format('HH:mm a'),
                React.createElement('br', null),
                moment(item.end).format('HH:mm a')
              )
            ),
            React.createElement(
              'div',
              { className: 'col col_3' },
              React.createElement(
                'div',
                { className: 'wg_m_title' },
                React.createElement(
                  'span',
                  null,
                  item.title
                ),
                item.recurrenceType == "recurring" ? React.createElement('i', { className: 'icon icon-recurring_16' }) : ""
              )
            ),
            React.createElement(
              'div',
              { className: 'col col_4' },
              React.createElement(MeetingAction, {
                hostName: item.hostUserId,
                userName: 'Y2lzY29zcGFyazovL3VzL1BFT1BMRS84MmM4YjQ5Yi00ZDI1LTQ0NjQtODY2MS05ZDU3YzhjMzY1OWU',
                webLink: item.webLink,
                endPoint: _this2.props.endPoint
              })
            ),
            React.createElement(
              'div',
              { className: 'col col_1' },
              React.createElement(MeetingHost, {
                token: _this2.props.token,
                meetingID: item.meetingSeriesId,
                userEmail: item.hostEmail,
                endPoint: _this2.props.endPoint
              })
            )
          )
        );
      });

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

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