/*
 * 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 i from"@typo3/core/ajax/ajax-request.js";import r from"@typo3/core/event/regular-event.js";import n from"@typo3/core/document-service.js";class s{constructor(){this.ready=!0,this.options={error:".t3js-login-error",errorNoCookies:".t3js-login-error-nocookies",errorNoReferrer:".t3js-login-error-noreferrer",formFields:".t3js-login-formfields",loginForm:"#typo3-login-form",loginUrlLink:"t3js-login-url",submitButton:".t3js-login-submit",submitHandler:null,useridentField:".t3js-login-userident-field"},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 i(TYPO3.settings.ajaxUrls.login_preflight).get().then(async o=>{(await o.resolve("application/json")).capabilities.referrer!==!0&&document.querySelectorAll(this.options.errorNoReferrer).forEach(t=>t.classList.remove("hidden"))})}showCookieWarning(){document.querySelector(this.options.formFields)?.classList.add("hidden"),document.querySelector(this.options.errorNoCookies)?.classList.remove("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 n.ready(),new r("submit",this.handleSubmit.bind(this)).bindTo(document.querySelector(this.options.loginForm)),document.querySelectorAll(".t3js-clearable").forEach(e=>e.clearable())}}var l=new s;export{l as default};
