//@ts-nocheck

import * as components from './packages/components'
import * as businessComponents from './packages/business-components'
import { DasAutoRegisterAllIcon } from '@das-fed/upf-ui'
import { setLang, loadLocale } from '@das-fed/upf-web'

DasAutoRegisterAllIcon(import('@das-fed/upf-ui/packages/icons'))

const allComponents = { ...components, ...businessComponents }

const install = (app) => {
  Object.entries(allComponents).forEach(([name, component]) => {
    if (!component?.install) return
    app.component(name, component)
  })
}

/**
 * 全局切换 das-ui 语言
 * - 内部调用 @das-fed/upf-web 的 setLang 来切换 t()/currentLang
 * - 同时按需加载 Ant Design Vue 与 dayjs 的对应语言包
 * - 返回 AntD 的 locale（可传递给 ConfigProvider）
 */
export const setDasUiLanguage = async (lang) => {
  try {
    setLang(lang)
    // 返回 antd 的 locale，供业务侧 ConfigProvider 使用（如果需要）
    const antdLocale = await loadLocale?.(lang)
    return antdLocale
  } catch (e) {
    console.warn('[das-ui] setDasUiLanguage error:', e)
  }
}

export default { install }
export * from './packages/business-components'
export * from './packages/components'
export * from './packages/icons'
