<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<!--{hook thread_start.htm}-->

<div class="row">
	<div class="col-lg-12 main">
		<!--{hook thread_breadcrumb_before.htm}-->
		<?php if(empty($hide_breadcrumb)) { ?>
		<ol class="breadcrumb d-none d-md-flex">
			<li class="ztlog_btn breadcrumb-item"><a href="./" aria-label="<?php echo lang('index_page');?>"><i class="icon-home"></i></a></li>
			<li class="ztlog_btn breadcrumb-item"><a href="<?php echo url("forum-$fid");?>"><?php echo $forum['name'];?></a></li>
			<li class="ztlog_btn breadcrumb-item active"><a href="<?php echo url("thread-$tid");?>" title="<?php echo lang('index_page');?>返回主题第一页"><?php echo $thread['subject'];?></a></li>
			<!--{hook thread_breadcrumb.htm}-->
		</ol>
		<?php } ?>
		<!--{hook thread_breadcrumb_after.htm}-->
		
		<div class="card card-thread">
			<div class="card-body">
				<div class="media">
					<a href="<?php echo url("user-$thread[uid]");?>" tabindex="-1">
						<img class="ztlog_avatar-3 mr-3" src="<?php echo $thread['user_avatar_url'];?>">
					</a>
					<div class="media-body">
						<!--{hook thread_subject_before.htm}-->
						<h5 class="break-all">
							<!--{hook thread_subject_start.htm}-->
							<?php echo $thread['subject'];?>
							<!--{hook thread_subject_end.htm}-->
						</h5>
						<!--{hook thread_subject_after.htm}-->
						<div class="d-flex justify-content-between small">
							<div>
								<!--{hook thread_username_before.htm}-->
								<span class="username">
									<a href="<?php echo url("user-$thread[uid]");?>" class="ztlog_option"><?php echo $thread['username'];?><i class="text-ztlog-icon-v<?php echo $thread['uid'];?>"></i></a>
								</span>
                                <span class="date text-grey ml-2"><i class="icon-pencil-square-o"></i> 发表于 <?php echo date('Y-m-d H:i:s',$thread['create_date']); ?></span>
								<!--<span class="text-grey ml-2"><i class="icon-wpforms"></i> <?php echo $thread['views'];?></span>-->
								<!--{hook thread_views_after.htm}-->
							</div>
							<div>
								<!--{hook thread_update_before.htm}-->
								<?php if($allowupdate || $first['allowupdate']) { ?>
								<a href="<?php echo url("post-update-$thread[firstpid]");?>" class="text-grey mr-2 post_update"><i class="icon-edit"></i> <?php echo lang('edit');?></a>
								<?php } ?>
								
								<?php if($allowdelete || $first['allowdelete']) { ?>
								<a data-href="<?php echo url("post-delete-$thread[firstpid]");?>" href="javascript:void(0);" class="text-grey post_delete" isfirst="1"><i class="icon-remove"></i> <?php echo lang('delete');?></a>
								<?php } ?>
								<!--{hook thread_delete_after.htm}-->
							</div>
						</div>
						<hr>
					<div class="small d-flex bg-light position-absolute px-2" style="margin-top: -25px;right: 1.25rem;border-radius: 1rem;">
					    <span style="color: #67C23A;" data-toggle="tooltip" data-placement="top" data-html="true" title="浏览"><i class="icon-wpforms"></i> <?php echo $thread['views'];?>
					    </span>
					    <a href="javascript:void(0)" onclick="$(&quot;html, body&quot;).animate({scrollTop:$(&quot;.card-postlist&quot;).offset().top},{duration:500,easing:&quot;swing&quot;});" data-toggle="tooltip" data-placement="top" data-html="true" title="评论">
					        <span class="ml-2" style="color: #ff4949;"><i class="icon-comment-o"></i> <?php echo $thread['posts'];?>
					        </span>
					     </a>
					     <span class="ml-2" style="color: #20a0ff" data-toggle="tooltip" data-placement="top" data-html="true" title="赞">
					     <i class="icon-heart-o" aria-hidden="true"></i> <?php echo ($thread['likes']);?>
					     </span>
					</div>	
					</div>
				</div>
				<div class="message break-all" isfirst="1">
				<?php if($page == 1) { ?>
				
					<!--{hook thread_message_before.htm}-->
					<?php echo $first['message_fmt'];?>
					<!--{hook thread_message_after.htm}-->
                  
					<!--{hook thread_filelist_before.htm}-->
                    <?php echo post_file_list_html($first['filelist']);?>
					<!--{hook thread_filelist_after.htm}-->
					
				<?php } else { ?>
				
					<!--{hook thread_message_more_before.htm}-->
					<p><a href="<?php echo url("thread-$tid");?>"><?php echo lang('view_thread_message');?></a></p>
					<!--{hook thread_message_more_after.htm}-->
					
				<?php } ?>
				</div>
                <div class="alert alert-primary mt-4" role="alert">
                <i class="icon-bell" style="color:gold;" aria-hidden="true" title="ttPay"></i> 友情提示：本论坛项目均为互联网收录，仅供娱乐，折腾需谨慎！
                <hr><i class="icon-bell" style="color:#24b9bf;" aria-hidden="true" title="ttPay"></i> 声明： 遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
                </div>

				<!--{hook thread_plugin_before.htm}-->
				<div class="plugin d-flex justify-content-center mt-3">
					<!--{hook thread_plugin_body.htm}-->
				</div>
				<!--{hook thread_plugin_after.htm}-->

			</div>
		</div>
		
		<!--{hook thread_postlist_before.htm}-->
		
		<div class="card card-postlist">
			<div class="card-body">
				<div class="card-title">
					<div class="d-flex justify-content-between">
						<div>
							<b><?php echo lang('new_post');?></b> (<span class="posts"><?php echo $thread['posts'];?></span>)
						</div>
						<!--{hook thread_post_list_title_middle.htm}-->
						<div>
							<!--{hook thread_post_list_title_right.htm}-->
						</div>
					</div>
				</div>
				<ul class="list-unstyled postlist">
					<?php include _include(APP_PATH.'view/htm/post_list.inc.htm'); ?>
					
					<?php if(!empty($user)) { ?>
					<li class="post newpost media">
						<a href="<?php echo url("user-$user[uid]");?>" class="mr-3" tabindex="-1">
							<img class="avatar-3" src="<?php echo $user['avatar_url'];?>">
						</a>
						<div class="media-body">
							<div class="d-flex justify-content-between small text-muted">
								<div>
									<div><?php echo $user['username'];?><i class="text-ztlog-icon-v<?php echo $user['uid'];?>"></i></div>
								</div>
								<div>
									<span class="floor" id="newfloor"><?php echo ($thread['posts'] + 2);?></span><?php echo lang('floor');?>
								</div>
							</div>
							<div>
								<form action="<?php echo url("post-create-$tid-1");?>" method="post" id="quick_reply_form" class="d-block">	
									<input type="hidden" name="doctype" value="1" />
									<input type="hidden" name="return_html" value="1" />
									<input type="hidden" name="quotepid" value="0" />
									
									<div class="message mt-1">
										<textarea class="form-control" placeholder="<?php echo lang('message');?>" name="message" id="message"></textarea>
									</div>
                                    <!--{hook thread_quick_reply_message_after.htm}-->
									<div class="text-muted mt-2 small">
										<div class="d-flex justify-content-between">
											<div>
												<!--{hook thread_quick_reply_left_start.htm}-->
												<button type="submit" class="btn btn-sm btn-secondary" id="submit" data-loading-text="<?php echo lang('submiting');?>..."> <?php echo lang('post_create');?> </button>
												<!--{hook thread_quick_reply_left_end.htm}-->
											</div>
											<div>
												<!--{hook thread_quick_reply_right_start.htm}-->
												<a class="icon-mail-forward text-muted" href="<?php echo url("post-create-$tid");?>" id="advanced_reply"> <?php echo lang('advanced_reply');?></a>
												<!--{hook thread_quick_reply_right_end.htm}-->
											</div>
										</div>
									</div>
								</form>
							</div>
						</div>
					</li>
					<?php } ?>
							
				</ul>
			</div>
		</div>
		<!--{hook thread_postlist_after.htm}-->
		
		<div class="d-none threadlist"><input type="checkbox" name="modtid" value="<?php echo $thread['tid']; ?>" checked /></div>
		<?php include _include(APP_PATH.'view/htm/thread_list_mod.inc.htm');?>
		
		<?php if($pagination) { ?>
		<nav><ul class="pagination my-4 justify-content-center flex-wrap"><?php echo $pagination; ?></ul></nav>
		<?php }?>
		
		<!--{hook thread_page_after.htm}-->


<!--{hook thread_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>


<script>
var jform = $('#quick_reply_form');
var jsubmit = $('#submit');
jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			var s = '<ul>'+message+'</ul>';
			var jli = $(s).find('li');
			jli.insertBefore($('.postlist > .post').last());
			jsubmit.button('reset');
			$('#message').val('');
			
			// 楼层 +1
			var jfloor = $('#newfloor');
			jfloor.html(xn.intval(jfloor.html()) + 1);
			
			// 回复数 +1
			var jposts = $('.posts');
			jposts.html(xn.intval(jposts.html()) + 1);
			
		} else if(code < 0) {
			$.alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});


// 缩放图片，适应屏幕大小。
function resize_image() {
	var jmessagelist = $('div.message');
	var first_width = jmessagelist.width(); // 815 : 746; //  734 746
	jmessagelist.each(function() {
		var jdiv = $(this);
		var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); //  734 746
		var jmessage_width = Math.min(jdiv.width(), maxwidth);
		jdiv.find('img, embed, iframe, video').each(function() {
			var jimg = $(this);
			var img_width = this.org_width;
			var img_height = this.org_height;
			if(!img_width) {
				var img_width = jimg.attr('width');
				var img_height = jimg.attr('height');
				this.org_width = img_width;
				this.org_height = img_height;
			}
			//var percent = xn.min(100, xn.ceil((img_width / jmessage_width) * 100));
			if(img_width > jmessage_width) {
				if(this.tagName == 'IMG') {
					jimg.width(jmessage_width);
					jimg.css('height', 'auto');
					jimg.css('cursor', 'pointer');
					jimg.on('click', function() {
						//window.open(jimg.attr('src'));
					});
				} else {
					jimg.width(jmessage_width);
					var height = (img_height / img_width) * jimg.width();
					jimg.height(height);
				}
			}
		});
	});
}

// 对于超宽的表格，加上响应式
function resize_table() {
	$('div.message').each(function() {
		var jdiv = $(this);
		jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); 
	});
}

$(function() {
	resize_image();
	resize_table();
	$(window).on('resize', resize_image);
});

// 输入框自动伸缩

var jmessage = $('#message');
jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '8rem'); });
jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); });

$('li[data-active="fid-<?php echo $fid;?>"]').addClass('active');



</script>

<?php if($thread['closed'] && ($gid == 0 || $gid > 5)) { ?>
<script>
jmessage.val('<?php echo lang('thread_has_already_closed');?>').attr('readonly', 'readonly');
</script>
<?php } ?>
<!--{hook thread_js.htm}-->