text: define(["exports", "../../@polymer/polymer/lib/elements/dom-module.js", "./vaadin-theme-property-mixin.js"], function (_exports, _domModule, _vaadinThemePropertyMixin) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.ThemableMixin = void 0;
  
    /**
     * @polymerMixin
     */
    var ThemableMixin = function ThemableMixin(superClass) {
      return (
        /*#__PURE__*/
        function (_ThemePropertyMixin) {
          babelHelpers.inherits(VaadinThemableMixin, _ThemePropertyMixin);
  
          function VaadinThemableMixin() {
            babelHelpers.classCallCheck(this, VaadinThemableMixin);
            return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(VaadinThemableMixin).apply(this, arguments));
          }
  
          babelHelpers.createClass(VaadinThemableMixin, null, [{
            key: "finalize",
  
            /** @protected */
            value: function finalize() {
              var _this = this;
  
              babelHelpers.get(babelHelpers.getPrototypeOf(VaadinThemableMixin), "finalize", this).call(this);
              var template = this.prototype._template;
              var hasOwnTemplate = this.template && this.template.parentElement && this.template.parentElement.id === this.is;
  
              var inheritedTemplate = Object.getPrototypeOf(this.prototype)._template;
  
              if (inheritedTemplate && !hasOwnTemplate) {
                // The element doesn't define its own template -> include the theme modules from the inherited template
                Array.from(inheritedTemplate.content.querySelectorAll('style[include]')).forEach(function (s) {
                  _this._includeStyle(s.getAttribute('include'), template);
                });
              }
  
              this._includeMatchingThemes(template);
            }
            /** @protected */
  
          }, {
            key: "_includeMatchingThemes",
            value: function _includeMatchingThemes(template) {
              var _this2 = this;
  
              var domModule = _domModule.DomModule;
              var modules = domModule.prototype.modules;
              var hasThemes = false;
              var defaultModuleName = this.is + '-default-theme';
              Object.keys(modules).sort(function (moduleNameA, moduleNameB) {
                var vaadinA = moduleNameA.indexOf('vaadin-') === 0;
                var vaadinB = moduleNameB.indexOf('vaadin-') === 0;
                var vaadinThemePrefixes = ['lumo-', 'material-'];
                var vaadinThemeA = vaadinThemePrefixes.filter(function (prefix) {
                  return moduleNameA.indexOf(prefix) === 0;
                }).length > 0;
                var vaadinThemeB = vaadinThemePrefixes.filter(function (prefix) {
                  return moduleNameB.indexOf(prefix) === 0;
                }).length > 0;
  
                if (vaadinA !== vaadinB) {
                  // Include vaadin core styles first
                  return vaadinA ? -1 : 1;
                } else if (vaadinThemeA !== vaadinThemeB) {
                  // Include vaadin theme styles after that
                  return vaadinThemeA ? -1 : 1;
                } else {
                  // Lastly include custom styles so they override all vaadin styles
                  return 0;
                }
              }).forEach(function (moduleName) {
                if (moduleName !== defaultModuleName) {
                  var themeFor = modules[moduleName].getAttribute('theme-for');
  
                  if (themeFor) {
                    themeFor.split(' ').forEach(function (themeForToken) {
                      if (new RegExp('^' + themeForToken.split('*').join('.*') + '$').test(_this2.is)) {
                        hasThemes = true;
  
                        _this2._includeStyle(moduleName, template);
                      }
                    });
                  }
                }
              });
  
              if (!hasThemes && modules[defaultModuleName]) {
                // No theme modules found, include the default module if it exists
                this._includeStyle(defaultModuleName, template);
              }
            }
            /** @private */
  
          }, {
            key: "_includeStyle",
            value: function _includeStyle(moduleName, template) {
              if (template && !template.content.querySelector("style[include=\"".concat(moduleName, "\"]"))) {
                var styleEl = document.createElement('style');
                styleEl.setAttribute('include', moduleName);
                template.content.appendChild(styleEl);
              }
            }
          }]);
          return VaadinThemableMixin;
        }((0, _vaadinThemePropertyMixin.ThemePropertyMixin)(superClass))
      );
    };
  
    _exports.ThemableMixin = ThemableMixin;
  });