{% extends "pi_fyad/base.html" %}
{% load pi_fyad_tags %}

{% block pi_content %}

<nav aria-label="breadcrumb" class="mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'pi_fyad:template_list' %}">Templates</a></li>
        <li class="breadcrumb-item active">Create Template</li>
    </ol>
</nav>

<div class="row">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-plus-circle me-2"></i>Create Planet Template</h5>
            </div>
            <div class="card-body">
                <form method="post" id="template-form">
                    {% csrf_token %}

                    {% if form.errors %}
                    <div class="alert alert-danger">
                        <strong>Please fix the errors below:</strong>
                        <ul class="mb-0 mt-2">
                            {% for field, errors in form.errors.items %}
                            {% for error in errors %}
                            <li>{{ field|title }}: {{ error }}</li>
                            {% endfor %}
                            {% endfor %}
                        </ul>
                    </div>
                    {% endif %}

                    <div class="mb-3">
                        <label for="{{ form.name.id_for_label }}" class="form-label">Template Name</label>
                        {{ form.name }}
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.description.id_for_label }}" class="form-label">Description</label>
                        {{ form.description }}
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="{{ form.planet_type_id.id_for_label }}" class="form-label">Planet Type</label>
                            {{ form.planet_type_id }}
                        </div>
                        <div class="col-md-6">
                            <label for="{{ form.visibility.id_for_label }}" class="form-label">Visibility</label>
                            {{ form.visibility }}
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.clipboard_raw.id_for_label }}" class="form-label">
                            PI Clipboard Export
                        </label>
                        {{ form.clipboard_raw }}
                        <div class="form-text">
                            In EVE: open your planet view, select all pins, and use the export/copy function.
                            Paste the result here.
                        </div>
                    </div>

                    <div class="d-flex justify-content-between">
                        <a href="{% url 'pi_fyad:template_list' %}" class="btn btn-outline-secondary">
                            <i class="fas fa-arrow-left me-1"></i>Cancel
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-1"></i>Create Template
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-lg-4">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0"><i class="fas fa-info-circle me-2"></i>How It Works</h6>
            </div>
            <div class="card-body small">
                <ol>
                    <li>Open your planet in EVE</li>
                    <li>Export your PI setup to clipboard</li>
                    <li>Paste the clipboard text in the field</li>
                    <li>Choose a name, planet type, and visibility</li>
                    <li>Click Create — others can then copy your setup</li>
                </ol>
            </div>
        </div>
    </div>
</div>

{% endblock %}
