{% extends "framework_modern.html" %}
{% load envipytags %}

{% block content %}

  {% block action_modals %}
    {% include "modals/objects/edit_node_modal.html" %}
    {% include "modals/objects/generic_set_aliases_modal.html" %}
    {% include "modals/objects/generic_set_scenario_modal.html" %}
    {% include "modals/objects/generic_delete_modal.html" %}
  {% endblock action_modals %}

  <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">{{ node.get_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/node.html" %}
              {% endblock %}
            </ul>
          </div>
        </div>
        <p class="mt-2">
          The underlying structure can be found
          <a href="{{ node.default_node_label.url }}" class="link link-primary"
            >here</a
          >.
        </p>
      </div>
    </div>

    <!-- Description -->
    {% if node.description and node.description != "no description" %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">Description</div>
        <div class="collapse-content">{{ node.description }}</div>
      </div>
    {% endif %}
    {% epdb_slot_templates "epdb.objects.node.viz" as viz_templates %}

    {% for tpl in viz_templates %}
      {% include tpl %}
    {% endfor %}

    <!-- Image Representation -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Image Representation</div>
      <div class="collapse-content">
        <div class="flex justify-center">
          {{ node.default_node_label.as_svg|safe }}
        </div>
      </div>
    </div>

    <!-- SMILES Representation -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">
        SMILES Representation
      </div>
      <div class="collapse-content">{{ node.default_node_label.smiles }}</div>
    </div>

    {% if node.default_node_label.aliases %}
      <!-- Aliases -->
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">Aliases</div>
        <div class="collapse-content">
          <ul class="menu bg-base-100 rounded-box">
            {% for alias in node.default_node_label.aliases %}
              <li><a class="hover:bg-base-200">{{ alias }}</a></li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

    {% if node.default_node_label.half_lifes %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" />
        <div class="collapse-title text-xl font-medium">Half-lives</div>
        <div class="collapse-content">
          <div class="overflow-x-auto">
            <table class="table-zebra table">
              <thead>
                <tr>
                  <th>Scenario</th>
                  <th>Values</th>
                </tr>
              </thead>
              <tbody>
                {% for scenario, half_lifes in node.default_node_label.half_lifes.items %}
                  <tr>
                    <td>
                      <a href="{{ scenario.url }}" class="hover:bg-base-200"
                        >{{ scenario.name }}
                        <i>({{ scenario.package.name }})</i></a
                      >
                    </td>
                    <td>
                      <table class="table-zebra table">
                        <tbody>
                          <tr>
                            <td>Scenario Type</td>
                            <td>{{ scenario.scenario_type }}</td>
                          </tr>
                          <tr>
                            <td>Half-life (days)</td>
                            <td>{{ half_lifes.0.dt50 }}</td>
                          </tr>
                          <tr>
                            <td>Model</td>
                            <td>{{ half_lifes.0.model.value }}</td>
                          </tr>
                        </tbody>
                      </table>
                    </td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    {% endif %}

    {% if node.scenarios.all %}
      <!-- Scenarios -->
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">Scenarios</div>
        <div class="collapse-content">
          <ul class="menu bg-base-100 rounded-box">
            {% for s in node.scenarios.all %}
              <li>
                <a href="{{ s.url }}" class="hover:bg-base-200"
                  >{{ s.name }} <i>({{ s.package.name }})</i></a
                >
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

    {% if app_domain_assessment_data %}
      <div id="appDomainAssessmentResultTable"></div>
      {# prettier-ignore-start #}
      {# FIXME: This is a hack to get the app domain assessment data into the JavaScript code. #}
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                if (typeof handleAssessmentResponse === 'function') {
                    handleAssessmentResponse("{% url 'depict' %}", {{ app_domain_assessment_data|safe }});
                }
            });
            </script>
        {# prettier-ignore-end #}
    {% endif %}
  </div>

  <script>
    // Show actions button if there are actions
    document.addEventListener("DOMContentLoaded", function () {
      const actionsButton = document.getElementById("actionsButton");
      const actionsList = actionsButton?.querySelector("ul");
      if (actionsList && actionsList.children.length > 0) {
        actionsButton?.classList.remove("hidden");
      }
    });
  </script>
{% endblock content %}
