export function useVariantData() {
  const { t, tm, rt } = useI18n()
  const route = useRoute()
  const config = useRuntimeConfig()

  function vtm(key: string) {
    // Get the latest variant *each time* this runs for reactivity!
    const variant = route.params.variant || config.public.websites.defaultVariant
    const value = tm(key)
    if (value && typeof value === 'object' && value[`#${variant}`] !== undefined) {
      return value[`#${variant}`]
    }
    return value
  }

  function vt(key: string) {
    try {
      return rt(vtm(key))
    } catch {
      return key
    }
  }

  function vrt(value) {
    const variant = route.params.variant || config.public.websites.defaultVariant
    if (value && typeof value === 'object' && value[`#${variant}`]) {
      value = value[`#${variant}`]
    }
    try {
      return rt(value)
    } catch (err) {
      console.error('Exception in vrt:', err)
      return value || err
    }
  }

  return {
    t: vt,
    tm: vtm,
    rt: vrt,
  }
}
