export interface ClientModuleScope {
  output: Record<string, (payload?: unknown) => void>;
  server: Record<string, (...args: unknown[]) => Promise<unknown>>;
  props: Readonly<Record<string, unknown>>;
  refs: Record<string, Element>;
}
const moduleCache = new Map<string, Promise<any>>();
export async function loadClientFunctions(
  url: string,
  scope: ClientModuleScope,
): Promise<Record<string, (...args: unknown[]) => unknown>> {
  const module = await (moduleCache.get(url) ??
    (() => {
      const promise = import(/* @vite-ignore */ url);
      moduleCache.set(url, promise);
      return promise;
    })());
  if (typeof module.bindClientScope === "function") return module.bindClientScope(scope);
  return module.__wrnexusClientFunctions ?? {};
}
export function invalidateClientModule(url: string): void {
  moduleCache.delete(url);
}
