{% extends "frontend/base.html" %}
{% load i18n static %}
{% load partials %}
{% block html_title %}
    {% block page_title %}
        {% translate "Organization Details" %}
    {% endblock page_title %}
{% endblock html_title %}
{% partialdef org-name %}
<td>
    {{ form.instance.name }}
    {% if has_change_permission %}
        <button class="btn btn-primary"
                hx-get="{{ request.path }}?fragment=org-name-edit&hx-single-field=name"
                hx-target="closest td"
                hx-swap="outerHTML">{% translate "Edit" %}</button>
    {% endif %}
</td>
{% endpartialdef org-name %}
{% partialdef org-name-edit %}
<td>
    <form hx-target="closest td"
          hx-swap="outerHTML"
          hx-post="{{ request.url }}">
        <div class="d-flex align-items-baseline">
            {{ form.name.as_field_group }}
            <input type="hidden" name="hx-single-field" value="name">
            <input type="hidden" name="fragment" value="org-name">
            <button type="submit" class="btn btn-primary mx-1">{% translate "Save" %}</button>
            <button type="button"
                    class="btn btn-secondary"
                    hx-get="{{ request.path }}?fragment=org-name"
                    hx-target="closest td"
                    hx-swap="outerHTML">{% translate "Cancel" %}</button>
        </div>
    </form>
</td>
{% endpartialdef org-name-edit %}
{% block content %}
    <section class="section">
        <div class="card">
            <div class="card-content">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-lg">
                            <tbody>
                                <tr>
                                    <th class="w-25">
                                        <span class="d-flex mt-2">{% translate "Name" %}</span>
                                    </th>
                                    {% partial org-name %}
                                </tr>
                                <tr>
                                    <th class="w-25">
                                        <span class="d-flex mt-2">{% translate "Namespace" %}</span>
                                    </th>
                                    <td>
                                        <div>{{ form.instance.namespace }}</div>
                                        <small class="text-muted">{% translate "System-generated namespace for Kubernetes resources." %}</small>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        {% if form.instance.billing_entity and form.instance.billing_entity.odoo_data.invoice_address %}
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title">{% translate "Billing Address" %}</h4>
                </div>
                <div class="card-content">
                    <div class="card-body">
                        {% with odoo_data=form.instance.billing_entity.odoo_data %}
                            <div class="table-responsive">
                                <table class="table table-lg">
                                    <tbody>
                                        {% if odoo_data.invoice_address %}
                                            <tr>
                                                <th class="w-25">
                                                    <span class="d-flex mt-2">{% translate "Invoice Contact Name" %}</span>
                                                </th>
                                                <td>{{ odoo_data.invoice_address.name|default:"" }}</td>
                                            </tr>
                                            <tr>
                                                <tr>
                                                    <th class="w-25">
                                                        <span class="d-flex mt-2">{% translate "Street" %}</span>
                                                    </th>
                                                    <td>{{ odoo_data.invoice_address.street|default:"" }}</td>
                                                </tr>
                                                {% if odoo_data.invoice_address.street2 %}
                                                    <tr>
                                                        <th class="w-25">
                                                            <span class="d-flex mt-2">{% translate "Street 2" %}</span>
                                                        </th>
                                                        <td>{{ odoo_data.invoice_address.street2 }}</td>
                                                    </tr>
                                                {% endif %}
                                                <tr>
                                                    <th class="w-25">
                                                        <span class="d-flex mt-2">{% translate "City" %}</span>
                                                    </th>
                                                    <td>{{ odoo_data.invoice_address.city|default:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <th class="w-25">
                                                        <span class="d-flex mt-2">{% translate "ZIP Code" %}</span>
                                                    </th>
                                                    <td>{{ odoo_data.invoice_address.zip|default:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <th class="w-25">
                                                        <span class="d-flex mt-2">{% translate "Country" %}</span>
                                                    </th>
                                                    <td>{{ odoo_data.invoice_address.country_id.1|default:"" }}</td>
                                                </tr>
                                                <th class="w-25">
                                                    <span class="d-flex mt-2">{% translate "Invoice Email" %}</span>
                                                </th>
                                                <td>{{ odoo_data.invoice_address.email|default:"" }}</td>
                                            </tr>
                                        {% endif %}
                                    </tbody>
                                </table>
                            </div>
                        {% endwith %}
                    </div>
                </div>
            </div>
        {% endif %}
    </section>
{% endblock content %}
