define(["dialogHelper","jQuery","loading","emby-button","emby-select"],function(dialogHelper,$,loading){"use strict";function onFileReaderError(evt){switch(loading.hide(),evt.target.error.code){case evt.target.error.NOT_FOUND_ERR:require(["toast"],function(toast){toast(Globalize.translate("MessageFileNotFound"))});break;case evt.target.error.ABORT_ERR:break;default:require(["toast"],function(toast){toast(Globalize.translate("MessageFileReadError"))})}}function setFiles(page,files){var file=files[0];if(!file||!file.type.match("image.*"))return $("#imageOutput",page).html(""),$("#fldUpload",page).hide(),void(currentFile=null);currentFile=file;var reader=new FileReader;reader.onerror=onFileReaderError,reader.onloadstart=function(){$("#fldUpload",page).hide()},reader.onabort=function(){loading.hide(),console.log("File read cancelled")},reader.onload=function(theFile){return function(e){var html=[''].join("");$("#imageOutput",page).html(html),$("#fldUpload",page).show()}}(file),reader.readAsDataURL(file)}function processImageChangeResult(page){hasChanges=!0,history.back()}function onSubmit(){var file=currentFile;if(!file)return!1;if("image/png"!=file.type&&"image/jpeg"!=file.type&&"image/jpeg"!=file.type)return!1;loading.show();var page=$(this).parents(".dialog"),imageType=$("#selectImageType",page).val();return ApiClient.uploadItemImage(currentItemId,imageType,file).then(function(){$("#uploadImage",page).val("").trigger("change"),loading.hide(),processImageChangeResult(page)}),!1}function initEditor(page){$("form",page).off("submit",onSubmit).on("submit",onSubmit),$("#uploadImage",page).on("change",function(){setFiles(page,this.files)}),$("#imageDropZone",page).on("dragover",function(e){return e.preventDefault(),e.originalEvent.dataTransfer.dropEffect="Copy",!1}).on("drop",function(e){return e.preventDefault(),setFiles(page,e.originalEvent.dataTransfer.files),!1})}function showEditor(itemId,options){options=options||{};var xhr=new XMLHttpRequest;xhr.open("GET","components/imageuploader/imageuploader.template.html",!0),xhr.onload=function(e){var template=this.response;currentItemId=itemId;var dlg=dialogHelper.createDialog({size:"fullscreen-border"}),theme=options.theme||"b";dlg.classList.add("ui-body-"+theme),dlg.classList.add("background-theme-"+theme);var html="";html+='