{% extends "framework_modern.html" %}
{% load static %}
{% load envipytags %}
{% block content %}
  <div class="space-y-2 p-4">
    <!-- Header Section -->
    <div class="card bg-base-100">
      <div class="card-body">
        <h2 class="card-title text-2xl">User Prediction Jobs</h2>
        <p class="mt-2">Job Logs Desc</p>
      </div>
    </div>

    <!-- Jobs -->
    <div class="collapse-arrow bg-base-200 collapse">
      <input type="checkbox" checked />
      <div class="collapse-title text-xl font-medium">Recent Jobs</div>
      <div class="collapse-content" id="job-content">
        <div class="overflow-x-auto">
          <table class="table-zebra table">
            <thead>
              <tr>
                {% if meta.user.is_superuser %}
                  <th>User</th>
                {% endif %}
                <th>ID</th>
                <th>Name</th>
                <th>Status</th>
                <th>Queued</th>
                <th>Done</th>
                <th>Result</th>
              </tr>
            </thead>
            <tbody>
              {% for job in jobs %}
                <tr>
                  {% if meta.user.is_superuser %}
                    <td>
                      <a href="{{ job.user.url }}">{{ job.user.username }}</a>
                    </td>
                  {% endif %}
                  <td>
                    <a href="{% url 'job detail' job.task_id %}"
                      >{{ job.task_id }}</a
                    >
                  </td>
                  <td>{{ job.job_name }}</td>
                  <td>{{ job.status }}</td>
                  <td>{{ job.created }}</td>
                  <td>{{ job.done_at }}</td>
                  {% if job.task_result and job.task_result|is_url == True %}
                    <td>
                      <a href="{{ job.task_result }}" class="link link-primary"
                        >Result</a
                      >
                    </td>
                  {% elif job.task_result %}
                    <td>{{ job.task_result|slice:"40" }}...</td>
                  {% else %}
                    <td>Empty</td>
                  {% endif %}
                </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
      </div>
    </div>

    {% if objects %}
      <!-- Unreviewable objects such as User / Group / Setting -->
      <div class="card bg-base-100 shadow-xl">
        <div class="card-body">
          <ul class="menu bg-base-200 rounded-box">
            {% for obj in objects %}
              {% if object_type == 'user' %}
                <li>
                  <a href="{{ obj.url }}" class="hover:bg-base-300"
                    >{{ obj.username }}</a
                  >
                </li>
              {% else %}
                <li>
                  <a href="{{ obj.url }}" class="hover:bg-base-300"
                    >{{ obj.name }}</a
                  >
                </li>
              {% endif %}
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}
  </div>
{% endblock content %}
