{% extends "base.html" %}
{% import "macros.html" as utils %}

{% block title %}Bioregistry - {{ name }}{% endblock %}

{% block styles %}
{{ super() }}
<link href="https://cdn.jsdelivr.net/npm/prismjs@1.23.0/themes/prism.css" rel="stylesheet"/>
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script type="text/javascript">
        $(function () {
            $('[data-toggle="tooltip"]').tooltip()
        })
    </script>
    <script src="https://cdn.jsdelivr.net/npm/prismjs@1.23.0/prism.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/prismjs@1.23.0/plugins/autoloader/prism-autoloader.min.js"></script>
{% endblock %}

{% block container %}
    <div class="card">
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col-8">
                    <h5 style="margin: 0"><a href="{{ url_for("ui.resources") }}">Registry</a> <i
                            class="fas fa-angle-right"></i> {{ name }}
                        {% if deprecated %}
                            <span class="badge badge-warning" style="display: inline-block;">
                                Deprecated <i class="fas fa-exclamation-triangle"></i>
                            </span>
                        {% elif provides %}
                            <span class="badge badge-danger" style="display: inline-block;">
                                Provider <i class="fas fa-exclamation-triangle"></i>
                            </span>
                        {% endif %}
                    </h5>
                </div>
                <div class="col-4 text-right">
                    <div class="dropdown">
                        <button class="btn btn-sm btn-outline-dark dropdown-toggle" type="button"
                                id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
                                aria-expanded="false">
                            Download
                        </button>
                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                            {% for label, key in formats %}
                                <a class="dropdown-item"
                                   href="{{ url_for("api.resource", prefix=prefix, format=key) }}">
                                    {{ label }} <i class="fas fa-download"></i>
                                </a>
                            {% endfor %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-body">
            {% if description %}<p>{{ description }}</p>{% endif %}
            {% if provides %}
                <p>
                    This resource is a <span class="badge badge-danger">provider</span>. This means that
                    while it may have its own prefix, it actually reuses the identifiers provided by the
                    <a href="{{ url_for(".resource", prefix=provides) }}"><code>{{ provides }}</code></a>
                    prefix. For <b>all</b> use cases, you should use <a
                        href="{{ url_for(".resource", prefix=provides) }}"><code>{{ provides }}</code></a>
                    instead of <code>{{ prefix }}</code>.
                </p>
            {% endif %}
            {% if resource.comment %}
                <p class="text-muted"><span class="badge badge-info">Comment</span> {{ resource.comment }}</p>
            {% endif %}
            <dl>
                <dt>Prefix</dt>
                <dd><code>{{ prefix }}</code></dd>
                {% set preferred_prefix = resource.get_preferred_prefix() %}
                {% if preferred_prefix %}
                    <dt>Preferred Prefix</dt>
                    <dd><code>{{ preferred_prefix }}</code></dd>
                {% endif %}
                {% if synonyms %}
                    <dt>
                        Alternative Prefixes
                        <a type="button" data-toggle="modal" data-target="#synonyms-modal">
                            <i class="far fa-question-circle"></i>
                        </a>
                    </dt>
                    <dd>
                        {% for synonym in synonyms %}
                            <span class="badge badge-light">{{ synonym }}</span>
                        {% endfor %}
                    </dd>
                {% endif %}
                {% if version %}
                    <dt>
                        Version
                        <a type="button" data-toggle="modal" data-target="#version-modal">
                            <i class="far fa-question-circle"></i>
                        </a>
                    </dt>
                    <dd>{{ version }}</dd>
                {% endif %}
                <dt>
                    Links
                    {% if homepage or obo_download or owl_download or json_download %}
                    <a type="button" data-toggle="modal" data-target="#links-modal">
                        <i class="far fa-question-circle"></i>
                    </a>
                    {% endif %}
                </dt>
                <dd>
                    {% if homepage %}
                        <a class="badge badge-pill badge-light" href="{{ homepage }}">
                            Homepage <i class="fas fa-home"></i>
                        </a>
                    {% else %}
                        <span class="badge badge-pill badge-warning">Missing Homepage</span>
                    {% endif %}
                    {% if repository %}
                        <a class="badge badge-pill badge-light" href="{{ repository }}">
                            Repository <i class="fab fa-github"></i>
                        </a>
                    {% endif %}
                    {% if obo_download %}
                        <a class="badge badge-pill badge-light" href="{{ obo_download }}">
                            OBO <i class="fas fa-download"></i>
                        </a>
                    {% endif %}
                    {% if owl_download %}
                        <a class="badge badge-pill badge-light" href="{{ owl_download }}">
                            OWL <i class="fas fa-download"></i>
                        </a>
                    {% endif %}
                    {% if json_download %}
                        <a class="badge badge-pill badge-light" href="{{ json_download }}">
                            OBO JSON <i class="fas fa-download"></i>
                        </a>
                    {% endif %}
                </dd>
                <dt>
                    Contact
                    {% if contact %}
                    <a type="button" data-toggle="modal" data-target="#contact-modal">
                        <i class="far fa-question-circle"></i>
                    </a>
                    {% endif %}
                </dt>
                <dd>
                    {% if contact %}
                        {{ utils.render_author(contact, link=none) }}
                    {% else %}
                        <span class="badge badge-pill badge-warning">Missing Contact</span>
                    {% endif %}
                </dd>
                <dt>Pattern for Local Unique Identifiers</dt>
                <dd>
                    {% if pattern %}
                        <p>
                            Local identifiers in {{ name }} should match this
                            regular expression:<br/><kbd>{{ pattern }}</kbd>
                        </p>
                    {% elif has_no_terms %}
                        <span class="badge badge-pill badge-secondary">No terms in {{ prefix }}</span>
                    {% else %}
                        <span class="badge badge-pill badge-warning">Missing LUI pattern</span>
                    {% endif %}
                </dd>
                <dt>Example Local Unique Identifier</dt>
                <dd>
                    {% if example %}
                        <a href="{{ url_for("ui.reference", prefix=prefix, identifier=example) }}">{{ example }}</a>
                        {% if providers %}
                        &nbsp;
                        <a class="badge badge-pill badge-info" href="{{ url_for("ui.resolve", prefix=prefix, identifier=example) }}"><i class="fas fa-share-square"></i> Resolve</a>
                        {% endif %}
                    {% elif has_no_terms %}
                        <span class="badge badge-pill badge-secondary">No Terms in {{ prefix }}</span>
                    {% else %}
                        <span class="badge badge-pill badge-warning">Missing Example Local Unique Identifier</span>
                    {% endif %}
                </dd>
                <dt>Pattern for CURIES</dt>
                <dd>
                    {% if curie_pattern %}
                        <p>
                            Compact URIs (CURIEs) constructed from {{ name }} should match
                            this regular expression:<br/><kbd>{{ curie_pattern }}</kbd>
                        </p>
                    {% elif has_no_terms %}
                        <span class="badge badge-pill badge-secondary">No terms in {{ prefix }}</span>
                    {% else %}
                        <span class="badge badge-pill badge-warning">Could not construct CURIE pattern</span>
                    {% endif %}
                </dd>
                <dt>Example CURIE</dt>
                <dd>
                    {% if example_curie %}
                        <a href="{{ url_for("ui.reference", prefix=prefix, identifier=example) }}">{{ example_curie }}</a>
                    {% elif has_no_terms %}
                        <span class="badge badge-pill badge-secondary">No Terms in {{ prefix }}</span>
                    {% else %}
                        <span class="badge badge-pill badge-warning">Missing Example Local Unique Identifier</span>
                    {% endif %}
                </dd>
                {% if namespace_in_lui %}
                    <dt>MIRIAM Namespace Embedded in LUI</dt>
                    <dd>
                        The legacy MIRIAM standard for generating CURIEs with this resource
                        includes the <code>namespaceEmbeddedInLUI</code> as true. The actual
                        part that gets prefixed before the local unique identifier regex,
                        otherwise known as the banana, is <code>{{ banana if banana else prefix.upper() }}:</code>.
                        Therefore, you might see local unique identifiers written out as CURIEs.
                    </dd>
                {% endif %}

                {% if resource.references %}
                    <dt>References</dt>
                    <dd>
                        <ul>
                            {% for reference in resource.references %}
                                <li><a href="{{ reference }}">{{ reference }}</a></li>
                            {% endfor %}
                        </ul>
                    </dd>
                {% endif %}
                {% if resource.contributor %}
                    <dt>Contributor</dt>
                    <dd>
                        {{ utils.render_author(resource.contributor, link=url_for('ui.contributor', orcid=resource.contributor.orcid)) }}
                    </dd>
                {% endif %}
                {% if resource.reviewer %}
                    <dt>Reviewer</dt>
                    <dd>
                        {{ utils.render_author(resource.reviewer, link=url_for('ui.contributor', orcid=resource.reviewer.orcid)) }}
                    </dd>
                {% endif %}
            </dl>
        </div>

    </div>

    {% if provides or provided_by or part_of or has_parts or has_canonical or canonical_for or depends_on or appears_in %}
    <div class="card" style="margin-top: 20px">
        <a id="ontology"></a>
        <h5 class="card-header">Ontology</h5>
        <div class="card-body">
            <dl>
                {% if provides %}
                    <dt>
                        Provides
                    </dt>
                    <dd>
                        <a href="{{ url_for("ui.resource", prefix=provides) }}"
                           class="badge badge-pill badge-light" data-toggle="tooltip"
                           title="{{ bioregistry.get_name(provides) }}">
                            {{ bioregistry.get_preferred_prefix(provides) or provides }}
                        </a>
                    </dd>
                {% endif %}
                {% if provided_by %}
                    <dt>
                        Provided By
                    </dt>
                    <dd>
                        {% for rel_prefix in provided_by %}
                            <a href="{{ url_for("ui.resource", prefix=rel_prefix) }}"
                               class="badge badge-pill badge-light" data-toggle="tooltip"
                               title="{{ bioregistry.get_name(rel_prefix) }}">
                                {{ bioregistry.get_preferred_prefix(rel_prefix) or rel_prefix }}
                            </a>
                        {% endfor %}
                    </dd>
                {% endif %}
                {% if part_of %}
                    <dt>
                        Part Of
                    </dt>
                    <dd>
                        <a href="{{ url_for("ui.resource", prefix=part_of) }}"
                           class="badge badge-pill badge-light" data-toggle="tooltip"
                           title="{{ bioregistry.get_name(part_of) }}">
                            {{ bioregistry.get_preferred_prefix(part_of) or part_of }}
                        </a>
                    </dd>
                {% endif %}
                {% if has_parts %}
                    <dt>
                        Has Part
                    </dt>
                    <dd>
                        {% for rel_prefix in has_parts %}
                            <a href="{{ url_for("ui.resource", prefix=rel_prefix) }}"
                               class="badge badge-pill badge-light" data-toggle="tooltip"
                               title="{{ bioregistry.get_name(rel_prefix) }}">
                                {{ bioregistry.get_preferred_prefix(rel_prefix) or rel_prefix }}
                            </a>
                        {% endfor %}
                    </dd>
                {% endif %}
                {% if has_canonical %}
                    <dt>
                        Has Canonical
                    </dt>
                    <dd>
                        <a href="{{ url_for("ui.resource", prefix=has_canonical) }}"
                           class="badge badge-pill badge-light" data-toggle="tooltip"
                           title="{{ bioregistry.get_name(has_canonical) }}">
                            {{ bioregistry.get_preferred_prefix(has_canonical) or has_canonical }}
                        </a>
                    </dd>
                {% endif %}
                {% if canonical_for %}
                    <dt>
                        Canonical For
                    </dt>
                    <dd>
                        {% for rel_prefix in canonical_for %}
                            <a href="{{ url_for("ui.resource", prefix=rel_prefix) }}"
                               class="badge badge-pill badge-light" data-toggle="tooltip"
                               title="{{ bioregistry.get_name(rel_prefix) }}">
                                {{ bioregistry.get_preferred_prefix(rel_prefix) or rel_prefix }}
                            </a>
                        {% endfor %}
                    </dd>
                {% endif %}
                {% if depends_on %}
                    <dt>
                        Depends On
                    </dt>
                    <dd>
                        {% for rel_prefix in depends_on %}
                            <a href="{{ url_for("ui.resource", prefix=rel_prefix) }}"
                               class="badge badge-pill badge-light" data-toggle="tooltip"
                               title="{{ bioregistry.get_name(rel_prefix) }}">
                                {{ bioregistry.get_preferred_prefix(rel_prefix) or rel_prefix }}
                            </a>
                        {% endfor %}
                    </dd>
                {% endif %}
                {% if appears_in %}
                    <dt>
                        Appears In
                    </dt>
                    <dd>
                        {% for rel_prefix in appears_in %}
                            <a href="{{ url_for("ui.resource", prefix=rel_prefix) }}"
                               class="badge badge-pill badge-light" data-toggle="tooltip"
                               title="{{ bioregistry.get_name(rel_prefix) }}">
                                {{ bioregistry.get_preferred_prefix(rel_prefix) }}
                            </a>
                        {% endfor %}
                    </dd>
                {% endif %}
            </dl>
        </div>
    </div>
    {% endif %}

    {% if mappings %}
        <div class="card" style="margin-top: 20px">
            <a id="mappings"></a>
            <h5 class="card-header">Metaregistry</h5>
            <div class="card-body">
                <p>
                    The metaregistry provides mappings between the Bioregistry and other registries. There are
                    {{ mappings | length }} mappings to external registries for <code>{{ prefix }}</code>.
                </p>
            </div>
            <table class="table table-hover table-striped">
                <thead class="table-">
                <tr>
                    <th scope="col">Registry Name</th>
                    <th scope="col">Metaprefix</th>
                    <th scope="col">External Prefix</th>
                </tr>
                </thead>
                <tbody>
                {% for mapping in mappings %}
                    <tr>
                        <td>
                            {% if mapping.homepage %}
                                <a href="{{ mapping.homepage }}">{{ mapping.name }}</a>
                            {% else %}
                                {{ mapping.name }}
                            {% endif %}
                        </td>
                        <td><code>{{ mapping.metaprefix }}</code></td>
                        <td>
                            {% if mapping.uri %}
                                <a href="{{ mapping.uri }}"><code>{{ mapping.xref }}</code> <i class="fas fa-link"></i></a>
                            {% else %}
                                <span title="{{ mapping.name }} does not resolve metaidentifiers"
                                      data-toggle="tooltip" data-placement="right"><code>{{ mapping.xref }}</code>
                                    <i class="fas fa-info-circle"></i></span>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
    {% if providers %}
        <div class="card" style="margin-top: 20px">
            <a id="mappings"></a>
            <h5 class="card-header">Providers</h5>
            <div class="card-body">
                <p>
                    Providers are various services that resolve CURIEs to URLs. The example CURIE
                    <code>{{ prefix }}:{{ example }}</code> is used to demonstrate the provides available for
                    <code>{{ prefix }}</code>. Generation of OLS and BioPortal URLs requires additional programmatic
                    logic beyond string formatting.
                </p>
            </div>
            {{ utils.render_provider_table(prefix=prefix, identifier=example, providers=providers) }}
        </div>
    {% endif %}
    {% set extra_providers = resource.get_extra_providers() %}
    {% if extra_providers %}
        <div class="card" style="margin-top: 20px">
            <a id="mappings"></a>
            <h5 class="card-header">Extra Providers</h5>
            <div class="card-body">
                <p>
                    Additional providers curated in the Bioregistry are listed here.
                </p>
            </div>
            <table class="table table-hover table-striped">
                <thead class="table-">
                <tr>
                    <th scope="col">Code</th>
                    <th scope="col">Name</th>
                    <th scope="col">URL</th>
                </tr>
                </thead>
                <tbody>
                {% for provider in extra_providers %}
                    <tr>
                        <td>{{ provider.code }}</td>
                        <td>{{ provider.name }}</td>
                        {% set url = provider.resolve(example) %}
                        <td><a href="{{ url }}">{{ url }}</a></td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}

    {% if synonyms %}
    <div class="modal fade" id="synonyms-modal" tabindex="-1" role="dialog" aria-labelledby="synonymsModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="synonymsModalLabel">Programmatic Access to Synonyms</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>
                        Normalize prefixes. This can be any capitalization or punctuation
                        variant of the synonyms listed below.
                    </p>
                    <pre><code class="language-python">&gt;&gt;&gt; import bioregistry as br
&gt;&gt;&gt; br.normalize_prefix("{{ synonyms|first }}")
'{{ prefix }}'</code></pre>
                    <p>Get all synonyms:</p>
                    {{ utils.code_example(prefix, "get_synonyms", synonyms, quote=False) }}
                </div>
            </div>
        </div>
    </div>
    {% endif %}

    {% if version %}
    <div class="modal fade" id="version-modal" tabindex="-1" role="dialog" aria-labelledby="versionModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="versionModalLabel">Programmatic Access to Version</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>Get the version:</p>
                    {{ utils.code_example(prefix, "get_version", version) }}
                </div>
            </div>
        </div>
    </div>
    {% endif %}

    <div class="modal fade" id="links-modal" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="linkModalLabel">Programmatic Access to Links</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    {% if homepage %}
                        <p>Get the homepage:</p>
                        {{ utils.code_example(prefix, "get_homepage", homepage) }}
                    {% endif %}
                    {% if repository %}
                        <p>Get the repository:</p>
                        {{ utils.code_example(prefix, "get_repository", repository) }}
                    {% endif %}
                    {% if obo_download %}
                        <p>Get the OBO download link:</p>
                        {{ utils.code_example(prefix, "get_obo_download", obo_download) }}
                    {% endif %}
                    {% if owl_download %}
                        <p>Get the OWL download link:</p>
                        {{ utils.code_example(prefix, "get_owl_download", owl_download) }}
                    {% endif %}
                    {% if json_download %}
                        <p>Get the JSON download link:</p>
                        {{ utils.code_example(prefix, "get_json_download", json_download) }}
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    {% if contact %}
        {{ utils.render_author_modal(prefix, contact, "contact") }}
    {% endif %}
{% endblock %}
