/**
@license
Copyright (c) 2015 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"../iron-location/iron-location.js";import"../marked-element/marked-element.js";import"../polymer/polymer-legacy.js";import"../prism-element/prism-highlighter.js";import"../prism-element/prism-theme-default.js";import"./iron-doc-behavior.js";import"./iron-doc-class.js";import"./iron-doc-demo.js";import"./iron-doc-element.js";import"./iron-doc-mixin.js";import"./iron-doc-namespace.js";import{Polymer as e}from"../polymer/lib/legacy/polymer-fn.js";import{flush as r}from"../polymer/lib/legacy/polymer.dom.js";import{html as t}from"../polymer/lib/utils/html-tag.js";e({_template:t`
    <style include="iron-doc-viewer-styles prism-theme-default">
      iron-doc-demo {
        height: 100%;
      }
    </style>

    <iron-location path="{{_urlPath}}" hash="{{_urlHash}}"></iron-location>

    <template is="dom-if" if="[[_equal(_descriptorType,'demos')]]" restamp>
      <iron-doc-demo class="active" demo="[[_demo]]" src-prefix="[[demoSrcPrefix]]" title="{{title}}">
      </iron-doc-demo>
    </template>

    <template is="dom-if" if="[[_equal(_descriptorType,'namespaces')]]" restamp>
      <iron-doc-namespace class="active" descriptor="[[_currentDescriptor]]" fragment-prefix="[[_fragmentPrefix]]" title="{{title}}" base-href="[[baseHref]]">
      </iron-doc-namespace>
    </template>

    <template is="dom-if" if="[[_equal(_descriptorType,'elements')]]" restamp>
      <iron-doc-element class="active" descriptor="[[_currentDescriptor]]" fragment-prefix="[[_fragmentPrefix]]" title="{{title}}" base-href="[[baseHref]]">
      </iron-doc-element>
    </template>

    <template is="dom-if" if="[[_equal(_descriptorType,'mixins')]]" restamp>
      <iron-doc-mixin class="active" descriptor="[[_currentDescriptor]]" fragment-prefix="[[_fragmentPrefix]]" title="{{title}}" base-href="[[baseHref]]">
      </iron-doc-mixin>
    </template>

    <template is="dom-if" if="[[_equal(_descriptorType,'behaviors')]]" restamp>
      <iron-doc-behavior class="active" descriptor="[[_currentDescriptor]]" fragment-prefix="[[_fragmentPrefix]]" title="{{title}}" base-href="[[baseHref]]">
      </iron-doc-behavior>
    </template>

    <template is="dom-if" if="[[_equal(_descriptorType,'classes')]]" restamp>
      <iron-doc-class class="active" descriptor="[[_currentDescriptor]]" fragment-prefix="[[_fragmentPrefix]]" title="{{title}}" base-href="[[baseHref]]">
      </iron-doc-class>
    </template>
`,is:"iron-doc-viewer",properties:{descriptor:{type:Object},baseHref:{type:String,value:"#"},demoSrcPrefix:String,path:{type:String,notify:!0,value:null},rootNamespace:{type:String},title:{type:String,notify:!0},demo:{type:Boolean,computed:"_computeDemo(_demo)",reflectToAttribute:!0,notify:!0},_descriptorType:String,_urlPath:String,_urlHash:String,_currentDescriptor:Object,_fragmentPrefix:String,_scrollTo:String,_demo:Object},observers:["_routingChanged(baseHref, _urlPath, _urlHash)","_dataChanged(descriptor, path, _scrollTo)"],_equal:function(e,r){return e==r},_computeDemo:function(e){return!!e},_routingChanged:function(e,r,t){if(0===e.indexOf("#")){var i=(t||"").split("#");this.path=i[0],this._scrollTo=i[1]||null,this._fragmentPrefix=i[0]+"#"}else e&&r&&0===r.indexOf(e)?this.path=r.substring(e.length):this.path=r,this._scrollTo=t},_dataChanged:function(e,t,i){if(this.descriptor)if(t&&"/"!==t){var s,o,n;this.baseHref&&t.indexOf(this.baseHref)>=0&&(t=t.substring(this.baseHref.length));var a=t.split("/");a.length>1&&(s=a[1],o=a[2]),a.length>3&&"demos"===a[3]&&(n=a.slice(4).join("/"));var c=function getNamespace(e,r){var t=r.split(".");if(t.length<2)return;t=t.slice(0,t.length-1);for(var i=e,s=0;s<t.length;s++){if(!i.namespaces)return;var o=i.namespaces.filter((function(e){return e.name===t[s]}));if(0===o.length)return;i=o[0]}return i}(this.descriptor,o)||this.descriptor;if(null!=c){if(this._descriptorType=s,"namespaces"===s)this._currentDescriptor=c.namespaces&&c.namespaces.filter((function(e){return e.name===o}))[0];else if("elements"===s)this._currentDescriptor=c.elements&&c.elements.filter((function(e){return e.name===o||e.tagname===o}))[0];else if("classes"===s)this._currentDescriptor=c.classes&&c.classes.filter((function(e){return(e.name||e.tagname)===o}))[0];else if("mixins"===s)this._currentDescriptor=c.mixins&&c.mixins.filter((function(e){return e.name===o}))[0];else if("behaviors"===s){var l=((c.metadata||{}).polymer||{}).behaviors;this._currentDescriptor=l&&l.filter((function(e){return e.name===o}))[0]}else"functions"===s&&(this._currentDescriptor=c.functions&&c.functions.filter((function(e){return e.name===o}))[0]);if(this._demo=null,n&&this._currentDescriptor&&this._currentDescriptor.demos)for(var m=0;m<this._currentDescriptor.demos.length;m++){var p=this._currentDescriptor.demos[m],f=p.description&&p.description.toLowerCase().replace(/\s+/g,"-");if(p.url===n||f&&f===n){this._demo=p,this._descriptorType="demos";break}}if(this.fire("view-changed"),i){r();var d=this.$$(".active");d&&d.scrollToAnchor&&d.scrollToAnchor(i)}}}else this.rootNamespace?this.path="/namespaces/"+this.rootNamespace:(this._descriptorType="namespaces",this._currentDescriptor=e);else this._descriptorType=null}});