import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { definePlugin } from "@wrnexus/plugin";

export interface RealtimePluginOptions {
  components?: boolean;
  componentDir?: string;
}

const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));

export function realtimeComponentsDir(): string {
  return join(packageRoot, "components");
}

export function realtimePlugin(options: RealtimePluginOptions = {}) {
  return definePlugin({
    name: "@wrnexus/realtime",
    version: "0.8.0",
    componentDirs:
      options.components === false ? [] : [options.componentDir ?? realtimeComponentsDir()],
  });
}

export default realtimePlugin;
