<% if (problem.id) {
    this.title = '修改题目';
} else {
    this.title = '添加题目';
} %>
<% include header %>
<style type="text/css">
  .problem_header{
    text-align: center;
  }
</style>
<div class="padding">
    <form class="ui form" method="post" action="<%= syzoj.utils.makeUrl(['problem', req.params.id, 'edit']) %>">
      <div class="ui top attached tabular menu">
        <a class="item active" data-tab="edit">编辑</a>
        <a class="item" data-tab="preview" id="preview_tab">预览</a>
      </div>
      <div class="ui bottom attached tab segment active" data-tab="edit">
        <div class="field">
          <label for="title">题目名称</label>
          <input type="text" id="title" name="title" value="<%= problem.title %>">
          <label for="description">题目描述</label>
          <textarea rows="15" id="description" name="description"><%= problem.description %></textarea>
          <label for="input_format">输入格式</label>
          <textarea rows="3" id="input" name="input_format"><%= problem.input_format %></textarea>
          <label for="output_format">输出格式</label>
          <textarea rows="3" id="output" name="output_format"><%= problem.output_format %></textarea>
          <label>样例</label>
          <textarea rows="15" id="example" name="example"><%= problem.example %></textarea>
          <label>数据范围与提示</label>
          <textarea rows="10" id="hint" name="limit_and_hint"><%= problem.limit_and_hint %></textarea>
        </div>
      </div>
      <div class="ui bottom attached tab segment" data-tab="preview" id="preview">
        <h1 class="ui header problem_header" id="pv-title"></h1>
        <h2 class="ui header">题目描述</h2>
        <div id="pv-description"></div>
        <h2 class="ui header">输入格式</h2>
        <div id="pv-input"></div>
        <h2 class="ui header">输出格式</h2>
        <div id="pv-output"></div>
        <h2 class="ui header">样例</h2>
        <div id="pv-example"></div>
        <h2 class="ui header">数据范围与提示</h2>
        <div id="pv-hint"></div>
      </div>
      <% if (problem.allowedEdit) { %>
      <button type="submit" class="ui button">提交</button>
      <% } %>
    </form>
</div>
<script type="text/javascript">
$(function () {
    function render(output, input) {
      $.post('/api/markdown', { s: input.val() }, function (s) {
        // console.log(s);
        output.html(s);
      });
    }
    $("#preview_tab").click(function () {
      $("#pv-title").text($("#title").val());
      $("#pv-description, #pv-input, #pv-output, #pv-example, #pv-hint").text('Loading...');
      render($("#pv-description"), $("#description"));
      render($("#pv-input"), $("#input"));
      render($("#pv-output"), $("#output"));
      render($("#pv-example"), $("#example"));
      render($("#pv-hint"), $("#hint"));
    });
    $('.tabular.menu .item').tab();
});
</script>
<% include footer %>