{{ define "ticket-search-result" }}

    {{ if .Found }}

        <hr />

        <h1>Ticket</h1>

        <table>
            <tr>
                <th>Hash</th>
                <td>
                    <a href="{{ txURL .Ticket.Hash }}">
                        {{ .Ticket.Hash }}
                    </a>
                </td>
            </tr>
            <tr>
                <th>Status</th>
                {{ if .Ticket.Confirmed }}
                    <td>
                        Confirmed (purchase height: 
                        <a href="{{ blockURL .Ticket.PurchaseHeight }}">{{ .Ticket.PurchaseHeight }}</a>)
                    </td>
                {{ else }}
                    <td>Not confirmed</td>
                {{ end }}
            </tr>
            <tr>
                <th>Ticket Outcome</th>
                <td>{{ .Ticket.Outcome }}</td>
            </tr>
            <tr>
                <th>Voting WIF</th>
                <td>{{ .Ticket.VotingWIF }}</td>
            </tr>
            <tr>
                <th>Commitment Address</th>
                <td>
                    <a href="{{ addressURL .Ticket.CommitmentAddress }}">
                        {{ .Ticket.CommitmentAddress }}
                    </a>
                </td>
            </tr>
        </table>

        <h1>Fee</h1>

        <table>
            <tr>
                <th>Fee Address</th>
                <td>
                    <a href="{{ addressURL .Ticket.FeeAddress }}">
                        {{ .Ticket.FeeAddress }}
                    </a>
                    (XPub ID: {{ .Ticket.FeeAddressXPubID }} Address: {{ .Ticket.FeeAddressIndex }})
                </td>
            </tr>
            <tr>
                <th>Fee Amount</th>
                <td>{{ atomsToDCR .Ticket.FeeAmount }}</td>
            </tr>
            <tr>
                <th>Fee Expiration</th>
                <td>{{ .Ticket.FeeExpiration }} ({{ dateTime .Ticket.FeeExpiration }}) </td>
            </tr>
            <tr>
                <th>Fee Tx Hash</th>
                <td>
                    <a href="{{ txURL .Ticket.FeeTxHash }}">
                        {{ .Ticket.FeeTxHash }}
                    </a>
                </td>
            </tr>
            <tr>
                <th>Fee Tx</th>
                <td>
                    {{ if .Ticket.FeeTxHex }}
                    <details>
                        <summary>Raw Bytes</summary>
                        <div class="small-text">
                            {{ .Ticket.FeeTxHex }}
                        </div>
                    </details>
                    <details>
                        <summary>Decoded</summary>
                        <div class="small-text">
                            <pre>{{ indentJSON .FeeTxDecoded }}</pre>
                        </div>
                    </details>
                    {{ end }}
                </td>
            </tr>
            <tr>
                <th>Fee Tx Status</th>
                <td>{{ .Ticket.FeeTxStatus }}</td>
            </tr>
        </table>

        <h1>Vote Choices</h1>
        
        <table>
            <tr>
                <th>Consensus Vote Choices</th>
                <td>
                    {{ range $key, $value := .Ticket.VoteChoices }}
                        {{ $key }}: {{ $value }} <br />
                    {{ end }}
                </td>
            </tr>
            <tr>
                <th>TSpend Policy</th>
                <td>
                    {{ range $key, $value := .Ticket.TSpendPolicy }}
                        {{ $key }}: {{ $value }} <br />
                    {{ end }}
                </td>
            </tr>
            <tr>
                <th>Treasury Policy</th>
                <td>
                    {{ range $key, $value := .Ticket.TreasuryPolicy }}
                        {{ $key }}: {{ $value }} <br />
                    {{ end }}
                </td>
            </tr>
            <tr>
                <th>
                    Vote Choice Changes<br />
                    <em>({{ .MaxVoteChanges }} most recent)</em>
                </th>
                <td>
                    {{ range $key, $value := .VoteChanges }}
                    <details>
                        <summary>
                            {{ if eq $key 0}}
                                Initial choices
                            {{ else }}
                                Change {{ $key }}
                            {{ end }}
                        </summary>
                        <table class="my-2">
                            <tr>
                                <th>Request</th>
                                <td><pre>{{ indentJSON $value.Request }}</pre></td>
                            </tr>
                            <tr>
                                <th>Request<br />Signature</th>
                                <td>{{ $value.RequestSignature }}</td>
                            </tr>
                            <tr>
                                <th>Response</th>
                                <td><pre>{{ indentJSON $value.Response }}</pre></td>
                            </tr>
                            <tr>
                                <th>Response<br />Signature</th>
                                <td>{{ $value.ResponseSignature }}</td>
                            </tr>
                        </table>
                    </details>
                    {{end}}
                </td>
            </tr>
        </table>

        <h1>Alternate Signing Address</h1>
        
        <table>
            <tr>
                <th>Alternate Signing Address</th>
                <td>
            {{if .AltSignAddrData}}
                    <a href="{{ addressURL .AltSignAddrData.AltSignAddr }}">
                        {{ .AltSignAddrData.AltSignAddr }}
                    </a>
            {{end}}
                </td>
            </tr>
            <tr>
                <th>
                    AltSignAddress Change 
                </th>
                <td>
                    {{if .AltSignAddrData}}
                    <details>
                        <table class="my-2">
                            <tr>
                                <th>Request</th>
                                <td><pre>{{ indentJSON .AltSignAddrData.Req }}</pre></td>
                            </tr>
                            <tr>
                                <th>Request<br />Signature</th>
                                <td>{{ .AltSignAddrData.ReqSig }}</td>
                            </tr>
                            <tr>
                                <th>Response</th>
                                <td><pre>{{ indentJSON .AltSignAddrData.Resp }}</pre></td>
                            </tr>
                            <tr>
                                <th>Response<br />Signature</th>
                                <td>{{ .AltSignAddrData.RespSig }}</td>
                            </tr>
                        </table>
                    </details>
                    {{end}}
                </td>
            </tr>
        </table>

    {{ else }}
        <p class="vsp-text-orange">No ticket found with hash <span class="code">{{ .Hash }}</span></p>
    {{ end }}
{{ end }}
