/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
import{BroadcastMessage as n}from"@typo3/backend/broadcast-message.js";import i from"@typo3/backend/broadcast-service.js";var r;(function(d){d.colorSchemeSwitch="typo3-backend-color-scheme-switch"})(r||(r={}));class l{constructor(){document.addEventListener("typo3:color-scheme:update",t=>this.onColorSchemeUpdate(t.detail)),document.addEventListener("typo3:theme:update",t=>this.onThemeUpdate(t.detail)),document.addEventListener("typo3:title-format:update",t=>this.onTitleFormatUpdate(t.detail)),document.addEventListener("typo3:backend-language:update",t=>this.onBackendLanguageFormatUpdate(t.detail)),document.addEventListener("typo3:color-scheme:broadcast",t=>this.activateColorScheme(t.detail.payload.colorScheme)),document.addEventListener("typo3:theme:broadcast",t=>this.activateTheme(t.detail.payload.theme)),document.addEventListener("typo3:title-format:broadcast",t=>this.activateTitleFormat(t.detail.payload.format)),document.addEventListener("typo3:backend-language:broadcast",t=>this.updateBackendLanguage(t.detail.payload.language,t.detail.payload.direction))}onColorSchemeUpdate(t){const{colorScheme:e}=t;this.activateColorScheme(e),i.post(new n("color-scheme","broadcast",{colorScheme:e}))}onThemeUpdate(t){const{theme:e}=t;this.activateTheme(e),i.post(new n("theme","broadcast",{theme:e}))}onTitleFormatUpdate(t){const{format:e}=t;this.activateTitleFormat(e),i.post(new n("title-format","broadcast",{format:e}))}onBackendLanguageFormatUpdate(t){const{language:e,direction:a}=t;this.updateBackendLanguage(e,a),i.post(new n("language-update","broadcast",{language:e,direction:a}))}activateColorScheme(t){const e=document.querySelector(r.colorSchemeSwitch);e&&(e.activeColorScheme=t),this.setStyleChangingDocumentAttribute("data-color-scheme",t)}activateTheme(t){this.setStyleChangingDocumentAttribute("data-theme",t)}activateTitleFormat(t){t==="sitenameFirst"?document.querySelector("typo3-backend-module-router")?.setAttribute("sitename-first",""):document.querySelector("typo3-backend-module-router")?.removeAttribute("sitename-first")}updateBackendLanguage(t,e){const a=document.documentElement,o=window.frames.list_frame?.document.documentElement;a.setAttribute("lang",t),o?.setAttribute("lang",t),e!==null?(a.setAttribute("dir",e),o?.setAttribute("dir",e)):(a.removeAttribute("dir"),o?.removeAttribute("dir"))}async setStyleChangingDocumentAttribute(t,e){const a=document.documentElement,o=window.frames.list_frame?.document.documentElement,c=()=>{a.classList.add("t3js-disable-transitions"),o?.classList.add("t3js-disable-transitions"),a.setAttribute(t,e),o?.setAttribute(t,e)},m=()=>{a.classList.remove("t3js-disable-transitions"),o?.classList.remove("t3js-disable-transitions")};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches||!("startViewTransition"in document)||typeof document.startViewTransition!="function"){c(),await new Promise(s=>requestAnimationFrame(s)),o&&await new Promise(s=>window.frames.list_frame.requestAnimationFrame(s)),m();return}await document.startViewTransition(c).finished,m()}}var u=new l;export{u as default};
