@*
    List of user's notes
*@

@inject ILanguageService LanguageService
@inject IImagePathHelper ImagePathHelper

@{
    ViewData["Title"] = LanguageService.GetKey("UserNotes_Title");

    var currentUser = new ClaimsPrincipalWrapper(User);
}

@model UserNotesViewModel

@if (Model == null)
{
    <h3>@LanguageService.GetKey("UserNotes_Nothing")</h3>
}
else
{
    var user = Model.User;
    var profilePicture = Model.ProfilePicture;
    var notesDetails = Model.Notes;
    var pagingVM = Model.PagingViewModel;

    @if (user == null)
    {
        <h3>@LanguageService.GetKey("UserNotes_Nothing")</h3>
    }
    else
    {
        ViewData["Title"] = $"{LanguageService.GetKey("UserNotes_NotesOfUser")} {user.UserName}";

        <div class="note-author">
            <div class="thumb">
                <a class="fancybox-frame profile-picture" data-fancybox href="@ImagePathHelper.GetHref(profilePicture.ImageFileName)">
                    <img src="@ImagePathHelper.GetPath(profilePicture.ImageFileName)" asp-append-version="true">
                </a>

                <a asp-controller="Users" asp-action="Details" asp-route-userId="@user.Id" class="btn btn-sm btn-outline-secondary my-button avatar-button">@user.UserName</a>
            </div>

            <p class="title-text">@user.Status</p>
        </div>

        <h3 class="title-text">@LanguageService.GetKey("UserNotes_NotesOfUser") @user.UserName</h3>

        var noteNumber = 0;
        @foreach (var noteDetail in notesDetails)
        {
            var note = noteDetail.Note;
            if (note == null)
            {
                continue;
            }

            var images = noteDetail.Images;
            var thread = noteDetail.Thread;

            <div class="note">
                @if (thread != null)
                {
                    <div>
                        <div class="note-controls">
                            <a asp-controller="Threads" asp-action="GetByThread" asp-route-thread="@thread.Thread" class="btn btn-sm btn-outline-secondary my-button">@thread.Thread</a>
                        </div>
                    </div>
                }
                
                <h4 class="title-text"><b>@note.Title</b></h4>
                <p class="title-text note-description">@note.Description</p>

                <div class="gallery-column">
                    @foreach (var image in images)
                    {
                        var imagePath = ImagePathHelper.GetPath(image.ImageFileName);
                        var href = ImagePathHelper.GetHref(image.ImageFileName);

                        <div class="thumb">
                            <a class="fancybox-frame" data-fancybox="gallery-@noteNumber" href="@href">
                                <img src="@imagePath" asp-append-version="true">
                            </a>
                        </div>
                    }
                </div>

                <div class="note-controls">
                    @if (currentUser.IsAdmin() ||
                        currentUser.IsOwner(note))
                    {
                        <a asp-controller="Notes" asp-action="Edit" asp-route-noteId="@note.NoteId" class="btn btn-sm btn-outline-secondary my-button">@LanguageService.GetKey("Edit")</a>
                        <a asp-controller="Notes" asp-action="Delete" asp-route-noteId="@note.NoteId" class="btn btn-sm btn-outline-secondary my-button">@LanguageService.GetKey("Delete")</a>
                    }

                    <a asp-controller="Notes" asp-action="Details" asp-route-noteId="@note.NoteId" class="btn btn-sm btn-outline-secondary my-button">@LanguageService.GetKey("Details")</a>
                </div>
            </div>

            noteNumber += 1;
        }

        <div class="d-flex align-items-center mb-4 paginator-control">
            @if (pagingVM.IsValidPage)
            {
                <a class="btn btn-sm btn-outline-primary @pagingVM.PrevDisabled" asp-controller="Users" asp-action="Notes" asp-route-page="@(pagingVM.Page - 1)">
                    @LanguageService.GetKey("PaginationResults_Prev")
                </a>
                <a class="btn btn-sm btn-outline-primary @pagingVM.NextDisabled" asp-controller="Users" asp-action="Notes" asp-route-page="@(pagingVM.Page + 1)">
                    @LanguageService.GetKey("PaginationResults_Next")
                </a>
                <span class="text-muted text-small">@LanguageService.GetKey("PaginationResults") @pagingVM.ResultStart - @pagingVM.ResultEnd @LanguageService.GetKey("PaginationResults_of") @pagingVM.TotalItems</span>
            }
        </div>
    }
}