@using BTCPayServer.Components.TruncateCenter
@using BTCPayServer.Payments
@using BTCPayServer.Services
@using NBitcoin
@using WalletWasabi.Blockchain.Analysis
@model List<BTCPayServer.Plugins.Wabisabi.BTCPayWallet.CoinjoinData>
@inject TransactionLinkProviders TransactionLinkProviders
@{
    
    var pmi = PaymentTypes.CHAIN.GetPaymentMethodId("BTC");
}

<div class="table-responsive" style="  transform: rotateX(180deg);">
    <table class="table table-hover  w-100" style="  transform: rotateX(180deg);">
        <thead>
        <tr>
            <th class="w-125px">Round</th>
            <th class="w-125px">Timestamp</th>
            <th class="w-125px">Coordinator</th>
            <th class="w-125px">Transaction</th>
            <th class="text-nowrap">In</th>
            <th class="text-nowrap">Out</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var cjData in Model)
        {
            var cjInWeightedAverage = @CoinjoinAnalyzer.WeightedAverage.Invoke(@cjData.CoinsIn.Select(coin => new CoinjoinAnalyzer.AmountWithAnonymity(coin.AnonymitySet, new Money(coin.Amount, MoneyUnit.BTC))));
            var cjOutWeightedAverage = @CoinjoinAnalyzer.WeightedAverage.Invoke(@cjData.CoinsOut.Where(coin => coin.PayoutId is null).Select(coin => new CoinjoinAnalyzer.AmountWithAnonymity(coin.AnonymitySet, new Money(coin.Amount, MoneyUnit.BTC))));
            <tr>
                <td>
                    <a class="d-flex cursor-pointer " data-bs-toggle="collapse" data-bs-target="#txcoins-@cjData.Round">

                        <vc:truncate-center text="@cjData.Round" classes="truncate-center-id"/>
                        <vc:icon symbol="caret-down"/>
                    </a>

                </td>
                <td>
                    <span class="text-break">@cjData.Timestamp.ToTimeAgo()</span>
                </td>
                <td>
                    <span class="text-break">@cjData.CoordinatorName</span>
                </td>
                <td>
                    <vc:truncate-center text="@cjData.Transaction" link="@TransactionLinkProviders.GetTransactionLink(pmi, cjData.Transaction)" classes="truncate-center-id"/>
                </td>
                <td>
                    <div class="card truncate-center-id">
                        <span class="text-nowrap">@cjData.CoinsIn.Length coins</span>
                        <span class="text-nowrap">@cjData.CoinsIn.Sum(coin => coin.Amount) BTC</span>
                        <span class="text-nowrap">@cjInWeightedAverage.ToString("0.##") anonset wavg</span>
                    </div>
                </td>
                <td>

                    <div class="card truncate-center-id">
                        <span class="text-nowrap">@cjData.CoinsOut.Length coins</span>
                        <span class="text-nowrap">@cjData.CoinsOut.Sum(coin => coin.Amount) BTC</span>
                        <span class="text-nowrap">@cjOutWeightedAverage.ToString("0.##") anonset wavg</span>
                    </div>
                </td>

            </tr>

            <tr id="txcoins-@cjData.Round" class="collapse  overflow-y-auto " style="    max-height: 30vh;">
                <td colspan="6" >
                    <div class="d-flex justify-content-start">
                        
                    <ul class="list-group list-group-flush" style="--btcpay-list-group-bg: transparent;">
                        <li class="list-group-item list-group-item-heading h5">Inputs</li>
                        @foreach (var c in cjData.CoinsIn)
                        {
                            <partial name="Wabisabi/CoinView" model="@c"/>
                        }
                    </ul>


                    <ul class="list-group list-group-flush" style="--btcpay-list-group-bg: transparent;">

                        <li class="list-group-item list-group-item-heading h5">Outputs</li>
                        @foreach (var c in cjData.CoinsOut)
                        {
                            <partial name="Wabisabi/CoinView" model="@c"/>
                        }
                    </ul>


                    </div>
                </td>
            </tr>
        }
        </tbody>
    </table>
</div>