!function(){var e,t;e=this,t=function(e){"use strict";var a,i,r;let t=Spina.spina(h=class extends Spina.BaseModel{static defaults(){return{configuration:{},serviceID:null,services:{}}}})||h;function o(e,t,a){t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a}function s(e,t){t=l(e,t,"get");return t.get?t.get.call(e):t.value}function n(e,t,a){t=l(e,t,"set");if(t.set)t.set.call(e,a);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=a}}function l(e,t,a){if(t.has(e))return t.get(e);throw new TypeError("attempted to "+a+" private field on non-instance")}function d(e,t,a){var i=e;if(t.has(i))throw new TypeError("Cannot initialize the same private elements twice on an object");t.set(e,a)}let g=Spina.spina(h=class extends Spina.BaseView{validate(){return!0}hide(){var e=this.el;return e.disabled=!0,e.hidden=!0,this}show(){var e=this.el;return e.disabled=!1,e.hidden=!1,this}})||h;const v=["image/gif","image/jpeg","image/png"];let f=Spina.spina((a=new WeakMap,i=new WeakMap,r=new WeakMap,o(h=class extends g{constructor(){super(...arguments),d(this,a,{writable:!0,value:void 0}),d(this,i,{writable:!0,value:void 0}),d(this,r,{writable:!0,value:void 0})}validate(){const t=s(this,r)[0].files[0];return t?!!v.some(e=>e===t.type)||(alert(gettext("This wasn't a valid image file format. Please provide a PNG, JPEG, or GIF file.")),!1):(alert(gettext("You must choose a file.")),!1)}onInitialRender(){n(this,a,this.$(".avatar-file-upload-config")),n(this,i,this.$(".avatar-preview")),n(this,r,this.$("#id_file-upload-avatar_upload"))}_onBrowseClicked(e){e.preventDefault(),e.stopPropagation(),this.$("#avatar-file-upload-browse-label").click()}_onDragEnter(e){e.preventDefault(),e.stopPropagation(),e.target===s(this,a)[0]&&s(this,a).width(s(this,a).width()).addClass("drag-hover")}_onDragOver(e){e.preventDefault(),e.stopPropagation(),e.target===s(this,a)[0]&&(e=e.originalEvent.dataTransfer)&&(e.dropEffect="copy")}_onDragLeave(e){e.preventDefault(),e.stopPropagation(),e.target===s(this,a)[0]&&(s(this,a).removeClass("drag-hover").width("auto"),e=e.originalEvent.dataTransfer)&&(e.dropEffect="none")}_onDrop(e){e.preventDefault(),e.stopPropagation(),s(this,a).removeClass("drag-hover");e=e.originalEvent.dataTransfer,e=e&&e.files;if(e&&0!==e.length)if(1<e.length)alert(gettext("You can only set one file as your avatar. Please drag and drop a single file."));else{var t=e[0].type;if("image/png"!==t&&"image/jpeg"!==t&&"image/gif"!==t)alert(gettext("This doesn't appear to be a compatible image file for avatars. Please upload a PNG, JPEG, or GIF file."));else{try{s(this,r)[0].files=e}catch(e){return void alert(gettext("Looks like dragging to upload a file isn't going to work with your browser. Try browsing for a file instead."))}this._setAvatarFromFile(e[0])}}}_onFileChanged(e){e=e.target.files[0];e&&this._setAvatarFromFile(e)}_setAvatarFromFile(e){const t=new FileReader;t.addEventListener("load",()=>{s(this,i).empty().removeClass("avatar-preview-unset").append($("<img>").attr({alt:gettext("Your new avatar"),src:t.result}))}),t.readAsDataURL(e)}},"events",{"change #id_file-upload-avatar_upload":"_onFileChanged","click .avatar-file-upload-browse":"_onBrowseClicked","click .avatar-preview":"_onBrowseClicked","dragenter .avatar-file-upload-config":"_onDragEnter","dragleave .avatar-file-upload-config":"_onDragLeave","dragover .avatar-file-upload-config":"_onDragOver","drop .avatar-file-upload-config":"_onDrop"}),h=h))||h,c;var h=new Promise((e,t)=>{c=e});let p=Spina.spina((o(u=class p extends Spina.BaseView{static addConfigForm(e,t){p.instance._configForms.set(e,new t({el:$(`[data-avatar-service-id="${e}"]`),model:p.instance.model}))}initialize(){console.assert(null===p.instance),(p.instance=this)._configForms=new Map,this._$config=this.$(".avatar-service-configuration"),this.listenTo(this.model,"change:serviceID",()=>this._showHideForms()),c()}_onSubmit(e){var t=this.model.get("serviceID"),t=this._configForms.get(t);t&&!t.validate()&&e.preventDefault()}renderForms(){for(const e of this._configForms.values())e.render();this.$("#id_avatar_service_id").change(),this._showHideForms()}_showHideForms(){var e=this.model.get("serviceID"),e=this._configForms.get(e),t=this.model.previous("serviceID"),t=t?this._configForms.get(t):void 0;t&&e?(t.hide(),e.show()):t?(t.hide(),this._$config.hide()):e&&(e.show(),this._$config.show())}_onServiceChanged(e){e=$(e.target).val();this.model.set("serviceID",e)}},"events",{"change #id_avatar_service_id":"_onServiceChanged",submit:"_onSubmit"}),o(u,"instance",null),o(u,"ready",h),h=u))||h;var u={FileUploadSettingsFormView:f,ServiceSettingsFormView:g,Settings:t,SettingsFormView:p};e.Avatars=u},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Djblets=e.Djblets||{})}.call(this);
