{% extends "admin/base.html" %}

{% block title %}Edit Note - StarPunk Admin{% endblock %}

{% block admin_content %}
<div class="note-editor">
  <h2>Edit Note</h2>
  <p class="note-meta">
    Slug: <code>{{ note.slug }}</code> |
    Created: {{ note.created_at.strftime('%B %d, %Y at %I:%M %p') }}
  </p>

  <form action="{{ url_for('admin.update_note_submit', note_id=note.id) }}" method="POST" class="note-form">
    <div class="form-group">
      <label for="content">Content (Markdown)</label>
      <textarea
        id="content"
        name="content"
        rows="20"
        required
        autofocus
      >{{ note.content }}</textarea>
      <small>Use Markdown syntax for formatting</small>
    </div>

    <div class="form-group">
      <label for="slug">Slug (permanent)</label>
      <input type="text"
             id="slug"
             name="slug"
             value="{{ note.slug }}"
             readonly
             class="form-control"
             disabled>
      <small class="form-text text-muted">
        Slugs cannot be changed after creation to preserve permalinks.
      </small>
    </div>

    <div class="form-group">
      <label for="tags">Tags</label>
      <input type="text"
             id="tags"
             name="tags"
             value="{{ note.tags|map(attribute='display_name')|join(', ') if note.tags else '' }}"
             placeholder="Comma-separated tags (e.g., IndieWeb, Python, Thoughts)">
      <small>Separate multiple tags with commas. Leave blank to remove all tags.</small>
    </div>

    <div class="form-group form-checkbox">
      <input type="checkbox" id="published" name="published" {% if note.published %}checked{% endif %}>
      <label for="published">Published</label>
    </div>

    <div class="form-actions">
      <button type="submit" class="button button-primary">Update Note</button>
      <a href="{{ url_for('admin.dashboard') }}" class="button button-secondary">Cancel</a>
      <form action="{{ url_for('admin.delete_note_submit', note_id=note.id) }}" method="POST" class="delete-form" style="display: inline;" onsubmit="return confirm('Are you sure you want to delete this note? This cannot be undone.');">
        <input type="hidden" name="confirm" value="yes">
        <button type="submit" class="button button-danger">Delete Note</button>
      </form>
    </div>
  </form>
</div>
{% endblock %}

{% block head %}
{{ super() }}
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="{{ url_for('static', filename='js/preview.js') }}"></script>
{% endblock %}
