{% extends "base.html" %}
{% from "_macros.html" import render_resource_link, render_rdfa_resource_link, get_label, facts_panel, summary_panel, content %}

{% macro render_reference(ref) %}

{{ref.value(ns.dc.creator)}}.
<em>{{ref.value(ns.dc.title)}}</em>,
{{ref.value(ns.dc.bibliographicCitation)}}
{% for also in ref[ns.RDFS.seeAlso] %}
<a href="{{also.identifier}}">
{% if also[ns.RDF.type:ns.hbgd.PubMedCentralArticle] %}
<img style="height: 1em" src="http://static.pubmed.gov/portal/portal3rc.fcgi/4066669/img/3977009"></img>
{% elif also[ns.RDF.type:ns.hbgd.PubMedArticle] %}
<img style="height: 1em" src="http://static.pubmed.gov/portal/portal3rc.fcgi/4066669/img/2318832"></img>
{% endif %}
</a>
{% endfor %}

{% endmacro %}

{% macro render_definition(def) %}
<div layout="column" layout-fill>
<div class="panel panel-default {% if def[ns.RDF.type:ns.hbgd.UnreviewedDefinition] %}panel-warning{% endif %} {% if def[ns.RDF.type:ns.hbgd.PreferredDefinition] %}panel-primary{% endif %}" >
  <div class="panel-body">
    <blockquote>
      <p>{{def.value(ns.prov.value)}}</p>
    </blockquote>

    <dl class="dl-horizontal clearfix">
      <dt>Status</dt>
      {% for type in def[ns.RDF.type] %}
      {% if type[ns.RDFS.subClassOf:ns.sio.definition] %}
      <dd>{{type.value(ns.RDFS.label)}}</dd>
      {% endif %}
      {% endfor %}
    </dl>
    <div class="collapse" id="{{def.identifier.split('/')[-1]}}_more">
    {% if def.value(ns.skos.editorialNote) %}  
    <dl class="dl-horizontal clearfix">
      <dt>Editorial Notes</dt>
      <dd>
        {% for note in def[ns.skos.editorialNote] %}
          <p>{{note}}</p>
        {% endfor %}
      </dd>
    </dl>
    {% endif %}
    {% if def.value(ns.skos.example) %}  
    <dl class="dl-horizontal clearfix">
      <dt>Appears in</dt>
      <dd>
        {% for ex in def[ns.skos.example] %}
          {% if ex.value(ns.dc.title) %} <p>{{render_reference(ex)}}</p>{% endif %}
        {% endfor %}
      </dd>
    </dl>
    {% endif %}
    {% if def.value(ns.RDFS.isDefinedBy) %}  
    <dl class="dl-horizontal clearfix">
      <dt>Definition Source</dt>
      <dd>
        {% for defsource in def[ns.RDFS.isDefinedBy] %}
        <p><a href="{{defsource.identifier}}">{{defsource.value(ns.RDFS.label) or defsource.identifier}}</a></p>
        {% endfor %}
      </dd>
    </dl>
    {% endif %}
    {% if def.value(ns.RDFS.seeAlso) %}  
    <dl class="dl-horizontal clearfix">
      <dt>See also</dt>
      <dd>
        {% for quoted in def[ns.RDFS.seeAlso] %}
          <p><a href="{{quoted.identifier}}">{{quoted.value(ns.RDFS.label) or quoted.identifier}}</a></p>
        {% endfor %}
      </dd>
    </dl>
    {% endif %}
    {% if def.value(ns.prov.wasAttributedTo) %}  
    <dl class="dl-horizontal clearfix">
      <dt>Attributed To</dt>
      <dd>
        {% for attrib in def[ns.prov.wasAttributedTo] %}
          <p><a href="{{url_for('entity.view',uri=attrib.identifier)}}">{{attrib.value(ns.RDFS.label) or attrib.identifier}}</a></p>
        {% endfor %}
      </dd>
    </dl>
    {% endif %}
  </div>
<a class="btn pull-right" role="button" data-toggle="collapse" href="#{{def.identifier.split('/')[-1]}}_more" aria-expanded="false" aria-controls="{{def.identifier.split('/')[-1]}}_more">
  More
    </a>
  </div>
</div>
{% endmacro %}


{% block title %}{{get_label(this.description())}}{% endblock %}
{% block subtitle %}Class{% endblock %}
{% block content %}
<style>
.HighRatingDefinition span.pull-right span:after {
  content: " &#9733;&#9733;&#9733;";
}
.MediumRatingDefinition span.pull-right span:after {
  content: " &#9733;&#9733;&#9734;";
}
.LowRatingDefinition span.pull-right span:after {
  content: " &#9733;&#9734;&#9734;";
}
.PreferredDefinition span.status:before {
  content: "Preferred";
}
.AlternateDefinition span.status:before {
  content: "Alternate";
}
</style>
<div class="row" >
  <div class="col-md-5">
    {{ summary_panel(this.description()) }}
    {{ content(this.description()) }}
              <h2>Super Classes</h2>
              <p>Super class definitions also apply to this class.</p>
              <div class="panel panel-default">
                    <ul class="list-group">
                      {% for superClass in this.description()[ns.RDFS.subClassOf] %}
                        <li class="list-group-item">
                          {{render_resource_link(superClass)}}
                          {% if superClass.value(ns.skos.definition) %}
                          <span>{{lang_filter(superClass[ns.skos.definition])}}</span>
                          {% endif %}
                        </li>
                      {% endfor %}
                    </ul>
                </div>
               <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2 class="panel-title">Details</h2>
                    </div>
                    <div class="panel-body">
                      <p style="font-weight: bold"><a href="{{url_for('entity.view', uri=this.identifier)}}">{{this.identifier}}</a></p>
                        <dl class="dl-horizontal clearfix">
                            <dt>Term</dt>
                            <dd>{{get_label(this.description())}}</dd>
                        </dl>
                        {% if lang_filter(this.description()[ns.skos.altLabel]) %}  
                        <dl class="dl-horizontal clearfix">
                            <dt>Alternate Labels</dt>
                            <dd>
                              {% for term in lang_filter(this.description()[ns.skos.altLabel]) %}
                              <p>{{term}}</p>
                              {% endfor %}
                            </dd>
                        </dl>
                        {% endif %}
                        {% if this.description().graph.value(predicate=ns.RDFS.subClassOf, object=this.description().identifier) %}  
                        <dl class="dl-horizontal clearfix">
                            <dt>Sub Classes</dt>
                            <dd>
                              {% for subClass in this.description().subjects(ns.RDFS.subClassOf) %}
                              <p>
                              {{render_resource_link(subClass)}}
                                {% if subClass.value(ns.skos.definition) %}
                                <span>{{subClass.value(ns.skos.definition)}}</span>
                                {% endif %}
                              </p>
                              {% endfor %}
                            </dd>
                        </dl>
                        {% endif %}
                        {% if this.description().value(ns.cmo.hasPrimaryConcept) %}  
                        <dl class="dl-horizontal clearfix">
                            <dt>Terminology Reference</dt>
                            <dd>
                              {% for concept in this.description()[ns.cmo.hasPrimaryConcept] %}
                              <p>{{render_resource_link(concept)}}</p>
                              {% endfor %}
                            </dd>
                        </dl>
                        {% endif %}  
                        {% if this.description().value(ns.owl.equivalentClass) %}  
                        <dl class="dl-horizontal clearfix">
                            <dt>Equivalent To</dt>
                            <dd>
                              {% for concept in this.description()[ns.owl.equivalentClass] %}
                              <p>{{render_resource_link(concept)}}</p>
                              {% endfor %}
                            </dd>
                        </dl>
                        {% endif %}  
                        {% if this.description().value[ns.prov.wasAttributedTo] %}
                        {% set attrib = this.description().value(ns.prov.wasAttributedTo) %}
                        <dl class="dl-horizontal clearfix">
                            <dt>Attributed to</dt>
                            <dd>
                              {{render_resource_link(concept)}}
                            </dd>
                        </dl>
                        {%endif%}
                    </div>
                </div>               

  </div>
  <div class="col-md-7" >
    <section md-whiteframe="2" layout="column" style="height: 40em; margin-bottom:1em;">
      <explore flex start="{{this.identifier}}"></explore>
    </section>
  </div>
</div>

<instance-facets title="'Instances'" type="'{{this.identifier}}'">
    <md-button ng-href="{{url_for('entity.view',view='new',uri=this.identifier)}}" class="md-icon-button" aria-label="Create Instance">
      <md-icon>add</md-icon>
    </md-button>
</instance-facets>

<div md-whiteframe="2">
  <nanopubs resource="{{this.description().identifier}}"/>
</div>
</div>
{%endblock%}

