{% extends "admin_base.html" %} {% block content %}
<h1>Manage Blogs</h1>

<a href="{{ url_for('admin_blueprint.add_blog') }}" class="btn btn-primary mb-3"
  >Add New Blog Post</a
>

<table class="table">
  <thead>
    <tr>
      <th>Title</th>
      <th>Created At</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    {% for blog in blogs %}
    <tr>
      <td>{{ blog.title }}</td>
      <td>{{ blog.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
      <td>
        <a
          href="{{ url_for('admin_blueprint.edit_blog', id=blog.id) }}"
          class="btn btn-sm btn-primary"
          >Edit</a
        >
        <form
          action="{{ url_for('admin_blueprint.delete_blog', id=blog.id) }}"
          method="POST"
          class="d-inline"
        >
          <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
          <button
            type="submit"
            class="btn btn-sm btn-danger"
            onclick="return confirm('Are you sure you want to delete this blog post?')"
          >
            Delete
          </button>
        </form>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
