"use strict";var KTSigninGeneral = function () {var form = document.getElementById('signin_form');var submitButton = document.getElementById('signin_submit');var lang = getCookie("sessLang");var validator;var handleValidation = function (e) {validator = FormValidation.formValidation(form,{fields: {'username': {validators: {regexp: {regexp: /^[a-zA-Z0-9_.]+$/,message: lang_table(lang, 'The value is not a valid user name character.')},notEmpty: {message: lang_table(lang, 'User Name is required.')}}},'password': {validators: {notEmpty: {message: lang_table(lang, 'Password is required.')}}}},plugins: {trigger: new FormValidation.plugins.Trigger(),bootstrap: new FormValidation.plugins.Bootstrap5({rowSelector: '.fv-row',eleInvalidClass: '',eleValidClass: ''})}});};var handleSubmitAjax = function (e) {submitButton.addEventListener('click', function (e) {e.preventDefault();validator.validate().then(function (status) {if (status === 'Valid') {submitButton.setAttribute('data-kt-indicator', 'on');submitButton.disabled = true;axios.post(submitButton.closest('form').getAttribute('action'), new FormData(form), {headers: {'Content-Type': 'application/json'}}).then(function (response) {if (response) {console.log(response);var res = JSON.stringify(response.data);if (res.indexOf("error_msg")>-1 || res.indexOf("info_msg")>-1 || res.indexOf("success_msg")>-1) {const obj = JSON.parse(res);var txt;var ico;if (res.indexOf("error_msg")>-1) {txt = obj.error_msg.toString();ico = "error";} else if (res.indexOf("info_msg")>-1) {txt = obj.info_msg.toString();ico = "info";} else if (res.indexOf("success_msg")>-1) {txt = obj.success_msg.toString();ico = "success";}let delay = 2000;if (ico != null && ico == "success" && txt == "") {delay = 0;} else {Swal.fire({text: lang_table(lang, txt),icon: ico,buttonsStyling: false,confirmButtonText: "Ok",customClass: {confirmButton: "btn btn-primary"}});}if (ico != null && (ico == "success" || ico == "info")) {form.reset();setTimeout(function() {const redirectUrl = form.getAttribute('data-kt-redirect-url');if (redirectUrl) {location.href = redirectUrl;}}, delay);}}} else {Swal.fire({text: response.toString(),icon: "error",buttonsStyling: false,confirmButtonText: "Ok",customClass: {confirmButton: "btn btn-primary"}});}}).catch(function (error) {Swal.fire({text: error.toString(),icon: "error",buttonsStyling: false,confirmButtonText: "Ok",customClass: {confirmButton: "btn btn-primary"}});}).then(() => {submitButton.removeAttribute('data-kt-indicator');submitButton.disabled = false;});}});});};var isValidUrl = function(url) {try {new URL(url);return true;} catch (e) {return false;}};return {init: function () {handleValidation();if (form.action !== "" && form.action !== "#") {handleSubmitAjax();} else {Swal.fire({text: lang_table(lang, "Invalid action URL!"),icon: "error",buttonsStyling: false,confirmButtonText: "Ok",customClass: {confirmButton: "btn btn-primary"}});}}};}();KTUtil.onDOMContentLoaded(function () {KTSigninGeneral.init();});