@page "/messages"

<Title Value="Messages - Unturned Store"></Title>

<Meta name="description" content="Marketplace of products for Unturned" />
<Meta property="og:title" content="Messages" />


<Meta property="og:image" content="/img/logo.png" />
<Meta property="og:image:width" content="128" />
<Meta property="og:image:height" content="128" />
<Meta property="og:description" content="Marketplace of products for Unturned" />


@if (Messages != null)
{
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item active" aria-current="page">Messages</li>
        </ol>
    </nav>

    <div class="bg-light p-3 rounded-3 mb-3">
        <h5>Active Messages</h5>
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Title</th>
                    <th>Replies</th>
                    <th>Participant</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var msg in ActiveMessages.OrderByDescending(x => x.CreateDate))
                {
                    <tr style="cursor: pointer;" @onclick="() => GoToMessage(msg)">
                        <td class="align-middle">@msg.Id</td>
                        <td class="align-middle">@msg.Title</td>
                        <td class="align-middle">@msg.Replies.Count</td>
                        <td class="align-middle" style="position: relative;">
                            <Username User="@(msg.ToUserId == UserService.UserId ? msg.FromUser : msg.ToUser)" />
                            @if (MessageReadService.HasNewMessage(msg))
                            {
                                <div class="NewMessagesIcon"><i class="fas fa-envelope-open-text"></i></div>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    <div class="bg-light p-3 rounded-3 mb-3">
        <h5>Closed Messages</h5>
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Title</th>
                    <th>Replies</th>
                    <th>Participant</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var msg in ClosedMessages.OrderByDescending(x => x.CreateDate))
                {
                    <tr style="cursor: pointer;" @onclick="() => GoToMessage(msg)">
                        <td class="align-middle">@msg.Id</td>
                        <td class="align-middle">@msg.Title</td>
                        <td class="align-middle">@msg.Replies.Count</td>
                        <td class="align-middle"><Username User="@(msg.ToUserId == UserService.UserId ? msg.FromUser : msg.ToUser)" /></td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}
