text: import "./main";
  import CTFd from "core/CTFd";
  import $ from "jquery";
  import { ezAlert, ezQuery } from "core/ezq";
  
  function deleteSelectedChallenges(_event) {
    let challengeIDs = $("input[data-challenge-id]:checked").map(function() {
      return $(this).data("challenge-id");
    });
    let target = challengeIDs.length === 1 ? "challenge" : "challenges";
  
    ezQuery({
      title: "删除题目",
      body: `Are you sure you want to delete ${challengeIDs.length} ${target}?`,
      success: function() {
        const reqs = [];
        for (var chalID of challengeIDs) {
          reqs.push(
            CTFd.fetch(`/api/v1/challenges/${chalID}`, {
              method: "DELETE"
            })
          );
        }
        Promise.all(reqs).then(_responses => {
          window.location.reload();
        });
      }
    });
  }
  
  function bulkEditChallenges(_event) {
    let challengeIDs = $("input[data-challenge-id]:checked").map(function() {
      return $(this).data("challenge-id");
    });
  
    ezAlert({
      title: "编辑题目",
      body: $(`
      <form id="challenges-bulk-edit">
        <div class="form-group">
          <label>Category</label>
          <input type="text" name="category" data-initial="" value="">
        </div>
        <div class="form-group">
          <label>Value</label>
          <input type="number" name="value" data-initial="" value="">
        </div>
        <div class="form-group">
          <label>State</label>
          <select name="state" data-initial="">
            <option value="">--</option>
            <option value="visible">Visible</option>
            <option value="hidden">Hidden</option>
          </select>
        </div>
      </form>
      `),
      button: "提交",
      success: function() {
        let data = $("#challenges-bulk-edit").serializeJSON(true);
        const reqs = [];
        for (var chalID of challengeIDs) {
          reqs.push(
            CTFd.fetch(`/api/v1/challenges/${chalID}`, {
              method: "PATCH",
              body: JSON.stringify(data)
            })
          );
        }
        Promise.all(reqs).then(_responses => {
          window.location.reload();
        });
      }
    });
  }
  
  $(() => {
    $("#challenges-delete-button").click(deleteSelectedChallenges);
    $("#challenges-edit-button").click(bulkEditChallenges);
  });
  