{% extends "frontend/base.html" %}
{% load i18n %}
{% load static %}
{% load partials %}
{% block html_title %}
    {% block page_title %}
        {% block title %}
            {% blocktranslate with instance_name=instance.display_name organization_name=request.organization.name %}Update {{ instance_name }} in {{ organization_name }}{% endblocktranslate %}
        {% endblock %}
    {% endblock page_title %}
{% endblock html_title %}
{% block page_title_extra %}
    <a href="{{ instance.urls.base }}" class="btn btn-secondary me-1 mb-1">{% translate "Back" %}</a>
{% endblock page_title_extra %}
{% partialdef service-form %}
{% if form or custom_form %}
    <div class="card">
        <div class="card-header d-flex align-items-center"></div>
        <div class="card-body">
            {% if form_error %}
                <div class="alert alert-danger">
                    {% translate "Oops! Something went wrong with the service form generation. Please try again later." %}
                </div>
            {% else %}
                {% translate "Update" as update_label %}
                {% include "includes/tabbed_fieldset_form.html" with form=custom_form expert_form=form form_submit_label=update_label hide_form_errors=True %}
            {% endif %}
        </div>
    </div>
{% endif %}
{% endpartialdef %}
{% block content %}
    <section class="section">
        <form class="form form-vertical crd-form" method="post" novalidate>
            {% csrf_token %}
            {% if plan_form.errors or form.errors or custom_form.errors %}
                <div class="row mt-3">
                    <div class="col-12">
                        {% include "frontend/forms/errors.html" with form=plan_form %}
                        {% if form %}
                            {% include "frontend/forms/errors.html" with form=form %}
                        {% endif %}
                        {% if custom_form %}
                            {% include "frontend/forms/errors.html" with form=custom_form %}
                        {% endif %}
                    </div>
                </div>
            {% endif %}
            <!-- Compute Plan Selection -->
            {% if plan_form %}
                <div class="card mb-3">
                    <div class="card-header">
                        <h5 class="mb-0">{% translate "Compute Plan" %}</h5>
                    </div>
                    <div class="card-body">
                        {% include "includes/plan_selection.html" with plan_form=plan_form storage_plan=storage_plan %}
                    </div>
                </div>
            {% endif %}
            <!-- Service Form -->
            <div class="card">
                {% if not form and not custom_form %}
                    <div class="alert alert-warning" role="alert">
                        {% translate "Cannot update this service instance because its details could not be retrieved from the underlying system. It might have been deleted externally." %}
                    </div>
                {% else %}
                    <div id="service-form">{% partial service-form %}</div>
                {% endif %}
            </div>
        </form>
    </section>
{% endblock content %}
