import{r as registerInstance,h as h$1,c as Host}from"./index-38ad4957.js";import{b as browser,n as h,k as useState,f as useEffect}from"./dom-context-hooks.module-50442785.js";import{I as In,b as useCallback,i as isDemo}from"./index.module-b23fdad8.js";import{a as VERIFICATION_PARENT_NAMESPACE}from"./keys-406491dc.js";var debug=browser("sq:widget-verification");function useTemplateChildren(e){var t=e.parent,r=e.callback;var n=new MutationObserver(o);var i=new MutationObserver(r);n.observe(t,{childList:true,subtree:false});o({addedNodes:t.querySelectorAll("template")});function o(e){var t;(t=e.addedNodes)===null||t===void 0?void 0:t.forEach((function(e){i.observe(e.content,{childList:true,attributes:true,subtree:true})}))}return function(){n.disconnect();i.disconnect()}}var WidgetVerificationController=function(){function e(e){registerInstance(this,e);this.stateController="{}";h(this)}e.prototype.disconnectedCallback=function(){};e.prototype.render=function(){var e;var t=In({namespace:VERIFICATION_PARENT_NAMESPACE,initialValue:false}),r=t[0],n=t[1];var i=JSON.parse(this.stateController);var o=isDemo()&&((e=i["sqm-widget-verification-controller"])===null||e===void 0?void 0:e.isAuth);var s=useState(undefined),a=s[0],l=s[1];var f=useState(undefined),u=f[0],d=f[1];var c=useCallback((function(){var e=o||r;var t=u.querySelectorAll("template");var n=Array.from(t).find((function(t){return t.slot===(e?"verified":"not-verified")}));if(n){var i=n.innerHTML||n.firstElementChild.outerHTML;if(i===a.innerHTML){debug("don't rerender")}else if(n){a.innerHTML=i}}var s=Array.from(u.children).filter((function(e){return e.tagName==="RAISINS-PLOP-TARGET"}));if(s.length){var l=s.filter((function(e){return e.slot==="verified"}));var f=s.filter((function(e){return e.slot==="not-verified"}));f.forEach((function(t,r){if(e){t.style.display="none";return}if(r===f.length-1){t.style.bottom="0px";t.style.left="0px";t.style.right="0px";t.style.position="absolute"}t.style.height="25px"}));l.forEach((function(t,r){if(!e){t.style.display="none";return}if(r===l.length-1){t.style.bottom="0px";t.style.left="0px";t.style.right="0px";t.style.position="absolute"}t.style.height="25px"}))}}),[a,u,r,o]);useEffect((function(){if(!a||!u){debug("DOM not ready:");return}c();return useTemplateChildren({parent:u,callback:c})}),[u,a,r,o]);return h$1(Host,null,h$1("div",{ref:d,style:{display:"contents"}},h$1("slot",{name:"not-verified"}),h$1("slot",{name:"verified"})),h$1("div",{ref:l},h$1("slot",{name:"shown"})))};return e}();export{WidgetVerificationController as sqm_widget_verification_controller};