export interface IPrismLangInfo {
  grammar: Prism.Grammar
  lang: string
}

export function getLanguage(mime = ''): IPrismLangInfo {
  if (!mime) {
    return {
      lang: 'plain',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.plain,
    }
  }
  if (mime.includes('json')) {
    return {
      lang: 'json',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.json,
    }
  }
  if (mime.includes('xml')) {
    return {
      lang: 'xml',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.xml,
    }
  }
  if (mime.includes('markdown')) {
    return {
      lang: 'markdown',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.markdown,
    }
  }
  if (mime.includes('yaml') || mime.includes('/raml')) {
    return {
      lang: 'yaml',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.yaml,
    }
  }
  if (mime.includes('/javascript')) {
    return {
      lang: 'javascript',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.javascript,
    }
  }
  if (mime.includes('/css')) {
    return {
      lang: 'css',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.css,
    }
  }
  if (mime.includes('svg')) {
    return {
      lang: 'svg',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.svg,
    }
  }
  if (mime.includes('/html')) {
    return {
      lang: 'html',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.html,
    }
  }
  if (mime.includes('/form-data')) {
    return {
      lang: 'http',
      // @ts-expect-error These are globally loaded...
      grammar: Prism.languages.http,
    }
  }
  return {
    lang: 'clike',
    // @ts-expect-error These are globally loaded...
    grammar: Prism.languages.clike,
  }
}

/* [
    "plain",
    "plaintext",
    "text",
    "txt",
    "DFS",
    "markup",
    "mathml",
    "ssml",
    "atom",
    "rss",
    "clike",
    "webmanifest",
] */
