<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>APS — New Post</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body { background: #f0f2f5; }
    .navbar { background: #fff; border-bottom: 1px solid #e5e7eb; }
  </style>
</head>
<body>

<nav class="navbar px-4 py-3 mb-4">
  <a href="<%= basePath %>/dashboard" class="text-decoration-none text-muted small">← Back to dashboard</a>
  <span class="fw-semibold text-dark ms-3">New Post</span>
  <a href="<%= basePath %>/logout" class="text-muted small text-decoration-none ms-auto">Sign out</a>
</nav>

<div class="container" style="max-width:680px">

  <% if (error) { %>
    <div class="alert alert-danger py-2 small"><%= error %></div>
  <% } %>

  <div class="card border-0 shadow-sm">
    <div class="card-body p-4">

      <form method="POST" action="<%= basePath %>/posts" enctype="multipart/form-data">

        <!-- Scheduled date/time -->
        <div class="mb-3">
          <label for="scheduledAt" class="form-label fw-medium">Scheduled date & time <span class="text-danger">*</span></label>
          <input type="datetime-local" id="scheduledAt" name="scheduledAt" class="form-control" required
                 min="<%= new Date(Date.now() + 5*60000).toISOString().slice(0,16) %>">
          <div class="form-text">Times are in your local timezone.</div>
        </div>

        <!-- Platforms -->
        <div class="mb-3">
          <label class="form-label fw-medium">Platforms <span class="text-danger">*</span></label>
          <div class="d-flex flex-wrap gap-3">
            <% platforms.forEach(p => { %>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" name="platforms" value="<%= p %>"
                       id="plat_<%= p %>" checked>
                <label class="form-check-label" for="plat_<%= p %>"><%= p %></label>
              </div>
            <% }) %>
          </div>
        </div>

        <!-- Content type -->
        <div class="mb-3">
          <label for="contentType" class="form-label fw-medium">Content type <span class="text-danger">*</span></label>
          <select id="contentType" name="contentType" class="form-select" required>
            <option value="">— Select —</option>
            <% contentTypes.forEach(ct => { %>
              <option value="<%= ct %>"><%= ct %></option>
            <% }) %>
          </select>
        </div>

        <!-- Caption -->
        <div class="mb-3">
          <label for="caption" class="form-label fw-medium">Caption</label>
          <textarea id="caption" name="caption" class="form-control" rows="4"
                    placeholder="Post caption (hashtags are added automatically at publish time)"></textarea>
        </div>

        <!-- Hooks / Overlay text -->
        <div class="mb-3">
          <label for="hooks" class="form-label fw-medium">Hooks / Overlay text</label>
          <textarea id="hooks" name="hooks" class="form-control" rows="2"
                    placeholder="For Level 1 posts: text rendered on the image. For events: countdown prefix."></textarea>
          <div class="form-text">Leave blank for standard posts.</div>
        </div>

        <!-- Media upload -->
        <div class="mb-4">
          <label for="media" class="form-label fw-medium">Image or video</label>
          <input type="file" id="media" name="media" class="form-control"
                 accept="image/jpeg,image/png,image/gif,image/webp,image/heic,video/mp4,video/quicktime,video/x-m4v">
          <div class="form-text">Accepted: JPEG, PNG, HEIC, WebP, MP4, MOV. Max 500 MB.</div>
        </div>

        <!-- Submit -->
        <div class="d-flex gap-2">
          <button type="submit" class="btn btn-primary">Schedule Post</button>
          <a href="<%= basePath %>/dashboard" class="btn btn-outline-secondary">Cancel</a>
        </div>

      </form>
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
