include ../../../../../../pillar/src/templates/mixins/components

| {% import 'projects/_macros.html' as projectmacros %}
| {% macro render_blog_post(node, project=None, pages=None) %}

.expand-image-links.imgs-fluid
	| {% if node.picture %}
	+jumbotron(
		"{{ node.name }}",
		"{{ node._created | pretty_date }}{% if node.user.full_name %} · {{ node.user.full_name }}{% endif %}",
		"{{ node.picture.thumbnail('h', api=api) }}",
		"{{ node.url }}")(
		class="jumbotron-overlay")
	| {% else %}
	.pt-5.text-center.text-muted
		h2.pb-2
			a.text-muted(href="{{ node.url }}")
				| {{ node.name }}
		ul.d-flex.list-unstyled.justify-content-center
			| {% if node.project.name %}
			li.pr-2 {{ node.project.name }}
			| {% endif %}
			| {% if node.user.full_name %}
			li.pr-2
				| {{ node.user.full_name }}
			| {% endif %}
			li
				a.px-2.text-muted(href="{{ node.url }}",
					title="Updated {{ node._updated | pretty_date }}")
					| {{ node._created | pretty_date }}
			li
				a.px-2(href="{{ node.url }}#comments")
					| Leave a comment

			| {% if node.has_method('PUT') %}
			li
				a.px-2(href="{{url_for('nodes.edit', node_id=node._id)}}")
					i.pi-edit
					| Edit Post
			| {% endif %}
	| {% endif %}

	.node-details-description.mx-auto.py-5
		| {{ node.properties | markdowned('content') }}

	hr.my-4

	#comments-embed.d-flex.justify-content-center.mx-auto
| {% endmacro %}

//- ******************************************************* -//
| {% macro render_blog_list_item(node) %}
a.card.asset.card-image-fade.pr-0.mx-0.mb-4(
	href="{{ node.url }}")
	.embed-responsive.embed-responsive-16by9
		| {% if node.picture %}
		.card-img-top.embed-responsive-item(style="background-image: url({{ node.picture.thumbnail('m', api=api) }})")
		| {% else %}
		.card-img-top.card-icon.embed-responsive-item
			i.pi-document-text
		| {% endif %}

	.card-body.py-2.d-flex.flex-column
		.card-title.mb-1.font-weight-bold
			| {{ node.name }}

		ul.card-text.list-unstyled.d-flex.text-black-50.mt-auto
			li.pr-2 {{ node.user.full_name }}
			li {{ node._created | pretty_date }}
			| {% if node.properties.status != 'published' %}
			li.text-info.font-weight-bold {{ node.properties.status}}
			| {% endif %}

| {% endmacro %}


//- ******************************************************* -//
| {% macro render_blog_index(current_post, project, posts, can_create_blog_posts, api, more_posts_available, posts_meta, pages=None) %}
| {% if can_create_blog_posts %}
+nav-secondary
	+nav-secondary-link(href="{{url_for('nodes.posts_create', project_id=project._id)}}")
		span.text-success
			i.pi-plus
			| Create New Blog Post
| {% endif %}

| {% if posts %}
| {{ render_blog_post(current_post, project=project, pages=pages) }}

.container
	.pt-4.text-center
		h5
			| {% if more_posts_available %}
			a.text-muted.py-3.d-block(href="{{ project.blog_archive_url }}")
				| More from {{ project.name }} blog
			| {% else %}
			| More from {{ project.name }} blog
			| {% endif %}

	+card-deck(class="px-2 justify-content-center")
		| {% for node in posts %}
		| {# Skip listing the current post #}
		| {% if node._id != current_post._id %}
		| {{ render_blog_list_item(node) }}
		| {% endif %}
		| {% endfor %}

	| {% if more_posts_available %}
	a.d-block.pb-4.text-center(href="{{ project.blog_archive_url }}")
		| {{posts_meta.total - posts|length}} more blog posts over here
		i.pi-angle-right
	| {% endif %}

| {% else %}

.text-center
	p No posts... yet!

| {% endif %} {# posts #}
| {% endmacro %}


//- Macro for rendering the navigation buttons for prev/next pages -//
| {% macro render_archive_pagination(project) %}
.blog-archive-navigation.mb-4
	| {% if project.blog_archive_prev %}
	a.archive-nav-button(
		href="{{ project.blog_archive_prev }}", rel="prev")
		i.pi-angle-left
		| Previous page
	| {% else %}
	span.archive-nav-button
		i.pi-angle-left
		| Previous page
	| {% endif %}

	a.archive-nav-button(
		href="{{ url_for('main.project_blog', project_url=project.url) }}")
		| Blog Index

	| {% if project.blog_archive_next %}
	a.archive-nav-button(
		href="{{ project.blog_archive_next }}", rel="next")
		| Next page
		i.pi-angle-right
	| {% else %}
	span.archive-nav-button
		| Next page
		i.pi-angle-right
	| {% endif %}

| {% endmacro %}

| {% macro render_archive(project, posts, posts_meta) %}

| {{ render_archive_pagination(project) }}

+card-deck(class="px-2")
	| {% for node in posts %}
	| {{ render_blog_list_item(node) }}
	| {% endfor %}

| {{ render_archive_pagination(project) }}

| {% endmacro %}
