@page
@model Admin.Pages.Crypto.Board.IndexModel
@{
    ViewData["Title"] = $"게시판 연결 - {Model.CoinSymbol}";
}

<div class="container-fluid">
    <h3>@ViewData["Title"]</h3>
    <p class="text-muted">@Model.CoinName</p>
    <hr />

    <partial name="_StatusMessage" />

    <ul class="nav nav-tabs mb-3">
        <li class="nav-item">
            <a class="nav-link" href="/Crypto/List/Edit/@Model.CoinID">기본 정보</a>
        </li>
        <li class="nav-item">
            <a class="nav-link active" href="/Crypto/Board/Index?coinID=@Model.CoinID">게시판 연결</a>
        </li>
    </ul>

    <div class="row g-4">
        <div class="col-md-6">
            <h5 class="mb-3">연결된 게시판 (@Model.Linked.Count)</h5>
            <table class="table table-sm table-bordered table-hover">
                <thead class="table-success">
                    <tr>
                        <th>게시판</th>
                        <th>분류</th>
                        <th>활성</th>
                        <th>관리</th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model.Linked.Count == 0)
                    {
                        <tr>
                            <td colspan="4" class="text-muted">연결된 게시판이 없습니다.</td>
                        </tr>
                    }
                    else
                    {
                        @foreach (var board in Model.Linked)
                        {
                            <tr>
                                <td>[@board.Code] @board.Name</td>
                                <td>@board.GroupName</td>
                                <td>@board.IsActive</td>
                                <td>
                                    <form method="post" asp-page-handler="Unlink" style="display:inline;">
                                        @Html.AntiForgeryToken()
                                        <input type="hidden" name="coinID" value="@Model.CoinID" />
                                        <input type="hidden" name="boardID" value="@board.ID" />
                                        <button type="submit" class="btn btn-sm btn-outline-danger"
                                                onclick="return confirm('게시판 연결을 해제하시겠습니까?')">해제</button>
                                    </form>
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
        </div>

        <div class="col-md-6">
            <h5 class="mb-3">연결 가능한 게시판 (@Model.Unlinked.Count)</h5>
            <table class="table table-sm table-bordered table-hover">
                <thead class="table-light">
                    <tr>
                        <th>게시판</th>
                        <th>분류</th>
                        <th>활성</th>
                        <th>관리</th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model.Unlinked.Count == 0)
                    {
                        <tr>
                            <td colspan="4" class="text-muted">연결 가능한 게시판이 없습니다.</td>
                        </tr>
                    }
                    else
                    {
                        @foreach (var board in Model.Unlinked)
                        {
                            <tr>
                                <td>[@board.Code] @board.Name</td>
                                <td>@board.GroupName</td>
                                <td>@board.IsActive</td>
                                <td>
                                    <form method="post" asp-page-handler="Link" style="display:inline;">
                                        @Html.AntiForgeryToken()
                                        <input type="hidden" name="coinID" value="@Model.CoinID" />
                                        <input type="hidden" name="boardID" value="@board.ID" />
                                        <button type="submit" class="btn btn-sm btn-outline-success"
                                                onclick="return confirm('이 게시판을 코인에 연결하시겠습니까?')">연결</button>
                                    </form>
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
        </div>
    </div>

    <div class="mt-3">
        <a class="btn btn-secondary" asp-page="/Crypto/List/Index">목록으로</a>
    </div>
</div>