import type { UiProvider } from './UiProvider'

export type UiProviderName = 'primevue' | 'native'

export async function resolveUiProvider(name: string | undefined): Promise<UiProvider> {
  const normalized = (name ?? 'primevue').trim().toLowerCase()
  if (normalized === 'primevue') {
    return (await import('../adapter/primevue/installPrimeVueAdapter')).primeVueUiProvider
  }
  if (normalized === 'native') {
    if (import.meta.env.PROD) {
      throw new Error('The native UI provider is test/reference-only and cannot be used in a production artifact.')
    }
    return (await import('../adapter/native/installNativeAdapter')).nativeUiProvider
  }
  throw new Error(`Unsupported VITE_UI_ADAPTER '${name}'. Allowed values: primevue, native.`)
}
