<?php
declare(strict_types=1);
$questionTags=is_array($questionTags??null)?$questionTags:[];
$reportedItems=is_array($reportedItems??null)?$reportedItems:['question'=>[],'answer'=>[],'comment'=>[]];
$contentDirection=$question!==null?$localeContext->contentDirection($question['content_locale']??null):$localeContext->htmlAttributes()['dir'];
$reportReasons=['spam','abuse','duplicate','misleading','other'];
$postingRules=is_array($postingRules??null)?array_replace(\App\Community\PostingPolicyService::defaults(),$postingRules):\App\Community\PostingPolicyService::defaults();
$commentMin=max(0,(int)($postingRules['comment_min']??3));$commentMax=max(0,(int)($postingRules['comment_max']??600));$answerMin=max(0,(int)($postingRules['answer_min']??10));$answerMax=max(0,(int)($postingRules['answer_max']??20000));
// The canonical view URL follows the configured permalink structure; the action
// endpoints stay on the slug form so no structure change can break a form post.
$questionViewUrl=quaeriva_question_url((string)$slug,(int)($question['id']??0));
$questionActionBase=quaeriva_question_action_url((string)$slug);
$answersMeta=is_array($answersMeta??null)?$answersMeta:['page'=>1,'per_page'=>50,'total'=>count($answers??[]),'total_pages'=>1];
$answerPage=max(1,(int)($answersMeta['page']??1));$answerPages=max(1,(int)($answersMeta['total_pages']??1));$answerTotal=max(0,(int)($answersMeta['total']??count($answers??[])));
?>
<?php
// Optional widget sidebar; without configured widgets the question keeps its
// original full-width layout.
$questionSidebar = isset($renderSection) && is_callable($renderSection) ? $renderSection('question_sidebar') : '';
?>
<section class="content-section question-section question-shell"><div class="container question-container<?= $questionSidebar !== '' ? ' has-sidebar' : '' ?>">
<?php if ($questionSidebar !== ''): ?><aside class="content-sidebar"><?= $questionSidebar ?></aside><?php endif; ?>
<?php if($question===null): ?>
 <div class="empty-state question-empty"><h1><?= quaeriva_t($translator,'questions.not_found') ?></h1><p><?= quaeriva_t($translator,'questions.not_found_hint') ?></p><a class="button button-secondary" href="<?= quaeriva_escape(quaeriva_url()) ?>"><?= quaeriva_t($translator,'common.back_home') ?></a></div>
<?php else: ?>
 <?php $questionAuthor=trim((string)($question['author_name']??''));$questionUsername=trim((string)($question['author_username']??''));$questionOwnerId=(int)($question['user_id']??0);$currentUserId=(int)($currentUser['id']??0);$questionAvatar=trim((string)($question['author_avatar_url']??''));if($questionAvatar===''&&$questionAuthor!=='')$questionAvatar=quaeriva_default_avatar_url($questionOwnerId); ?>
 <?php if(trim((string)($notice??''))!==''): ?><div class="notice" role="status"><?= quaeriva_escape($notice) ?></div><?php endif; ?>
 <?php if((string)($_GET['answer']??'')==='pending'): ?><div class="notice" role="status"><?= quaeriva_t($translator,'questions.answer_pending') ?></div><?php endif; ?>
 <?php if((string)($_GET['commented']??'')==='pending'): ?><div class="notice" role="status"><?= quaeriva_t($translator,'questions.comment_pending') ?></div><?php endif; ?>
 <article class="question-detail">
  <h1 dir="<?= quaeriva_escape($contentDirection) ?>"><?= quaeriva_escape($question['title']??'') ?></h1>
  <div class="question-meta question-meta-large question-status-row">
   <?php if($questionAuthor!==''&&$questionUsername!==''): ?><a class="author-chip" href="<?= quaeriva_escape(quaeriva_url('u/'.rawurlencode($questionUsername))) ?>"><?php if($questionAvatar!==''): ?><img src="<?= quaeriva_escape($questionAvatar) ?>" alt="" width="36" height="36" loading="lazy" decoding="async"><?php endif; ?><span><bdi><?= quaeriva_escape($questionAuthor) ?></bdi></span></a><?php elseif($questionAuthor!==''): ?><span class="author-chip author-chip-static"><?php if($questionAvatar!==''): ?><img src="<?= quaeriva_escape($questionAvatar) ?>" alt="" width="36" height="36" loading="lazy" decoding="async"><?php endif; ?><span><bdi><?= quaeriva_escape($questionAuthor) ?></bdi></span></span><?php else: ?><span><?= quaeriva_t($translator,'common.anonymous') ?></span><?php endif; ?>
   <span><bdi><?= (int)($question['views_count']??0) ?></bdi> <?= quaeriva_t($translator,'common.views') ?></span>
   <span><bdi><?= (int)($question['answers_count']??count($answers??[])) ?></bdi> <?= quaeriva_t($translator,'common.answers') ?></span>
  </div>
  <?php if($questionTags!==[]): ?><nav class="question-tags" aria-label="<?= quaeriva_t($translator,'questions.tags') ?>"><?php foreach($questionTags as $tag):$tagSlug=trim((string)($tag['slug']??''));if($tagSlug==='')continue; ?><a class="question-tag" href="<?= quaeriva_escape(quaeriva_url('t/'.rawurlencode($tagSlug))) ?>"><bdi dir="auto"><?= quaeriva_escape((string)($tag['name']??$tagSlug)) ?></bdi></a><?php endforeach; ?></nav><?php endif; ?>
  <div class="rich-text" dir="<?= quaeriva_escape($contentDirection) ?>"><?= quaeriva_rich_text($question['body']??'', 'full') ?></div>
   <div class="action-row question-action-bar" aria-label="<?= quaeriva_t($translator,'questions.actions') ?>">
    <div class="vote-controls"><strong><?= (int)($question['votes_count']??0) ?></strong><?php if($currentUser !== null && ($questionOwnerId <= 0 || $questionOwnerId !== $currentUserId)): ?><form method="post" action="<?= quaeriva_escape($questionActionBase.'/vote') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><button class="button button-small button-secondary action-button" type="submit" name="value" value="1" aria-label="<?= quaeriva_t($translator,'questions.vote_up') ?>" title="<?= quaeriva_t($translator,'questions.vote_up') ?>"><?= quaeriva_icon('thumbs-up') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.vote_up') ?></span></button><button class="button button-small button-secondary action-button" type="submit" name="value" value="-1" aria-label="<?= quaeriva_t($translator,'questions.vote_down') ?>" title="<?= quaeriva_t($translator,'questions.vote_down') ?>"><?= quaeriva_icon('thumbs-down') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.vote_down') ?></span></button></form><?php elseif($currentUser===null): ?><a class="text-link" href="<?= quaeriva_escape(quaeriva_url('login',['redirect'=>$currentPath??$questionViewUrl])) ?>"><?= quaeriva_t($translator,'questions.login_to_vote') ?></a><?php endif; ?></div>
    <?php if(($site['follows_enabled']??true)===true): ?><?php if($currentUser!==null): ?><form class="follow-form" method="post" action="<?= quaeriva_escape($questionActionBase.'/follow') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><button class="button button-small action-button <?= !empty($isFollowing)?'button-active':'button-secondary' ?>" type="submit" aria-label="<?= quaeriva_t($translator,!empty($isFollowing)?'questions.unfollow':'questions.follow') ?>" title="<?= quaeriva_t($translator,!empty($isFollowing)?'questions.unfollow':'questions.follow') ?>"><?= quaeriva_icon('bookmark') ?><span class="action-button-label"><?= quaeriva_t($translator,!empty($isFollowing)?'questions.unfollow':'questions.follow') ?></span></button></form><?php else: ?><a class="button button-small button-secondary action-button" href="<?= quaeriva_escape(quaeriva_url('login',['redirect'=>$currentPath??$questionViewUrl])) ?>" aria-label="<?= quaeriva_t($translator,'questions.follow') ?>" title="<?= quaeriva_t($translator,'questions.follow') ?>"><?= quaeriva_icon('bookmark') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.follow') ?></span></a><?php endif; ?><?php endif; ?>
   <?php $isQuestionReported = in_array((int)($question['id']??0), (array)($reportedItems['question'] ?? []), true); ?>
    <?php if($currentUser!==null): ?><?php if($isQuestionReported): ?><span class="report-done"><?= quaeriva_t($translator,'questions.report_done') ?></span><?php else: ?><details class="report-action question-report-action"><summary class="button button-small button-secondary action-button" aria-label="<?= quaeriva_t($translator,'questions.report_question') ?>" title="<?= quaeriva_t($translator,'questions.report_question') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_question') ?></span></summary><form class="question-form compact-form report-popover" method="post" action="<?= quaeriva_escape($questionActionBase.'/report') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><label><?= quaeriva_t($translator,'questions.report_reason') ?><select name="reason"><?php foreach($reportReasons as $reason): ?><option value="<?= quaeriva_escape($reason) ?>"><?= quaeriva_t($translator,'questions.report_reasons.'.$reason) ?></option><?php endforeach; ?></select></label><label><?= quaeriva_t($translator,'questions.report_notes') ?><textarea name="notes" rows="3" maxlength="1000" dir="<?= quaeriva_escape($contentDirection) ?>"></textarea></label><button class="button button-small" type="submit"><?= quaeriva_t($translator,'questions.report_submit') ?></button></form></details><?php endif; ?><?php else: ?><a class="button button-small button-secondary action-button" href="<?= quaeriva_escape(quaeriva_url('login',['redirect'=>$currentPath??$questionViewUrl])) ?>" aria-label="<?= quaeriva_t($translator,'questions.report_question') ?>" title="<?= quaeriva_t($translator,'questions.report_question') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_question') ?></span></a><?php endif; ?>
    <button class="button button-small button-secondary action-button" type="button" data-share-question data-share-url="<?= quaeriva_escape($currentPath??$questionViewUrl) ?>" aria-label="<?= quaeriva_t($translator,'questions.share') ?>" title="<?= quaeriva_t($translator,'questions.share') ?>"><?= quaeriva_icon('share') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.share') ?></span></button>
  </div>
  <?php $questionComments = (array)($comments['question'] ?? []); ?>
  <?php if(($site['comments_enabled']??true)===true): ?>
  <div class="question-comments compact-comment-thread" id="question-comments">
   <?php if($questionComments!==[]): ?>
    <div class="comment-list compact-comment-list">
     <?php foreach($questionComments as $comment):$commentId=(int)($comment['id']??0);$isCommentReported=in_array($commentId, (array)($reportedItems['comment'] ?? []), true); ?>
      <article class="comment-item" id="comment-<?= $commentId ?>">
       <div class="comment-body" dir="<?= quaeriva_escape($contentDirection) ?>"><?= quaeriva_rich_text($comment['body']??'', 'comment') ?></div>
       <footer class="comment-meta"><small><bdi><?= quaeriva_escape(trim((string)($comment['author_name']??''))?:$translator->get('common.anonymous')) ?></bdi></small>
       <?php if($currentUser!==null&&$commentId>0): ?>
        <?php if($isCommentReported): ?>
         <span class="report-done"><?= quaeriva_t($translator,'questions.report_done') ?></span>
        <?php else: ?>
          <details class="report-action comment-report-action"><summary class="action-button" aria-label="<?= quaeriva_t($translator,'questions.report_comment') ?>" title="<?= quaeriva_t($translator,'questions.report_comment') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_comment') ?></span></summary>
          <form class="compact-form report-popover" method="post" action="<?= quaeriva_escape($questionActionBase.'/comments/'.$commentId.'/report') ?>">
           <input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>">
           <input type="hidden" name="answers_page" value="<?= $answerPage ?>">
           <select name="reason"><?php foreach($reportReasons as $reason): ?><option value="<?= quaeriva_escape($reason) ?>"><?= quaeriva_t($translator,'questions.report_reasons.'.$reason) ?></option><?php endforeach; ?></select>
           <textarea name="notes" rows="2" maxlength="1000" dir="<?= quaeriva_escape($contentDirection) ?>"></textarea>
           <button class="button button-small button-secondary" type="submit"><?= quaeriva_t($translator,'questions.report_submit') ?></button>
          </form>
         </details>
        <?php endif; ?>
       <?php endif; ?>
       </footer>
      </article>
     <?php endforeach; ?>
    </div>
   <?php endif; ?>
   <?php if($currentUser!==null): ?>
    <details class="comment-composer"<?= !empty($expandQuestionComments)?' open':'' ?>>
     <summary class="text-link"><?= quaeriva_t($translator,'questions.question_comment') ?></summary>
     <form class="comment-form compact-comment-form" method="post" action="<?= quaeriva_escape($questionActionBase.'/comments') ?>">
      <input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>">
      <?= quaeriva_bot_guard_fields() ?>
      <textarea class="comment-textarea" name="body" dir="<?= quaeriva_escape($contentDirection) ?>" rows="2"<?= quaeriva_rich_editor_attributes($translator, 'comment', '') ?><?= $commentMax>0?' maxlength="'.$commentMax.'"':'' ?><?= $commentMin>0?' minlength="'.$commentMin.'"':'' ?> required placeholder="<?= quaeriva_t($translator,'questions.comment_placeholder') ?>"></textarea>
      <button class="button button-small button-secondary" type="submit"><?= quaeriva_t($translator,'questions.comment') ?></button>
     </form>
    </details>
   <?php endif; ?>
  </div>
  <?php endif; ?>
 </article>
 <?php if(isset($renderAd)&&is_callable($renderAd)): ?><?= $renderAd('after_question') ?><?php endif; ?>
 <section class="answers-section question-answer-stack" aria-labelledby="answers-heading"><div class="section-heading compact"><h2 id="answers-heading"><?= quaeriva_t($translator,'questions.answer_count',['count'=>$answerTotal]) ?></h2></div>
 <?php if(($answers??[])===[]): ?><div class="empty-state empty-state-small"><p><?= quaeriva_t($translator,'questions.no_answers') ?></p></div><?php else: ?><div class="answer-list">
 <?php foreach($answers as $answerIndex=>$answer):$answerId=(int)($answer['id']??0);$answerOwnerId=(int)($answer['user_id']??0);$answerAuthor=trim((string)($answer['author_name']??''));$answerUsername=trim((string)($answer['author_username']??''));$answerAvatar=trim((string)($answer['author_avatar_url']??''));if($answerAvatar===''&&$answerAuthor!=='')$answerAvatar=quaeriva_default_avatar_url($answerOwnerId);$answerComments=(array)($comments['answers'][$answerId]??[]);$isAnswerReported=in_array($answerId, (array)($reportedItems['answer'] ?? []), true); ?>
  <article id="answer-<?= $answerId ?>" class="answer-card<?= !empty($answer['is_best'])?' answer-best':'' ?>"><?php if(!empty($answer['is_best'])): ?><span class="best-badge"><?= quaeriva_t($translator,'questions.best_answer') ?></span><?php endif; ?><div class="rich-text" dir="<?= quaeriva_escape($contentDirection) ?>"><?= quaeriva_rich_text($answer['body']??'', 'full') ?></div>
   <div class="answer-meta"><?php if($answerAuthor!==''&&$answerUsername!==''): ?><a class="author-chip" href="<?= quaeriva_escape(quaeriva_url('u/'.rawurlencode($answerUsername))) ?>"><?php if($answerAvatar!==''): ?><img src="<?= quaeriva_escape($answerAvatar) ?>" alt="" width="28" height="28" loading="lazy" decoding="async"><?php endif; ?><bdi><?= quaeriva_escape($answerAuthor) ?></bdi></a><?php elseif($answerAuthor!==''): ?><span class="author-chip author-chip-static"><?php if($answerAvatar!==''): ?><img src="<?= quaeriva_escape($answerAvatar) ?>" alt="" width="28" height="28" loading="lazy" decoding="async"><?php endif; ?><bdi><?= quaeriva_escape($answerAuthor) ?></bdi></span><?php else: ?><span><?= quaeriva_t($translator,'common.anonymous') ?></span><?php endif; ?></div>
   <?php $canAccept=$currentUser!==null&&((int)($currentUser['id']??0)===(int)($question['user_id']??0)||in_array((string)($currentUser['role']??''),['moderator','admin'],true)); ?><div class="action-row answer-actions"><div class="vote-controls answer-vote-controls"><strong><?= (int)($answer['votes_count']??0) ?></strong><?php if($currentUser!==null&&($answerOwnerId<=0||$answerOwnerId!==$currentUserId)): ?><form method="post" action="<?= quaeriva_escape($questionActionBase.'/answers/'.$answerId.'/vote') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><input type="hidden" name="answers_page" value="<?= $answerPage ?>"><button class="button button-small button-secondary action-button" type="submit" name="value" value="1" aria-label="<?= quaeriva_t($translator,'questions.vote_up') ?>" title="<?= quaeriva_t($translator,'questions.vote_up') ?>"><?= quaeriva_icon('thumbs-up') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.vote_up') ?></span></button><button class="button button-small button-secondary action-button" type="submit" name="value" value="-1" aria-label="<?= quaeriva_t($translator,'questions.vote_down') ?>" title="<?= quaeriva_t($translator,'questions.vote_down') ?>"><?= quaeriva_icon('thumbs-down') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.vote_down') ?></span></button></form><?php elseif($currentUser===null): ?><a class="text-link" href="<?= quaeriva_escape(quaeriva_url('login',['redirect'=>$questionViewUrl.'#answer-'.$answerId])) ?>"><?= quaeriva_t($translator,'questions.login_to_vote') ?></a><?php endif; ?></div><?php if($canAccept&&empty($answer['is_best'])&&$answerId>0): ?><form method="post" action="<?= quaeriva_escape($questionActionBase.'/answers/'.$answerId.'/accept') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><input type="hidden" name="answers_page" value="<?= $answerPage ?>"><button class="button button-small button-secondary action-button" type="submit" aria-label="<?= quaeriva_t($translator,'questions.accept_answer') ?>" title="<?= quaeriva_t($translator,'questions.accept_answer') ?>"><?= quaeriva_icon('check') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.accept_answer') ?></span></button></form><?php endif; ?><?php if($answerId>0): ?><?php if($currentUser!==null): ?><?php if($isAnswerReported): ?><span class="report-done"><?= quaeriva_t($translator,'questions.report_done') ?></span><?php else: ?><details class="report-action answer-report-action"><summary class="button button-small button-secondary action-button" aria-label="<?= quaeriva_t($translator,'questions.report_answer') ?>" title="<?= quaeriva_t($translator,'questions.report_answer') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_answer') ?></span></summary><form class="compact-form report-popover" method="post" action="<?= quaeriva_escape($questionActionBase.'/answers/'.$answerId.'/report') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><input type="hidden" name="answers_page" value="<?= $answerPage ?>"><select name="reason"><?php foreach($reportReasons as $reason): ?><option value="<?= quaeriva_escape($reason) ?>"><?= quaeriva_t($translator,'questions.report_reasons.'.$reason) ?></option><?php endforeach; ?></select><textarea name="notes" rows="2" maxlength="1000" dir="<?= quaeriva_escape($contentDirection) ?>"></textarea><button class="button button-small button-secondary" type="submit"><?= quaeriva_t($translator,'questions.report_submit') ?></button></form></details><?php endif; ?><?php else: ?><a class="text-link answer-report-login action-button" href="<?= quaeriva_escape(quaeriva_url('login',['redirect'=>$questionViewUrl.'#answer-'.$answerId])) ?>" aria-label="<?= quaeriva_t($translator,'questions.report_answer') ?>" title="<?= quaeriva_t($translator,'questions.report_answer') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_answer') ?></span></a><?php endif; ?><?php endif; ?></div>
   <?php if(($site['comments_enabled']??true)===true): ?>
    <div class="answer-comments compact-comment-thread" id="answer-<?= $answerId ?>-comments">
     <?php if($answerComments!==[]): ?>
      <div class="comment-list compact-comment-list">
       <?php foreach($answerComments as $comment):$commentId=(int)($comment['id']??0);$isCommentReported=in_array($commentId, (array)($reportedItems['comment'] ?? []), true); ?>
        <article class="comment-item" id="comment-<?= $commentId ?>">
         <div class="comment-body" dir="<?= quaeriva_escape($contentDirection) ?>"><?= quaeriva_rich_text($comment['body']??'', 'comment') ?></div>
         <footer class="comment-meta">
          <small><bdi><?= quaeriva_escape(trim((string)($comment['author_name']??''))?:$translator->get('common.anonymous')) ?></bdi></small>
          <?php if($currentUser!==null&&$commentId>0): ?>
           <?php if($isCommentReported): ?>
            <span class="report-done"><?= quaeriva_t($translator,'questions.report_done') ?></span>
           <?php else: ?>
             <details class="report-action comment-report-action">
              <summary class="action-button" aria-label="<?= quaeriva_t($translator,'questions.report_comment') ?>" title="<?= quaeriva_t($translator,'questions.report_comment') ?>"><?= quaeriva_icon('flag') ?><span class="action-button-label"><?= quaeriva_t($translator,'questions.report_comment') ?></span></summary>
             <form class="compact-form report-popover" method="post" action="<?= quaeriva_escape($questionActionBase.'/comments/'.$commentId.'/report') ?>">
              <input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>">
              <input type="hidden" name="answers_page" value="<?= $answerPage ?>">
              <select name="reason"><?php foreach($reportReasons as $reason): ?><option value="<?= quaeriva_escape($reason) ?>"><?= quaeriva_t($translator,'questions.report_reasons.'.$reason) ?></option><?php endforeach; ?></select>
              <textarea name="notes" rows="2" maxlength="1000" dir="<?= quaeriva_escape($contentDirection) ?>"></textarea>
              <button class="button button-small button-secondary" type="submit"><?= quaeriva_t($translator,'questions.report_submit') ?></button>
             </form>
            </details>
           <?php endif; ?>
          <?php endif; ?>
         </footer>
        </article>
       <?php endforeach; ?>
      </div>
     <?php endif; ?>
     <?php if($currentUser!==null&&$answerId>0): ?>
      <details class="comment-composer">
       <summary class="text-link"><?= quaeriva_t($translator,'questions.answer_comment') ?></summary>
       <form class="comment-form compact-comment-form" method="post" action="<?= quaeriva_escape($questionActionBase.'/answers/'.$answerId.'/comments') ?>">
        <input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>">
        <?= quaeriva_bot_guard_fields() ?>
        <input type="hidden" name="answers_page" value="<?= $answerPage ?>">
        <textarea class="comment-textarea" name="body" dir="<?= quaeriva_escape($contentDirection) ?>" rows="2"<?= quaeriva_rich_editor_attributes($translator, 'comment', '') ?><?= $commentMax>0?' maxlength="'.$commentMax.'"':'' ?><?= $commentMin>0?' minlength="'.$commentMin.'"':'' ?> required placeholder="<?= quaeriva_t($translator,'questions.comment_placeholder') ?>"></textarea>
        <button class="button button-small button-secondary" type="submit"><?= quaeriva_t($translator,'questions.comment') ?></button>
       </form>
      </details>
     <?php endif; ?>
    </div>
   <?php endif; ?>
  </article>
  <?php if(isset($renderBetweenAnswers)&&is_callable($renderBetweenAnswers)): ?><?= $renderBetweenAnswers((int)$answerIndex+1, count($answers)) ?><?php endif; ?>
 <?php endforeach; ?></div><?php endif; ?>
 <?php if($answerPages>1): ?><nav class="pagination answers-pagination" aria-label="<?= quaeriva_t($translator,'questions.answers_pagination') ?>"><span><?= quaeriva_t($translator,'questions.answers_page_summary',['page'=>$answerPage,'pages'=>$answerPages]) ?></span><?php if($answerPage>1): ?><a class="button button-small button-secondary" href="<?= quaeriva_escape(quaeriva_question_url((string)$slug,(int)($question['id']??0),['answers_page'=>$answerPage-1]).'#answers-heading') ?>"><?= quaeriva_t($translator,'questions.previous_page') ?></a><?php endif; ?><?php if($answerPage<$answerPages): ?><a class="button button-small button-secondary" href="<?= quaeriva_escape(quaeriva_question_url((string)$slug,(int)($question['id']??0),['answers_page'=>$answerPage+1]).'#answers-heading') ?>"><?= quaeriva_t($translator,'questions.next_page') ?></a><?php endif; ?></nav><?php endif; ?>
 </section>
 <section class="answer-composer" aria-labelledby="answer-form-heading"><h2 id="answer-form-heading"><?= quaeriva_t($translator,'questions.answer_prompt') ?></h2><?php if($currentUser!==null): ?><form class="question-form" method="post" action="<?= quaeriva_escape($questionActionBase.'/answers') ?>"><input type="hidden" name="_csrf" value="<?= quaeriva_escape($csrfToken) ?>"><?= quaeriva_bot_guard_fields() ?><textarea id="answer-body" name="body" class="comment-textarea" dir="<?= quaeriva_escape($contentDirection) ?>" rows="7"<?= quaeriva_rich_editor_attributes($translator, 'full', '') ?> required<?= $answerMax>0?' maxlength="'.$answerMax.'"':'' ?><?= $answerMin>0?' minlength="'.$answerMin.'"':'' ?> placeholder="<?= quaeriva_t($translator,'questions.answer_placeholder') ?>"></textarea><button class="button" type="submit"><?= quaeriva_t($translator,'questions.answer_submit') ?></button></form><?php else: ?><p class="notice notice-muted"><?= quaeriva_t($translator,'questions.login_to_answer') ?></p><?php endif; ?></section>
<?php endif; ?>
</div></section>
