(function(){var e,t;e=this,t=function(e){"use strict";var t;let i=Spina.spina(t=class Settings extends Spina.BaseModel{static defaults(){return{configuration:{},serviceID:null,services:{}}}})||t;var a;let s=Spina.spina(a=class ServiceSettingsFormView extends Spina.BaseView{validate(){return!0}hide(){const e=this.el;return e.disabled=!0,e.hidden=!0,this}show(){const e=this.el;return e.disabled=!1,e.hidden=!1,this}})||a;var o;const r=["image/gif","image/jpeg","image/png"];let n=Spina.spina(o=class FileUploadSettingsFormView extends s{static 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"};#e;#t;#i;validate(){const e=this.#i[0].files[0];return e?!!r.some(t=>t===e.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(){this.#e=this.$(".avatar-file-upload-config"),this.#t=this.$(".avatar-preview"),this.#i=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===this.#e[0]&&this.#e.width(this.#e.width()).addClass("drag-hover")}_onDragOver(e){if(e.preventDefault(),e.stopPropagation(),e.target===this.#e[0]){const t=e.originalEvent.dataTransfer;t&&(t.dropEffect="copy")}}_onDragLeave(e){if(e.preventDefault(),e.stopPropagation(),e.target===this.#e[0]){this.#e.removeClass("drag-hover").width("auto");const t=e.originalEvent.dataTransfer;t&&(t.dropEffect="none")}}_onDrop(e){e.preventDefault(),e.stopPropagation(),this.#e.removeClass("drag-hover");const t=e.originalEvent.dataTransfer,i=t&&t.files;if(!i||0===i.length)return;if(i.length>1)return void alert(gettext("You can only set one file as your avatar. Please drag and drop a single file."));const a=i[0].type;if("image/png"===a||"image/jpeg"===a||"image/gif"===a){try{this.#i[0].files=i}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(i[0])}else alert(gettext("This doesn't appear to be a compatible image file for avatars. Please upload a PNG, JPEG, or GIF file."))}_onFileChanged(e){const t=e.target.files[0];t&&this._setAvatarFromFile(t)}_setAvatarFromFile(e){const t=new FileReader;t.addEventListener("load",()=>{this.#t.empty().removeClass("avatar-preview-unset").append($("<img>").attr({alt:gettext("Your new avatar"),src:t.result}))}),t.readAsDataURL(e)}})||o;var l;let d;const g=new Promise((e,t)=>{d=e});let c=Spina.spina(l=class SettingsFormView extends Spina.BaseView{static events={"change #id_avatar_service_id":"_onServiceChanged",submit:"_onSubmit"};static instance=null;static ready=g;static addConfigForm(e,t){SettingsFormView.instance._configForms.set(e,new t({el:$(`[data-avatar-service-id="${e}"]`),model:SettingsFormView.instance.model}))}initialize(){console.assert(null===SettingsFormView.instance),SettingsFormView.instance=this,this._configForms=new Map,this._$config=this.$(".avatar-service-configuration"),this.listenTo(this.model,"change:serviceID",()=>this._showHideForms()),d()}_onSubmit(e){const t=this.model.get("serviceID"),i=this._configForms.get(t);i&&!i.validate()&&e.preventDefault()}renderForms(){for(const e of this._configForms.values())e.render();this.$("#id_avatar_service_id").change(),this._showHideForms()}_showHideForms(){const e=this.model.get("serviceID"),t=this._configForms.get(e),i=this.model.previous("serviceID"),a=i?this._configForms.get(i):void 0;a&&t?(a.hide(),t.show()):a?(a.hide(),this._$config.hide()):t&&(t.show(),this._$config.show())}_onServiceChanged(e){const t=$(e.target).val();this.model.set("serviceID",t)}})||l;const v={FileUploadSettingsFormView:n,ServiceSettingsFormView:s,Settings:i,SettingsFormView:c};e.Avatars=v},"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);
