/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import{LegacyElementMixin as e}from"./legacy-element-mixin.js";import{legacyOptimizations as t}from"../utils/settings.js";const r={attached:!0,detached:!0,ready:!0,created:!0,beforeRegister:!0,registered:!0,attributeChanged:!0,listeners:!0,hostAttributes:!0},s={attached:!0,detached:!0,ready:!0,created:!0,beforeRegister:!0,registered:!0,attributeChanged:!0,behaviors:!0,_noAccessors:!0},o=Object.assign({listeners:!0,hostAttributes:!0,properties:!0,observers:!0},s);export function mixinBehaviors(t,r){return GenerateClassFromInfo({},e(r),t)}function applyInfo(e,t,s,o){!function copyProperties(e,t,r){const s=e._noAccessors,o=Object.getOwnPropertyNames(e);for(let i=0;i<o.length;i++){let n=o[i];if(!(n in r))if(s)t[n]=e[n];else{let r=Object.getOwnPropertyDescriptor(e,n);r&&(r.configurable=!0,Object.defineProperty(t,n,r))}}}(t,e,o);for(let e in r)t[e]&&(s[e]=s[e]||[],s[e].push(t[e]))}function flattenBehaviors(e,t,r){t=t||[];for(let s=e.length-1;s>=0;s--){let o=e[s];o?Array.isArray(o)?flattenBehaviors(o,t):t.indexOf(o)<0&&(!r||r.indexOf(o)<0)&&t.unshift(o):console.warn("behavior is null, check for missing or 404 import")}return t}function mergeProperties(e,t){for(const r in t){const s=e[r],o=t[r];e[r]=!("value"in o)&&s&&"value"in s?Object.assign({value:s.value},o):o}}const i=e(HTMLElement);function GenerateClassFromInfo(e,r,i){let n;const a={};class PolymerGenerated extends r{static _finalizeClass(){if(this.hasOwnProperty(JSCompiler_renameProperty("generatedFrom",this))){if(n)for(let e,t=0;t<n.length;t++)e=n[t],e.properties&&this.createProperties(e.properties),e.observers&&this.createObservers(e.observers,e.properties);e.properties&&this.createProperties(e.properties),e.observers&&this.createObservers(e.observers,e.properties),this._prepareTemplate()}else r._finalizeClass.call(this)}static get properties(){const t={};if(n)for(let e=0;e<n.length;e++)mergeProperties(t,n[e].properties);return mergeProperties(t,e.properties),t}static get observers(){let t=[];if(n)for(let e,r=0;r<n.length;r++)e=n[r],e.observers&&(t=t.concat(e.observers));return e.observers&&(t=t.concat(e.observers)),t}created(){super.created();const e=a.created;if(e)for(let t=0;t<e.length;t++)e[t].call(this)}_registered(){const e=PolymerGenerated.prototype;if(!e.hasOwnProperty(JSCompiler_renameProperty("__hasRegisterFinished",e))){e.__hasRegisterFinished=!0,super._registered(),t&&copyPropertiesToProto(e);const r=Object.getPrototypeOf(this);let s=a.beforeRegister;if(s)for(let e=0;e<s.length;e++)s[e].call(r);if(s=a.registered,s)for(let e=0;e<s.length;e++)s[e].call(r)}}_applyListeners(){super._applyListeners();const e=a.listeners;if(e)for(let t=0;t<e.length;t++){const r=e[t];if(r)for(let e in r)this._addMethodEventListenerToNode(this,e,r[e])}}_ensureAttributes(){const e=a.hostAttributes;if(e)for(let t=e.length-1;t>=0;t--){const r=e[t];for(let e in r)this._ensureAttribute(e,r[e])}super._ensureAttributes()}ready(){super.ready();let e=a.ready;if(e)for(let t=0;t<e.length;t++)e[t].call(this)}attached(){super.attached();let e=a.attached;if(e)for(let t=0;t<e.length;t++)e[t].call(this)}detached(){super.detached();let e=a.detached;if(e)for(let t=0;t<e.length;t++)e[t].call(this)}attributeChanged(e,t,r){super.attributeChanged();let s=a.attributeChanged;if(s)for(let o=0;o<s.length;o++)s[o].call(this,e,t,r)}}if(i){Array.isArray(i)||(i=[i]);let e=r.prototype.behaviors;n=flattenBehaviors(i,null,e),PolymerGenerated.prototype.behaviors=e?e.concat(i):n}const copyPropertiesToProto=t=>{n&&function applyBehaviors(e,t,r){for(let s=0;s<t.length;s++)applyInfo(e,t[s],r,o)}(t,n,a),applyInfo(t,e,a,s)};return t||copyPropertiesToProto(PolymerGenerated.prototype),PolymerGenerated.generatedFrom=e,PolymerGenerated}export const Class=function(e,t){e||console.warn("Polymer.Class requires `info` argument");let r=t?t(i):i;return r=GenerateClassFromInfo(e,r,e.behaviors),r.is=r.prototype.is=e.is,r};