<template>
  <div class="admin-cms-page">
    <section class="admin-page-hero"><div><span class="admin-eyebrow">SITE SETTINGS</span><h2>站点设置</h2><p>控制全站标题、LOGO、ico、默认 SEO、GSO/GEO、联系方式和地图密钥。</p></div><button class="primary-button admin-primary-action" type="button" @click="save">保存设置</button></section>
    <section class="admin-edit-panel site-settings-panel"><div><span class="admin-eyebrow">BRAND</span><h3>品牌与基础信息</h3></div><form @submit.prevent="save">
      <label><span>站点标题</span><input v-model="form.site_title" class="form-input" /></label><label><span>站点 LOGO</span><input v-model="form.site_logo" class="form-input" /></label><label><span>暗色 LOGO</span><input v-model="form.site_logo_dark" class="form-input" /></label><label><span>ICO/Favicon</span><input v-model="form.site_favicon" class="form-input" /></label><label><span>联系电话</span><input v-model="form.contact_phone" class="form-input" /></label><label><span>联系邮箱</span><input v-model="form.contact_email" class="form-input" /></label><label class="full"><span>联系地址</span><input v-model="form.contact_address" class="form-input" /></label><label><span>备案信息</span><input v-model="form.icp_text" class="form-input" /></label><label><span>版权信息</span><input v-model="form.copyright" class="form-input" /></label>
      <label class="full"><span>默认 SEO JSON</span><textarea v-model="seoJson" class="form-input" rows="5"></textarea></label><label class="full"><span>默认 GSO/GEO JSON</span><textarea v-model="gsoJson" class="form-input" rows="5"></textarea></label><label><span>高德 Key</span><input v-model="form.amap_key" class="form-input" /></label><label><span>高德安全密钥</span><input v-model="form.amap_security_code" class="form-input" /></label><button class="primary-button" type="submit">保存设置</button>
    </form><div v-if="message" class="pricing-message">{{ message }}</div></section>
  </div>
</template>
<script setup>
import { onMounted, reactive, ref } from 'vue'
import { getAdminSiteSettings, saveAdminSiteSettings } from '@/api/request/site'
const message = ref(''), seoJson = ref('{}'), gsoJson = ref('{}')
const form = reactive({ site_title: '', site_logo: '', site_logo_dark: '', site_favicon: '', icp_text: '', copyright: '', contact_phone: '', contact_email: '', contact_address: '', default_seo: {}, default_gso: {}, amap_key: '', amap_security_code: '' })
const load = async () => { const data = await getAdminSiteSettings().catch(() => ({})); Object.assign(form, data); seoJson.value = JSON.stringify(form.default_seo || {}, null, 2); gsoJson.value = JSON.stringify(form.default_gso || {}, null, 2) }
const save = async () => { form.default_seo = JSON.parse(seoJson.value || '{}'); form.default_gso = JSON.parse(gsoJson.value || '{}'); await saveAdminSiteSettings({ ...form }); message.value = '站点设置已保存。' }
onMounted(load)
</script>
