<div class="ebom_section_header">
    <div>Power Stations</div>
    <div id="add_new_power_station"
         class="clickable add_button">
        <i class="icon-plus"></i>Add power station
    </div>
</div>
<form name="power_station_form" action="" method="post" enctype="multipart/form-data">
    <div id="power_station_form"
         class="form_section ebom_form {{ 'hidden' if ebom_form.errors|count == 0 }}">
        {{ ebom_form.csrf_token }}
        {% for field in ebom_form.group('hidden') %}
            {{ field }}
        {% endfor %}
        {% for field in ebom_form.group('header') %}
            {% if field.type == 'BooleanField' %}
                {% include 'checkbox_form_row.html.jinja' %}
            {% else %}
                {% include 'form_row.html.jinja' %}
            {% endif %}
        {% endfor %}

        <div class="ebom_subsection">
            {% for field in ebom_form.group('inverter_quantity') %}
                {% include 'form_row.html.jinja' %}
            {% endfor %}
            {% for inverter_field in ebom_form.group('inverters') %}
                {% include 'inverter_form_row.html.jinja' %}
            {% endfor %}
        </div>
        <div class="ebom_subsection submit">
            <input type="submit" name="submit_button" class="button" value="Add">
            <a class="cancel_button button" href=".">Cancel</a>

            <div class="spacer"></div>

            <a class="delete_button button hidden" href="">Delete</a>
        </div>
    </div>
</form>
{% if context['power_stations']|length > 0 %}
    <div class="form_section">
        <table class="power_station_table">
            <tr>
                <th>Description</th>
                <th>Inverters</th>
                <th>DC Strings<br> Quantity</th>
                <th>Power Station<br> Quantity</th>
                <th></th>
            </tr>
            {% for power_station in context['power_stations'] %}
                <tr class="alternating_row_color">
                    <td>{{ power_station['power_station_description'] }}
                        {% if power_station_has_monitor(power_station, context['power_monitors']) %}
                            <br>
                            <span class="monitoring_tag">Monitoring</span>
                        {% endif %}
                    </td>
                    <td class="narrow_line">
                        {% for inverter_map in power_station['inverters'] %}
                            <p>{{ inverter_map['model'].label }}</p>
                        {% endfor %}
                    </td>
                    <td class="centered narrow_line">
                        {% for inverter_map in power_station['inverters'] %}
                            <p>{{ inverter_map['strings_per_inverter'] }}</p>
                        {% endfor %}
                    </td>
                    <td class="centered">{{ power_station['power_station_quantity'] }}</td>
                    <td>
                        <a href="{{ url_for('delete_power_station', uuid=power_station['power_station_id']) }}"
                           class="trash_can_link">

                            <i class="icon-trash"></i>
                        </a>
                        <i id="edit_{{ power_station['power_station_id'] }}" class="icon-pencil clickable"></i>
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
{% else %}
    <div class="ebom_form empty_state">
        <div>No Power Stations have been added yet.</div>
    </div>
{% endif %}

<div class="ebom_section_header">
    <div>Standalone Inverters</div>
    <div id="add_standalone_inverter" class="clickable add_button">
        <i class="icon-plus"></i>Add standalone inverter
    </div>
</div>
<form name="standalone_inverter_form" action="" method="post" enctype="multipart/form-data">
    <div id="standalone_inverter_form"
         class="form_section ebom_form {{ 'hidden' if standalone_inverter_form.errors|count == 0 }}">
        {{ standalone_inverter_form.csrf_token }}
        {% for field in standalone_inverter_form.group('hidden') %}
            {{ field }}
        {% endfor %}

        {% for inverter_field in standalone_inverter_form.group('inverters') %}
            {% set quantity = True %}
            {% include 'inverter_form_row.html.jinja' %}
        {% endfor %}
        {% for field in standalone_inverter_form.group('power_station') %}
            {% include 'form_row.html.jinja' %}
        {% endfor %}
        <div class="ebom_subsection submit">
            <input type="submit" name="submit_button" class="button" value="Add">
            <a class="cancel_button button" href=".">Cancel</a>

            <div class="spacer"></div>

            <a class="delete_button button hidden" href="">Delete</a>
        </div>
    </div>
</form>
{% if context['standalone_inverters']|length > 0 %}
    <div class="form_section">
        <table class="standalone_inverter_table">
            <tr>
                <th>Model</th>
                <th>Attachment Point</th>
                <th>DC Strings<br> Quantity</th>
                <th>Sun<br>Shade</th>
                <th>DC<br>Switch</th>
                <th></th>
            </tr>
            {% for inverter in context['standalone_inverters'] %}
                <tr class="alternating_row_color">
                    <td>{{ inverter['model'].label }}</td>
                    <td>{{ inverter['attachment_point'][0] }}</td>
                    <td class="centered">{{ inverter['strings_per_inverter'] }}</td>
                    <td><i class="icon-ok {{ 'hidden' if not inverter['sunshade'] }}"></i></td>
                    <td><i class="icon-ok {{ 'hidden' if not inverter['dc_switch'] }}"></i></td>
                    <td>
                        <a href="{{ url_for('delete_standalone_inverter', uuid=inverter['standalone_inverter_id']) }}"
                           class="trash_can_link">

                            <i class="icon-trash"></i>
                        </a>
                        <i id="edit_{{ inverter['standalone_inverter_id'] }}"
                           class="icon-pencil clickable"></i>
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
{% else %}
    <div class="ebom_form empty_state">
        No Standalone Inverters have been added yet.
    </div>
{% endif %}
<div class="ebom_section_header">
    <div>Monitoring</div>
    <div id="add_supervisor_monitor" class="clickable add_button">
        <i class="icon-plus"></i>Add Monitoring
    </div>
</div>
<form name="supervisor_monitor_form" action="" method="post" enctype="multipart/form-data">
    <div id="supervisor_monitor_form"
         class="form_section ebom_form {{ 'hidden' if supervisor_monitor_form.errors|count == 0 }}">
        {{ supervisor_monitor_form.csrf_token }}
        {% for field in supervisor_monitor_form.group('hidden') %}
            {{ field }}
        {% endfor %}

        {% for field in supervisor_monitor_form.group('power_source') %}
            {% include 'form_row.html.jinja' %}
        {% endfor %}
        <div class="ebom_subsection submit">
            <input type="submit" name="submit_button" class="button" value="Add">
            <a class="cancel_button button" href=".">Cancel</a>

            <div class="spacer"></div>

            <a class="delete_button button hidden" href="">Delete</a>
        </div>
    </div>
</form>
{% if context['power_monitors']|length > 0 %}
    <div class="form_section">
        <table class="supervisor_monitor_table">
            <tr>
                <th>Attachment Point</th>
                <th></th>
            </tr>
            {% for monitor in context['power_monitors'] %}
                <tr class="alternating_row_color">
                    <td>{{ monitor['power_source'][0] }}</td>
                    <td>
                        <a href="{{ url_for('delete_supervisor_monitor', uuid=monitor['monitor_id']) }}"
                           class="trash_can_link">

                            <i class="icon-trash"></i>
                        </a>
                        <i id="edit_{{ monitor['monitor_id'] }}"
                           class="icon-pencil clickable"></i>
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
{% else %}
    <div class="ebom_form empty_state">
        No Supervisor Monitors have been added yet.
    </div>
{% endif %}
