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

{% block title %}{{ "Edit" if page else "New" }} Page - Admin - {{ site_name() }}{% endblock %}

{% block admin_content %}
<hgroup>
    <h1>{{ "Edit" if page else "New" }} Page</h1>
    <p>{{ "Update page details" if page else "Create a new page" }}</p>
</hgroup>

<form method="post" action="{{ '/admin/pages/' ~ page.id ~ '/edit' if page else '/admin/pages/new' }}">
    <label for="title">Title</label>
    <input type="text" id="title" name="title" value="{{ page.title if page else '' }}" required>

    <label for="slug">Slug</label>
    <input type="text" id="slug" name="slug" value="{{ page.slug if page else '' }}" required placeholder="e.g., about or services/consulting">
    <small class="sk-text-muted">The URL path for this page (e.g., "about" becomes /about)</small>

    <label for="content">Content</label>
    <textarea id="content" name="content" rows="15">{{ page.content if page else '' }}</textarea>

    <fieldset class="form-group">
        <legend>Publication</legend>

        <label>
            <input type="checkbox" name="is_published" {% if page and page.is_published %}checked{% endif %}>
            Published
        </label>

        <label for="order">Display Order</label>
        <input type="number" id="order" name="order" value="{{ page.order if page else 0 }}" min="0">
        <small class="sk-text-muted">Lower numbers appear first (default: 0)</small>

        <label for="publish_at">Schedule Publish</label>
        <input type="datetime-local" id="publish_at" name="publish_at" value="{{ page.publish_at.strftime('%Y-%m-%dT%H:%M') if page and page.publish_at else '' }}">
        <small class="sk-text-muted">Leave empty to publish immediately when published is checked</small>
    </fieldset>

    <details class="seo-settings">
        <summary>SEO Settings</summary>
        <fieldset>
            <label for="meta_description">Meta Description</label>
            <textarea id="meta_description" name="meta_description" rows="3" maxlength="320" placeholder="Brief description for search engines (max 320 chars)">{{ page.meta_description if page else '' }}</textarea>

            <label for="meta_robots">Meta Robots</label>
            <select id="meta_robots" name="meta_robots">
                <option value="">Default (index, follow)</option>
                <option value="noindex" {% if page and page.meta_robots == 'noindex' %}selected{% endif %}>noindex</option>
                <option value="nofollow" {% if page and page.meta_robots == 'nofollow' %}selected{% endif %}>nofollow</option>
                <option value="noindex, nofollow" {% if page and page.meta_robots == 'noindex, nofollow' %}selected{% endif %}>noindex, nofollow</option>
            </select>

            <label for="og_title">OpenGraph Title</label>
            <input type="text" id="og_title" name="og_title" value="{{ page.og_title if page else '' }}" placeholder="Custom title for social sharing (uses page title if empty)">

            <label for="og_description">OpenGraph Description</label>
            <textarea id="og_description" name="og_description" rows="2" placeholder="Custom description for social sharing">{{ page.og_description if page else '' }}</textarea>

            <label for="og_image">OpenGraph Image URL</label>
            <input type="url" id="og_image" name="og_image" value="{{ page.og_image if page else '' }}" placeholder="https://example.com/image.jpg">
        </fieldset>
    </details>

    <div class="sk-form-actions">
        <button type="submit">{{ "Update" if page else "Create" }} Page</button>
        <a href="/admin/pages" role="button" class="sk-btn-outline">Cancel</a>
        {% if page %}
        <a href="/admin/pages/{{ page.id }}/revisions" role="button" class="sk-btn-outline">View History</a>
        {% endif %}
    </div>
</form>
{% endblock %}
