<!--
Copyright 2025 XTX Markets Technologies Limited

SPDX-License-Identifier: GPL-2.0-or-later
-->

{{define "body"}}
    <table class="table">
        <tbody>
            {{if .Path}}
                <tr>
                    <th>Path</th>
                    <td>
                        <code>
                            <a href="/browse">/</a>
                            {{range $segment := .PathSegments}}
                                {{if eq $segment.PathSoFar $.Path}}
                                    <a href="{{$.DirectoryLink}}">{{$segment.Segment}}</a>
                                {{else}}
                                    <a href="/browse{{$segment.PathSoFar}}">{{$segment.Segment}}</a> /
                                {{end}}
                            {{end}}
                        </code>
                    </td>
                </tr>
            {{end}}
            <tr>
                <th>Id</th>
                <td><code>{{.Id}}</code></td>
            </tr>
            <tr>
                <th>Size</th>
                <td><code>{{.Size}}</code></td>
            </tr>
            <tr>
                <th>Mtime</th>
                <td><code>{{.Mtime}}</code></td>
            </tr>
            {{if .Atime}}
                <tr>
                    <th>Atime</th>
                    <td><code>{{.Atime}}</code></td>
                </tr>
            {{end}}
            <tr>
                <th>Transient</th>
                <td>
                    {{if .TransientNote}}
                        Yes
                    {{else}}
                        No
                    {{end}}
                </td>
            </tr>
            {{if .TransientNote}}
                <tr>
                    <th>Note</th>
                    <td>{{.TransientNote}}</td>
                </tr>
            {{end}}
            <tr>
                <td><a href="{{.DownloadLink}}">Download</a></td>
            </tr>
        </tbody>
    </table>
    <h2>Spans</h2>
    <table class="table table-striped">
        <thead>
            <tr>
                <th class="text-end">Offset</th>
                <th class="text-end">Size</th>
                <th>Crc</th>
                <th>Storage</th>
                {{if not $.AllInline}}
                    <th class="text-end">Stripes</th>
                    <th class="text-end">CellSize</th>
                {{end}}
                <th>Body</th>
            </tr>
        </thead>
        <tbody>
            {{range $span := .Spans}}
                <tr>
                    <td class="text-end">{{$span.Offset}}</td>
                    <td class="text-end">{{$span.Size}}</td>
                    <td><code>{{$span.Crc}}</code></td>
                    <td>{{$span.StorageClass}}</td>
                    {{if not $.AllInline}}
                        <td class="text-end">
                            {{if $span.Stripes}}
                                {{$span.Stripes}}
                            {{end}}
                        </td>
                        <td class="text-end">
                            {{if $span.CellSize}}
                                {{$span.CellSize}}
                            {{end}}
                        </td>
                    {{end}}
                    <td>
                        <small>
                            {{if $span.BodyBytes}}
                                <code>{{$span.BodyBytes}}</code>
                            {{else}}
                                <table class="table table-sm mb-0">
                                    <thead>
                                        <tr>
                                            <th></th>
                                            <th colspan="{{$span.DataBlocks}}">
                                                data
                                            </th>    
                                            <th colspan="{{$span.ParityBlocks}}">
                                                parity
                                            </th>    
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <th>Id</th>
                                            {{range $block := $span.BodyBlocks}}
                                                <td>
                                                    <a href="{{$block.Link}}"><code>{{$block.Id}}</code></a>
                                                </td>
                                            {{end}}
                                        </tr>
                                        <tr>
                                            <th>Crc</th>
                                            {{range $block := $span.BodyBlocks}}
                                                <td><code>{{$block.Crc}}<code></td>
                                            {{end}}
                                        </tr>
                                        <tr>
                                            <th>BlockService</th>
                                            {{range $block := $span.BodyBlocks}}
                                                <td><a href="/#bs-{{$block.BlockService}}" title="{{$block.Hosts}}"><code>{{$block.BlockService}}</code></a></td>
                                            {{end}}
                                        </tr>
                                    </tbody>
                                </table>    
                            {{end}}
                        </small>
                    </td>
                </tr>
            {{end}}
        </tbody>
    </table>
{{end}}