"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[3847],{85386(e,t,a){a.r(t),a.d(t,{RecaptchaClass:()=>d,componentName:()=>r});var n=a(25964),s=a(79365),c=a(81365),i=a(9696),h=a(97810);const r=(0,h.xE)("recaptcha"),o=["enabled","site-key","action","enterprise"],p=(0,c.q)({componentName:r,baseSelector:":host > div"}),d=(0,i.Zz)(s.VO)(class extends p{static get observedAttributes(){return o.concat(p.observedAttributes||[])}attributeChangedCallback(e,t,a){super.attributeChangedCallback?.(e,t,a),t!==a&&"enabled"===e&&this.#e("true"===a)}renderRecaptcha(e){this.children.length?this.updatePreview():this.toggleRecaptchaEles(e)}toggleRecaptchaEles(e){e?(this.recaptchaEle.style.display="",this.mockRecaptchaEle.style.display="none"):(this.recaptchaEle.style.display="none",this.mockRecaptchaEle.style.display="")}constructor(){super(),this.attachShadow({mode:"open"}).innerHTML='\n    <div class="badge">\n      <span id="recaptcha"></span>\n      <img src="https://imgs.descope.com/connectors/templates/recaptcha/recaptcha-big.png" alt="recaptcha"/>\n    </div>\n    <slot></slot>\n\t',(0,n.fz)('\n      :host {\n        display: inline-flex;\n      }\n      :host > div:not(.hidden) {\n        display: flex;\n      }\n      :host #recaptcha .grecaptcha-badge {\n        box-shadow: none !important;\n      }\n      :host #recaptcha .grecaptcha-logo {\n        height: 100%;\n      }\n      :host #recaptcha {\n\t\t\t\twidth: 100%;\n        height: 100%;\n\t\t\t}\n      :host img {\n        width: 256px;\n      }\n      :host([full-width="true"]) {\n        width: 100%;\n      }\n      .hidden {\n        display: none;\n      }\n        ',this),this.recaptchaEle=this.baseElement.querySelector("#recaptcha"),this.mockRecaptchaEle=this.baseElement.querySelector("img"),this.badge=this.shadowRoot.querySelector(".badge")}init(){super.init?.(),(0,h.Ge)(this,this.updatePreview.bind(this))}updatePreview(){this.children.length?(this.recaptchaEle.style.display="none",this.mockRecaptchaEle.style.display="none",this.badge.classList.add("hidden")):(this.toggleRecaptchaEles(this.enabled),this.badge.classList.remove("hidden"))}get enterprise(){return"true"===this.getAttribute("enterprise")}get siteKey(){return this.getAttribute("site-key")}get action(){return this.getAttribute("action")||"load"}get enabled(){return"true"===this.getAttribute("enabled")}get scriptURL(){const e=new URL("https://www.google.com/recaptcha/");return e.pathname+=(this.enterprise?"enterprise":"api")+".js",e.searchParams.append("onload","onRecaptchaLoadCallback"),e.searchParams.append("render","explicit"),e.toString()}#e(e){this.renderRecaptcha(e),e&&(this.#t(),document.getElementById("recaptcha-script")?window.onRecaptchaLoadCallback():this.#a())}#a(){const e=document.createElement("script");e.src=this.scriptURL,e.async=!0,e.id="recaptcha-script",e.defer=!0,document.body.appendChild(e)}get grecaptchaInstance(){return this.enterprise?window.grecaptcha?.enterprise:window.grecaptcha}#n(e,t,a){this.isConnected&&e.ready(()=>{const n=t.querySelector('textarea[name^="g-recaptcha-response"]')?.cloneNode();if(n&&(n.style.display="none",document.body.appendChild(n)),!this.siteKey)return;const s=e?.execute(a,{action:this.action});s.then((s,c)=>{c?console.warn("could not execute recaptcha",c):(this.updateComponentsContext({risktoken:s,riskaction:this.action}),this.isConnected&&setTimeout(()=>{this.#n(e,t,a)},11e4)),n.remove()})})}#t(){window.onRecaptchaLoadCallback=()=>{const e=this.recaptchaEle;if(e.hasChildNodes())return;const{grecaptchaInstance:t}=this;t&&setTimeout(()=>{const a=t.render(e,{sitekey:this.siteKey,badge:"inline",size:"invisible"});this.#n(t,e,a)},0)}}});customElements.define(r,d)}}]);
//# sourceMappingURL=descope-recaptcha-index-js.js.map