/*
 * 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"bootstrap";import"@typo3/backend/input/clearable.js";import a from"@typo3/core/ajax/ajax-request.js";import n from"@typo3/core/event/regular-event.js";import r from"@typo3/backend/login/pasted-password-checker.js";import c from"@typo3/core/document-service.js";class d{constructor(){this.ready=!0,this.options={error:".t3js-login-error",errorNoCookies:".t3js-login-error-nocookies",errorNoReferrer:".t3js-login-error-noreferrer",warningPasswordWhitespace:".t3js-login-warning-password-whitespace",warningPasswordWhitespaceActionLink:".t3js-login-warning-password-whitespace-action",formFields:".t3js-login-formfields",loginForm:"#typo3-login-form",loginUrlLink:"t3js-login-url",submitButton:".t3js-login-submit",submitHandler:null,useridentField:".t3js-login-userident-field",passwordField:"#t3-password"},this.checkLoginRefresh(),this.checkCookieSupport(),this.checkDocumentReferrerSupport(),this.initializeEvents(),top.location.href!==location.href&&(this.ready=!1,top.location.href=location.href),this.ready&&document.body.setAttribute("data-typo3-login-ready","true")}showLoginProcess(){this.showLoadingIndicator(),document.querySelector(this.options.error)?.classList.add("hidden"),document.querySelector(this.options.errorNoCookies)?.classList.add("hidden")}showLoadingIndicator(){const e=document.querySelector(this.options.submitButton);e.innerHTML=e.dataset.loadingText}handleSubmit(e){this.showLoginProcess(),typeof this.options.submitHandler=="function"&&this.options.submitHandler(e)}checkDocumentReferrerSupport(){const e=document.getElementById(this.options.loginUrlLink);e!==null&&typeof e.dataset.referrerCheckEnabled>"u"&&e.dataset.referrerCheckEnabled!=="1"||typeof TYPO3.settings>"u"||typeof TYPO3.settings.ajaxUrls>"u"||new a(TYPO3.settings.ajaxUrls.login_preflight).get().then(async o=>{(await o.resolve("application/json")).capabilities.referrer!==!0&&document.querySelectorAll(this.options.errorNoReferrer).forEach(i=>i.classList.remove("hidden"))})}showCookieWarning(){document.querySelector(this.options.formFields)?.classList.add("hidden"),document.querySelector(this.options.errorNoCookies)?.classList.remove("hidden")}showWhitespaceAroundPasswordWarning(){document.querySelector(this.options.warningPasswordWhitespace)?.classList.remove("hidden")}removeWhitespaceAroundPasswordWarning(){document.querySelector(this.options.warningPasswordWhitespace)?.classList.add("hidden")}checkLoginRefresh(){const e=document.querySelector(this.options.loginForm+' input[name="loginRefresh"]');e instanceof HTMLInputElement&&e.value&&window.opener&&window.opener.TYPO3&&window.opener.TYPO3.LoginRefresh&&(window.opener.TYPO3.LoginRefresh.startTask(),window.close())}checkCookieSupport(){const e=navigator.cookieEnabled;e===!1?this.showCookieWarning():!document.cookie&&e===null&&(document.cookie="typo3-login-cookiecheck=1",document.cookie?document.cookie="typo3-login-cookiecheck=; expires="+new Date(0).toUTCString():this.showCookieWarning())}async initializeEvents(){await c.ready();const e=document.querySelector(this.options.loginForm);e!==null&&new n("submit",this.handleSubmit.bind(this)).bindTo(e),document.querySelectorAll(".t3js-clearable").forEach(i=>i.clearable());const o=document.querySelector(this.options.passwordField);if(o===null)return;new n("paste",i=>{const s=i.clipboardData.getData("text/plain");r.hasSurroundingWhitespace(s)&&this.showWhitespaceAroundPasswordWarning()}).bindTo(o);const t=document.querySelector(this.options.warningPasswordWhitespaceActionLink);t!==null&&new n("click",()=>{o.value=r.removeSurroundingWhitespace(o.value),this.removeWhitespaceAroundPasswordWarning()}).bindTo(t)}}var l=new d;export{l as default};
