<html>
    <head>
        <style>
            {{ log_css }}
        </style>
    </head>

    <body style="font-size: 14px">
        <h1>An LVM LN<sub>2</sub> fill was completed successfully.</h1>

        {% if lvmweb_url %}
            <div style="padding: 5px 0px">
                Information about the fill can be found at <a href="{{ lvmweb_url }}">this link</a>. Grafana plots are available <a href="{{ grafana_url }}">here</a>.
            </div>
        {% endif %}

        <div style="padding-top: 20px; font-weight: 600">Events</div>
        <hr/>
        <div style="padding: 5px 20px">
            <table style="border-spacing: 5px 10px; border: 0px solid">
                <tr>
                    <td>Time at the start of the purge</td>
                    <td style="padding-left: 20px">{{ event_times.purge_start.strftime('%H:%M:%S') if event_times.purge_start }}</td>
                </tr>
                <tr>
                    <td>Time at the end of the purge</td>
                    <td style="padding-left: 20px">{{ event_times.purge_complete.strftime('%H:%M:%S') if event_times.purge_complete }}</td>
                </tr>
                <tr>
                    <td>Time at the start of the fill</td>
                    <td style="padding-left: 20px">{{ event_times.fill_start.strftime('%H:%M:%S') if event_times.fill_start }}</td>
                </tr>
                <tr>
                    <td>Time at the end of the fill</td>
                    <td style="padding-left: 20px">{{ event_times.fill_complete.strftime('%H:%M:%S') if event_times.fill_complete }}</td>
                </tr>
                <tr>
                    <td>Time when the purge or fill failed</td>
                    <td style="padding-left: 20px">{{ event_times.fail_time.strftime('%H:%M:%S') if event_times.fail_time }}</td>
                </tr>
                <tr>
                    <td>Time when the purge or fill was aborted</td>
                    <td style="padding-left: 20px">{{ event_times.abort_time.strftime('%H:%M:%S') if event_times.abort_time }}</td>
                </tr>
            </table>
        </div>

        <div style="padding-top: 20px; font-weight: 600">Cryostat status</div>
        <hr/>
        {% if spec_data %}
            <div style="padding: 5px 20px">
                <table style="border-spacing: 10px 10px; border: 0px solid; font-family: monospace">
                    <tr>
                        <th>Cryostat</th>
                        <th>CCD temp. (C)</th>
                        <th>LN<sub>2</sub> temp. (C)</th>
                        <th>Pressure (torr)</th>
                    </tr>
                    {% for cryostat in spec_data %}
                        <tr>
                            <td style="text-align: center">{{ cryostat }}</td>
                            {% for key, value in spec_data[cryostat].items() %}
                                <td style="padding-left: 20px">
                                    {% if key == "ccd" or key == "ln2" %}
                                        {{ value | round(1) }}</td>
                                    {% else %}
                                        {{ "{:.2e}".format(value) }}
                                    {% endif %}
                                </td>
                            {% endfor %}
                        </tr>
                    {% endfor %}
                </table>
            </div>
        {% else %}
            <div style="padding-top: 20px">Cryostat data was not available at the time of sending this email.</div>
        {% endif %}

        <div style="padding-top: 20px; font-weight: 600">Valve open times</div>
        <hr/>
        {% if valve_data %}
            <div style="padding: 5px 20px">
                <table style="border-spacing: 10px 10px; border: 0px solid; font-family: monospace">
                    <tr>
                        <th>Valve</th>
                        <th>Open</th>
                        <th>Closed</th>
                        <th>Elapsed</th>
                        <th>Therm. after</th>
                        <th>Timed out?</th>
                    </tr>
                    {% for valve, data in valve_data.items() %}
                        <tr>
                            <td style="text-align: center">{{ valve }}</td>
                            <td style="padding-left: 20px">{{ data.open_time.strftime('%H:%M:%S') if data.open_time }}</td>
                            <td style="padding-left: 20px">{{ data.close_time.strftime('%H:%M:%S') if data.close_time }}</td>
                            <td style="padding-left: 20px">{{ "{:.1f}".format(data.elapsed) if data.elapsed }}</td>
                            <td style="padding-left: 20px">{{ "{:.1f}".format(data.thermistor_after) if data.thermistor_after }}</td>
                            <td style="padding-left: 20px">{{ "Y" if data.timed_out else "" }}</td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        {% else %}
            <div style="padding-top: 20px">Valve times were not available at the time of sending this email.</div>
        {% endif %}

        <div style="padding-top: 20px; font-weight: 600">Log stream</div>
        <hr/>
        {% if log_lines %}
            <pre style="padding: 0px 20px; font-family: monospace !important">
                {% for line in log_lines -%}
                    {{ line }}
                {%- endfor %}
            </pre>
        {% else %}
            <div style="padding-top: 20px">Log stream was not available at the time of sending this email.</div>
        {% endif %}

        <div style="padding-top: 20px; font-weight: 600">Images</div>
        <hr/>
        {% if has_images %}
        <div style="text-align:center;width:100%">
            <img src="cid:temps" style="width: 80%"/>
            <img src="cid:pressure" style="width: 80%"/>
            <img src="cid:thermistors" style="width: 80%"/>
        </div>
        {% else %}
            <div style="padding-top: 20px">No images were provided.</div>
        {% endif %}

    </body>

</html>
