'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

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

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

var _Loading2 = _interopRequireDefault(_Loading);

var _PmrDetail = require('./PmrDetail');

var _PmrDetail2 = _interopRequireDefault(_PmrDetail);

var _MeetingDetail = require('../meetingCalenderViews/MeetingDetail');

var _MeetingDetail2 = _interopRequireDefault(_MeetingDetail);

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

// import pmrStyle from '../../assets/styles/widgets/pmr/pmr.module.scss';


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

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

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

    _this.state = {
      topic: "Dongdong Wang's Personal Room",
      hostPin: '683100',
      enabledAutoLock: false,
      autoLockMinutes: 0,
      enabledNotifyHost: true,
      supportCoHost: true,
      supportAnyoneAsCoHost: false,
      avatar: '',
      personalMeetingRoomLink: 'https://cisco.webex.com/meet/dongdwan'
    };
    return _this;
  }

  Pmr.prototype.render = function render() {
    var meFetch = this.props.meFetch;

    var myPMR = _reactRefetch.PromiseState.all([meFetch]);

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

      // get pmr info

      return _react2.default.createElement(
        'div',
        { className: 'wg_pmr' },
        _react2.default.createElement(
          'div',
          { className: 'pmr_card_c' },
          _react2.default.createElement(
            'div',
            { id: 'avatar_div', className: 'pmr_avatar' },
            _react2.default.createElement(
              'div',
              { className: 'avatar_editor' },
              _react2.default.createElement(
                'div',
                {
                  role: 'application',
                  'aria-label': 'Press Enter to change your profile picture.',
                  tabIndex: '0',
                  className: 'user_avatar'
                },
                myInfo.avatar ? _react2.default.createElement(
                  'span',
                  { className: 'avatar_xlarge avatar_img' },
                  _react2.default.createElement('img', {
                    src: myInfo.avatar,
                    alt: myInfo.displayName
                  })
                ) : _react2.default.createElement(_react3.Avatar, { title: myInfo.displayName, size: '80' })
              )
            )
          ),
          _react2.default.createElement(_PmrDetail2.default, {
            token: this.props.token,
            userID: myInfo.id,
            endPoint: this.props.endPoint
          })
        )
      );
    }
  };

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