"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[2460,6186],{52460:(e,s,t)=>{t.r(s),t.d(s,{ICurrentUser:()=>n,IUserMenu:()=>i,RendererUserMenu:()=>I,USER:()=>r,User:()=>_,UserMenu:()=>N,getAnonymousUserName:()=>m,moonsOfJupyter:()=>c,requestAPI:()=>l});var a=t(74547);const r="@jupyterlab/user:userDB",n=new a.Token("@jupyterlab/user:ICurrentUser"),i=new a.Token("@jupyterlab/user:IUserMenu");var o=t(58646),h=t(49748),u=t(27714);async function l(e="",s={}){const t=u.ServerConnection.makeSettings(),a=h.URLExt.join(t.baseUrl,e);let r;try{r=await u.ServerConnection.makeRequest(a,s,t)}catch(e){throw new u.ServerConnection.NetworkError(e)}let n=await r.text();if(n.length>0)try{n=JSON.parse(n)}catch(e){console.log("Not a JSON response body.",r)}if(!r.ok)throw new u.ServerConnection.ResponseError(r,n.message||n);return n}const c=["Metis","Adrastea","Amalthea","Thebe","Io","Europa","Ganymede","Callisto","Themisto","Leda","Ersa","Pandia","Himalia","Lysithea","Elara","Dia","Carpo","Valetudo","Euporie","Eupheme","Helike","Euanthe","Hermippe","Praxidike","Thyone","Thelxinoe","Ananke","Mneme","Orthosie","Harpalyke","Iocaste","Erinome","Aitne","Herse","Taygete","Eukelade","Carme","Isonoe","Autonoe","Philophrosyne","Cyllene","Pasithee","Pasiphae","Sponde","Eurydome","Kalyke","Hegemone","Kale","Kallichore","Chaldene","Arche","Eirene","Kore","Megaclite","Aoede","Callirrhoe","Sinope"],m=()=>c[Math.floor(Math.random()*c.length)];class _{constructor(){this._isReady=!1,this._ready=new o.Signal(this),this._changed=new o.Signal(this),this._fetchUser(),this._isReady=!0,this._ready.emit(!0)}get username(){return this._username}get name(){return this._name}get displayName(){return this._displayName}get initials(){return this._initials}get color(){return this._color}get anonymous(){return this._anonymous}get cursor(){return this._cursor}get isReady(){return this._isReady}get ready(){return this._ready}get changed(){return this._changed}fromJSON(e){this._username=e.username,this._name=e.name,this._displayName=e.displayName,this._initials=e.initials,this._color=e.color,this._anonymous=e.anonymous,this._cursor=e.cursor,this._save()}toJSON(){return{username:this._username,name:this.name,displayName:this._displayName,initials:this._initials,color:this._color,anonymous:this._anonymous,cursor:this._cursor}}_save(){const{localStorage:e}=window;e.setItem(r,JSON.stringify(this.toJSON())),this._changed.emit()}_fetchUser(){const e=new URLSearchParams(location.search);let s=e.get("username")||"",t=e.get("usercolor")||"",n=e.get("initials")||"";const{localStorage:i}=window,o=i.getItem(r);if(null!==o){const e=JSON.parse(o);this._username=e.username,this._name=""!==s?s:e.name,this._displayName=""!==s?s:e.displayName,this._initials=""!==n?n:e.initials,this._color=""!==t?"#"+t:e.color,this._anonymous=e.anonymous,this._cursor=e.cursor||void 0,""===s&&""===t||this._save()}else{const e=m();this._username=a.UUID.uuid4(),this._name=""!==s?s:"Anonymous "+e,this._displayName=this._name,this._initials=""!==n?n:`A${e.substring(0,1).toLocaleUpperCase()}`,this._color="#"+(""!==t?t:d.getRandomColor().slice(1)),this._anonymous=!0,this._cursor=void 0,this._save()}}}var d;!function(e){const s=["#12A0D3","#17AB30","#CC8500","#A79011","#ee6352","#609DA9","#4BA749","#00A1B3"];e.getRandomColor=()=>s[Math.floor(Math.random()*s.length)]}(d||(d={}));var y=t(25167),p=t(28877),g=t(96158);class I extends p.MenuBar.Renderer{constructor(e){super(),this._user=e}renderItem(e){let s=this.createItemClass(e),t=this.createItemDataset(e),a=this.createItemARIA(e);return g.h.li(Object.assign({className:s,dataset:t,tabindex:"0",onfocus:e.onfocus},a),this._createUserIcon(),this.renderLabel(e),this.renderIcon(e))}renderLabel(e){let s=this.formatLabel(e);return g.h.div({className:"lm-MenuBar-itemLabel p-MenuBar-itemLabel jp-MenuBar-label"},s)}_createUserIcon(){return this._user.isReady&&this._user.avatar_url?g.h.div({className:"lm-MenuBar-itemIcon p-MenuBar-itemIcon jp-MenuBar-imageIcon"},g.h.img({src:this._user.avatar_url})):this._user.isReady?g.h.div({className:"lm-MenuBar-itemIcon p-MenuBar-itemIcon jp-MenuBar-anonymousIcon",style:{backgroundColor:this._user.color}},g.h.span({},this._user.initials)):g.h.div({className:"lm-MenuBar-itemIcon p-MenuBar-itemIcon jp-MenuBar-anonymousIcon"},y.userIcon)}}class N extends p.Menu{constructor(e){super(e),this._updateLabel=e=>{const s=""!==e.displayName?e.displayName:e.name;this.title.label=s,this.update()},this._user=e.user;const s=""!==this._user.displayName?this._user.displayName:this._user.name;this.title.label=this._user.isReady?s:"",this.title.icon=y.caretDownIcon,this.title.iconClass="jp-UserMenu-caretDownIcon",this._user.ready.connect(this._updateLabel),this._user.changed.connect(this._updateLabel)}dispose(){this._user.ready.disconnect(this._updateLabel),this._user.changed.disconnect(this._updateLabel)}}}}]);