@using RazorLight
@inherits TemplatePage<Elwig.Documents.MemberList>
@model Elwig.Documents.MemberList
@{ Layout = "Document"; }
<link rel="stylesheet" href="file:///@Raw(Model.DataPath)\resources\MemberList.css"/>
<main>
    <h1>Mitgliederliste</h1>
    <h2>@Model.Filter</h2>
    <table class="members">
        <colgroup>
            <col style="width: 8mm;"/>
            <col style="width: 42mm;"/>
            <col style="width: 40mm;"/>
            <col style="width:  8mm;"/>
            <col style="width: 20mm;"/>
            <col style="width: 12mm;"/>
            <col style="width:  5mm;" />
            <col style="width: 18mm;"/>
            <col style="width: 12mm;"/>
        </colgroup>
        <thead>
            <tr>
                <th rowspan="2">Nr.</th>
                <th rowspan="2" style="text-align: left;">Name</th>
                <th rowspan="2" style="text-align: left;">Adresse</th>
                <th rowspan="2">PLZ</th>
                <th rowspan="2" style="text-align: left;">Ort</th>
                <th rowspan="2">Betr.-Nr.</th>
                <th rowspan="2">GA</th>
                <th rowspan="2" style="text-align: left;">Stamm-KG</th>
                <th>Geb. Fl.</th>
            </tr>
            <tr>
                <th class="unit">[m²]</th>
            </tr>
        </thead>
        <tbody class="small">
            @{
                string? lastBranch = Model.Members.Select(m => m.Branch).Distinct().Count() == 1 ? null : "";
            }
            @foreach (var m in Model.Members) {
                if (lastBranch != null && m.Branch != lastBranch) {
                    <tr class="spacing"><td colspan="9"></td></tr>
                    <tr class="header">
                        <th colspan="9">@m.Branch</th>
                    </tr>
                    lastBranch = m.Branch;
                }
                <tr>
                    <td class="number" rowspan="@(m.BillingName != null ? 2 : 1)">@m.MgNr</td>
                    <td>@m.Name.Replace('ß', 'ẞ').ToUpper() @m.GivenName</td>
                    <td>@m.Address</td>
                    <td>@m.Plz</td>
                    <td class="tiny">@m.Locality</td>
                    <td>@m.LfbisNr</td>
                    <td class="number">@m.BusinessShares</td>
                    <td class="tiny">@m.DefaultKg</td>
                    <td class="number">@($"{m.AreaCommitment:N0}")</td>
                </tr>
                if (m.BillingName != null) {
                    <tr>
                        <td>@m.BillingName</td>
                        <td>@m.BillingAddress</td>
                        <td>@m.BillingPlz</td>
                        <td class="tiny">@m.BillingLocality</td>
                        <td colspan="4"></td>
                    </tr>
                }
            }
        </tbody>
    </table>
</main>
