@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Drawing
@using OurUmbraco.Forum.Extensions
@using OurUmbraco.Forum.Services
@using OurUmbraco.Our
@{
    var topicService = new TopicService(ApplicationContext.DatabaseContext);
    Image avatarImage = null;
    if (Members.IsLoggedIn())
    {
        avatarImage = Utils.GetMemberAvatarImage(Members.GetCurrentMember());
    }
}
<div class="quick-menu">
    <div class="container">
        <div class="row">
            <div class="col-md-12">

                @if (Members.IsLoggedIn() && Members.GetCurrentMember() != null)
                {
                    var member = Members.GetCurrentMember();

                    var roles = member.GetRoles();

                    var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100);

                    <div class="close">
                        <i class="icon-Delete"></i>Close
                    </div>
                    <div class="settings">
                        <a href="/member/profile"><i class="icon-Settings"></i>Edit profile</a>
                    </div>


                    <div class="user-image">
                        @Html.Raw(Utils.GetMemberAvatar(member, 100))
                    </div>

                    <div class="user-profile">
                        <h2>@member.Name</h2>
                        <div class="posts">

                            @member.ForumPosts()
                            
                            @if (member.ForumPosts() == 0 || member.ForumPosts() > 1)
                            {
                                <text>Posts</text>
                            }
                            else
                            {
                              <text>Post</text>
                            }
                        </div>
                        <div class="karma">
                            @member.Karma()
                        </div>
                        @if (member.HasValue("twitter"))
                        {
                            var twitterHandle = member.GetPropertyValue<string>("twitter").Replace("@", string.Empty);
                            <div class="user-twitter">
                                <a href="https://twitter.com/@twitterHandle">&commat;<span>@twitterHandle</span></a>
                            </div>
                        }
                        @if (roles.Any())
                        {
                            <span class="roles">
                                @foreach (var role in roles)
                                {
                                    <span class="@role">@role</span>
                                }
                            </span>
                        }
                        <div class="public-profile">
                            <a href="/member/@member.Id">View my public profile</a>
                        </div>
                        @if (member.IsAdmin())
                        {
                            <div class="public-profile">
                                <a href="/antispam">Check the spam queue</a>
                            </div>
                        }
                        <div class="log-out">
                            <a href="/umbraco/Surface/Login/Logout">Log out</a>
                        </div>
                    </div>

                    if (avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400))
                    {

                        <div class="user-notifications">
                            <small>
                                Your Notifications
                            </small>

                            <a href="/member/profile" class="user-notification__green">
                                <div class="user-notification-text">
                                    <p>Your profile picture is a little on the small side, It would look <strong>much nicer</strong> if you could update it to be larger image.</p>
                                </div>
                            </a>
                        </div>
                    }

                    <div class="user-latest-posts">

                        <small>
                            Activity in threads you participated in
                        </small>

                        @foreach (var topic in latestTopics)
                        {
                            var forum = Umbraco.TypedContent(topic.ParentId);
                            // if forum == null then it's been hidden/unpublished (example: v5 forum)
                            // if this is the case: don't show forum post in list
                            if (forum != null)
                            {
                                <a href="@topic.GetUrl()" class="forum-thread @(topic.Answer != 0 ? "solved" : null)">
                                    <div class="forum-thread-text">
                                        <h3>@topic.Title</h3>
                                        <p>
                                            @if (topic.Replies != 0 && !string.IsNullOrEmpty(topic.LastReplyAuthorName))
                                            {
                                                <text>last edited by @topic.LastReplyAuthorName</text>
                                            }
                                            else
                                            {
                                                <text>created by @topic.AuthorName</text>
                                            }
                                            @topic.Updated.ConvertToRelativeTime()
                                        </p>
                                    </div>

                                    <div class="category frontend"><span class="cat">@forum.Name</span></div>
                                </a>
                            }
                        }
                    </div>


                }
                else
                {
                    <a href="/member/login">Sign in</a>  <a href="/member/Signup">Register</a>
                }

            </div>
        </div>
    </div>
</div>