{{ template "header" . }}

<div class="vsp-overview pt-4 pb-3 mb-3">
    <div class="container">

        <div class="d-flex flex-wrap">
            <h1>Admin Panel</h1>
        </div>
        
        {{ template "vsp-stats" . }}

    </div>
</div>

<div class="container">
    <div class="row">

        <div class="col-12 pt-2 pb-4">
            <div class="block__content">

                <div class="tabset">
                    <input
                        type="radio"
                        name="tabset_1"
                        id="tabset_1_1"
                        hidden
                        {{ with .SearchResult }}{{ else }}checked{{ end }}
                    >
                    <input
                        type="radio"
                        name="tabset_1"
                        id="tabset_1_2"
                        hidden
                        {{ with .SearchResult }}checked{{ end }}
                    >
                    <input
                        type="radio"
                        name="tabset_1"
                        id="tabset_1_3"
                        hidden
                    >
                    <input
                        type="radio"
                        name="tabset_1"
                        id="tabset_1_4"
                        hidden
                    >
                    <ul>
                        <li><label for="tabset_1_1">VSP Status</label></li>
                        <li><label for="tabset_1_2">Ticket Search</label></li>
                        <li><label for="tabset_1_3">Database</label></li>
                        <li><label for="tabset_1_4">Logout</label></li>
                    </ul>
                    
                    <div>

                        <section class="d-flex row justify-content-center">

                            <div class="vsp-status">
                                <h1>Local dcrd</h1>

                                <table class="vsp-status">
                                    <thead>
                                        <th>URL</th>
                                        <th>Height</th>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>{{ stripWss .DcrdStatus.Host }}</td>
                                            
                                            {{ if .DcrdStatus.Connected }}
                    
                                                {{ if .DcrdStatus.BestBlockError }}
                                                    <td>
                                                        <div class="center">
                                                            <div class="status bad center with-text">
                                                                Error
                                                            </div>
                                                        </div>
                                                    </td>
                                                {{ else }}
                                                    <td>{{ .DcrdStatus.BestBlockHeight }}</td>
                                                {{ end }}
                    
                                            {{else}}
                                                <td>
                                                    <div class="center">
                                                        <div class="status bad center with-text">
                                                            Cannot connect
                                                        </div>
                                                    </div>
                                                </td>
                                            {{end}}
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            
                            <div class="vsp-status">
                                <h1>Voting Wallets</h1>

                                <table class="vsp-status">
                                    <thead>
                                        <th>URL</th>
                                        <th>Height</th>
                                        <th>Connected<br />to dcrd</th>
                                        <th>Unlocked</th>
                                        <th>Voting</th>
                                        <th>Vote<br />Version</th>
                                    </thead>
                                    <tbody>
                                        {{ range $host, $status := .WalletStatus }}
                                        <tr>
                                            <td>{{ stripWss $host }}</td>
                                        
                                            {{ if $status.Connected }}
                
                                                {{ if $status.BestBlockError }}
                                                    <td>
                                                        <div class="center">
                                                            <div class="status bad center with-text">
                                                                Error
                                                            </div>
                                                        </div>
                                                    </td>
                                                {{ else }}
                                                    <td>{{ $status.BestBlockHeight }}</td>
                                                {{ end }}
                
                                                {{ if $status.InfoError }}
                                                    <td colspan="4">
                                                        <div class="center">
                                                            <div class="status bad center with-text">
                                                                Error getting wallet info
                                                            </div>
                                                        </div>
                                                    </td>
                                                {{ else }}
                                                    <td>
                                                        <div class="center">
                                                            <div class="status {{ if $status.DaemonConnected }}good{{else}}bad{{end}}"></div>
                                                        </div>
                                                    </td>
                                                
                                                
                                                    <td>
                                                        <div class="center">
                                                            <div class="status {{ if $status.Unlocked }}good{{else}}bad{{end}}"></div>
                                                        </div>
                                                    </td>
                                                
                                                
                                                    <td>
                                                        <div class="center">
                                                            <div class="status {{ if $status.Voting }}good{{else}}bad{{end}}"></div>
                                                        </div>
                                                    </td>
                                                
                                                    <td>{{ $status.VoteVersion }}</td>
                                                {{ end }}
                
                                            {{else}}
                                                <td colspan="5">
                                                    <div class="center">
                                                        <div class="status bad center with-text">
                                                            Cannot connect to wallet
                                                        </div>
                                                    </div>
                                                </td>
                                            {{end}}
                                        </tr>
                                        {{end}}
                                    </tbody>
                                </table>
                            </div>

                        </section>
                        
                        <section>
                            <form class="mt-2 mb-4" action="/admin/ticket" method="post">
                                <input type="text" name="hash" size="64" minlength="64" maxlength="64" required placeholder="Ticket hash" autocomplete="off"
                                {{ with .SearchResult }}
                                value="{{ .Ticket.Hash }}"
                                {{ end }}>
                                <button class="btn btn-primary d-block my-2" type="submit">Search</button>
                            </form>
            
                            {{ with .SearchResult }}
                                {{ template "ticket-search-result" . }}
                            {{ end }}
                        </section>

                        <section>
                            <p>Database size: {{ .WebApiCache.DatabaseSize }}</p>
                            <a class="btn btn-primary" href="/admin/backup" download>Download Backup</a>
                        </section>

                        <section>
                            <form action="/admin/logout" method="post">
                                <button type="submit" class="btn btn-primary">Logout</button>
                            </form>
                        </section>

                    </div>
                </div>

            </div>
        </div>

    </div>
</div>

{{ template "footer" . }}
