import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import path from "node:path";
import {
  applyBrandingInjection,
  createBrandingRoutes,
  resolveBrandingConfig,
} from "./src/injector.js";

export default definePluginEntry({
  id: "ui-whatsynaptor",
  name: "UI Whatsynaptor",
  description: "Inject non-destructive Control UI branding overlays without replacing upstream UI bundles.",
  register(api) {
    const pluginRoot = api.rootDir ?? path.dirname(api.source);
    const cfg = resolveBrandingConfig(api.pluginConfig);

    for (const route of createBrandingRoutes({
      config: api.config,
      logger: api.logger,
      pluginRoot,
      runtimeConfig: cfg,
    })) {
      api.registerHttpRoute(route);
    }

    api.registerService({
      id: "ui-whatsynaptor-branding",
      start: async (ctx) => {
        await applyBrandingInjection({
          config: api.config,
          logger: api.logger,
          pluginRoot,
          runtimeConfig: cfg,
          stateDir: ctx.stateDir,
        });
      },
    });
  },
});
