import { getURLSearchParams } from '@/tools';

type Lib = 'eruda' | 'vconsole';

export default function debugLoader(tag = 'debug', ignoreDevelop = true): DEV.Loader {
  return async function () {
    if (import.meta.env.DEV && ignoreDevelop) return;

    const query = getURLSearchParams();
    const lib = query.get(tag) as Lib;
    switch (lib) {
      case 'eruda':
        const { default: eruda } = await import('eruda');
        // @ts-ignore
        const { default: erudaMonitor } = await import('eruda-monitor');
        // @ts-ignore
        const { default: erudaFeatures } = await import('eruda-features');
        // @ts-ignore
        const { default: erudaTiming } = await import('eruda-timing');
        eruda.init();
        eruda.add(erudaMonitor);
        eruda.add(erudaFeatures);
        eruda.add(erudaTiming);
        break;
      case 'vconsole':
        const { default: VConsole } = await import('vconsole');
        new VConsole();
        break;
    }
  };
}
