{{ define "home" -}}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>SQS Redriver</title>
        <link rel="stylesheet" href="/assets/styles.css"/>
        <link rel="stylesheet" href="/assets/bootstrap.min.css">
    </head>
    <body>
    <main class="container">
        <div class="container mt-5">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">Home</li>
                </ol>
            </nav>
        </div>

        <h1 class="text-3xl font-bold underline">SQS Queues
            {{ if .prefix }}
                matching prefix: {{ .prefix }}
            {{ end}}
        </h1>
        <table id="home-table" class="table">
            <caption>Having DLQs not allowing any source queue is a configuration anomaly.
                So is having a DLQ allowing a source queue and that source using another DLQ instead.
            </caption>
            <thead>
            <th scope="col">Queue name</th>
            <th scope="col">DLQ name</th>
            </thead>
            <tbody>
            {{ range .rows }}
                {{ template "home-row" . }}
            {{ end }}
            </tbody>
        </table>
    </main>
    </body>
    </html>
{{ end }}

{{ define "home-row" }}
    <tr>
        <td>{{ template "home-cell" (index . 0) }}</td>
        <td>{{ template "home-cell" (index . 1) }}</td>
    </tr>
{{ end }}

{{ define "home-cell" }}
    {{ if .Message }}
        <p class="lead">{{ .Message }}</p>
    {{else if .Link }}
        <a href="{{ .Link.URL }}">{{ .Link.Text }}</a>
    {{ else }}
        {{/* Bound queues: 3 named lists */}}
        {{ if eq (len .Links) 3 }}
            {{ if index .Links 0 }}
                <p class="lead">Bound queues</p>
            {{end }}
            <ul>
                {{ range index .Links 0 }}
                    <li><a href="{{ .URL }}">{{ .Text }}</a></li>
                {{ end }}
            </ul>
            {{ if index .Links 1 }}
                <p class="lead">Allowed source queues using another DLQ</p>
            {{end }}
            <ul>
                {{ range index .Links 1 }}
                    <li><a href="{{ .URL }}">{{ .Text }}</a></li>
                {{ end }}
            </ul>
            {{ if index .Links 2 }}
                <p class="lead">Allowed source queues not declaring a DLQ or with another prefix</p>
            {{ end}}
            <ul>
                {{ range index .Links 2 }}
                    <li><a href="{{ .URL }}">{{ .Text }}</a></li>
                {{ end }}
            </ul>
        {{ else }}
            {{ range .Links }}
                <ul>
                    {{ range . }}
                        <li><a href="{{ .URL }}">{{ .Text }}</a></li>
                    {{ end }}
                </ul>
            {{ end }}
        {{end}}
    {{ end }}
{{ end }}