@model DerivationSchemeViewModel
@{
    Layout = "../Shared/_NavLayout.cshtml";
    ViewData.SetActivePageAndTitle(StoreNavPages.Index, $"{Model.CryptoCode} Derivation scheme");
}

@section HeadScripts {
    <style type="text/css">
        .hw-fields {
            display: none;
        }
    </style>
}

<partial name="_StatusMessage" />
<div class="row">
    <div class="col-md-6">
        <div asp-validation-summary="All" class="text-danger"></div>
    </div>
</div>
<div class="row">
    <div class="col-md-8">
        @if (!Model.Confirmation)
        {
            <partial name="AddDerivationSchemes_HardwareWalletDialogs" model="@Model" />
        }
        <form method="post">

            <input id="Config" asp-for="Config" type="hidden" />

            @if (!Model.Confirmation)
            {
                <input id="CryptoCurrency" asp-for="CryptoCode" type="hidden" />
                <input id="DerivationSchemeFormat" asp-for="DerivationSchemeFormat" type="hidden" />
                <input id="AccountKey" asp-for="AccountKey" type="hidden" />
                <div class="form-group">
                    <h5>Derivation Scheme</h5>
                    <span>The DerivationScheme represents the destination of the funds received by your invoice. It is generated by your wallet software. Please, verify that you are generating the right addresses by clicking on 'Check ExtPubKey'</span>
                </div>
                <div class="form-group">
                    <label asp-for="DerivationScheme"></label>
                    <input asp-for="DerivationScheme" class="form-control store-derivation-scheme" />
                    <span asp-validation-for="DerivationScheme" class="text-danger"></span>

                    <div class="dropdown mt-2 text-right">
                        <div class="btn-group">
                            <button class="btn btn-link dropdown-toggle" type="button" id="hardwarewlletimportdropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                Import from hardware device
                            </button>
                            <div class="dropdown-menu  dropdown-menu-right w-100" aria-labelledby="hardwarewlletimportdropdown">
                                <button class="dropdown-item" type="button" data-toggle="modal" data-target="#coldcardimport">Coldcard</button>
                                <button class="dropdown-item check-for-ledger" data-toggle="modal" data-target="#ledgerimport" type="button">Ledger Wallet</button>
                                @* <button class="dropdown-item check-for-trezor" type="button" data-toggle="modal" data-target="#trezorimport">Trezor</button> *@
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <span>BTCPay format memo</span>
                    <table class="table table-sm table-responsive-md">
                        <thead>
                            <tr>
                                <th>Address type</th>
                                <th>Example</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>P2WPKH</td>
                                <td>xpub...</td>
                            </tr>
                            <tr>
                                <td>P2SH-P2WPKH</td>
                                <td>xpub...-[p2sh]</td>
                            </tr>
                            <tr>
                                <td>P2PKH</td>
                                <td>xpub...-[legacy]</td>
                            </tr>
                            <tr>
                                <td>Multi-sig P2WSH</td>
                                <td>2-of-xpub1...-xpub2...</td>
                            </tr>
                            <tr>
                                <td>Multi-sig P2SH-P2WSH</td>
                                <td>2-of-xpub1...-xpub2...-[p2sh]</td>
                            </tr>
                            <tr>
                                <td>Multi-sig P2SH</td>
                                <td>2-of-xpub1...-xpub2...-[legacy]</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="form-group hw-fields">
                    <h5>Additional pairing information</h5>
                </div>
                <div class="form-group hw-fields">
                    <label asp-for="Source"></label>
                    <input asp-for="Source" class="form-control" readonly />
                </div>
                <div class="form-group hw-fields">
                    <label asp-for="RootFingerprint"></label>
                    <input asp-for="RootFingerprint" class="form-control" readonly />
                </div>
                <div class="form-group hw-fields">
                    <label asp-for="KeyPath"></label>
                    <input asp-for="KeyPath" class="form-control" readonly />
                </div>
                <div class="form-group">
                    <div class="form-check">
                        <input asp-for="Enabled" type="checkbox" class="form-check-input" />
                        <label asp-for="Enabled" class="form-check-label"></label>
                    </div>
                </div>
                <button name="command" type="submit" class="btn btn-primary" value="save" id="Continue">Continue</button>
            }
            else
            {
                <div class="form-group">
                    <h5>Confirm the addresses (@Model.CryptoCode)</h5>
                    <span>Please check that your @Model.CryptoCode wallet is generating the same addresses as below.</span>
                </div>
                <input asp-for="Confirmation" type="hidden" />
                <input type="hidden" asp-for="DerivationScheme" />
                <input type="hidden" asp-for="Enabled" />
                <div class="form-group">
                    <table class="table table-sm table-responsive-md">
                        <thead>
                            <tr>
                                <th>Key path</th>
                                <th>Address</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var sample in Model.AddressSamples)
                            {
                                <tr>
                                    <td>@sample.KeyPath</td>
                                    <td>@sample.Address</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>

                <div class="form-group">
                    <h5>Wrong addresses?</h5>
                    <span>Help us to find the correct settings by telling us the first address of your wallet</span>
                </div>
                <div class="form-group">
                    <label asp-for="HintAddress"></label>
                    <input asp-for="HintAddress" class="form-control" />
                    <span asp-validation-for="HintAddress" class="text-danger"></span>
                </div>
                <button name="command" type="submit" class="btn btn-primary" value="save" id="Confirm">Confirm</button>
            }
        </form>
    </div>
</div>
@section Scripts {
    @await Html.PartialAsync("_ValidationScriptsPartial")
    <script src="~/js/ledgerwebsocket.js" type="text/javascript" defer="defer"></script>
    <script src="~/js/StoreAddDerivationScheme.js" type="text/javascript" defer="defer"></script>
    <script src="~/vendor/trezor/trezor.js-umd.min.js" defer="defer"></script>
    <script src="~/js/trezor/trezor-client.js" type="text/javascript" defer="defer"></script>
    <script src="~/js/trezor/trezor-add-derivation-scheme.js" type="text/javascript" defer="defer"></script>
    <script>
        window.coinName = "@Model.Network.DisplayName.ToLowerInvariant()";
    </script>
}
