@using FastBlog.Web.Helpers
@model FastBlog.Core.Models.PagedResponse<FastBlog.Core.Models.Files.FileMeta>


@{
    ViewBag.Title = "Files";
}

<div class="container" id="file-list">


    <br/>

    <article>
        <header>
            <h3>Upload a file</h3>
        </header>
        <form hx-encoding="multipart/form-data"
              hx-post="/files"
              hx-swap="outerHTML"
              hx-target="#file-list">
            <input type="file" name="file" required/>
            <label for="upload-path">Path to upload (optional)</label>
            <input type="text" id="upload-path" name="sourcePath" placeholder="/subfolders/"/>
            <button type="submit" class="btn-fw">
                Upload
            </button>
        </form>
    </article>

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

        @if (Model.Data.Length is 0)
        {
            <h4>No files have been found</h4>
        }
        
        @foreach (var file 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 target="_blank" href="/static/@file.SourceLocation">@file.SourceLocation</a>
                    </p>
                    <p class="no-margin">
                        <a class="pico-color-red" hx-delete="/files/@file.Id"
                           hx-swap="outerHTML"
                           hx-target="#file-list">
                            [ Delete ]
                        </a>
                    </p>
                </div>
                <div>
                    <p class="no-margin">
                        <strong>Created:</strong> @file.CreatedAt.ToString("d");
                    </p>
                </div>
                <div>
                    <p class="no-margin">
                        <strong>Type:</strong> @file.MimeType;
                    </p>
                </div>
            </div>
            <hr/>
        }
        </body>
        <footer>
            <div>
                <button
                    hx-get="/files?page=@(Model.Offset - 25)"
                    hx-swap="outerHTML"
                    hx-target="#file-list"
                    @PropertyHelper.If(Math.Clamp(Model.Offset, 0, Model.Amount) == 0, "disabled")>
                    Previous
                </button>
                <button
                    hx-get="/files?page=@(Model.Offset + 25)"
                    hx-swap="outerHTML"
                    hx-target="#file-list"
                    @PropertyHelper.If(Math.Clamp(Model.Offset, 0, Model.Amount) >= Model.Amount - 25, "disabled")>
                    Next
                </button>
            </div>
        </footer>
    </article>
</div>