import t from"/static/logging/index.js";const e=t.getLogger("@quotquot/i18n");class s extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(document.createElement("slot"))}show(){this.shadowRoot.firstChild.style.removeProperty("display")}hide(){this.shadowRoot.firstChild.style.setProperty("display","none","important")}}window.customElements.define("default-route",class extends s{accepts(t){return this.show(),!0}});class o extends s{hide(){if(super.hide(),!this.hasAttribute("keep")){const t=this.firstElementChild;t&&this.removeChild(t)}}}window.customElements.define("static-route",class extends o{accepts(t){const e=this.getAttribute("element");return!(!e||t!==this.getAttribute("path")||(this.hasAttribute("keep")&&this.firstElementChild||this.appendChild(document.createElement(e)),this.show(),0))}}),window.customElements.define("pattern-route",class extends o{accepts(t){const e=this.getAttribute("regexp"),s=this.getAttribute("element");if(!e||!s)return!1;const o=new RegExp(e,"u").exec(window.location.hash);if(!o)return!1;const n=o.groups||function(t,e){const s={};if(null===t)for(let t=0;t<e.length;++t)s[`data-group-${t}`]=e[t];else{const o=t.split(",");if(o.length!==e.length)throw new Error("incorrect number of group names");for(let t=0;t<e.length;++t)s[o[t]]=e[t]}return s}(this.getAttribute("groups"),o.splice(1)),i=Object.entries(n);let r=this.firstElementChild;if(r)for(const[t,e]of i)r.getAttribute(t)!==e&&r.setAttribute(t,e);else r=document.createElement(s),i.forEach((t=>r.setAttribute(...t))),this.appendChild(r),this.show();return!0}});class n extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"});const t=document.createElement("slot");function o(o){const n=window.location.hash;let i=!0;for(const o of t.assignedElements())o instanceof s?i&&o.accepts(n)?i=!1:o.hide():e.warn("hash-router: slot is not a route")}t.addEventListener("slotchange",o),this.shadowRoot.appendChild(t),window.addEventListener("hashchange",o,!1)}}window.customElements.define("hash-router",n);export{s as default};
