@using Orchard.Comments;
@using Orchard.Comments.Models
@using Orchard.Comments.Settings
@using Orchard.Utility.Extensions;

@{
    CommentsPart commentsPart = Model.ContentPart;
    bool canStillCommentOn = Model.CanStillComment;
    var settings = commentsPart.TypePartDefinition.Settings.GetModel<CommentsPartSettings>();
    var isAuthorized = AuthorizedFor(Permissions.AddComment, Model.ContentItem);
}

@if (!Model.ContentPart.CommentsActive || !canStillCommentOn) 
{
    <p class="alert-comments alert-info alert">@T("Comments have been disabled for this content.")</p>
}
else if ((settings.MustBeAuthenticated || !isAuthorized) && WorkContext.CurrentUser == null) 
{
    <p class="alert-comments alert-info alert">@T("You must {0} to comment.", Html.ActionLink(T("log on").ToString(), "LogOn",
                            new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = string.Format("{0}#addacomment", Context.Request.RawUrl) }))</p>
}
else if (WorkContext.CurrentUser != null && !isAuthorized) 
{
    <p class="alert-comments alert-warning">@T("You are not authorized to add a comment.")</p>
}
else if (isAuthorized) 
{
    @Html.ValidationSummary() 
    <span id="comment-form-beacon"></span>
    
    using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Comment", new { Area = "Orchard.Comments", ReturnUrl = Context.Request.ToUrlString() }), FormMethod.Post, new { @class = "comment-form" })) {
        if (TempData.ContainsKey("Comments.InvalidCommentEditorShape")) {
            @Display(TempData["Comments.InvalidCommentEditorShape"]);
        }
        else {
            @Display(Model.EditorShape)
        }
        <button class="btn btn-primary" type="submit">@T("Submit Comment")</button>
    }

}