@using FastBlog.Web.Helpers
@model FastBlog.Core.Models.PagedResponse<FastBlog.Core.Models.Users.User>


@{
    ViewData["Title"] = "Users";
}

<div class="container" id="user-list">
    <br/>
    <article>
        <header>
            <h3>Create a user</h3>
        </header>
        @if (ViewData.TryGetValue("error", out var errorMsg))
        {
            <div class="alert alert-caution">@errorMsg</div>
        }
        
        <form
            hx-post="/users"
            hx-swap="outerHTML"
            hx-target="#user-list">
            <label for="login">Login</label>
            <input required type="text" id="login" name="login" placeholder="username"/>
            <label for="password">Password</label>
            <input required type="password" id="password" name="password"/>
            <button type="submit" class="btn-fw">
                Create
            </button>
        </form>
    </article>

    <article>
        <header>
            <h3>Manage users</h3>
        </header>
        <body>

        @if (Model.Data.Length is 0)
        {
            <h4>No users have been found</h4>
        }

        @foreach (var user in Model.Data)
        {
            <div class="grid">
                <div style="display: flex; font-size: 16px">
                    <p class="no-margin" style="margin-right: 10px; font-weight: bold">
                        <a href="~/users/@user.Id/">@user.Username</a>
                    </p>
                </div>
            </div>
            <hr/>
        }
        </body>
        <footer>
            <div>
                <button
                    hx-get="/users?page=@(Model.Offset - 25)"
                    hx-swap="outerHTML"
                    hx-target="#file-list"
                    @HtmlPropertyHelper.If(Math.Clamp(Model.Offset, 0, Model.Amount) == 0, "disabled")>
                    Previous
                </button>
                <button
                    hx-get="/users?page=@(Model.Offset + 25)"
                    hx-swap="outerHTML"
                    hx-target="#file-list"
                    @HtmlPropertyHelper.If(Math.Clamp(Model.Offset, 0, Model.Amount) >= Model.Amount - 25, "disabled")>
                    Next
                </button>
            </div>
        </footer>
    </article>
</div>