<%@ Reference VirtualPath="~/bitrix/components/bitrix/blog.posts/component.ascx" %>
<%@ Control Language="C#" Inherits="Bitrix.Blog.Components.BlogPostsTemplate" EnableViewState="false" %>
<%@ Import Namespace="Bitrix.Blog" %>
<%@ Import Namespace="Bitrix.Blog.Components" %>
<%@ Import Namespace="System.Collections.Generic" %>

<%	if (Component.FatalError != BlogPostsComponent.ErrorCode.None) { %>
<div class="blog-content">
	<div class="blog-note-box blog-note-error">
		<div class="blog-note-box-text">
			<%= Component.GetErrorHtml(Component.FatalError) %>
		</div>
	</div>
</div><%
	return;
}
else if (Component.Posts.Count < 1)
{
%>
	<div class="blog-content">
	<div class="blog-note-box blog-note-success">
		<div class="blog-note-box-text"><%= GetMessage("PostsNotFound") %></div>
	</div>
</div>
<%
	return;
} %>

<div class="blog-content">

	<div class="blog-posts">
		<div id="blog-posts-content">
			<%if (Component.Paging.IsTopPosition) {%>
			<div class="blog-navigation-box blog-navigation-top">
				<div class="blog-page-navigation">
					<bx:IncludeComponent runat="server" ID="HeaderPager" ComponentName="bitrix:system.pager"  Template="<%$ Parameters:PagingTemplate %>" CurrentPosition="top" CssClassPrefix="blog-" />
				</div>
			</div>
			<%} %>
			<%
				BlogPostsComponent.PostInfo post = null;
				int cutNum = 0;
				Component.Processor.HideCut = true;				
				Component.RenderHideCut += delegate(object sender, BXBlogCutTagEventArgs e)
				{
					cutNum++;
					string title = !Bitrix.Services.Text.BXStringUtility.IsNullOrTrimEmpty(e.Option) ? e.Option.Trim() : GetMessage("CutDefaultTitle");
					e.Writer.Write(String.Concat(@"<a href=""", post.PostViewHref, "#cut", cutNum,  @""">", Encode(title), "</a>"));
					
				};			
				for(int i = 0; i < Component.Posts.Count; i++)
				{
					cutNum = 0;
					post = Component.Posts[i];
			%>
			<div class="blog-post">
				<h2 class="blog-post-title"><a href="<%= post.PostViewHref %>" title="<%= post.Post.Title %>"><%= post.TitleHtml %></a></h2>
				<div class="blog-post-info-back">
					<div class="blog-post-info">
						<div class="blog-author">
							<a class="blog-author-icon" href="<%= post.UserProfileHref %>"></a><a class="" href="<%= post.BlogHref %>"><%= post.AuthorNameHtml %></a>
						</div>
						<div class="blog-post-date" title="<%= post.Post.DatePublished %>"><%= post.Post.DatePublished.ToString("g") %></div>
					</div>
				</div>
				<div class="blog-post-content">
					<% if (post.Post.Author != null && post.Post.Author.User != null && post.Post.Author.User.Image != null) { %>
					<div class="blog-post-avatar"><img alt="" width="<%= post.Post.Author.User.Image.Width %>" height="<%= post.Post.Author.User.Image.Height %>" src="<%= post.Post.Author.User.Image.FilePath %>" /></div>
					<% } %>
					<%= post.GetContentHtml() %>
					<div class="blog-clear-float"></div>
				</div>
				<div class="blog-post-meta">
					<div class="blog-post-meta-util">
						<span class="blog-post-comments-link"><a href="<%= post.PostViewHref %>#comments"><%= GetMessage("CommentsLinkTitle")%>:</a>
						<a href="<%= post.PostViewHref %>#comments"><%= post.Post.CommentCount %></a></span> <span class="blog-post-views-link">
						<a href="<%= post.PostViewHref %>"><%= GetMessage("ViewsLinkTitle")%>:</a> <a href="<%= post.PostViewHref %>"><%= post.Post.ViewCount %></a></span>
					</div>
				</div>
			</div>
			<%	} %>
			<%if (Component.Paging.IsBottomPosition) {%>
			<div class="blog-navigation-box blog-navigation-bottom">
				<div class="blog-page-navigation">
					<bx:IncludeComponent runat="server" ID="FooterPager" ComponentName="bitrix:system.pager" Template="<%$ Parameters:PagingTemplate %>" CurrentPosition="bottom" CssClassPrefix="blog-" />
				</div>
			</div>
			<%} %>
		</div>
	</div>
	<div class="blog-clear-float"></div>
</div>