{% extends "base.html" %}
{% block title %}nikola{% endblock %}

{% block content %}
  <div class="feed">
  <div class="card">
    <form method="post" enctype="multipart/form-data">
      <input type="hidden" name="action" value="create">
      <input name="title" required>
      <textarea name="body" rows="4" required></textarea>

      <input type="file" name="image" accept=".png,.jpg,.jpeg,.gif,.webp">
      <br>
      <label class="inline">
        <input type="checkbox" name="is_public">
        public
      </label>
      <br>

      <button type="submit">Создать</button>
    </form>
  </div>

  <br>

  {% for b in blocks %}
    <div class="card">
      <div class="row">
        <div>
          <strong>{{ b["id"] }}</strong> {{ b["title"] }}
          <p class="card-body">{{ b["body"] }}</p>

          {% if b["image_filename"] %}
            <img src="{{ url_for('static', filename='uploads/' ~ b['image_filename']) }}" alt="">
          {% endif %}
        </div>
        <br>
        <div class="muted">public={{ b["is_public"] }}</div>
        <div class="row-actions">
          <form method="post">
            <input type="hidden" name="action" value="toggle_public">
            <input type="hidden" name="block_id" value="{{ b['id'] }}">
            <button type="submit">Сделать public / private</button>
          </form>

          <form method="post" onsubmit="return confirm('Удалить блок?');">
            <input type="hidden" name="action" value="delete">
            <input type="hidden" name="block_id" value="{{ b['id'] }}">
            <button type="submit">Удалить</button>
          </form>
        </div>
      </div>
    </div>
  {% endfor %}
  </div>
{% endblock %}
