{% if not v or v.highlightcomments %}
	<script src="{{ 'js/new_comments_count.js' | asset }}"></script>
{% endif %}

{% if v and v.admin_level >= 2 %}
	<script src="{{ 'js/filter_actions.js' | asset }}"></script>
{% endif %}

<div style="display:none" id="popover">
	<div class="popover-user-profile" role="tooltip">
		<img loading="lazy" class="pop-banner w-100 h-64 object-cover">
		<div class="d-flex align-items-end px-3 mt-n6 mb-3">
			<img loading="lazy" class="pop-picture avatar-72 rounded img-thumbnail shadow-sm">
			<div class="px-3 text-truncate">
			<h5 class="pop-username text-truncate text-black"></h5>
			</div>
		</div>
		<div class="px-3">
			<span class="pop-bio popover-bio text-black"></span>
		</div>

		<div class="pop-badges ml-3 mr-3 my-2">
		</div>

	 <div class="border-top d-flex align-items-center p-3 gap-3 smol">
		<span>
		 <strong class="pop-postcount text-black"></strong>
		 <span class="text-black">posts</span>
		</span>
		<span class="ml-3">
		 <strong class="pop-commentcount text-black"></strong>
		 <span class="text-black">comments</span>
		</span>
		&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="/" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} class="pop-viewmore ml-auto text-decoration-none">
		 View
		 <i class="fas fa-arrow-right fa-sm px-1"></i>
		</a>
	 </div>
	</div>
</div>

{% include 'usernote.html' %}

{% for p in listing %}
<div class="card-container">

	{% if p.should_hide_score %}
		{% set ups="" %}
		{% set downs="" %}
		{% set score="" %}
	{% else %}
		{% set ups=p.upvotes %}
		{% set downs=p.downvotes %}
		{% set score=p.score %}
	{% endif %}

	{% if v %}
		{% set voted= p.voted %}
	{% else %}
		{% set voted=-2 %}
	{% endif %}

	{% if v and p.state_report == StateReport.REPORTED and v.can_manage_reports() %}
		<div id="flaggers-{{p.id}}" class="flaggers d-none">
			<strong><i class="far fa-fw fa-flag"></i> Reports:</strong>
			<a class="btn btn-primary" style="margin:1px 5px" onclick="filter_new_status({{p.id}}, 'normal')">Approve</a>
			<a class="btn btn-secondary" style="margin:1px 5px" onclick="filter_new_status({{p.id}}, 'ignored')">Approve and Ignore</a>
			<a class="btn btn-danger" style="margin:1px 5px" onclick="filter_new_status({{p.id}}, 'removed')">Remove</a>
			<pre></pre>
			<ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word">
				{% for f in p.flags(v) %}
					<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %}</li>
				{% endfor %}
			</ul>
		</div>
	{% endif %}

	<div id="post-{{p.id}}" class="card{% if p.state_mod == StateMod.REMOVED %} removed{% endif %}{% if p.state_mod == StateMod.FILTERED %} filtered{% endif %}{% if p.state_user_deleted_utc %} deleted{% endif %}{% if p.stickied %} stickied{% endif %}{% if voted==1 %} upvoted{% elif voted==-1 %} downvoted{% endif %}{% if p.over_18 %} nsfw{% endif %}">

		<div class="d-flex flex-row flex-nowrap justify-content-end align-items-center">

			{% if not postembed %}
				<div class="voting my-0 my-md-2 d-block pr-2">
					{% if v and request.path.startswith('/@') and v.admin_level < 2 %}

						{% if voted==1 %}
						<div class="mx-auto arrow-up post-{{p.id}}-up active"></div>
						{% endif %}

						<span class="post-score-{{p.id}} score post-score-{{p.id}} {% if voted==1 %}score-up{% elif voted==-1%}score-down{% endif %}{% if p.controversial %} controversial{% endif %}"{% if p.state_mod == StateMod.VISIBLE %} data-bs-toggle="tooltip" data-bs-placement="right" title="+{{ups}} | -{{downs}}"{% endif %}>{{score}}</span>

						{% if voted==-1 %}
							<div class="text-muted mx-auto arrow-down post-{{p.id}}-down active"></div>
						{% endif %}

					{% elif v %}

					<div tabindex="0" role="button" onclick="vote('post', '{{p.id}}', '1', '{{v.id}}')" class="post-{{p.id}}-up mx-auto arrow-up upvote-button post-{{p.id}}-up {% if voted==1 %}active{% endif %}"></div>

					<span class="post-score-{{p.id}} score post-score-{{p.id}} {% if voted==1 %}score-up{% elif voted==-1%}score-down{% endif %}{% if p.controversial %} controversial{% endif %}"{% if p.state_mod == StateMod.VISIBLE %} data-bs-toggle="tooltip" data-bs-placement="right" title="+{{ups}} | -{{downs}}"{% endif %}>{{score}}</span>

					<div {% if not ENABLE_DOWNVOTES %}style="display:None!important"{% endif %} tabindex="0" role="button" onclick="vote('post', '{{p.id}}', '-1', '{{v.id}}')" class="post-{{p.id}}-down text-muted mx-auto arrow-down downvote-button post-{{p.id}}-down {% if voted==-1 %}active{% endif %}"></div>

					{% else %}

					<div tabindex="0" role="button" onclick="vote('post', '{{p.id}}', '1', '{{v.id}}')" class="post-{{p.id}}-up mx-auto arrow-up" onclick="location.href='/login';"></div>

					<span class="post-{{p.id}}-score-none score{% if p.controversial %} controversial{% endif %}"{% if p.state_mod == StateMod.VISIBLE %} data-bs-toggle="tooltip" data-bs-placement="right" title="+{{ups}} | -{{downs}}"{% endif %}>{{score}}</span>

					<div {% if not ENABLE_DOWNVOTES %}style="display:None!important"{% endif %} tabindex="0" role="button" onclick="vote('post', '{{p.id}}', '-1', '{{v.id}}')" class="post-{{p.id}}-down text-muted mx-auto arrow-down" onclick="location.href='/login';"></div>

					{% endif %}

				</div>
			{% endif %}

			<div class="card-header bg-transparent border-0 d-flex flex-row flex-nowrap p-0 mr-3">

				<div style="z-index: 3;">
					{% if not p.url %}
						<a {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} href="{{p.permalink}}">
							<img alt="post thumbnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
						</a>
					{% elif p.is_image %}
						<img role="button" data-bs-toggle="modal" data-bs-target="#expandImageModal" onclick="expandDesktopImage('{{p.realurl(v)}}')" alt="post thumbnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
					{% elif p.is_video %}
						<a role="button" onclick="togglevideo({{p.id}})">
							<img alt="post thumbnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
						</a>
					{% elif p.is_youtube %}
						<a role="button" onclick="document.getElementById('video-{{p.id}}').classList.toggle('d-none')">
							<img alt="post thumbnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
						</a>
					{% else %}
						<a {% if not v or v.newtabexternal %}target="_blank"{% endif %} rel="nofollow noopener noreferrer" href="{{p.realurl(v)}}">
							<img alt="post thumbnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
						</a>
					{% endif %}
				</div>
			</div>
			
			
			<div class="card-block d-flex flex-column text-left x-scroll-parent my-md-auto w-100">

				<div class="post-meta text-left mb-md-2">
					<h5 class="card-title post-title text-left mb-0 pb-0 pb-md-1">
						<a id="{{p.id}}-title" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} href="{{p.permalink}}">
						{% if p.flair %}<span class="patron font-weight-bolder mr-1" style="background-color:var(--primary); font-size:12px; line-height:2;">{{p.flair | safe}}</span>{% endif %}
						{{p.realtitle(v) | safe}}
					</a></h5>
				</div>

				<div class="post-info text-left">
					<div class="post-author">
						<span class="post-traffic-info d-none d-md-inline-block"><a href="{{p.permalink}}">{{p.comment_count}} comments</a><span class="text-info d-none {{p.id}}-new-comments"></span> - {{p.views}} thread views</span>

						{% if p.bannedfor %}
							<a role="button"><i class="fas fa-hammer-crash text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was banned for this post{% if p.author.banned_by %} by @{{p.author.banned_by.username}}{% endif %}"></i></a>
						{% endif %}

						{% if FEATURES['AWARDS'] %}
							{% for a in p.awards|reverse %}
								<i class="{{a.class_list}} px-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{a.title}} Award given by @{{a.user.username}}"></i>
							{% endfor %}
						{% endif %}

						{% if v and v.admin_level >= 2 and p.author.shadowbanned %}
							<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Shadowbanned by @{{p.author.shadowbanned}}"></i>
						{% endif %}

						{% if p.stickied %}
							<i id='pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned by @{{p.stickied}}" {% if p.stickied_utc %}onmouseover="pinned_timestamp('pinned-{{p.id}}')" data-timestamp={{p.stickied_utc}} {% endif %}></i>
						{% endif %}

						{% if p.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{SITE_TITLE}} Admin, speaking officially"></i>{% endif %}
						{% if p.is_pinned and request.path.startswith('/@') %}<i class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned to profile"></i>{% endif %}
						{% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
						{% if p.is_bot %} <i class="fas fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom"	title="Bot"></i>{% endif %}
						{% if p.is_blocking %}<i class="fas fa-user-minus text-warning" data-bs-toggle="tooltip" data-bs-placement="bottom" title="You're blocking this user, but you can see this post because you're an admin."></i>{% endif %}
						{% if p.is_blocked %}<i class="fas fa-user-minus text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="This user is blocking you."></i>{% endif %}
						{% if p.private %}<span class="badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
						{% if v and p.state_report == StateReport.REPORTED and v.can_manage_reports() %}
						<a class="btn btn-primary" id="report-btn-{{p.id}}" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers-{{p.id}}').classList.toggle('d-none')">{{p.active_flags(v)}} Reports</a>
						{% endif %}
							

						<span>
							<span data-bs-toggle="tooltip" data-bs-placement="bottom" onmouseover="timestamp('timestamp-{{p.id}}','{{p.created_utc}}')" id="timestamp-{{p.id}}">{{p.age_string}} by </span>
							{% if p.ghost %}
								👻
							{% else %}
								{% if p.author.verified %}<i class="fas fa-badge-check align-middle ml-1 {% if p.author.verified=='Glowiefied' %}glow{% endif %}" style="color:{% if p.author.verifiedcolor %}#{{p.author.verifiedcolor}}{% else %}#1DA1F2{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{p.author.verified}}"></i>
								{% endif %}
								<a href="/@{{p.author_name}}" 
									class="user-name" 
									onclick='popclick({{p.author.json_popover(v) | tojson}}); return false'
									data-bs-placement="bottom" 
									data-bs-toggle="popover" 
									data-bs-trigger="click" 
									data-content-id="popover" 
									role="button" 
									tabindex="0" 
									style="font-weight: bold;">
										<span 
											{% if p.author.patron and not p.distinguish_level %}
												class="patron" 
												style="background-color:#{{p.author.namecolor}};"
											{% elif p.distinguish_level %}
												class="mod"
											{% endif %}>{{p.author_name}}</span>
								</a>{% if p.author.customtitle %}<bdi style="color: #{{p.author.titlecolor}}">&nbsp;&nbsp;{{p.author.customtitle | safe}}</bdi>{% endif %}
								{% if v and v.admin_level >= 2 %}
									<span 
										class="usernote-link" 
										data-micromodal-trigger="modal-1" 
										onclick='fillnote( {{p.author.json_notes(v) | tojson}}, {{p.id}}, null )'>U</span>
								{% endif %}
							{% endif %}
						</span>
						
						<span>
							({% if p.is_image %}image post{% elif p.is_video %}video post{% elif p.domain %}<a href="/search/posts/?q=domain%3A{{p.domain}}&sort=new&t=all" class="post-meta-domain" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>{{p.domain|truncate(35, True)}}</a>{% else %}text post{% endif %})
						</span>

						{% if p.edited_utc %}
							<span>Edited <span data-bs-toggle="tooltip" data-bs-placement="bottom" id="edited_timestamp-{{p.id}}" onmouseover="timestamp('edited_timestamp-{{p.id}}','{{p.edited_utc}}')">{{p.edited_string}}</span></span>
						{% endif %}
					</div>
					<div class="post-actions d-none d-md-block">
						<ul class="list-inline text-right d-flex">
							{% if p.realbody(v) %}
								<a class="list-inline-item" role="button" onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a>
							{% endif %}
							{% include 'component/post/actions.html' %}
						</ul>
					</div>
				</div>

				<div class="card-footer d-md-none mt-auto {% if request.path == '/changelog' %}px-0{% endif %}">
					<div class="post-actions">
						<ul class="list-inline text-right d-flex">
							<li class="list-inline-item mr-auto">
								<a {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} href="{{p.permalink}}">
									<i class="fas fa-comment-dots mobile-comment-link"></i>{{p.comment_count}}
									<span class="text-info d-none {{p.id}}-new-comments"></span>
								</a>
			
								{% if v and v.admin_level >= 2 %}
									<a class="ml-2" role="button" data-bs-toggle="modal" data-bs-target="#adminModal-{{p.id}}">
										<i class="fas fa-broom"></i>
									</a>
								{% endif %}
			
							</li>
							
							{% if p.realbody(v) and request.path != "/changelog"%}
								<a class="list-inline-item" role="button" onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a>
							{% endif %}
			
							{% if v %}
								<li class="list-inline-item">
									<a role="button" data-bs-toggle="modal" data-bs-target="#actionsModal-{{p.id}}">
										<i class="fas fa-ellipsis-h"></i>
									</a>
								</li>
							{% endif %}
						</ul>
					</div>
				</div>
			
				{% if v %}
					<div class="modal fade d-md-none" id="actionsModal-{{p.id}}" tabindex="-1" role="dialog" aria-labelledby="actionsModalTitle" aria-hidden="true">
						<div class="modal-dialog modal-dialog-centered" role="document">
							<div class="modal-content">
								<div class="modal-header p-3">
									<h5 class="col modal-title text-center h6">More options</h5>
									<button class="close position-absolute py-3" style="right: 1rem"data-bs-dismiss="modal" aria-label="Close">
										<span aria-hidden="true"><i class="fas fa-times-circle text-gray-500"></i></span>
									</button>
								</div>
								<div class="modal-body">
									<ul class="list-group post-actions">
										{% include "component/post/actions_mobile.html" %}
									</ul>
								</div>
							</div>
						</div>
					</div>
				{% endif %}
			</div>
		</div>
	</div>

	<script>
		{% if not v or v.highlightcomments %}
			showNewCommentCounts({{p.id}}, {{p.comment_count}})
		{% endif %}
	</script>

	{% if v and v.admin_level >= 2 %}
		{% include "component/post/actions_admin_mobile.html" %}
	{% endif %}

	{% if p.realbody(v) %}
		<div class="d-none card rounded border pt-3 pb-2 my-2" id="post-text-{{p.id}}">
			{{p.realbody(v) | safe}}
		</div>
	{% endif %}

	{% if p.is_image and not p.over_18 and ((v and v.cardview) or (not v and CARD_VIEW)) %}
		<div style="text-align: center" class="mt-3 mb-4">
			<a {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} rel="nofollow noopener noreferrer" href="{{p.realurl(v)}}">
				<img loading="lazy" data-src="{{p.realurl(v)}}" src="/assets/images/loading.webp" class="img-fluid" style="max-height:20rem" alt="Unable to load image">
			</a>
		</div>
	{% elif p.is_video %}
		<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and CARD_VIEW)) %}d-none{% endif %} mt-4">
			<video id="video2-{{p.id}}" controls preload="none" class="vid">
				<source src="{{p.realurl(v)}}" type="video/mp4">
			</video>
		</div>
	{% elif p.is_youtube %}
		<div id="video-{{p.id}}" class="{% if p.over_18 or not ((v and v.cardview) or (not v and CARD_VIEW)) %}d-none{% endif %} mt-3 mb-4 youtube_embed">
			{{p.embed_url | safe}}
		</div>
	{% endif %}

</div>
{% else %}
	{% if u %}
		{% if v and v.id == u.id %}
		<div class="row no-gutters">	
			<div class="col">			
				<div class="text-center px-3 my-3">
					<span class="fa-stack fa-2x text-muted mb-4">
						<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
						<i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i>
					</span>
					<h2 class="h5">You haven't {% if "saved" in request.full_path %}saved{% else %}made{% endif %} a post yet</h2>
					<p class="text-muted mb-md-5">Your {% if "saved" in request.full_path %}saved posts{% else %}posting history{% endif %} will show here.</p>
					{% if "saved" not in request.full_path %}<a href="/submit" class="btn btn-primary">Create a post</a>{% endif %}
				</div>			
			</div>	
		</div>
		{% else %}
		<div class="row no-gutters">	
			<div class="col">			
				<div class="text-center px-3 my-3">
					<span class="fa-stack fa-2x text-muted mb-4">
						<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
						<i class="fas text-gray-500 fa-scroll-old fa-stack-1x text-lg"></i>
					</span>
					<h2 class="h5">@{{u.username}} hasn't made a post yet</h2>
					<p class="text-muted">Their posting history will show here.</p>
					<pre>
					</pre>
				</div>			
			</div>	
		</div>
		{% endif %}
	{% else %}
		<div class="row no-gutters">	
			<div class="col">			
				<div class="text-center px-3 my-3">
					<span class="fa-stack fa-2x text-muted mb-4">
						<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
						<i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i>
					</span>
					{% if request.path.startswith('/search') and error %}
						<h2 class="h5">{{error}}</h2>
					{% endif %}
				</div>			
			</div>	
		</div>
	{% endif %}
{% endfor %}

{% if v %}
	{% include "component/modal/delete_post.html" %}
	{% include "component/modal/report_post.html" %}
	{% if v.admin_level >= 2 %}
		{% include "component/modal/ban.html" %}
	{% endif %}
	{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
		<script src="{{ 'js/comments+submission_admin.js' | asset }}"></script>
	{% endif %}
{% endif %}
{% include "component/modal/expanded_image.html" %}

<script src="{{ 'js/clipboard.js' | asset }}"></script>
<script src="{{ 'js/comments+submission_listing.js' | asset }}"></script>
<script src="{{ 'js/submission_listing.js' | asset }}"></script>
