{% extends "framework_modern.html" %}

{% block content %}

  {% block action_modals %}
    {% include "modals/objects/edit_package_modal.html" %}
    {% include "modals/objects/edit_package_permissions_modal.html" %}
    {% include "modals/objects/publish_package_modal.html" %}
    {% include "modals/objects/set_license_modal.html" %}
    {% include "modals/objects/export_package_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">{{ package.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/package.html" %}
              {% endblock %}
            </ul>
          </div>
        </div>
        <p class="mt-2">{{ package.description|safe }}</p>
        <ul class="menu bg-base-200 rounded-box mt-4 w-full">
          <li>
            <a href="{{ package.url }}/pathway" class="hover:bg-base-300"
              >Pathways ({{ package.pathways.count }})</a
            >
          </li>
          <li>
            <a href="{{ package.url }}/rule" class="hover:bg-base-300"
              >Rules ({{ package.rules.count }})</a
            >
          </li>
          <li>
            <a href="{{ package.url }}/compound" class="hover:bg-base-300"
              >Compounds ({{ package.compounds.count }})</a
            >
          </li>
          <li>
            <a href="{{ package.url }}/reaction" class="hover:bg-base-300"
              >Reactions ({{ package.reactions.count }})</a
            >
          </li>
          <li>
            <a href="{{ package.url }}/model" class="hover:bg-base-300"
              >Models ({{ package.models.count }})</a
            >
          </li>
          <li>
            <a href="{{ package.url }}/scenario" class="hover:bg-base-300"
              >Scenarios ({{ package.scenarios.count }})</a
            >
          </li>
        </ul>
      </div>
    </div>
  </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 %}
