@using BTCPayServer.Client
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using BTCPayServer.Abstractions.Contracts
@using BTCPayServer.Abstractions.TagHelpers
@using Newtonsoft.Json
@using WalletWasabi.Backend.Controllers
@model WalletWasabi.Backend.Controllers.DiscoveredCoordinator
@inject IScopeProvider ScopeProvider




@* <button type="button" class="btn btn-secondary mt-2" permission="@Policies.CanModifyServerSettings" *@
@*         data-bs-toggle="modal" data-bs-target="#discover-prompt"> *@
@*     Add Coordinator *@
@* </button> *@
<div class="modal fade" id="discover-prompt" permission="@Policies.CanModifyServerSettings">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Add Coordinator</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <ul class="nav nav-tabs" id="myTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <button class="nav-link active" id="nostr-tab" data-bs-toggle="tab" data-bs-target="#nostr-tab-pane" type="button" role="tab" aria-selected="true">Nostr</button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" id="manual-tab" data-bs-toggle="tab" data-bs-target="#manual-tab-pane" type="button" role="tab" aria-selected="false">Manual</button>
                </li>
            </ul>
            <div class="tab-content ">
                <form asp-action="AddCoordinator" asp-controller="WabisabiStore" asp-route-storeId="@ScopeProvider.GetCurrentStoreId()"
                      class="tab-pane fade show active " id="nostr-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">

                    <div class="modal-body">
                        <div class="form-group">
                            <label class="form-label">Nostr Relay</label>
                            <input type="url" class="form-control" asp-for="Relay" required="required" value="wss://relay.primal.net">

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button name="command" type="submit" value="discover" class="btn btn-primary">Discover</button>
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    </div>
                </form>
                <form asp-action="AddCoordinator" asp-controller="WabisabiStore"  asp-route-storeId="@ScopeProvider.GetCurrentStoreId()"
                      class="tab-pane fade" id="manual-tab-pane" role="tabpanel" tabindex="0">

                    <div class="modal-body">
                        <div class="form-group">
                            <label asp-for="Name" class="form-label">Coordinator Name</label>
                            <input asp-for="Name" type="text" required class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label asp-for="Uri" class="form-label">Coordinator URL</label>
                            <input asp-for="Uri" type="url" required class="form-control"/>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button name="command" type="submit" class="btn btn-primary">Add</button>
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>


        </div>
    </div>
</div>


@if (TempData.TryGetValue("DiscoveredCoordinators" , out var v)&& v is string vs)
{
    var discoveredCoordinators = JsonConvert.DeserializeObject<List<DiscoveredCoordinator>>(vs);
    foreach (var coordinator in discoveredCoordinators)
    {
        <partial model="@coordinator" name="Wabisabi/AddCoordinator"/>
    }
}