@model ReadOnlyTopic
@using System.Web.Mvc.Html
@using OurUmbraco.Forum.Models
@using Umbraco.Core.Logging

<!-- COPY LINK -->
<div id="overlay" class="overlay"></div>

<div id="copy-link-wrapper" class="copy-link-wrapper">
    <i class="icon-Link"></i>
    <textarea class="getLink" readonly type="text"></textarea>
    <p>Press Ctrl / CMD + C to copy this to your clipboard.</p>
</div>

<div id="thankyou">
    Copied to clipboard
</div>
<!-- COPY LINK END -->
<!-- DELETE THREAD/COMMENT START -->
@if (Model.MemberData != null)
{
    <div id="confirm-wrapper" class="confirm-wrapper">
        <h4>Are you sure?</h4>
        <p>This <span class="type-of"></span> will be gone forever and ever</p>
        <br />
        <button type="button" class="button green tiny">Yes</button>
        <button type="button" class="button red tiny">No</button>
    </div>
}

<!-- DELETE THREAD END -->
<!-- FLAG SPAM START -->
<div id="confirm-wrapper-flag" class="confirm-wrapper-flag">
    <h4>Flag this post as spam?</h4>
    <p>This post will be reported to the moderators as potential spam to be looked at</p>
    <br />
    <button type="button" class="button green tiny">Yes</button>
    <button type="button" class="button red tiny">No</button>
</div>
<!-- FLAG SPAM END -->

@if (Model.ForumNewTopicsAllowed == false)
{
    <div class="alertbar__yellow" style="margin-bottom: 10px;">
        @Html.Raw(Model.MainNotification)
    </div>
}

<ul class="comments">
    @{
        try
        {
            @Html.Partial("forum/question", Model)
        }
        catch (Exception ex)
        {
            LogHelper.Error<string>(string.Format("~/Views/MacroPartials/Forum/Thread.cshtml - error rendering topic with id {0}", Model.Id), ex);
        }
    }

    @foreach (var comment in Model.Comments.Where(x => x.ParentCommentId == 0))
    {
        Html.RenderPartial("forum/comment", comment);

        if (comment.HasChildren)
        {
            foreach (var child in Model.Comments.Where(c => c.ParentCommentId == comment.Id))
            {
                Html.RenderPartial("forum/comment", child);
            }
        }
    }
</ul>

@if (Model.MemberData != null)
{
    if (Model.ForumNewTopicsAllowed)
    {
        <div class="replybutton">
            <a href="#" class="button green large reply forum-reply" data-author="@Model.AuthorName" data-topic="@Model.Id" data-controller="comment"><i class="icon-Reply-arrow"></i>&nbsp;Reply to topic</a>
        </div>

        <div class="utilities">
            <div class="utility-actions thread-bottom">
                @if (Model.MemberData.IsAdmin)
                {
                    <a href="#" class="delete-thread button" data-id="@Model.Id">
                        <i class="icon-Delete-key"></i><span>Delete thread</span>
                    </a>
                }

                <a href="#" class="follow button @(Model.Subscribed ? "following" : "transparent")" data-id="@Model.Id" data-controller="topic">
                    <i class="icon-Bookmark"></i><span>@(Model.Subscribed ? "Following" : "Follow")</span>
                </a>

                @if (Model.Answer > 0)
                {
                    <a href="#comment-@Model.Answer.ToString()" class="go-to-solution button transparent">
                        <i class="icon-Check"></i><span>Go to solution</span>
                    </a>
                }
            </div>
        </div>
    }
    else
    {
        <div class="alertbar__yellow">
            @Html.Raw(Model.MainNotification)
        </div>
    }
}
else
{
    <div class="replybutton notloggedin">
        Please <a href="/member/login?redirectUrl=@(Server.UrlEncode(Request.Url.AbsoluteUri))">Sign in</a> or <a href="/member/signup">register</a> to post replies
    </div>
}
