<template>
  <ConfigPageBase
    section="vehicle"
    title="车辆维护策略"
    description="电量阈值、故障上报、自动报修（VehicleMaintenancePolicy）"
    :defaults="DEFAULT_VEHICLE">
    <template #default="{ payload, update }">
      <el-form label-width="160px" :model="payload">
        <el-form-item label="低电量阈值">
          <el-slider :model-value="payload.lowBatteryThreshold * 100" :min="0" :max="100" :format-tooltip="v => `${v}%`" @update:model-value="(v: any) => update({ ...payload, lowBatteryThreshold: (Number(v) || 0) / 100 })" />
        </el-form-item>
        <el-form-item label="临界电量阈值">
          <el-slider :model-value="payload.criticalBatteryThreshold * 100" :min="0" :max="100" :format-tooltip="v => `${v}%`" @update:model-value="(v: any) => update({ ...payload, criticalBatteryThreshold: (Number(v) || 0) / 100 })" />
        </el-form-item>
        <el-divider content-position="left">故障上报</el-divider>
        <el-form-item label="启用">
          <el-switch :model-value="payload.faultReport.enabled" @update:model-value="(v: string | number | boolean) => update({ ...payload, faultReport: { ...payload.faultReport, enabled: Boolean(v) } })" />
        </el-form-item>
        <el-form-item label="接收邮箱">
          <el-input :model-value="payload.faultReport.emailTo.join(', ')" @update:model-value="(v: string) => update({ ...payload, faultReport: { ...payload.faultReport, emailTo: v.split(/[,\s]+/).filter(Boolean) } })" />
        </el-form-item>
        <el-divider content-position="left">自动报修</el-divider>
        <el-form-item label="启用">
          <el-switch :model-value="payload.autoRepair.enabled" @update:model-value="(v: string | number | boolean) => update({ ...payload, autoRepair: { ...payload.autoRepair, enabled: Boolean(v) } })" />
        </el-form-item>
        <el-form-item label="冷却时间 (秒)">
          <el-input-number :model-value="payload.autoRepair.cooldownSec" :min="0" :max="86400" @update:model-value="(v: number | undefined) => update({ ...payload, autoRepair: { ...payload.autoRepair, cooldownSec: v ?? 0 } })" />
        </el-form-item>
      </el-form>
    </template>
  </ConfigPageBase>
</template>

<script setup lang="ts">
import ConfigPageBase from '@/components/ConfigPageBase.vue'
import { DEFAULT_VEHICLE } from '@/mock/data/configs'
</script>
