{% extends "framework_modern.html" %}
{% load static %}
{% load envipytags %}
{% block content %}

  {% block action_modals %}
    {% include "modals/objects/edit_model_modal.html" %}
    {% include "modals/objects/evaluate_model_modal.html" %}
    {% include "modals/objects/retrain_model_modal.html" %}
    {% include "modals/objects/generic_delete_modal.html" %}
  {% endblock action_modals %}

  {% block libraries %}
  {% endblock %}

  <div class="space-y-2 p-4">
    <!-- Header Section -->
    <div class="card bg-base-100">
      <div class="card-body">
        <div class="flex items-center justify-between">
          <h2 class="card-title text-2xl">{{ model.name }}</h2>
          <div id="actionsButton" class="dropdown dropdown-end hidden">
            <div tabindex="0" role="button" class="btn btn-ghost btn-sm">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                width="16"
                height="16"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                class="lucide lucide-wrench"
              >
                <path
                  d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"
                />
              </svg>
              Actions
            </div>
            <ul
              tabindex="-1"
              class="dropdown-content menu bg-base-100 rounded-box z-50 w-52 p-2"
            >
              {% block actions %}
                {% include "actions/objects/model.html" %}
              {% endblock %}
            </ul>
          </div>
        </div>
        <p class="mt-2">{{ model.description|safe }}</p>
      </div>
    </div>

    <!-- Model Status -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Model Status</div>
      <div class="collapse-content">{{ model.status }}</div>
    </div>

    {% block packages %}
      {% if model.rule_packages.all|length > 0 %}
        <!-- Rule Packages -->
        <div class="collapse-arrow bg-base-200 collapse">
          <input type="checkbox" checked />
          <div class="collapse-title text-xl font-medium">Rule Packages</div>
          <div class="collapse-content">
            <ul class="menu bg-base-100 rounded-box w-full">
              {% for p in model.rule_packages.all %}
                <li>
                  <a href="{{ p.url }}" class="hover:bg-base-200"
                    >{{ p.name }}</a
                  >
                </li>
              {% endfor %}
            </ul>
          </div>
        </div>
      {% endif %}
      {% if model.data_packages.all|length > 0 %}
        <!-- Reaction Packages -->
        <div class="collapse-arrow bg-base-200 collapse">
          <input type="checkbox" checked />
          <div class="collapse-title text-xl font-medium">
            Reaction Packages
          </div>
          <div class="collapse-content">
            <ul class="menu bg-base-100 rounded-box w-full">
              {% for p in model.data_packages.all %}
                <li>
                  <a href="{{ p.url }}" class="hover:bg-base-200"
                    >{{ p.name }}</a
                  >
                </li>
              {% endfor %}
            </ul>
          </div>
        </div>
      {% endif %}
      {% if model.eval_packages.all|length > 0 %}
        <!-- Eval Packages -->
        <div class="collapse-arrow bg-base-200 collapse">
          <input type="checkbox" checked />
          <div class="collapse-title text-xl font-medium">Eval Packages</div>
          <div class="collapse-content">
            <ul class="menu bg-base-100 rounded-box w-full">
              {% for p in model.eval_packages.all %}
                <li>
                  <a href="{{ p.url }}" class="hover:bg-base-200"
                    >{{ p.name }}</a
                  >
                </li>
              {% endfor %}
            </ul>
          </div>
        </div>
      {% endif %}

      {% if model.parameters %}
        <!-- Model Parameters Panel -->
        <div class="collapse-arrow bg-base-200 collapse">
          <input type="checkbox" checked />
          <div class="collapse-title text-xl font-medium">Model Parameters</div>
          <div class="collapse-content">
            <div class="flex justify-center">
              <div
                id="model-stats"
                class="overflow-x-auto rounded-box shadow-md bg-base-100"
              >
                <table class="table table-fixed w-full">
                  <thead class="text-base">
                    <tr>
                      <th class="w-3/5">Parameter</th>
                      <th>Value</th>
                    </tr>
                  </thead>
                  <tbody>
                    {% for param, value in model.parameters.items %}
                      <tr>
                        <td>{{ param }}</td>
                        <td>{{ value }}</td>
                      </tr>
                    {% endfor %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      {% endif %}
    {% endblock %}

    {% block usemodel %}
    {% endblock %}

    {% block evaluation %}
    {% endblock %}
  </div>
  <script>
    function makeLoadingGif(selector, gifPath) {
      const element = document.querySelector(selector);
      if (element) {
        element.innerHTML = '<img src="' + gifPath + '" alt="Loading...">';
      }
    }

    function clear(divid) {
      const element = document.getElementById(divid);
      if (element) {
        element.classList.remove("alert", "alert-error");
        element.innerHTML = "";
      }
    }
  </script>
{% endblock content %}
