function generateRouter(context) {
  const { spec, models = [], views = [] } = context;
  const specViews = views.length > 0 ? views : spec?.views ? Object.entries(spec.views) : [];
  const imports = [];
  const routes = [];
  routes.push(`  {
    path: '/',
    element: <div className="home-page">
      <h1>Welcome</h1>
      <nav>
        <ul>
${generateHomeLinks(specViews, models)}
        </ul>
      </nav>
    </div>
  }`);
  const usedPaths = /* @__PURE__ */ new Set();
  specViews.forEach((viewEntry) => {
    const [viewName, viewDef] = Array.isArray(viewEntry) ? viewEntry : [viewEntry.name, viewEntry];
    const viewType = viewDef?.type || "list";
    const model = Array.isArray(viewDef?.model) ? viewDef.model[0] : viewDef?.model;
    if (!model) return;
    const modelLower = model.toLowerCase();
    const modelPlural = modelLower + "s";
    imports.push(`import ${viewName} from './components/${viewName}';`);
    const basePath = `/${modelPlural}`;
    switch (viewType) {
      case "list":
        const listPath = usedPaths.has(basePath) ? `${basePath}/${viewName.toLowerCase().replace(/view$/, "")}` : basePath;
        if (!usedPaths.has(listPath)) {
          routes.push(`  {
    path: '${listPath}',
    element: <${viewName} />
  }`);
          usedPaths.add(listPath);
        }
        break;
      case "detail":
        const detailPath = `${basePath}/:id`;
        if (!usedPaths.has(detailPath)) {
          routes.push(`  {
    path: '${detailPath}',
    element: <${viewName} />
  }`);
          usedPaths.add(detailPath);
        }
        break;
      case "form":
        const newPath = `${basePath}/new`;
        const editPath = `${basePath}/:id/edit`;
        if (!usedPaths.has(newPath)) {
          routes.push(`  {
    path: '${newPath}',
    element: <${viewName} />
  }`);
          usedPaths.add(newPath);
        }
        if (!usedPaths.has(editPath)) {
          routes.push(`  {
    path: '${editPath}',
    element: <${viewName} />
  }`);
          usedPaths.add(editPath);
        }
        break;
      case "dashboard":
        const dashPath = modelLower === "author" || modelLower === "user" ? "/dashboard" : `/dashboard/${modelLower}`;
        if (!usedPaths.has(dashPath)) {
          routes.push(`  {
    path: '${dashPath}',
    element: <${viewName} />
  }`);
          usedPaths.add(dashPath);
        }
        break;
    }
  });
  return `/**
 * React Router Configuration
 * Auto-generated by SpecVerse
 */

import { createBrowserRouter } from 'react-router-dom';
${imports.join("\n")}

/**
 * Application Router
 */
export const router = createBrowserRouter([
${routes.join(",\n")}
]);
`;
}
function generateHomeLinks(views, models) {
  const links = [];
  const usedPaths = /* @__PURE__ */ new Set();
  views.forEach((viewEntry) => {
    const [viewName, viewDef] = Array.isArray(viewEntry) ? viewEntry : [viewEntry.name, viewEntry];
    const viewType = viewDef?.type || "list";
    const model = Array.isArray(viewDef?.model) ? viewDef.model[0] : viewDef?.model;
    if (!model) return;
    const modelLower = model.toLowerCase();
    const modelPlural = modelLower + "s";
    const basePath = `/${modelPlural}`;
    const viewLabel = viewName.replace(/View$/, "").replace(/([A-Z])/g, " $1").trim();
    switch (viewType) {
      case "list":
        const listPath = usedPaths.has(basePath) ? `${basePath}/${viewName.toLowerCase().replace(/view$/, "")}` : basePath;
        if (!usedPaths.has(listPath)) {
          links.push(`          <li><a href="${listPath}">${viewLabel}</a></li>`);
          usedPaths.add(listPath);
        }
        break;
      case "form":
        const formPath = `${basePath}/new`;
        if (!usedPaths.has(formPath)) {
          links.push(`          <li><a href="${formPath}">Create ${model}</a></li>`);
          usedPaths.add(formPath);
        }
        break;
      case "dashboard":
        const dashPath = modelLower === "author" || modelLower === "user" ? "/dashboard" : `/dashboard/${modelLower}`;
        if (!usedPaths.has(dashPath)) {
          links.push(`          <li><a href="${dashPath}">${viewLabel}</a></li>`);
          usedPaths.add(dashPath);
        }
        break;
      case "detail":
        break;
    }
  });
  return links.join("\n");
}
export {
  generateRouter as default
};
