import { createRouter } from '@btst/yar';
export { sitemapEntryToXmlString } from '../packages/stack/src/client/sitemap-utils.mjs';
export { metaElementsToObject } from '../packages/stack/src/client/meta-utils.mjs';
export { normalizePath } from '../packages/stack/src/client/path-utils.mjs';

function createStackClient(config) {
  const { plugins, basePath } = config;
  const allRoutes = {};
  const clientStackContext = {
    plugins,
    basePath
  };
  for (const [pluginKey, plugin] of Object.entries(plugins)) {
    const pluginRoutes = plugin.routes(clientStackContext);
    Object.assign(allRoutes, pluginRoutes);
  }
  const router = createRouter(allRoutes);
  return {
    router,
    async generateSitemap() {
      const sitemapEntries = [];
      for (const plugin of Object.values(plugins)) {
        if (typeof plugin.sitemap === "function") {
          const entries = await plugin.sitemap();
          if (Array.isArray(entries)) sitemapEntries.push(...entries);
        }
      }
      const seen = /* @__PURE__ */ new Set();
      const deduped = [];
      for (const entry of sitemapEntries) {
        if (!entry?.url || seen.has(entry.url)) continue;
        seen.add(entry.url);
        deduped.push(entry);
      }
      return deduped;
    }
  };
}

export { createStackClient };
