const api = require('../../utils/api')

Page({
  data: {
    sections: [],
    loading: true,
    error: null
  },

  onLoad() {
    this.loadBrandInfo()
  },

  onBack() {
    wx.navigateBack()
  },

  async loadBrandInfo() {
    this.setData({ loading: true, error: null })
    
    try {
      const res = await api.common.getBrandConfig()
      console.log('[brand] 品牌配置响应:', res)
      
      if (res.success && res.data) {
        const data = res.data
        const sections = []
        
        if (data.about_brand && data.about_brand.value) {
          sections.push({ title: '关于品牌', content: data.about_brand.value })
        }
        if (data.company_intro && data.company_intro.value) {
          sections.push({ title: '公司简介', content: data.company_intro.value })
        }
        if (data.contact_info && data.contact_info.value) {
          sections.push({ title: '联系我们', content: data.contact_info.value })
        }
        
        this.setData({ sections })
        console.log('[brand] 品牌信息sections:', this.data.sections)
      } else {
        this.setData({ error: res.error || '加载失败' })
      }
    } catch (err) {
      console.error('[brand] 加载品牌信息失败:', err)
      this.setData({ error: err.message || '加载失败' })
    } finally {
      this.setData({ loading: false })
    }
  }
})
