{%- if element.title %}
    {%- set title = element.title ~ ' (' ~ element.name ~ ')' -%}
{%- else %}
    {%- if gen.use_class_uris -%}
        {%- set title = element.name -%}
    {%- else -%}
        {%- set title = gen.name(element) -%}
    {%- endif -%}
{%- endif -%}

{% macro compute_range(slot) -%}
    {%- if slot.any_of or slot.exactly_one_of -%}
        {%- for subslot_range in schemaview.slot_range_as_union(slot) -%}
            {{ gen.link(subslot_range) }}
            {%- if not loop.last -%}
                &nbsp;or&nbsp;<br />
            {%- endif -%}
        {%- endfor -%}
    {%- else -%}
        {{ gen.link(slot.range) }}
    {%- endif -%}
{% endmacro %}

# Class: {{ title }} {% if element.deprecated %} <span style="color: red;"><strong> (DEPRECATED) </strong></span> {% endif %}

{%- if header -%}
{{ header }}
{%- endif -%}

{% if element.description %}
{% set element_description_lines = element.description.split('\n') %}
{% for element_description_line in element_description_lines %}
_{{ element_description_line }}_
{% endfor %}
{% endif %}

{% if element.abstract %}
* __NOTE__: this is an abstract class and should not be instantiated directly
{% endif %}

URI: {{ gen.uri_link(element) }}

{% if diagram_type == "er_diagram" %}
```{{ gen.mermaid_directive() }}
{{ gen.mermaid_diagram([element.name]) }}
```
{% elif diagram_type == "plantuml_class_diagram" %}
```puml
{{ gen.mermaid_diagram([element.name]) }}
```
{% else %}
{% include "class_diagram.md.jinja2" %}
{% endif %}

{% if schemaview.class_parents(element.name) or schemaview.class_children(element.name, mixins=False) %}

## Inheritance
{{ gen.inheritance_tree(element, mixins=True) }}
{% else %}
<!-- no inheritance hierarchy -->
{% endif %}

## Slots

| Name | Cardinality and Range | Description | Inheritance |
| ---  | --- | --- | --- |
{% if gen.get_direct_slots(element)|length > 0 %}
{%- for slot in gen.get_direct_slots(element) -%}
| {{ gen.link(slot) }} | {{ gen.cardinality(slot) }} <br/> {{ compute_range(slot) }} | {{ slot.description|enshorten }} | direct |
{% endfor -%}
{% endif -%}
{% if gen.get_indirect_slots(element)|length > 0 %}
{%- for slot in gen.get_indirect_slots(element) -%}
| {{ gen.link(slot) }} | {{ gen.cardinality(slot) }} <br/> {{ compute_range(slot) }} | {{ slot.description|enshorten }} | {{ gen.links(gen.get_slot_inherited_from(element.name, slot.name))|join(', ') }} |
{% endfor -%}
{% endif %}

{% if schemaview.is_mixin(element.name) %}
## Mixin Usage

| mixed into | description |
| --- | --- |
{% for c in schemaview.class_children(element.name, is_a=False) -%}
| {{ gen.link(c) }} | {{ schemaview.get_class(c).description|enshorten }} |
{% endfor %}
{% endif %}

{% if schemaview.usage_index().get(element.name) %}
## Usages

| used by | used in | type | used |
| ---  | --- | --- | --- |
{% for usage in schemaview.usage_index().get(element.name) -%}
| {{ gen.link(usage.used_by) }} | {{ gen.link(usage.slot) }} | {{ usage.metaslot }} | {{ gen.link(usage.used) }} |
{% endfor %}
{% endif %}

{% if element.rules %}
## Rules

{% for rule in gen.classrule_to_dict_view(element) %}
### {{ rule.title }}

| Rule Applied | Preconditions | Postconditions | Elseconditions |
|--------------|---------------|----------------|----------------|
{% for key in rule.preconditions -%}
| {{ key }} |
{%- if rule.preconditions[key] is defined -%}
```{{ rule.preconditions[key] }}```
{%- else -%}
{% endif %} |
{%- if rule.postconditions and rule.postconditions[key] is defined -%}
```{{ rule.postconditions[key] }}```
{%- else -%}
{% endif %} |
{%- if rule.elseconditions and rule.elseconditions[key] is defined -%}
```{{ rule.elseconditions[key] }}```
{%- else -%}
{% endif %} |
{% endfor %}

{% endfor %}
{% endif %}

{% include "common_metadata.md.jinja2" %}

{% if gen.example_object_blobs(element.name) -%}
## Examples
{% for name, blob in gen.example_object_blobs(element.name) -%}
### Example: {{ name }}

```yaml
{{ blob }}
```
{% endfor %}
{% endif %}

## LinkML Source

<!-- TODO: investigate https://stackoverflow.com/questions/37606292/how-to-create-tabbed-code-blocks-in-mkdocs-or-sphinx -->

### Direct

<details>
```yaml
{{ gen.yaml(element) }}
```
</details>

### Induced

<details>
```yaml
{{ gen.yaml(element, inferred=True) }}
```
</details>

{%- if footer -%}
{{ footer }}
{%- endif -%}
