import Vue from 'vue'
import { getConfigByKey } from '@/api/system/config'
import { buildRuntimeConfigFromAdminUi } from '@/utils/adminUiConfig'

/** 从租户库 his.adminUi.config 加载运行时配置到 $runtimeConfig */
export async function loadRuntimeConfig() {
  try {
    const res = await getConfigByKey('his.adminUi.config')
    const configValue = res?.data?.configValue
    if (!configValue) {
      console.warn('his.adminUi.config 为空，火山云上传等能力可能不可用')
      return
    }
    const form = JSON.parse(configValue)
    Vue.prototype.$runtimeConfig = buildRuntimeConfigFromAdminUi(form)
  } catch (error) {
    console.error('加载运行时配置失败', error)
  }
}
