<template>
  <div id="problem-page-body">
    <el-card>
      <template #header>
        <page-header>
          <template #actions>
            <el-input
              v-model="nameInput"
              :debounce-events="['input']"
              placeholder="搜索"
              style="width: 200px;"
            />
            <el-select
              v-model="typeInput"
              style="width: 200px"
              @change="fetchData(1)"
            >
              <el-option
                v-for="item in typeOptions"
                :key="item.value"
                :value="item.value"
              >
                {{ item.label }}
              </el-option>
            </el-select>
            <router-link
              :to="{name:'ProblemUpload'}"
            >
              <el-button type="primary">
                上传题目
              </el-button>
            </router-link>
          </template>
          题目列表
        </page-header>
      </template>
      <problem-list
        :page-info="pageInfo"
        :problem-list="problemList"
        @current-change="fetchData"
      />
    </el-card>
  </div>
</template>

<script>
import ProblemList from "@/views/ProblemPage/components/ProblemList";
import { problemTypeOptions } from "@/utils/coder-utils";
import PageHeader from "@/views/ProblemPage/components/PageHeader";

export default {
  components: {
    PageHeader,
    ProblemList
  },
  data() {
    return {
      typeInput: "",
      nameInput: "",
      pageInfo: {},
      problemList: []
    };
  },
  computed: {
    typeOptions() {
      return problemTypeOptions(true);
    }
  },
  mounted() {
    this.fetchData(1);
  },
  methods: {
    fetchData(page = 1) {
      // todo @Arsekl 失效的api
      // this.$apis.getCoderProblem({ limit: 30, page, type: this.typeInput, name: this.nameInput })
      //     .then((res) => {
      //       const data=res.data;
      //       this.pageInfo = data.page ?? {};
      //       this.problemList = data.res ?? [];
      //     })
      //     .catch((err) => {
      //       this.$message.error({
      //         message: errorMessage(err),
      //         center: true
      //       });
      //     });
    }
  }
};
</script>

<style>
#problem-page-body {
  margin: 40px 10vw 80px 10vw;
  min-height: calc(100vh - 100px);
}
</style>