@using FastBlog.Web.Helpers
@model FastBlog.Core.Models.PagedResponse<FastBlog.Core.Models.Blogs.BlogMeta>

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

<div class="container" id="file-list">
    <article>
        <header>
            <a href="/edit">
                <button class="btn-fw secondary">
                    New
                </button>
            </a>
            
            <hr/>

            <h3>List of Blogs</h3>
        </header>
        <body>

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

        <div class="grid">
            <div style="display: flex; font-size: 16px">
                <p>Name</p>
            </div>
            <div style="display: flex; font-size: 16px">
                <p>Published</p>
            </div>
            <div style="display: flex; font-size: 16px">
                <p>Visible</p>
            </div>
            <div style="display: flex; font-size: 16px">
                <p>Actions</p>
            </div>
        </div>

        @foreach (var blog in Model.Data)
        {
            <div class="grid">
                <div style="display: flex; font-size: 16px">
                    <p class="no-margin" style="margin-right: 10px; font-weight: bold">
                        @if (blog.CreatedAt < DateTime.UtcNow)
                        {
                            <a target="_blank" href="/@blog.Slug">@blog.Title</a>
                        }
                        else
                        {
                            <a class="pico-color-purple-600" target="_blank" href="/unpublished/@blog.Slug">@blog.Title</a>
                        }
                    </p>
                </div>
                <div>
                    <p class="no-margin">
                        @if (blog.CreatedAt < DateTime.UtcNow)
                        {
                            @blog.CreatedAt.ToString("yy-MM-dd HH:mm:ss")
                            ;
                        }
                        else
                        {
                            <span class="pico-color-purple-400">@blog.CreatedAt.ToString("yy-MM-dd HH:mm:ss")</span>
                            ;
                        }
                    </p>
                </div>
                <div>
                    <p class="no-margin">
                        <strong>
                            @if (blog.Visible)
                            {
                                <spans>Yes</spans>
                            }
                            else
                            {
                                <span class="pico-color-yellow">No</span>
                            }
                        </strong>
                    </p>
                </div>
                <div>
                    <p class="no-margin">
                        <a class="pico-color-red" hx-delete="/blogs/@blog.Id"
                           hx-swap="outerHTML"
                           hx-target="#file-list">
                            [ Delete ]
                        </a>
                        <a class="pico-color-blue-100" target="_blank" href="/edit/@blog.Id">[ Edit ]</a>
                    </p>
                </div>
            </div>
            <hr/>
        }
        </body>
        <footer>
            <div>
                <button
                    hx-get="/edit-list?offset=@(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="/edit-list?offset=@(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>