{% extends "framework_modern.html" %}

{% block content %}

  {% block action_modals %}
    {% include "modals/objects/edit_reaction_modal.html" %}
    {% include "modals/objects/generic_set_aliases_modal.html" %}
    {% include "modals/objects/generic_set_scenario_modal.html" %}
    {% include "modals/objects/generic_copy_object_modal.html" %}
    {% include "modals/objects/generic_set_external_reference_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">{{ reaction.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/reaction.html" %}
              {% endblock %}
            </ul>
          </div>
        </div>
      </div>
    </div>

    <!-- 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">{{ reaction.description }}</div>
    </div>

    {% if reaction.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 reaction.aliases %}
              <li><a class="hover:bg-base-200">{{ alias }}</a></li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

    <!-- 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">{{ reaction.as_svg|safe }}</div>
      </div>
    </div>

    <!-- Reaction Description -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Reaction Description</div>
      <div class="collapse-content">
        <div class="flex flex-wrap items-center justify-center gap-4">
          {% for educt in reaction.educts.all %}
            <a href="{{ educt.url }}" class="btn btn-outline btn-sm"
              >{{ educt.name }}</a
            >
          {% endfor %}
          <svg
            xmlns="http://www.w3.org/2000/svg"
            width="24"
            height="24"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            class="lucide lucide-arrow-right"
          >
            <path d="M5 12h14" />
            <path d="m12 5 7 7-7 7" />
          </svg>
          {% for product in reaction.products.all %}
            <a href="{{ product.url }}" class="btn btn-outline btn-sm"
              >{{ product.name }}</a
            >
          {% endfor %}
        </div>
      </div>
    </div>

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

    <!-- Rules -->
    {% if reaction.rules.all %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">Rules</div>
        <div class="collapse-content">
          <ul class="menu bg-base-100 rounded-box">
            {% for r in reaction.rules.all %}
              <li>
                <a href="{{ r.url }}" class="hover:bg-base-200">{{ r.name }}</a>
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

    <!-- EC Numbers -->
    {% if reaction.get_related_enzymes %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">EC Numbers</div>
        <div class="collapse-content">
          <ul class="menu bg-base-100 rounded-box">
            {% for e in reaction.get_related_enzymes %}
              <li>
                <a
                  href="http://www.brenda-enzymes.org/enzyme.php?ecno={{ e.ec_number }}"
                  class="hover:bg-base-200"
                  >{{ e.name }}</a
                >
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

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

    <!-- Scenarios -->
    {% if reaction.scenarios.all %}
      <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 reaction.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 %}

    <!-- External Identifiers -->
    {% if reaction.get_external_identifiers %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">
          External Identifier
        </div>
        <div class="collapse-content">
          <div class="space-y-2">
            {% if reaction.get_rhea_identifiers %}
              <div class="collapse-arrow bg-base-100 collapse">
                <input type="checkbox" checked />
                <div class="collapse-title text-lg font-medium">Rhea</div>
                <div class="collapse-content">
                  <ul class="menu bg-base-200 rounded-box">
                    {% for eid in reaction.get_rhea_identifiers %}
                      <li>
                        <a
                          href="{{ eid.external_url }}"
                          class="hover:bg-base-300"
                          >{{ eid.identifier_value }}</a
                        >
                      </li>
                    {% endfor %}
                  </ul>
                </div>
              </div>
            {% endif %}
            {% if reaction.get_uniprot_identifiers %}
              <div class="collapse-arrow bg-base-100 collapse">
                <input type="checkbox" checked />
                <div class="collapse-title text-lg font-medium">UniProt</div>
                <div class="collapse-content">
                  <ul class="menu bg-base-200 rounded-box">
                    {% for eid in reaction.get_uniprot_identifiers %}
                      <li>
                        <a
                          href="{{ eid.external_url }}"
                          class="hover:bg-base-300"
                          >10 SwissProt entries ({{ eid.identifier_value }})</a
                        >
                      </li>
                    {% endfor %}
                  </ul>
                </div>
              </div>
            {% endif %}
          </div>
        </div>
      </div>
    {% 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 %}
