import { getEntry } from 'astro:content'
import type { GlobImage, ImportRecord } from '../types/generic'

export function plsLoadImage(record: ImportRecord<GlobImage>, path: string) {
  const loadedImage = record[path]?.()
  if (!loadedImage) throw new Error(`Asset was not found for path ${path}`)
  return loadedImage
}

export async function plsLoadTAEntry(key: string) {
  const filecontent = (await getEntry('taInfoData', key))?.data
  if (!filecontent) throw new Error(`Datafile was not found for key ${key}`)
  return filecontent
}
