type RefreshRegister = () => void;
type RefreshSignature = () => <T>(type: T) => T;

type RefreshWindow = Window &
  typeof globalThis & {
    $RefreshReg$?: RefreshRegister;
    $RefreshSig$?: RefreshSignature;
    __vite_plugin_react_preamble_installed__?: boolean;
  };

const refreshRuntimeSpecifier = "/@react-refresh";
const viteWindow = window as RefreshWindow;

void (async () => {
  const refreshRuntime = (await import(
    /* @vite-ignore */ refreshRuntimeSpecifier
  )) as {
    injectIntoGlobalHook(globalObject: typeof globalThis): void;
  };

  refreshRuntime.injectIntoGlobalHook(viteWindow);
  viteWindow.$RefreshReg$ = () => {};
  viteWindow.$RefreshSig$ =
    () =>
    <T>(type: T) =>
      type;
  viteWindow.__vite_plugin_react_preamble_installed__ = true;
})();
