<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/contrib/auto-render.min.js"></script>
  <script>
    document.addEventListener("DOMContentLoaded", function() {
      renderMathInElement(document.getElementById('markdown_content'), {
        displayMode: true,
        delimiters: [
          {left: "$$", right: "$$", display: true},
          {left: "$", right: "$", display: false}
         ]
      });
      function fix_frac_line(){
          var win = window;
          var frac_lines = document.getElementsByClassName("frac-line");
          for (var i = 0; i < frac_lines.length; i++) {
              var frac = frac_lines[i];
              if (win.getComputedStyle) {
                  style = win.getComputedStyle(frac, '');
                  if (style['border-bottom-width'] == '0px') {
                      frac.style['border-bottom-width'] = '1px';
                  }
              }
          }
      };

      fix_frac_line();
    })
  </script>
</head>
<body>
<div class="container" style="background-color:#fff;">
  <div>
    <div class="ex-title text-center mbt20">
      <div class="mbt10">
        <h3><%= @exercise.try(:exercise_name) %></h3>
      </div>
      <div class="plr15">
        <p class="text-gray">
          <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %>
        </p>
      </div>
    </div>
    <div class="mbt20 bgc width100">
      <div class="ex-scores pd10 text-gray fs13">
        <p class="clearfix inline-block width100">
          <% if @exercise_single_ques_count > 0 %>
        <span class="mr15">单选题<span class="mlr5"><%= @exercise_single_ques_count %></span>题,
        共<span class="mlr5"><%= @exercise_single_ques_scores %></span>分</span>
          <% end %>
          <% if @exercise_double_ques_count > 0 %>
        <span class="mr15">多选题<span class="mlr5"><%= @exercise_double_ques_count %></span>题,
        共<span class="mlr5"><%= @exercise_double_ques_scores %></span>分</span>
          <% end %>
          <% if @exercise_ques_judge_count > 0 %>
        <span class="mr15">判断题<span class="mlr5"><%= @exercise_ques_judge_count %></span>题,
        共<span class="mlr5"><%= @exercise_ques_judge_scores %></span>分</span>
          <% end %>
          <% if @exercise_ques_null_count > 0 %>
        <span class="mr15">填空题<span class="mlr5"><%= @exercise_ques_null_count %></span>题,
        共<span class="mlr5"><%= @exercise_ques_null_scores %></span>分</span>
          <% end %>
          <% if @exercise_ques_main_count > 0 %>
        <span class="mr15">主观题<span class="mlr5"><%= @exercise_ques_main_count %></span>题,
        共<span class="mlr5"><%= @exercise_ques_main_scores %></span>分</span>
          <% end %>
          <% if @exercise_ques_shixun_count > 0 %>
        <span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题,
        共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span>
          <% end %>
          <% if @exercise_ques_pro_count > 0 %>
        <span class="mr15">编程题<span class="mlr5"><%= @exercise_ques_pro_count %></span>题,
        共<span class="mlr5"><%= @exercise_ques_pro_scores %></span>分</span>
          <% end %>
          <span class="pull-right">
            <% if @exercise_ques_count > 0 %>
              <span class="mr15">
                合计<span class="text-blue mlr5"><%= @exercise_ques_count %></span>题
            </span>
            <span>
                共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分
            </span>
          <% end %>
          </span>
        </p>
      </div>
    </div>
    <div class="clearfix"></div>
    <div class="mbt10" id="markdown_content">
      <% @exercise_questions.each do |q| %>
        <div class="bdc">
          <div class="pbt5">
            <div class="pbt5">
              <span class="mr5 text-blue"><%= q.question_number %>、</span>
              <span class="text-blue">
                <%= q.question_type_name %>
              </span>
              <span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
            </div>
            <div class="pbt5">
              <% if q.question_type == 5 %>
                <span class="ques-title" ><%= to_markdown(q.shixun_name,@request_url) %></span>
                <div class="mt8 text-gray">
                  <span><%= to_markdown(q.question_title,@request_url) %></span>
                </div>
              <% else %>
                <span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
              <% end %>
            </div>
            <div class="pbt5">
              <% if q.question_type ==  0 %>
                <% q.exercise_choices.each_with_index do |s,index| %>
                  <div class="pbt5 clearfix main-choice">
                    <span class="choose-radio pull-left mt8"></span>
                    <div class="inline-block pull-left choice-text ml10"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></div>
                  </div>
                <% end %>
              <% elsif q.question_type == 1 %>
                <% q.exercise_choices.each_with_index do |s,index| %>
                  <div class="pbt5 clearfix main-choice">
                    <span class="choose-checkbox pull-left mt8"></span>
                    <div class="inline-block pull-left choice-text ml10"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></div>
                  </div>
                <% end %>
              <% elsif q.question_type == 2 %>
                <div class="pbt5 clearfix">
                  <% q.exercise_choices.each_with_index do |s,index| %>
                    <span class="mr15">
                      <span class="choose-radio "></span>
                      <span class="mlr5 inline-block"><%= "#{(index+65).chr}.#{s.choice_text}" %></span>
                    </span>
                  <% end %>
                </div>
              <% elsif q.question_type == 3 %>
                <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %>
                <% st_counts.each_with_index do |s,index| %>
                  <p class="pbt10 flex-nowrap">
                    <span class="pull-left line-34">答案（填空<%= index+1 %>）：</span>
                    <span class="null-answer"></span>
                  </p>
                <% end %>
              <% elsif q.question_type == 4 %>
                <p class="flex-nowrap">
                  <span class="null-answer main-height"></span>
                </p>
              <% elsif q.question_type == 5 %>
                <% q.exercise_shixun_challenges.each_with_index do |c,index| %>
                  <p class="pbt5">
                    <span>第<%= index+1 %>关</span>
                    <span class="mlr5"><%= c.challenge.subject %></span>
                    <span class="ml20"><%= c&.question_score %>&nbsp;分</span>
                  </p>
                <% end %>
              <% elsif q.question_type == 6 %>
                <div class="clearfix">
                  <% des = q.hack&.description %>
                  <% des = des.index('"') == 0 && des.rindex('"') == des.length - 1 ? des[1..(des.length-2)] : des %>
                  <% des = des.gsub("\n", "<br>") %>
                  <%= des.html_safe %>
                </div>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
    </div>
  </div>
</div>
</body>

</html>