{% extends "base.html" %}

{% block title %}New Blog Post{% endblock %}

{% block content %}

<!-- Hero -->
<section class="py-20 bg-gradient-to-br from-red-800 to-orange-400 text-white text-center">
  <h1 class="text-5xl font-extrabold mb-2">Create a New Blog Post</h1>
  <p class="text-lg">Share your thoughts, tutorials, or experiences with the world.</p>
</section>

<!-- Form -->
<section class="py-16 bg-black text-white">
  <div class="max-w-3xl mx-auto px-6 max-h-[85vh] overflow-y-auto">
    <form action="{{ url_for('new_blog') }}" method="post" enctype="multipart/form-data" class="space-y-6">

      <!-- Title -->
      <div>
        <label for="title" class="block font-semibold mb-1">Post Title</label>
        <input type="text" id="title" name="title" required
               class="text-black w-full border border-gray-300 rounded px-4 py-2 focus:ring-2 focus:ring-orange-400 focus:outline-none">
      </div>

      <!-- Content -->
      <div>
        <label for="content" class="block font-semibold mb-1">Post Content</label>
        <textarea id="content" name="content" required
          class="text-black w-full border border-gray-300 rounded px-4 py-2 leading-relaxed text-base focus:ring-2 focus:ring-orange-400 focus:outline-none resize-none overflow-hidden"
          rows="1"></textarea>
      </div>

      <!-- Category -->
      <div>
        <label for="category" class="block font-semibold mb-1">Category</label>
        <input type="text" id="category" name="category" placeholder="What's This Post About?"
               class="text-black w-full border border-gray-300 rounded px-4 py-2 focus:ring-2 focus:ring-orange-400 focus:outline-none">
      </div>

      <!-- Tags -->
      <div>
        <label for="tags" class="block font-semibold mb-1">Tags (comma-separated)</label>
        <input type="text" id="tags" name="tags" placeholder="e.g., Flask, SQLite, API"
               class="text-black w-full border border-gray-300 rounded px-4 py-2 focus:ring-2 focus:ring-orange-400 focus:outline-none">
      </div>

      <!-- Images -->
      <div>
        <label for="images" class="block font-semibold mb-1">Upload Images</label>
        <input type="file" name="images" id="images" multiple
               class="text-black w-full border border-gray-300 rounded px-3 py-2 text-gray-700 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:bg-orange-600 file:text-white hover:file:bg-orange-700">
      </div>

      <!-- Submit -->
      <div class="pt-4">
        <button type="submit"
                class="bg-orange-600 text-white px-6 py-2 rounded hover:bg-orange-700 transition">
          Submit Post
        </button>
      </div>
    </form>

    <!-- Back link -->
    <div class="mt-8 text-center">
      <a href="{{ url_for('blog') }}" class="text-blue-600 hover:underline">← Back to Blog</a>
    </div>
  </div>
</section>

<!-- Textarea autoresize -->
<script>
  document.addEventListener('DOMContentLoaded', function () {
    const textarea = document.getElementById('content');
    if (textarea) {
      const resize = () => {
        textarea.style.height = 'auto';
        textarea.style.height = textarea.scrollHeight + 'px';
      };
      resize(); // Initial sizing
      textarea.addEventListener('input', resize);
    }
  });
</script>

{% endblock %}

