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

Page({
  data: {
    info: null,
    loading: true,
    error: null
  },

  onLoad() {
    this.loadElderCareInfo()
  },

  onBack() {
    wx.navigateBack()
  },

  async loadElderCareInfo() {
    this.setData({ loading: true, error: null })
    
    try {
      const res = await api.common.getBrandConfig()
      console.log('[eldercare] 智慧康养配置响应:', res)
      
      if (res.success && res.data) {
        const data = res.data
        const smartHealth = data.smart_health || {}
        
        this.setData({
          info: {
            title: '智慧康养',
            content: smartHealth.value || ''
          }
        })
        console.log('[eldercare] 智慧康养信息:', this.data.info)
      } else {
        this.setData({ error: res.error || '加载失败' })
      }
    } catch (err) {
      console.error('[eldercare] 加载失败:', err)
      this.setData({ error: err.message || '加载失败' })
    } finally {
      this.setData({ loading: false })
    }
  }
})
