{% extends 'quotes/base.html' %}
{% load custom_tags_and_filters %}
{% block title %}Create Quote{% endblock %}
{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-12">
                <h2>Create New Quote</h2>
                <div class="card">
                    <div class="card-body">
                        <form method="post">
                            {% csrf_token %}
                            <div class="form-group">
                                <label for="id_name">Name</label>
                                <input type="text"
                                       class="form-control"
                                       id="id_name"
                                       name="name"
                                       required
                                       value="{{ form.name.value|default:'' }}">
                                {% if form.name.errors %}<div class="text-danger">{{ form.name.errors }}</div>{% endif %}
                            </div>
                            {% if configurations|length == 1 %}
                                <input type="hidden" name="configuration" value="{{ configurations.0.id }}">
                            {% else %}
                                <div class="form-group">
                                    <label for="configuration">Quote Configuration</label>
                                    <select name="configuration" id="configuration" class="form-control" required>
                                        <option value="">Select a configuration</option>
                                        {% for configuration in configurations %}
                                            <option value="{{ configuration.id }}" {% if selected_configuration == configuration %}selected{% endif %}>
                                                {{ configuration.name }}
                                            </option>
                                        {% endfor %}
                                    </select>
                                    {% if configuration_error %}<div class="text-danger">{{ configuration_error }}</div>{% endif %}
                                </div>
                            {% endif %}
                            <div class="form-group mt-4">
                                <button type="submit" class="btn btn-primary">Create Quote</button>
                                <a href="{% url 'quotes' %}" class="btn btn-secondary ml-2">Cancel</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
