/*
 * 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 s}from"@typo3/backend/broadcast-message.js";import o from"@typo3/backend/broadcast-service.js";import h from"@typo3/backend/storage/persistent.js";import u from"@typo3/backend/modal.js";import{SeverityEnum as p}from"@typo3/backend/enum/severity.js";import i from"~labels/backend.messages";var d;(function(c){c.colorSchemeSwitch="typo3-backend-color-scheme-switch"})(d||(d={}));class g{constructor(){document.addEventListener("typo3:color-scheme:update",e=>this.onColorSchemeUpdate(e.detail)),document.addEventListener("typo3:theme:update",e=>this.onThemeUpdate(e.detail)),document.addEventListener("typo3:title-format:update",e=>this.onTitleFormatUpdate(e.detail)),document.addEventListener("typo3:backend-language:update",e=>this.onBackendLanguageFormatUpdate(e.detail)),document.addEventListener("typo3:persistent:update",e=>this.onPersistentUpdate(e.detail)),document.addEventListener("typo3:date-time-first-day-of-week:update",e=>this.onDateTimeFirstDayOfWeekUpdate(e.detail)),document.addEventListener("typo3:color-scheme:broadcast",e=>this.activateColorScheme(e.detail.payload.colorScheme)),document.addEventListener("typo3:theme:broadcast",e=>this.activateTheme(e.detail.payload.theme)),document.addEventListener("typo3:title-format:broadcast",e=>this.activateTitleFormat(e.detail.payload.format)),document.addEventListener("typo3:backend-language:broadcast",()=>this.requestBackendLanguageRefresh()),document.addEventListener("typo3:persistent:broadcast",e=>this.updatePersistent(e.detail.payload.fieldName,e.detail.payload.value))}onColorSchemeUpdate(e){const{colorScheme:t}=e;this.activateColorScheme(t),o.post(new s("color-scheme","broadcast",{colorScheme:t}))}onThemeUpdate(e){const{theme:t}=e;this.activateTheme(t),o.post(new s("theme","broadcast",{theme:t}))}onTitleFormatUpdate(e){const{format:t}=e;this.activateTitleFormat(t),o.post(new s("title-format","broadcast",{format:t}))}onDateTimeFirstDayOfWeekUpdate(e){const{dow:t}=e;this.activateDateTimeFirstDayOfWeek(t),o.post(new s("date-time-first-day-of-week","broadcast",{dow:t}))}onBackendLanguageFormatUpdate(e){const{language:t}=e;this.requestBackendLanguageRefresh(),o.post(new s("backend-language","broadcast",{language:t}))}onPersistentUpdate(e){const{fieldName:t,value:a}=e;this.updatePersistent(t,a),o.post(new s("personalization","broadcast",{fieldName:t,value:a}))}activateColorScheme(e){const t=document.querySelector(d.colorSchemeSwitch);t&&(t.activeColorScheme=e),this.setStyleChangingDocumentAttribute("data-color-scheme",e)}activateTheme(e){this.setStyleChangingDocumentAttribute("data-theme",e)}activateTitleFormat(e){e==="sitenameFirst"?document.querySelector("typo3-backend-module-router")?.setAttribute("sitename-first",""):document.querySelector("typo3-backend-module-router")?.removeAttribute("sitename-first")}activateDateTimeFirstDayOfWeek(e){this.updatePersistent("dateTimeFirstDayOfWeek",e)}requestBackendLanguageRefresh(){const e="t3js-request-backend-language-refresh";u.currentModal?.querySelector("dialog")?.classList.contains(e)||u.confirm(i.get("userSettings.requestBackendLanguageRefresh.title"),i.get("userSettings.requestBackendLanguageRefresh.message"),p.notice,[{text:i.get("userSettings.requestBackendLanguageRefresh.buttonCancel"),btnClass:"btn-default",trigger:(t,a)=>a.hideModal(),name:"cancel"},{text:i.get("userSettings.requestBackendLanguageRefresh.buttonReload"),active:!0,btnClass:"btn-primary",trigger:()=>top.window.location.reload(),name:"ok"}],[e])}updatePersistent(e,t){h.set(e,t)}async setStyleChangingDocumentAttribute(e,t){const a=document.documentElement,n=window.frames.list_frame?.document.documentElement,m=()=>{a.classList.add("t3js-disable-transitions"),n?.classList.add("t3js-disable-transitions"),a.setAttribute(e,t),n?.setAttribute(e,t)},l=()=>{a.classList.remove("t3js-disable-transitions"),n?.classList.remove("t3js-disable-transitions")};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches||!("startViewTransition"in document)||typeof document.startViewTransition!="function"){m(),await new Promise(r=>requestAnimationFrame(r)),n&&await new Promise(r=>window.frames.list_frame.requestAnimationFrame(r)),l();return}await document.startViewTransition(m).finished,l()}}var f=new g;export{f as default};
