<template>
  <el-form
    ref="otherFormRef"
    :model="otherForm"
    label-width="120px"
    style="max-width: 600px"
  >
    <el-form-item label="开启维护模式">
      <el-switch v-model="otherForm.maintenanceMode" />
      <span class="form-tip">开启后，前台将显示维护中页面</span>
    </el-form-item>
    <el-form-item label="开启注册">
      <el-switch v-model="otherForm.allowRegister" />
      <span class="form-tip">允许用户在前台注册账号</span>
    </el-form-item>
    <el-form-item label="验证码">
      <el-switch v-model="otherForm.captchaEnabled" />
      <span class="form-tip">登录、注册等操作需要验证码</span>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="saveOtherSettings">保存设置</el-button>
      <el-button @click="resetOtherForm">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { ElMessage } from "element-plus";
import type { FormInstance } from "element-plus";

const otherFormRef = ref<FormInstance>();

const otherForm = reactive({
  maintenanceMode: false,
  allowRegister: false,
  captchaEnabled: true
});

const saveOtherSettings = () => {
  // TODO: 保存其他设置
  ElMessage.success("其他设置保存成功");
};

const resetOtherForm = () => {
  otherForm.maintenanceMode = false;
  otherForm.allowRegister = false;
  otherForm.captchaEnabled = true;
};

defineExpose({
  otherForm
});
</script>

<style lang="less" scoped>
.form-tip {
  margin-left: 10px;
  font-size: 12px;
  color: #909399;
}
</style>
