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

{% block styles %}
    {{ super() }}
    {% asset "selfinfo/selfinfo-css" %}
    <link href="https://cdn.datatables.net/v/bs5/jszip-3.10.1/dt-2.3.2/b-3.2.3/b-colvis-3.2.3/b-html5-3.2.3/b-print-3.2.3/date-1.5.5/sc-2.4.3/sb-1.8.2/datatables.min.css" rel="stylesheet" integrity="sha384-nt4QPs/3NJrYE8fn3KunRHwtBtL9vfdfLwxwEd77lbPCBTSlrSzSGMsPRpwC2ZGv" crossorigin="anonymous">
{% endblock styles %}

{% block scripts %}
    {{ super() }}
    {% asset "selfinfo/selfinfo-js" %}
    <script src="https://cdn.datatables.net/v/bs5/jszip-3.10.1/dt-2.3.2/b-3.2.3/b-colvis-3.2.3/b-html5-3.2.3/b-print-3.2.3/date-1.5.5/sc-2.4.3/sb-1.8.2/datatables.min.js" integrity="sha384-VMg7uILXNFuDPoDgaFIj7Rmy6mZD/EeLKvog5HaDz1b8cBRsJ075SkSr85d7vPR8" crossorigin="anonymous" defer></script>
    {% snippet 'selfinfo/scripts/selfinfo_custom_scripts.html' %}
{% endblock scripts %}

{% block secondary %}
{% endblock %}

{%- block page -%}
    {%- block header %}
        {% snippet 'selfinfo/header.html' %}
    {% endblock -%}
    {% block page_header %}
    {% endblock %}
    <div id="selfinfo-layout">
        {% block primary %}
            <div class="bg-dark px-3 py-2">
                <ul class="nav nav-pills nav-fill border border-primary rounded border-light" id="pills-tab" role="tablist">
                    <li class="nav-item fs-4" role="presentation">
                    <button class="nav-link rounded-0 fw-bold active" id="selfinfo-plugin-tab" data-bs-toggle="pill" data-bs-target="#selfinfo-plugin" type="button" role="tab">
                        {{ _('Selfinfo') }}
                    </button>
                    </li>
                    {% snippet 'selfinfo/snippets/selfinfo_plugin_tabs.html', full_url=full_url %}
                </ul>
            </div>
            <div class="primary col-md-12 col-xs-12" role="main">
                <div class="module">
                    {% if self.page_primary_action() | trim %}
                    <div class="page_primary_action">
                        {% block page_primary_action %}{{ super() }}{% endblock %}
                    </div>
                    {% endif %}
                    {% set full_url = h.full_current_url() %}
                    <div class="tab-content d-block">
                        <div class="tab-pane fade show active" id="selfinfo-plugin" role="tabpanel" aria-labelledby="selfinfo-plugin-tab">
                            <div class="px-3 py-2 bg-dark">
                                <ul class="nav nav-pills nav-fill border border-primary rounded border-light" id="pills-tab" role="tablist">
                                    {% for profile, data in profiles.items() %}
                                        <li class="nav-item" role="presentation">
                                        <button href="#pills-selfinfo-{{ profile }}" class="nav-link rounded-0 fw-bold {% if loop.index == 1 %} active {% endif %}" id="pills-selfinfo-{{ profile }}-tab" data-bs-toggle="pill" data-bs-target="#pills-selfinfo-{{ profile }}" role="tab" aria-controls="pills-selfinfo-{{ profile }}" aria-selected="true">
                                            {% if "label" in data %}
                                                {{ data.label }}
                                            {% else %}
                                                {{ profile }}
                                            {% endif %}
                                            {% if data.provided_on and h.selfinfo_is_profile_old(data.provided_on) %}
                                                <i class="fa fa-triangle-exclamation text-danger" aria-hidden="true"></i>
                                            {% endif %}
                                        </button>
                                        </li>
                                    {% endfor %}
                                </ul>
                            </div>
                            <div class="tab-content d-block" id="pills-tabContent">
                                {% for profile, data in profiles.items() %}
                                <div class="tab-pane fade {% if loop.index == 1 %} show active {% endif %}" id="pills-selfinfo-{{ profile }}" role="tabpanel" aria-labelledby="pills-selfinfo-{{ profile }}-tab">
                                    {% if data.provided_on %}
                                        <div class="d-flex justify-content-between align-items-center px-3 py-2 bg-dark text-white">
                                            <div class="d-flex align-items-center">
                                                <div class="p-2 rounded bg-success me-3">
                                                    Provided on: {{ h.render_datetime(data.provided_on, date_format='%d/%m/%y %H:%M') }}
                                                </div>
                                                <div class="bg-white text-dark p-2 rounded">
                                                    Redis key: {{ profile }}
                                                </div>
                                            </div>
                                            <div>
                                                <button class="btn btn-danger p-2 rounded" title="Delete Profile" hx-post="/selfinfo/delete-profile" hx-trigger="click" hx-swap="innerHTML" hx-target="#selfinfo-{{ profile }}-tab-content" hx-vals='{"profile": "{{profile}}"}'>
                                                    {{ _('Delete Profile') }}
                                                    <i class="fa fa-trash" aria-hidden="true"></i>
                                                </button>
                                            </div>
                                        </div>
                                    {% endif %}
                                    <div id="selfinfo-{{ profile }}-tab-content">
                                        <nav class="px-3 pt-2 pb-3 bg-dark">
                                            <div class="nav nav-pills nav-fill border border-primary rounded border-light" id="nav-tab" role="tablist">
                                                <button href="#nav-system-{{ profile }}" class="nav-link rounded-0 fw-bold active" id="nav-system-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-system-{{ profile }}" role="tab" aria-controls="nav-system-{{ profile }}" aria-selected="true">System Info</button>
                                                <button href="#nav-ckan-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-ckan-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-ckan-{{ profile }}" role="tab" aria-controls="nav-ckan-{{ profile }}" aria-selected="false">CKAN Info</button>
                                                {% if data.git_info %}
                                                    <button href="#nav-git-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-git-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-git-{{ profile }}" role="tab" aria-controls="nav-git-{{ profile }}" aria-selected="false">GIT Info</button>
                                                {% endif %}
                                                {% if data.python_modules %}
                                                    <button href="#nav-python-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-python-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-python-{{ profile }}" role="tab" aria-controls="nav-python-{{ profile }}" aria-selected="false">Python Info</button>
                                                {% endif %}
                                                {% if data.freeze %}
                                                    <button href="#nav-freeze-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-freeze-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-freeze-{{ profile }}" role="tab" aria-controls="nav-freeze-{{ profile }}" aria-selected="false">PIP Freeze</button>
                                                {% endif %}
                                                {% if data.ckan_queues %}
                                                    <button href="#nav-ckan_queues-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-ckan_queues-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-ckan_queues-{{ profile }}" role="tab" aria-controls="nav-ckan_queues-{{ profile }}" aria-selected="false">CKAN Queues</button>
                                                {% endif %}
                                                {% if data.ckan_solr_schema %}
                                                    <button href="#nav-ckan_solr_schema-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-ckan_solr_schema-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-ckan_solr_schema-{{ profile }}" role="tab" aria-controls="nav-ckan_solr_schema-{{ profile }}" aria-selected="false">Solr Schema</button>
                                                {% endif %}
                                                {% if 'errors' in data %}
                                                    <button href="#nav-errors-{{ profile }}" class="nav-link rounded-0 fw-bold" id="nav-errors-{{ profile }}-tab" data-bs-toggle="tab" data-bs-target="#nav-errors-{{ profile }}" role="tab" aria-controls="nav-errors-{{ profile }}" aria-selected="false">Errors</button>
                                                {% endif %}
                
                                                {% snippet 'selfinfo/snippets/additional_navigation_tabs.html', profile=profile, data=data, full_url=full_url %}
                
                                            </div>
                                        </nav>
                                        <div class="tab-content d-block p-3" id="nav-data-{{ profile }}">
                                            <div class="tab-pane fade show active" id="nav-system-{{ profile }}" role="tabpanel" aria-labelledby="nav-system-tab">
                                                {% snippet 'selfinfo/snippets/self_system_info.html', profile=profile, data=data, full_url=full_url, id='nav-system-' ~ profile %}
                                            </div>
                                            <div class="tab-pane fade" id="nav-ckan-{{ profile }}" role="tabpanel" aria-labelledby="nav-ckan-tab">
                                                {% snippet 'selfinfo/snippets/self_ckan_information.html', profile=profile, data=data, full_url=full_url, id='nav-ckan-' ~ profile %}
                                            </div>
                                            <div class="tab-pane fade" id="nav-git-{{ profile }}" role="tabpanel" aria-labelledby="nav-git-tab">
                                                {% snippet 'selfinfo/snippets/self_git_info.html', profile=profile, data=data, full_url=full_url, id='nav-git-' ~ profile %}
                                            </div>
                                            {% if data.python_modules %}
                                            <div class="tab-pane fade" id="nav-python-{{ profile }}" role="tabpanel" aria-labelledby="nav-python-tab">
                                                {% snippet 'selfinfo/snippets/self_python_packages.html', profile=profile, data=data, full_url=full_url, id='nav-python-' ~ profile %}
                                            </div>
                                            {% endif %}
                                            {% if data.freeze %}
                                            <div class="tab-pane fade mt-3" id="nav-freeze-{{ profile }}" role="tabpanel" aria-labelledby="nav-freeze-tab">
                                                {% snippet 'selfinfo/snippets/self_freeze.html', profile=profile, data=data, full_url=full_url, id='nav-freeze-' ~ profile %}
                                            </div>
                                            {% endif %}
                                            {% if data.ckan_queues %}
                                            <div class="tab-pane fade mt-3" id="nav-ckan_queues-{{ profile }}" role="tabpanel" aria-labelledby="nav-ckan_queues-tab">
                                                {% snippet 'selfinfo/snippets/ckan_queues.html', profile=profile, data=data, full_url=full_url, id='nav-ckan_queues-' ~ profile %}
                                            </div>
                                            {% endif %}
                                            {% if data.ckan_solr_schema %}
                                            <div class="tab-pane fade mt-3" id="nav-ckan_solr_schema-{{ profile }}" role="tabpanel" aria-labelledby="nav-ckan_solr_schema-tab">
                                                {% snippet 'selfinfo/snippets/self_ckan_solr_schema.html', profile=profile, data=data, full_url=full_url, id='nav-ckan_solr_schema-' ~ profile %}
                                            </div>
                                            {% endif %}
                                            {% if 'errors' in data %}
                                            <div class="tab-pane fade mt-3" id="nav-errors-{{ profile }}" role="tabpanel" aria-labelledby="nav-errors-tab">
                                                {% snippet 'selfinfo/snippets/self_errors.html', profile=profile, data=data, full_url=full_url, id='nav-errors-' ~ profile %}
                                            </div>
                                            {% endif %}
                
                                            {% snippet 'selfinfo/snippets/additional_content_tabs.html', profile=profile, data=data, full_url=full_url %}
                                        </div>
                                    </div>
                                </div>
                                {% endfor %}
                            </div>
                        </div>
                        {% snippet 'selfinfo/snippets/selfinfo_plugin_tabs_content.html', full_url=full_url %}
                    </div>
                </div>
            </div>
        {% endblock %}
    </div>
{% endblock %}
