!function(){"use strict";window.Joomla=window.Joomla||{},function(e,n){var t=function e(n,t){void 0===t&&(t="");var r="";return Object.keys(n).forEach((function(a){if("object"!=typeof n[a])return r.length>0&&(r+="&"),void(r+=""===t?encodeURIComponent(a)+"="+encodeURIComponent(n[a]):encodeURIComponent(t)+"["+encodeURIComponent(a)+"]="+encodeURIComponent(n[a]));r+=""+e(n[a],a)})),r},r=function(e,n){var t=e.querySelectorAll(n);return t.length?t[0]:null},a=function(e,n){var t=null;if(!e)return t;var a=e.parentElement;if("FORM"===a.nodeName)return t=r(a,n);var o=a.querySelectorAll("form");if(o.length)for(var i=0;i<o.length;i+=1)if(null!==(t=r(o[i],n)))return t;return null},o=function(n){e.renderMessages({error:[n]})};e.plgSystemWebauthnLogin=function(r){var i=n.getElementById(r),l=a(i,"input[name=username]"),u=a(i,"input[name=return]");if(null===l)return e.renderMessages({error:[e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_CANNOT_FIND_USERNAME")]}),!1;var s=l.value,c=u?u.value:null;if(""===s)return e.renderMessages({error:[e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_EMPTY_USERNAME")]}),!1;var d={option:"com_ajax",group:"system",plugin:"webauthn",format:"raw",akaction:"challenge",encoding:"raw",username:s,returnUrl:c};d[e.getOptions("csrf.token")]=1;var g=e.getOptions("system.paths");return e.request({url:(g?g.base+"/index.php":window.location.pathname)+"?"+e.getOptions("csrf.token")+"=1",method:"POST",data:t(d),onSuccess:function(n){var t,r,a,i={};try{i=JSON.parse(n)}catch(e){}r=function(e){return btoa(String.fromCharCode.apply(String,e))},a=function(e){var n=e.replace(/-/g,"+").replace(/_/g,"/"),t=n.length%4;if(t){if(1===t)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");n+=new Array(5-t).join("=")}return n},(t=i).challenge?(t.challenge=Uint8Array.from(window.atob(a(t.challenge)),(function(e){return e.charCodeAt(0)})),t.allowCredentials&&(t.allowCredentials=t.allowCredentials.map((function(e){return e.id=Uint8Array.from(window.atob(a(e.id)),(function(e){return e.charCodeAt(0)})),e}))),navigator.credentials.get({publicKey:t}).then((function(n){var t={id:n.id,type:n.type,rawId:r(new Uint8Array(n.rawId)),response:{authenticatorData:r(new Uint8Array(n.response.authenticatorData)),clientDataJSON:r(new Uint8Array(n.response.clientDataJSON)),signature:r(new Uint8Array(n.response.signature)),userHandle:n.response.userHandle?r(new Uint8Array(n.response.userHandle)):null}},a=e.getOptions("system.paths");window.location=(a?a.base+"/index.php":window.location.pathname)+"?"+e.getOptions("csrf.token")+"=1&option=com_ajax&group=system&plugin=webauthn&format=raw&akaction=login&encoding=redirect&data="+btoa(JSON.stringify(t))})).catch((function(e){o(e)}))):o(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_INVALID_USERNAME"))},onError:function(e){o(e.status+" "+e.statusText)}}),!1};var i=[].slice.call(n.querySelectorAll(".plg_system_webauthn_login_button"));i.length&&i.forEach((function(n){n.addEventListener("click",(function(n){var t=n.currentTarget;e.plgSystemWebauthnLogin(t.getAttribute("data-webauthn-form"))}))}))}(Joomla,document)}();