<template>
  <div class="api-config">
    <h2>系统配置</h2>
    <div class="form-item">
      <label>客户端地址：</label>
      <input
        type="text"
        v-model="h5ClientUrl"
        placeholder="请输入客户端访问地址"
      >
      <div class="hint">例如：http://10.102.8.56:18900</div>
    </div>
    <div class="button-group">
      <button @click="saveConfig">保存</button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const h5ClientUrl = ref('')

onMounted(async () => {
  // 从本地存储获取现有配置
  h5ClientUrl.value = await window.electron.ipcRenderer.invoke('getStoreValue', 'h5_client_url') || ''
})

const saveConfig = async () => {
  try {
    await window.electron.ipcRenderer.invoke('setStoreValue', 'h5_client_url', h5ClientUrl.value)

    // 重启应用
    await window.electron.ipcRenderer.invoke('restartApp')
  } catch (error) {
    alert('保存失败：' + error.message)
  }
}
</script>

<style scoped>
.api-config {
  padding: 20px;
  font-family: Arial, sans-serif;
}

h2 {
  margin-bottom: 20px;
  color: #333;
  text-align: center;
}

.form-item {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #666;
}

input {
  width: 400px;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

input:focus {
  outline: none;
  border-color: #4CAF50;
  box-shadow: 0 0 5px rgba(76, 175, 80, 0.2);
}

.hint {
  margin-top: 5px;
  font-size: 12px;
  color: #999;
}

.button-group {
  margin-top: 30px;
  text-align: right;
}

button {
  padding: 8px 20px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #45a049;
}
</style>
