import connectionManager from"./emby-apiclient/connectionmanager.js";import{appHost}from"./common/servicelocator.js";import userSettings from"./common/usersettings/usersettings.js";import browser from"./browser.js";import events from"./emby-apiclient/events.js";import appSettings from"./common/appsettings.js";let SupportsCSSAccentColor=!1,SupportsNativeAccentColor=SupportsCSSAccentColor||appHost.supports("systemaccentcolor"),themeStyleElement,currentThemeId,currentThemeInfo,currentThemeController;function tryRemove(elem){try{elem.remove()}catch(err){console.log("Error removing child node: "+err)}}let supportsCssVariables=CSS.supports("color","var(--fake-var)");function unloadTheme(){var nextSibling,elem=themeStyleElement;elem&&(supportsCssVariables||(nextSibling=elem.nextSibling)&&nextSibling.getAttribute("data-cssvars-job")&&tryRemove(nextSibling),tryRemove(elem),themeStyleElement=null,currentThemeId=null,currentThemeInfo=null,currentThemeController?.destroy(),currentThemeController=null)}supportsCssVariables||document.documentElement.classList.add("nocssvars");let defaultSettingsThemeIsMainTheme=!supportsCssVariables||appHost.supports("multiserver");function getThemes(){let defaultTheme="dark";supportsCssVariables&&browser.electron?defaultTheme="blueradiance":appHost.getPreferredTheme&&"windows"===appHost.getPreferredTheme()&&(defaultTheme="windows");var themes=[],defaultController="./modules/themes/themecontroller.js";return supportsCssVariables&&themes.push({name:"Apple TV",id:"appletv",controller:defaultController}),themes.push({name:"Black",id:"black",isDefault:"black"===defaultTheme,controller:defaultController}),themes.push({name:"Blue Radiance",id:"blueradiance",isDefault:"blueradiance"===defaultTheme,baseThemeId:"darkgradient",controller:defaultController}),supportsCssVariables,themes.push({name:"Dark",id:"dark",isDefault:"dark"===defaultTheme,controller:defaultController}),supportsCssVariables&&(themes.push({name:"Light",id:"light",isSettingsDefault:!defaultSettingsThemeIsMainTheme,controller:defaultController}),appHost.supports("windowstheme")&&themes.push({name:"Windows",id:"windows",isDefault:"windows"===defaultTheme,skipForSettingsthemes:!0,controller:Emby.Page.baseUrl()+"/modules/themes/windows/windowsthemecontroller.js"}),themes.push({name:"Superman",id:"superman",baseThemeId:"darkgradient",controller:defaultController})),supportsCssVariables&&themes.push({name:"Windows Media Center",id:"wmc",baseThemeId:"darkgradient",controller:defaultController}),themes}let skinManager={loadSkin:loadSkin,getThemes:getThemes,getCurrentThemeId:function(){return currentThemeId},getCurrentThemeInfo:function(){return currentThemeInfo},getCurrentThemeController:function(){return currentThemeController}};function loadSkin(){return skinManager.setTheme(userSettings.theme())}function onRegistrationSuccess(){appSettings.set("appthemesregistered","true")}function onRegistrationFailure(){appSettings.set("appthemesregistered","false")}function isRegistered(){return Emby.importModule("./modules/registrationservices/registrationservices.js").then(function(registrationServices){registrationServices.validateFeature("themes",{showDialog:!1}).then(onRegistrationSuccess,onRegistrationFailure)}),"false"!==appSettings.get("appthemesregistered")}function getThemeStylesheetInfo(id,isSettings,requiresRegistration){id||isSettings||(apiClient=connectionManager.currentApiClient())&&apiClient.getCurrentUserId()||(id=appSettings.get("lastTheme"));var themes=skinManager.getThemes();let defaultMainTheme,defaultSettingsTheme,selectedTheme;for(let i=0,length=themes.length;i{r/=255,g/=255,b/=255;var l=Math.max(r,g,b),s=l-Math.min(r,g,b),b=s?l===r?(g-b)/s:l===g?2+(b-r)/s:4+(r-g)/s:0;return[60*b<0?60*b+360:60*b,100*(s?l<=.5?s/(2*l-s):s/(2-(2*l-s)):0),100*(2*l-s)/2]};function getHslFromCSSProp(prop){var div=document.createElement("div");div.style.color=prop,document.body.appendChild(div);let color=getComputedStyle(div).getPropertyValue("color");div.remove();let hue,saturation,lightness;return color.startsWith("rgb(")&&(prop=(color=color.replace("rgb(","").replace(")")).split(","),div=RGBToHSL(parseInt(prop[0]),parseInt(prop[1]),parseInt(prop[2])),hue=div[0],saturation=div[1],lightness=div[2]),{hue:hue,saturation:saturation,lightness:lightness}}function getSystemAccentFromCSS(){var accentColor=getHslFromCSSProp("AccentColor");return{accentColor:accentColor,accentColorText:accentColor}}function getSystemAccent(){return SupportsCSSAccentColor?getSystemAccentFromCSS():appHost.supports("systemaccentcolor")?appHost.getSystemAccentColor():null}function createAccentNode(){var link=document.createElement("style"),list=(link.type="text/css",getAllAccentColors());let html="";for(let i=0,length=list.length;i