text: define ("mod_forum/local/grades/local/grader/user_picker",["exports","core/templates","./user_picker/selectors","core/str"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=e(b);c=e(c);function e(a){return a&&a.__esModule?a:{default:a}}function f(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);if(b)d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable});c.push.apply(c,d)}return c}function g(a){for(var b=1,c;b<arguments.length;b++){c=null!=arguments[b]?arguments[b]:{};if(b%2){f(Object(c),!0).forEach(function(b){h(a,b,c[b])})}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(a,Object.getOwnPropertyDescriptors(c))}else{f(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))})}}return a}function h(a,b,c){if(b in a){Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0})}else{a[b]=c}return a}function i(a,b){return n(a)||m(a,b)||k(a,b)||j()}function j(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function k(a,b){if(!a)return;if("string"==typeof a)return l(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return l(a,b)}function l(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function m(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function n(a){if(Array.isArray(a))return a}function o(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function p(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){o(h,d,e,f,g,"next",a)}function g(a){o(h,d,e,f,g,"throw",a)}f(void 0)})}}function q(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function r(a,b){for(var c=0,d;c<b.length;c++){d=b[c];d.enumerable=d.enumerable||!1;d.configurable=!0;if("value"in d)d.writable=!0;Object.defineProperty(a,d.key,d)}}function s(a,b,c){if(b)r(a.prototype,b);if(c)r(a,c);return a}var t=function(){function a(b,c,d){q(this,a);this.userList=b;this.showUserCallback=c;this.preChangeUserCallback=d;this.currentUserIndex=0;this.render=this.render.bind(this);this.setUserId=this.setUserId.bind(this)}s(a,[{key:"setUserId",value:function setUserId(a){var b=this.userList.findIndex(function(b){return b.id===parseInt(a)});if(-1===b){throw Error("User with id ".concat(a," not found"))}this.currentUserIndex=b}},{key:"render",value:function(){var a=p(regeneratorRuntime.mark(function a(){var c,d,e;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:this.root=document.createElement("div");a.next=3;return this.renderNavigator();case 3:c=a.sent;d=c.html;e=c.js;b.default.replaceNodeContents(this.root,d,e);a.next=9;return this.showUser(this.currentUser);case 9:this.registerEventListeners();case 10:case"end":return a.stop();}}},a,this)}));return function render(){return a.apply(this,arguments)}}()},{key:"renderNavigator",value:function renderNavigator(){return b.default.renderForPromise("".concat("mod_forum/local/grades/local/grader","/user_picker"),{})}},{key:"renderUserChange",value:function renderUserChange(a){return b.default.renderForPromise("".concat("mod_forum/local/grades/local/grader","/user_picker/user"),a)}},{key:"showUser",value:function(){var a=p(regeneratorRuntime.mark(function a(e){var f,g,h,j,k,l,m;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return Promise.all([this.renderUserChange(e),this.showUserCallback(e)]);case 2:f=a.sent;g=i(f,1);h=g[0];j=h.html;k=h.js;l=this.root.querySelector(c.default.regions.userRegion);b.default.replaceNodeContents(l,j,k);m=this.root.querySelector(c.default.regions.currentUser);a.next=12;return(0,d.get_string)("nowgradinguser","mod_forum",e.fullname);case 12:m.textContent=a.sent;case 13:case"end":return a.stop();}}},a,this)}));return function showUser(){return a.apply(this,arguments)}}()},{key:"registerEventListeners",value:function registerEventListeners(){var a=this;this.root.addEventListener("click",function(){var b=p(regeneratorRuntime.mark(function b(d){var e,f;return regeneratorRuntime.wrap(function(b){while(1){switch(b.prev=b.next){case 0:e=d.target.closest(c.default.actions.changeUser);if(!e){b.next=9;break}b.next=4;return a.preChangeUserCallback(a.currentUser);case 4:f=b.sent;if(f.failed){b.next=9;break}a.updateIndex(parseInt(e.dataset.direction));b.next=9;return a.showUser(a.currentUser);case 9:case"end":return b.stop();}}},b)}));return function(){return b.apply(this,arguments)}}())}},{key:"updateIndex",value:function updateIndex(a){this.currentUserIndex+=a;if(0>this.currentUserIndex){this.currentUserIndex=this.userList.length-1}else if(this.currentUserIndex>this.userList.length-1){this.currentUserIndex=0}return this.currentUserIndex}},{key:"currentUser",get:function get(){return g({},this.userList[this.currentUserIndex],{total:this.userList.length,displayIndex:this.currentUserIndex+1})}},{key:"rootNode",get:function get(){return this.root}}]);return a}(),u=function(){var a=p(regeneratorRuntime.mark(function a(b,c,d){var e,f,g,h,i=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:e=3<i.length&&i[3]!==void 0?i[3]:{},f=e.initialUserId,g=void 0===f?null:f;h=new t(b,c,d);if(g){h.setUserId(g)}a.next=5;return h.render();case 5:return a.abrupt("return",h);case 6:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.default=u;return a.default});
  //# sourceMappingURL=user_picker.min.js.map
  