@version(2)
@load('./lang')
<include target="_header.html" />

@if ($oDocument->isExists())
	<include target="_read.html" />
	<include target="_comment.html" />
@endif

@if (isset($list_config))

@php
$hrb_style = $module_info->hr_list_style ?? 'list';
if (!function_exists('hrb_relative_time')) {
	function hrb_relative_time($regdate) {
		$ts = ztime($regdate);
		if (!$ts) { return ''; }
		$diff = time() - $ts;
		// 문구는 스킨 언어 파일에서 받는다. 여기 박으면 다른 언어에서 한국어가 나온다
		if ($diff < 60) { return lang('hrb_just_now'); }
		if ($diff < 3600) { return sprintf(lang('hrb_minutes_ago'), floor($diff / 60)); }
		if ($diff < 86400) { return sprintf(lang('hrb_hours_ago'), floor($diff / 3600)); }
		if ($diff < 86400 * 30) { return sprintf(lang('hrb_days_ago'), floor($diff / 86400)); }
		return date('y.m.d', $ts);
	}
}
$hrb_author = true;
$hrb_count = true;
$hrb_cat = ($module_info->use_category ?? 'N') === 'Y';
$hrb_docs = [];
foreach ($notice_list ?: [] as $hrb_nd) { $hrb_docs['notice_' . $hrb_nd->document_srl] = $hrb_nd; }
foreach ($document_list ?: [] as $hrb_dk => $hrb_dd) { $hrb_docs[$hrb_dk] = $hrb_dd; }
@endphp

<div class="hrb-list hrb-style-{{ $hrb_style }}">

	@if (!$oDocument->isExists() && (!empty($module_info->board_title) || !empty($module_info->board_desc)))
	<div class="hr-head">
		<div>
			<h2 class="hr-title">{{ Context::replaceUserLang($module_info->board_title ?: $module_info->browser_title) }}</h2>
			@if (!empty($module_info->board_desc))<p class="hr-desc">{{ $module_info->board_desc }}</p>@endif
		</div>
	</div>
	@endif

	{{-- 목록이 길면 아래 글쓰기 버튼까지 내려가야 한다. 그래서 위에도 둔다 --}}
	@if (($hrb_cat && count($category_list)) || $grant->write_document)
	<div class="hrb-toolbar @if (!($hrb_cat && count($category_list))) is-bare @endif">
		@if ($hrb_cat && count($category_list))
		<div class="hrb-cats">
			<a class="hr-chip @if (empty($category)) is-on @endif" href="{{ getUrl('category', '', 'page', '') }}">{{ $lang->category_all ?? $lang->hrb_all }}</a>
			@foreach ($category_list as $hrb_c)
			<a class="hr-chip @if ((int)$category === (int)$hrb_c->category_srl) is-on @endif" href="{{ getUrl('category', $hrb_c->category_srl, 'document_srl', '', 'page', '') }}">{{ $hrb_c->title }} <em>{{ $hrb_c->document_count }}</em></a>
			@endforeach
		</div>
		@endif
		@if ($grant->write_document)
		<a class="hr-btn hr-btn-primary hrb-write-top" href="{{ getUrl('act', 'dispBoardWrite', 'document_srl', '') }}">{{ $lang->cmd_write_post ?? $lang->cmd_write ?? $lang->hrb_write }}</a>
		@endif
	</div>
	@endif

	@if (count($hrb_docs))

	@if ($hrb_style === 'list')
	<table class="hr-table hrb-table{{ ($module_info->hr_author_align ?? 'left') === 'center' ? ' hrb-author-center' : '' }}">
		<thead>
			<tr>
				@foreach ($list_config as $hrb_col)
				@if ($hrb_col->idx != -1)
				<th scope="col" class="hrb-col-extra"><a href="{{ getUrl('sort_index', $hrb_col->eid, 'order_type', $order_type) }}">{{ $hrb_col->name }}</a></th>
				@elseif ($hrb_col->type === 'no')
				<th scope="col" class="hrb-col-no">{{ $lang->no }}</th>
				@elseif ($hrb_col->type === 'module_title')
				<th scope="col" class="hrb-col-module">{{ $lang->module_title }}</th>
				@elseif ($hrb_col->type === 'title')
				<th scope="col" class="hrb-col-title">{{ $lang->title }}</th>
				@elseif ($hrb_col->type === 'nick_name')
				<th scope="col" class="hrb-col-author">{{ $lang->writer }}</th>
				@elseif ($hrb_col->type === 'user_id')
				<th scope="col" class="hrb-col-author">{{ $lang->user_id }}</th>
				@elseif ($hrb_col->type === 'user_name')
				<th scope="col" class="hrb-col-author">{{ $lang->user_name }}</th>
				@elseif ($hrb_col->type === 'regdate')
				<th scope="col" class="hrb-col-date"><a href="{{ getUrl('sort_index', 'regdate', 'order_type', $order_type) }}">{{ $lang->date }}</a></th>
				@elseif ($hrb_col->type === 'last_update')
				<th scope="col" class="hrb-col-date"><a href="{{ getUrl('sort_index', 'update_order', 'order_type', $order_type) }}">{{ $lang->last_update }}</a></th>
				@elseif ($hrb_col->type === 'last_post')
				<th scope="col" class="hrb-col-date"><a href="{{ getUrl('sort_index', 'update_order', 'order_type', $order_type) }}">{{ $lang->last_post }}</a></th>
				@elseif ($hrb_col->type === 'readed_count')
				<th scope="col" class="hrb-col-num"><a href="{{ getUrl('sort_index', 'readed_count', 'order_type', $order_type) }}">{{ $lang->readed_count }}</a></th>
				@elseif ($hrb_col->type === 'voted_count')
				<th scope="col" class="hrb-col-num"><a href="{{ getUrl('sort_index', 'voted_count', 'order_type', $order_type) }}">{{ $lang->voted_count }}</a></th>
				@elseif ($hrb_col->type === 'blamed_count')
				<th scope="col" class="hrb-col-num"><a href="{{ getUrl('sort_index', 'blamed_count', 'order_type', $order_type) }}">{{ $lang->blamed_count }}</a></th>
				@endif
				@endforeach
				@if ($grant->manager)
				<th scope="col" class="hrb-col-check"><input type="checkbox" onclick="XE.checkboxToggleAll({ doClick:true });" title="{{ $lang->check_all ?? $lang->hrb_check_all }}" /></th>
				@endif
			</tr>
		</thead>
		<tbody>
			@foreach ($hrb_docs as $hrb_no => $document)
			<tr class="@if ($document->isNotice()) is-notice @endif @if ($document_srl == $document->document_srl) is-current @endif">
				@foreach ($list_config as $hrb_col)

				@if ($hrb_col->idx != -1)
				<td class="hrb-col-extra">{!! $document->getExtraValueHTML($hrb_col->idx) !!}</td>

				@elseif ($hrb_col->type === 'no')
				<td class="hrb-col-no">
					@if ($document_srl == $document->document_srl)&raquo;
					@elseif ($document->isNotice())<span class="hr-badge">{{ $lang->notice }}</span>
					@else{{ $hrb_no }}@endif
				</td>

				@elseif ($hrb_col->type === 'module_title')
				<td class="hrb-col-module"><a href="{{ getUrl('', 'mid', $document->get('mid')) }}">{{ $document->get('module_title') }}</a></td>

				@elseif ($hrb_col->type === 'title')
				<td class="hrb-col-title">
					@if ($hrb_cat && $document->get('category_srl') && isset($category_list[$document->get('category_srl')]))
					<a class="hrb-cat" href="{{ getUrl('category', $document->get('category_srl'), 'document_srl', '', 'page', '') }}">{{ $category_list[$document->get('category_srl')]->title }}</a>
					@endif
					<a class="hrb-title-link" href="{{ getUrl('document_srl', $document->document_srl, 'listStyle', $listStyle, 'cpage', '') }}">
						@if ($document->isSecret())<svg class="hrb-ico" viewBox="0 0 16 16" aria-label="{{ $lang->hrb_secret }}"><path d="M4 7V5a4 4 0 1 1 8 0v2h.5A1.5 1.5 0 0 1 14 8.5v5A1.5 1.5 0 0 1 12.5 15h-9A1.5 1.5 0 0 1 2 13.5v-5A1.5 1.5 0 0 1 3.5 7H4zm1.5 0h5V5a2.5 2.5 0 0 0-5 0v2z"/></svg>@endif
						{!! $document->getTitle() !!}
					</a>
					@if ($document->getCommentCount())<a class="hrb-cmt" href="{{ getUrl('document_srl', $document->document_srl) }}#comment">[{{ $document->getCommentCount() }}]</a>@endif
					@if ($document->hasUploadedFiles())<svg class="hrb-ico hrb-ico-file" viewBox="0 0 16 16" aria-label="{{ $lang->hrb_attached }}"><path d="M9.5 2a3.5 3.5 0 0 1 3.5 3.5v5a4 4 0 0 1-8 0V5h1.5v5.5a2.5 2.5 0 0 0 5 0v-5a2 2 0 1 0-4 0v5a.5.5 0 0 0 1 0V5H10v5.5a2 2 0 0 1-4 0v-5A3.5 3.5 0 0 1 9.5 2z"/></svg>@endif
					@if ($document->getRegdateTime() > time() - 60 * 60 * ($module_info->duration_new ?? 24))<em class="hrb-new" aria-label="{{ $lang->hrb_new_post }}">N</em>@endif
				</td>

				@elseif ($hrb_col->type === 'nick_name')
				<td class="hrb-col-author">
					@php $hrb_row_photo = (($module_info->hr_show_photo ?? 'Y') === 'Y') ? $document->getProfileImage() : ''; @endphp
					@if ($hrb_row_photo)<img class="hrb-photo" src="{{ $hrb_row_photo }}" alt="" />@endif
					{{-- 기여 뱃지 애드온이 member_ 요소 안쪽을 다시 쓴다. 이 안에 태그를 더 넣으면 안 된다 --}}
					@if ($document->get('member_srl') > 0)
					<a href="#popup_menu_area" class="member_{{ $document->get('member_srl') }}" onclick="return false">{{ $document->getNickName() }}</a>
					@else<span class="hrb-nick">{{ $document->getNickName() }}</span>@endif
				</td>

				@elseif ($hrb_col->type === 'user_id')
				<td class="hrb-col-author"><span class="hrb-nick">{{ $document->getUserID() }}</span></td>

				@elseif ($hrb_col->type === 'user_name')
				<td class="hrb-col-author"><span class="hrb-nick">{{ $document->getUserName() }}</span></td>

				@elseif ($hrb_col->type === 'regdate')
				<td class="hrb-col-date">{{ hrb_relative_time($document->get("regdate")) }}</td>

				@elseif ($hrb_col->type === 'last_update')
				<td class="hrb-col-date">{{ zdate($document->get('last_update'), 'Y.m.d') }}</td>

				@elseif ($hrb_col->type === 'last_post')
				<td class="hrb-col-date">
					@if ((int)$document->get('comment_count') > 0)
					<a href="{{ $document->getUrl() }}#comment">{{ zdate($document->get('last_update'), 'Y.m.d') }}</a>
					@if ($document->getLastUpdater())<span class="hrb-last-by">{{ $document->getLastUpdater() }}</span>@endif
					@else&nbsp;@endif
				</td>

				@elseif ($hrb_col->type === 'readed_count')
				<td class="hrb-col-num is-read">{{ number_format((int)$document->get('readed_count')) }}</td>

				@elseif ($hrb_col->type === 'voted_count')
				<td class="hrb-col-num is-vote">{{ number_format((int)$document->get('voted_count')) }}</td>

				@elseif ($hrb_col->type === 'blamed_count')
				<td class="hrb-col-num is-blame">{{ number_format((int)$document->get('blamed_count')) }}</td>
				@endif

				@endforeach
				@if ($grant->manager)
				<td class="hrb-col-check"><input type="checkbox" name="cart" value="{{ $document->document_srl }}" title="{{ $lang->hrb_select_post }}" onclick="doAddDocumentCart(this)" @if ($document->isCarted()) checked @endif /></td>
				@endif
			</tr>
			@endforeach
		</tbody>
	</table>

	@else
	@if ($notice_list)
	@include("_notices")
	@endif

	@if ($hrb_style === "faq")
	<ul class="hrb-faq">
		@foreach ($document_list ?: [] as $document)
		<li>
			<details>
				<summary>
					<span class="hrb-faq-q">Q</span>
					@if ($hrb_cat && $document->get('category_srl') && isset($category_list[$document->get('category_srl')]))<em class="hrb-cat">{{ $category_list[$document->get('category_srl')]->title }}</em>@endif
					<span class="hrb-faq-title">{{ $document->getTitleText() }}</span>
					<svg class="hrb-faq-arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="m7 10 5 5 5-5z" /></svg>
				</summary>
				<div class="hrb-faq-a">
					<span class="hrb-faq-mark">A</span>
					<div class="hrb-faq-body rhymix_content xe_content">{!! $document->getContent(false) !!}</div>
				</div>
			</details>
		</li>
		@endforeach
	</ul>

	@elseif ($hrb_style === "webzine")
	<ul class="hrb-webzine">
		@foreach ($document_list ?: [] as $document)
		@php $hrb_thumb = $document->getThumbnail(320, 200, "crop"); @endphp
		<li>
			<a href="{{ getUrl('document_srl', $document->document_srl) }}">
				<span class="hrb-wz-thumb @if (!$hrb_thumb) is-none @endif">
					@if ($hrb_thumb)<img src="{{ $hrb_thumb }}" alt="" loading="lazy" />@endif
				</span>
				<span class="hrb-wz-body">
					<strong class="hrb-wz-title">
						@if ($hrb_cat && $document->get('category_srl') && isset($category_list[$document->get('category_srl')]))<em class="hrb-cat">{{ $category_list[$document->get('category_srl')]->title }}</em>@endif
						{{ $document->getTitleText() }}
						@if ($document->getCommentCount())<em class="hrb-cmt">{{ $document->getCommentCount() }}</em>@endif
					</strong>
					<span class="hrb-wz-summary">{{ $document->getSummary(120) }}</span>
					<span class="hrb-card-meta">
						@if ($hrb_author)<span>{{ $document->getNickName() }}</span>@endif
						<span>{{ hrb_relative_time($document->get("regdate")) }}</span>
						@if ($hrb_count)<span>{{ $lang->readed_count ?? $lang->hrb_read_count }} {{ number_format($document->get('readed_count')) }}</span>@endif
					</span>
				</span>
			</a>
		</li>
		@endforeach
	</ul>

	@else
	<div class="hrb-cards">
		@foreach ($document_list ?: [] as $document)
		@include("_card")
		@endforeach
	</div>
	@endif
	@endif

	@else
	<p class="hr-empty">{{ $lang->msg_not_founded ?? $lang->hrb_empty }}</p>
	@endif

	@if (count($hrb_docs))
	<nav class="hr-pages" aria-label="{{ $lang->hrb_pagination }}">
		<a href="{{ getUrl('page', 1, 'document_srl', '', 'division', $division, 'last_division', $last_division) }}" aria-label="{{ $lang->hrb_first_page }}">&laquo;</a>
		{@ while ($hrb_page_no = $page_navigation->getNextPage()): }
			@if ($page == $hrb_page_no)
			<strong aria-current="page">{{ $hrb_page_no }}</strong>
			@else
			<a href="{{ getUrl('page', $hrb_page_no, 'document_srl', '', 'division', $division, 'last_division', $last_division) }}">{{ $hrb_page_no }}</a>
			@endif
		{@ endwhile; }
		<a href="{{ getUrl('page', $page_navigation->last_page, 'document_srl', '', 'division', $division, 'last_division', $last_division) }}" aria-label="{{ $lang->hrb_last_page }}">&raquo;</a>
	</nav>
	@endif

	@if ($last_division)
	<p class="hrb-division"><a class="hr-btn" href="{{ getUrl('page', 1, 'document_srl', '', 'division', $last_division, 'last_division', '') }}">{{ $lang->cmd_search_next ?? $lang->hrb_search_next }}</a></p>
	@endif

	<div class="hrb-bar">
		@if ($grant->view)
		<form class="hrb-search" action="{{ getUrl() }}" method="get" rx-autoform="false">
			<input type="hidden" name="mid" value="{{ $mid }}" />
			<input type="hidden" name="category" value="{{ $category }}" />
			<select name="search_target">
				@foreach ($search_option as $hrb_sk => $hrb_sv)
				<option value="{{ $hrb_sk }}" @if ($search_target === $hrb_sk) selected @endif>{{ $hrb_sv }}</option>
				@endforeach
			</select>
			<input type="text" name="search_keyword" value="{{ $search_keyword }}" placeholder="{{ $lang->hrb_search_ph }}" />
			<button type="submit" class="hr-btn">{{ $lang->cmd_search }}</button>
		</form>
		@endif

		<div class="hrb-bar-actions">
			@if ($grant->manager)
			<a class="hr-btn" href="{{ getUrl('', 'mid', $mid, 'act', 'dispDocumentManageDocument') }}" onclick="popopen(this.href, 'manageDocument'); return false;">{{ $lang->cmd_manage_document ?? $lang->hrb_manage }}</a>
			<a class="hr-btn" href="{{ getUrl('', 'mid', $mid, 'act', 'dispBoardAdminBoardInfo') }}">{{ $lang->cmd_management ?? $lang->hrb_settings }}</a>
			@endif
			@if ($grant->write_document)
			<a class="hr-btn hr-btn-primary" href="{{ getUrl('act', 'dispBoardWrite', 'document_srl', '') }}">{{ $lang->cmd_write_post ?? $lang->cmd_write ?? $lang->hrb_write }}</a>
			@endif
		</div>
	</div>

</div>
@endif

<include target="_footer.html" />
