{% extends 'base.html' %}

{% load form_creator_tags %}

{% block head %}
<title>Forms</title>
{% endblock %}

{% block content %}

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item active" aria-current="page">Forms</li>
  </ol>
</nav>

<div class="d-flex justify-content-between align-items-center">
  <h1>Forms</h1>

  {% if perms.form_creator.add_form %}
    <a class="btn btn-primary" href="{% url 'form_creator:form_create' %}">New Form</a>
  {% endif %}
</div>

  {% for object in object_list %}
<table class="table mt-5">
  <thead>
    <tr>
      <th scope="col">Title</th>
      <th scope="col">Status</th>
      <th scope="col">Start Time</th>
      <th scope="col">End Time</th>
      <th scope="col">Actions</th>
  </thead>
  <tbody>
    <tr>
      <td>
        <a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
      </td>
      <td>{{ object.get_status_display }}</td>
      <td>{{ object.start_dt }}</td>
      <td>{{ object.end_dt }}</td>
      <td>
        <a href="{{ object.get_absolute_url }}" class="btn btn-primary">
          View
        </a>
        {% if object|can_edit_form:request.user %}
        <a href="{{ object.get_edit_url }}" class="btn btn-primary">
          Edit
        </a>
        <a href="{{ object.get_edit_questions_url }}" class="btn btn-primary">
          Edit Questions
        </a>
        {% endif %}

        {% if object|can_delete_form:request.user %}
        <a href="{{ object.get_delete_url }}" class="btn btn-danger">
          Delete
        </a>
        {% endif %}

        {% if object|can_complete_form:request.user %}
        <a href="{{ object.get_respond_url }}" class="btn btn-primary">
          Start
        </a>
        {% endif %}
      </td>
    </tr>
  </tbody>
</table>
{% endfor %}

{% endblock %}