<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <!--[if mso]><table width="600" align="center"><tr><td><![endif]-->
        <table align="center"
               style="width:100%;
                      max-width:600px;
                      font-family: 'Avenir Next', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif'">
            <tr>
                <td align="center"
                    style="color: white;
                           background: #5bc0de;
                           margin: 0;
                           padding: 50px 0"
                    bgcolor="#5bc0de">
                    <h1 style="max-width: 90%; margin: 0 auto; padding: 0;">
                        {% if not projects|length_is:1 %}
                            Projects expiring!
                        {% else %}
                            Project expiring in {{ projects.0.projectbillingdetails.expires_on|timeuntil:today }}!
                        {% endif %}
                    </h1>
                </td>
            </tr>
            <tr>
                <td style="padding: 10px;">
                    <p>Dear PI,</p>
                    <p>
                        {% if not projects|length_is:1 %}
                            The following projects are set to expire soon:
                        {% else %}
                            Your project {{ projects.0.projectbillingdetails.name }} is set to expire on {{ projects.0.projectbillingdetails.expires_on }}.
                        {% endif %}
                    </p>
                    {% if projects %}
                        {% regroup projects by projectbillingdetails.expires_on as projects_by_expiration %}
                        {% for project_by_expiration in projects_by_expiration %}
                            in {{ project_by_expiration.grouper|timeuntil:today }} ({{ project_by_expiration.grouper }}):
                            <ul>
                                {% for project in project_by_expiration.list %}<li>{{ project.projectbillingdetails.name }}</li>{% endfor %}
                            </ul>
                        {% endfor %}
                    {% endif %}
                    <p>Please contact the facility accounting department to make sure you don't lose access to the facility.</p>
                </td>
            </tr>
        </table>
        <!--[if mso]></td></tr></table><![endif]-->
    </body>
</html>
