@model dynamic
@{
    ViewBag.Title = $"Address {Model.Address}";
    Layout = "_Layout";
    ViewBag.Query = Model.Address;
}
@section Style
{
    <style>
        #crafted {
            position: relative;
            color: #111111;
        }
    </style>
}
<partial name="SearchBlock" model="@(new SearchBlockExplorer())" />
<section class="block-explorer-section section bg-bottom">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div class="center-heading">
                    <h2 class="section-title">Details for Address</h2>
                </div>
            </div>
        </div>			
        <div class="row m-bottom-70">
            <div class="col-lg-9 col-md-9 col-sm-12">
                <div class="table-responsive">
                    <table class="table table-striped table-latests table-detail">
                        <tbody>
                            <tr>
                                <td><strong>Address</strong></td>
                                <td>
                                    <a class="to-copy" asp-controller="BlockExplorer" asp-action="Address" asp-route-address="@Model.Address">@Model.Address</a>
                                    <a href="#" data-value="@Model.Address" class="copy-me"><i class="fa fa-copy"></i></a>
                                </td>
                            </tr>
                            <tr>
                                <td><strong>No. Transactions</strong></td>
                                <td>@Model.Transactions.Count</td>
                            </tr>
                            <tr>
                                <td><strong>Balance</strong></td>
                                <td>@Model.Balance.ToString("N8") @Model.CoinTag</td>
                            </tr>
                            
                            <tr>
                                <td><strong>Unconfirmed Balance</strong></td>
                                <td>@Model.UnconfirmedBalance.ToString("N8") @Model.CoinTag</td>
                            </tr>
                            <tr>
                                <td><strong>Total Received</strong></td>
                                <td>@Model.TotalReceived.ToString("N8") @Model.CoinTag</td>
                            </tr>
                            <tr>
                                <td><strong>Total Sent</strong></td>
                                <td>@Model.TotalSent.ToString("N8") @Model.CoinTag</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="col-lg-3 col-md-3 col-sm-12">
                <div class="qr">
                    <img src="@Url.Action("Qr", "Home", new {value=Model.Address})" class="img-fluid d-block mx-auto" alt="">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="center-heading">
                    <h2 class="section-title">Transactions</h2>
                </div>
            </div>
        </div>			
        <div class="row">
            <div class="col-lg-12">
                <div class="table-responsive">
                    <table class="table table-striped table-latests">
                        <thead>
                            <tr>
                                <th>Hash</th>
                                <th>Block</th>
                                <th>Date/Time</th>
                                <th>Amount</th>
                                <th>Balance</th>
                            </tr>
                        </thead>
                        <tbody>
                        @{
                            double total = 0;
                        }
                        @foreach (var transaction in Model.Transactions)
                        {
                            total += (double)transaction.Value;
                            string transactionId = (transaction.TransactionHash == null || transaction.TransactionHash == "" ? transaction.CoinBase : transaction.TransactionHash).ToString();
                            <tr>
                                <td><a asp-controller="BlockExplorer" asp-action="Transaction" asp-route-transactionId="@transactionId">@transactionId.Substring(0, 25)...</a></td>
                                <td><a asp-controller="BlockExplorer" asp-action="Block" asp-route-block="@transaction.BlockIndex">@transaction.BlockIndex</a></td>
                                <td>-</td>
                                <td><span class="@(transaction.Value > 0 ? "green" : "red")">@transaction.Value.ToString("N8") @Model.CoinTag</span></td>
                                <td>@total.ToString("N8") @Model.CoinTag</td>
                            </tr>
                        }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
@section Scripts
{
    <script type="text/javascript">
    $(document).ready(function()
    {
        $(".copy-me").click(function()
        {
            var tempField = document.createElement("textarea");
            tempField.value = $(this).attr("data-value");
            $("body").parent().append(tempField);
            tempField.select();
            document.execCommand("copy");
            tempField.remove();
        })
    });
    </script>
}