define(["exports","./../emby-apiclient/connectionmanager.js","./../common/globalize.js","./../layoutmanager.js","./../focusmanager.js","./../loading/loading.js","./../emby-elements/emby-scroller/emby-scroller.js","./../emby-elements/emby-input/emby-input.js","./../listview/listview.js","./../emby-elements/emby-button/paper-icon-button-light.js","./../emby-elements/emby-button/emby-button.js","./../dialoghelper/dialoghelper.js","./../formhelper.js"],function(_exports,_connectionmanager,_globalize,_layoutmanager,_focusmanager,_loading,_embyScroller,_embyInput,_listview,_paperIconButtonLight,_embyButton,_dialoghelper,_formhelper){function showAlert(options){Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}function onDialogClosed(){_loading.default.hide()}function refreshDirectoryBrowser(page,apiClient,path,fileOptions){if(path&&"string"!=typeof path)throw new Error("invalid path");_loading.default.show();var promises=[];"Network"===path?promises.push(apiClient.getNetworkDevices()):path?(promises.push(apiClient.getDirectoryContents(path,fileOptions)),promises.push(apiClient.getParentPath(path))):promises.push(apiClient.getDrives()),Promise.all(promises).then(function(responses){var folders=responses[0],responses=responses[1]||"",html=(page.querySelector(".txtDirectoryPickerPath").value=path||"","");path&&(html+=getItem("lnkPath lnkDirectory","",responses,". ."));for(var i=0,length=folders.length;i
',"Directory"===type?html+='folder':"File"===type?html+='description':"Network"===path&&(html+='wifi'),html=(html=(html=(html+='
')+'
'+name)+"
"+"
")+''+"
"}function initEditor(content,options,apiClient,fileOptions){content.addEventListener("click",function(e){var path,e=e.target.closest(".lnkPath");e&&(path=e.getAttribute("data-path"),e.classList.contains("lnkFile")?(content.querySelector(".txtDirectoryPickerPath").value=path,content.querySelector(".txtDirectoryPickerPath").dispatchEvent(new CustomEvent("change",{bubbles:!0}))):refreshDirectoryBrowser(content,apiClient,path,fileOptions))}),content.addEventListener("keydown",function(e){var path;13!==e.keyCode&&32!==e.keyCode||(e=e.target.closest(".lnkPath"))&&(path=e.getAttribute("data-path"),e.classList.contains("lnkFile")?content.querySelector("#txtDirectoryPickerPath").value=path:refreshDirectoryBrowser(content,path,fileOptions,!0))});var btnRefreshDirectories=content.querySelector(".btnRefreshDirectories");function onPathTextChange(e){var value=this.value,value=value&&(value.startsWith("\\\\")||value.toLowerCase().startsWith("smb://")),fldUsername=content.querySelector(".fldUsername"),fldPassword=content.querySelector(".fldPassword");value?(fldUsername&&fldUsername.classList.remove("hide"),fldPassword&&fldPassword.classList.remove("hide")):(fldUsername&&fldUsername.classList.add("hide"),fldPassword&&fldPassword.classList.add("hide"))}btnRefreshDirectories&&btnRefreshDirectories.addEventListener("click",function(e){var path=content.querySelector(".txtDirectoryPickerPath").value;refreshDirectoryBrowser(content,apiClient,path,fileOptions)}),content.querySelector(".txtDirectoryPickerPath").addEventListener("change",onPathTextChange),content.querySelector(".txtDirectoryPickerPath").addEventListener("input",onPathTextChange),content.querySelector("form").addEventListener("submit",function(e){var _this$querySelector,path,username,password,networkSharePath;return options.callback&&(path=this.querySelector(".txtDirectoryPickerPath").value,username=(null==(_this$querySelector=this.querySelector(".txtUsername"))?void 0:_this$querySelector.value)||null,password=(null==(_this$querySelector=this.querySelector(".txtPassword"))?void 0:_this$querySelector.value)||null,networkSharePath=(null==(_this$querySelector=this.querySelector(".txtNetworkPath"))?void 0:_this$querySelector.value)||null,function(path,validateWriteable,username,password,apiClient){return apiClient.ajax({type:"POST",url:apiClient.getUrl("Environment/ValidatePath"),data:{ValidateWriteable:validateWriteable,Path:path,Username:username,Password:password}}).catch(function(response){if(response){if(404===response.status)return showAlert("The path could not be found. Please ensure the path is valid and try again."),Promise.reject();if(500===response.status)return showAlert(validateWriteable?"Emby Server requires write access to this folder. Please ensure write access and try again.":"The path could not be found. Please ensure the path is valid and try again."),Promise.reject()}return Promise.resolve()})}(path,options.validateWriteable,username,password,apiClient).then(function(){options.callback(path,networkSharePath,username,password)})),e.preventDefault(),e.stopPropagation(),!1})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["formDialogStyle"]),_exports.default=function(){var currentDialog;this.show=function(options){var fileOptions={includeDirectories:!0},apiClient=(null!=(options=options||{}).includeDirectories&&(fileOptions.includeDirectories=options.includeDirectories),null!=options.includeFiles&&(fileOptions.includeFiles=options.includeFiles),_connectionmanager.default.currentApiClient());Promise.all([apiClient.getSystemInfo(),function(options,apiClient){return options.path?Promise.resolve(options.path):apiClient.getJSON(apiClient.getUrl("Environment/DefaultDirectoryBrowser")).then(function(result){return result.Path||""},function(){return""})}(options,apiClient)]).then(function(responses){var systemInfo=responses[0],responses=responses[1],dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"medium-tall",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("ui-body-a"),dlg.classList.add("background-theme-a"),dlg.classList.add("directoryPicker"),dlg.classList.add("formDialog"),""),systemInfo=(html=(html=(html=(html=(html+='
')+''+'

')+(options.header||_globalize.default.translate("HeaderSelectPath")))+"

"+"
")+function(options,apiClient,systemInfo){var html="",labelKey=(html=html+'
'+'
',options.pathReadOnly||(html=(html=html+'
'+(options.instruction?options.instruction+"

":""))+_globalize.default.translate("MessageDirectoryPickerInstruction").replace("{0}","\\\\server").replace("{1}","\\\\192.168.1.101"),"synology"===(systemInfo.PackageName||"").toLowerCase()?html=(html+="

")+''+_globalize.default.translate("LearnHowToCreateSynologyShares")+"":"bsd"===systemInfo.OperatingSystem.toLowerCase()?html=(html=(html+="

")+_globalize.default.translate("MessageDirectoryPickerBSDInstruction")+"
")+''+_globalize.default.translate("LearnMore")+"":"linux"===systemInfo.OperatingSystem.toLowerCase()&&(html=(html+="

")+_globalize.default.translate("MessageDirectoryPickerLinuxInstruction")+"
"),html+="
"),!0!==options.includeFiles?"LabelFolder":"LabelPath"),readOnlyAttribute=options.pathReadOnly?" readonly":"",autoCompleteAttribute=_layoutmanager.default.tv?' autocomplete="off" ':"";return html=(html=(html+='
')+'
'+'
')+('')+"
",readOnlyAttribute||(html+=''),html+="
",options.enableLoginCredentials&&"windows"!==systemInfo.OperatingSystem.toLowerCase()&&apiClient.isMinServerVersion("4.8.0.40")&&(html=(html=(html=(html=(html+='
')+'
')+_globalize.default.translate("UsernameForFolderHelp")+'
')+'
')+_globalize.default.translate("PasswordForFolderHelp")+"
"),readOnlyAttribute||(html+='
'),options.enableNetworkSharePath&&(html=(html=(html+='
')+'
')+_globalize.default.translate("LabelOptionalNetworkPathHelp")+"
"),html=(html=(html=(html+='
')+('")+"
")+"
"+"
")+"
"+""}(options,apiClient,systemInfo),dlg.innerHTML=html,initEditor(dlg,options,apiClient,fileOptions),dlg.addEventListener("close",onDialogClosed),_dialoghelper.default.open(dlg),dlg.querySelector(".btnCloseDialog").addEventListener("click",function(){_dialoghelper.default.close(dlg)}),(currentDialog=dlg).querySelector(".txtDirectoryPickerPath")),html=(systemInfo.value=responses,dlg.querySelector(".txtNetworkPath")),html=(html&&(html.value=options.networkSharePath||""),dlg.querySelector(".txtUsername")),html=(html&&(html.value=options.username||""),dlg.querySelector(".txtPassword"));html&&(html.value=options.password||""),systemInfo.dispatchEvent(new CustomEvent("change",{bubbles:!0})),options.pathReadOnly||refreshDirectoryBrowser(dlg,apiClient,responses,fileOptions)})},this.close=function(){currentDialog&&_dialoghelper.default.close(currentDialog)}}});