import{DomModule as e}from"../../@polymer/polymer/lib/elements/dom-module.js";import{ThemePropertyMixin as t}from"./vaadin-theme-property-mixin.js";export const ThemableMixin=i=>class VaadinThemableMixin extends(t(i)){static finalize(){super.finalize();const e=this.prototype._template,t=this.template&&this.template.parentElement&&this.template.parentElement.id===this.is,i=Object.getPrototypeOf(this.prototype)._template;i&&!t&&Array.from(i.content.querySelectorAll("style[include]")).forEach((t=>{this._includeStyle(t.getAttribute("include"),e)})),this._includeMatchingThemes(e)}static _includeMatchingThemes(t){const i=e.prototype.modules;let n=!1;const l=this.is+"-default-theme";Object.keys(i).sort(((e,t)=>{const i=0===e.indexOf("vaadin-"),n=0===t.indexOf("vaadin-"),l=["lumo-","material-"],s=l.filter((t=>0===e.indexOf(t))).length>0,o=l.filter((e=>0===t.indexOf(e))).length>0;return i!==n?i?-1:1:s!==o?s?-1:1:0})).forEach((e=>{if(e!==l){const l=i[e].getAttribute("theme-for");l&&l.split(" ").forEach((i=>{new RegExp("^"+i.split("*").join(".*")+"$").test(this.is)&&(n=!0,this._includeStyle(e,t))}))}})),!n&&i[l]&&this._includeStyle(l,t)}static _includeStyle(e,t){if(t&&!t.content.querySelector(`style[include="${e}"]`)){const i=document.createElement("style");i.setAttribute("include",e),t.content.appendChild(i)}}};