<script setup lang="ts">
withDefaults(
  defineProps<{
    hasSaveButton?: boolean
    hasNextButton?: boolean
    maxScore: number
  }>(),
  { hasSaveButton: true, hasNextButton: true }
)

const emits = defineEmits<{
  (e: 'save', params: { score: number | undefined; comment: string }): void
  (e: 'next'): void
}>()

const score = defineModel<number | undefined>('score', { required: true })
const comment = defineModel<string>('comment', { required: true })
</script>

<template>
  <div class="score-card">
    <div class="score-card-title">
      本模块分值：<span>{{ maxScore }}分</span>
    </div>
    <div class="score-card-form">
      <el-form label-suffix=":" label-width="46px">
        <el-form-item label="得分">
          <el-input-number v-model="score" :min="0" :max="maxScore" :controls="false" />
        </el-form-item>
        <el-form-item label="评语">
          <el-input v-model="comment" type="textarea" :rows="6" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" auto-insert-space @click="emits('save', { score, comment })" v-if="hasSaveButton"
            >保存</el-button
          >
          <el-button type="primary" plain auto-insert-space @click="emits('next')" v-if="hasNextButton"
            >下一步</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="score-card-content">
      <slot></slot>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.score-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-radius: 10px;
  border: 1px solid #dcdfe6;
  margin: 20px 0 40px;
}

.score-card-title {
  position: absolute;
  left: 20px;
  top: 0;
  background-color: #fff;
  font-size: 16px;
  font-weight: bold;
  transform: translateY(-50%);
  padding: 0 10px;
  span {
    font-size: 18px;
    color: var(--main-color);
  }
}
.score-card-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 40px 30px 0;
}
.score-card-content {
  border-top: 1px solid #dcdfe6;
  padding: 30px;
}
</style>
