{% extends "layout/base.html" %}

{% block title %}{{ metadata_type.name }} definition{% endblock %}

{% block panel %}

{% endblock %}
{% block content %}
    {% from "layout/macros.html" import show_raw_document %}

    <div class="panel highlight">
        <h2 class="followed">
            <span class="metadata-type-name">
                <i class="fa-regular fa-hdd" aria-hidden="true"></i>
                {{ metadata_type.name }}
            </span>
        </h2>
        <div class="header-follow">metadata type of {{ products_using_it | length }} products</div>

        <div><em>
            {{ metadata_type.definition['description'] }}
        </em></div>

    </div>
    <div class="panel odd">
        <h3>
            Used by Products
            {{ hanchor('products') }}
        </h3>
        {% if products_using_it %}
            <div class="type-usage-list {% if products_using_it | length > 4 %}columned{% endif %}">
                {% for product in products_using_it %}
                    <div class="type-usage-item">{{ product.name | product_link }}</div>
                {% endfor %}
            </div>
        {% else %}
            <em>None</em>
        {% endif %}
    </div>


    <div class="panel">
        <h3>
            Searchable Fields
            {{ hanchor('searchable-fields') }}
        </h3>
        <div class="{% if metadata_type.dataset_fields | length > 8 %}columned{% endif %}">
        {% for key, field in metadata_type.dataset_fields | dictsort %}
            {%- if field.indexed is true %}
                <div>
                    {{ key }}

                    <span class="badge">
                        {{- field.type_name -}}
                    </span>
                    {% if field.description and ('TODO' not in field.description) %}
                        <span class="muted">{{ field.description }}</span>
                    {% endif %}
                </div>
            {%- endif -%}
        {% endfor %}
        </div>
    </div>


    <div class="panel">
        <h3>
            Additional Fields
            {{ hanchor('additional-fields') }}
        </h3>
        <div class="{% if metadata_type.dataset_fields | length > 8 %}columned{% endif %}">
        {% for key, field in metadata_type.dataset_fields | dictsort %}
            {%- if field.indexed is false %}
                <div>
                    {{ key }}

                    <span class="badge">
                        {{- field.type_name -}}
                    </span>
                    {% if field.description and ('TODO' not in field.description) %}
                        <span class="muted">{{ field.description }}</span>
                    {% endif %}
                </div>
            {%- endif -%}
        {% endfor %}
        </div>
    </div>


    <div class="panel odd">
        <h3 class="followed">
            Definition
            {{ hanchor('definition-doc') }}
        </h3>
        <div class="header-follow">
            <a href="{{ url_for('product.raw_metadata_type_doc', name=metadata_type.name) }}"
               class="badge">
                View RAW
            </a>
        </div>
        {{ show_raw_document(metadata_doc) }}
    </div>

{% endblock %}
