{% extends "framework_modern.html" %}

{% block content %}

  {% block action_modals %}
    {% include "modals/objects/edit_rule_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_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">{{ rule.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/rule.html" %}
              {% endblock %}
            </ul>
          </div>
        </div>
        <p class="mt-2">{{ rule.description }}</p>
      </div>
    </div>

    {% if rule.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 rule.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">{{ rule.as_svg|safe }}</div>
      </div>
    </div>

    <!-- SMIRKS -->
    <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">
        <p>{{ rule.smirks }}</p>
      </div>
    </div>

    <!-- Reactants SMARTS -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Reactant SMARTS</div>
      <div class="collapse-content">
        <p>{{ rule.reactants_smarts }}</p>
      </div>
    </div>

    <!-- Reactant Filter SMARTS -->
    {% if rule.reactant_filter_smarts %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">
          Reactant Filter SMARTS
        </div>
        <div class="collapse-content">
          <p>{{ rule.reactant_filter_smarts }}</p>
        </div>
      </div>
    {% endif %}

    <!-- Products SMARTS -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Products SMARTS</div>
      <div class="collapse-content">
        <p>{{ rule.products_smarts }}</p>
      </div>
    </div>

    <!-- Product Filter SMARTS -->
    {% if rule.product_filter_smarts %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" checked />
        <div class="collapse-title text-xl font-medium">
          Product Filter SMARTS
        </div>
        <div class="collapse-content">
          <p>{{ rule.product_filter_smarts }}</p>
        </div>
      </div>
    {% endif %}

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

    <!-- Scenarios -->
    {% if rule.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 rule.scenarios.all %}
              <li>
                <a href="{{ s.url }}" class="hover:bg-base-200">{{ s.name }}</a>
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

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

    <!-- Pathways -->
    {% if rule.related_pathways %}
      <div class="collapse-arrow bg-base-200 collapse">
        <input type="checkbox" />
        <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 rule.related_pathways %}
              <li>
                <a href="{{ r.url }}" class="hover:bg-base-200">{{ r.name }}</a>
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}

    {% if rule.enzymelinks %}
      <!-- EC Numbers -->
      <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">
          <div class="space-y-2">
            {% for k, v in rule.get_grouped_enzymelinks.items %}
              <div class="collapse-arrow bg-base-100 collapse">
                <input type="checkbox" checked />
                <div class="collapse-title text-lg font-medium">{{ k }}</div>
                <div class="collapse-content">
                  <ul class="menu bg-base-200 rounded-box">
                    {% for enzyme in v %}
                      <li>
                        <a href="{{ enzyme.url }}" class="hover:bg-base-300">
                          <div class="flex w-full items-center justify-between">
                            <span>{{ enzyme.ec_number }}</span>
                            <span class="text-sm opacity-70"
                              >{{ enzyme.linking_method }}</span
                            >
                          </div>
                          <div class="text-sm opacity-60">
                            {{ enzyme.name }}
                          </div>
                        </a>
                      </li>
                    {% endfor %}
                  </ul>
                </div>
              </div>
            {% endfor %}
          </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 %}
