"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _IconTrash = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconTrash"));

var _IconReset = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconReset"));

var _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

var _Select = _interopRequireDefault(require("@instructure/ui-forms/lib/components/Select"));

var _ScreenReaderContent = _interopRequireDefault(require("@instructure/ui-a11y/lib/components/ScreenReaderContent"));

var _Grid = _interopRequireWildcard(require("@instructure/ui-layout/lib/components/Grid"));

var _View = _interopRequireDefault(require("@instructure/ui-layout/lib/components/View"));

var _Avatar = _interopRequireDefault(require("@instructure/ui-elements/lib/components/Avatar"));

var _Text = _interopRequireDefault(require("@instructure/ui-elements/lib/components/Text"));

var _constants = require("@instructure/quiz-common/lib/constants");

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var styles = {
  componentId: 'eeOol',
  template: function template(theme) {
    return "\n\n.SharingModal__styles__separator {\n  width: 100%;\n  margin: ".concat(theme.separatorMargin || 'inherit', " 0;\n  padding: 0;\n  border-bottom: solid ").concat(theme.separatorBorderWidth || 'inherit', ";\n  border-color: ").concat(theme.separatorColor || 'inherit', ";\n}\n\n.SharingModal__styles__labelRemoved {\n  text-decoration: line-through;\n}\n");
  },
  'separator': 'SharingModal__styles__separator',
  'labelRemoved': 'SharingModal__styles__labelRemoved'
};

var PeopleList =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(PeopleList, _Component);

  function PeopleList() {
    var _getPrototypeOf2;

    var _this;

    (0, _classCallCheck2.default)(this, PeopleList);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(PeopleList)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.removeButton = function (person, isPersonRemoved) {
      return _react.default.createElement(_Button.default, {
        "data-automation": "sdk-unshare-bank-user-".concat(person.get('userUuid')),
        variant: "icon",
        onClick: function onClick() {
          return _this.props.onPersonRemove(person.get('id'), isPersonRemoved);
        },
        icon: isPersonRemoved ? _IconReset.default : _IconTrash.default
      }, _react.default.createElement(_ScreenReaderContent.default, null, isPersonRemoved ? "Annuler supprimer pour " + person.get('fullName') : "Supprimer " + person.get('fullName')));
    };

    _this.renderPerson = function (person, index) {
      var isPersonRemoved = _this.props.peopleToRemove.includes(person.get('id'));

      return _react.default.createElement(_Grid.GridRow, {
        key: person.get('userUuid'),
        "data-automation": "sdk-shared-with-user-row"
      }, _react.default.createElement(_Grid.GridCol, {
        width: 1
      }, _react.default.createElement(_Avatar.default, {
        name: person.get('fullName'),
        src: person.get('avatar'),
        size: "small"
      })), _react.default.createElement(_Grid.GridCol, null, _react.default.createElement("span", {
        className: isPersonRemoved && styles.labelRemoved
      }, person.get('fullName'))), false && _react.default.createElement(_Grid.GridCol, {
        width: "auto"
      }, _react.default.createElement(_Select.default, {
        onChange: function onChange(event) {
          return _this.props.onPermissionChange(index, event.target.value);
        },
        value: person.get('permission'),
        label: _react.default.createElement(_ScreenReaderContent.default, null, "Acc\xE8s pour " + person.get('fullName'))
      }, _react.default.createElement("option", {
        value: _constants.CAN_EDIT
      }, "Peut \xE9diter"), _react.default.createElement("option", {
        value: _constants.READ_ONLY
      }, "Lecture seule"))), _react.default.createElement(_Grid.GridCol, {
        width: "auto"
      }, _this.props.people.size === 1 ? null : _this.removeButton(person, isPersonRemoved)));
    };

    return _this;
  }

  (0, _createClass2.default)(PeopleList, [{
    key: "render",
    value: function render() {
      var people = this.props.people;
      this.removeButtonRefs = [];
      return _react.default.createElement("div", null, _react.default.createElement(_Text.default, {
        as: "div",
        weight: "bold"
      }, "Actuellement partag\xE9 avec"), _react.default.createElement(_View.default, {
        as: "div",
        padding: "small 0 0 0",
        "data-automation": "sdk-shared-bank-user-list"
      }, _react.default.createElement(_Grid.default, {
        vAlign: "middle"
      }, people.map(this.renderPerson))));
    }
  }]);
  PeopleList.displayName = "PeopleList";
  return PeopleList;
}(_react.Component);

exports.default = PeopleList;
PeopleList.propTypes = {
  people: _propTypes.default.arrayOf(_propTypes.default.shape({
    avatar: _propTypes.default.string,
    fullName: _propTypes.default.string.isRequired,
    userUuid: _propTypes.default.string.isRequired,
    permission: _propTypes.default.string.isRequired
  })).isRequired,
  onPermissionChange: _propTypes.default.func.isRequired,
  onPersonRemove: _propTypes.default.func.isRequired,
  peopleToRemove: _propTypes.default.arrayOf(_propTypes.default.string).isRequired
};