/**
 * Package.json Generator for Runtime React Frontend
 *
 * Same as standard package-json-generator but adds:
 * - @specverse/runtime dependency
 * - js-yaml dependency (for spec parsing)
 * - Removes react-router-dom (routing handled by DevShell)
 */

import type { TemplateContext } from '@specverse/types';

export default function generateRuntimePackageJson(context: TemplateContext): string {
  const { spec } = context;

  const appName = spec.metadata?.component?.toLowerCase() || 'frontend';
  const version = spec.metadata?.version || '1.0.0';
  const description = spec.metadata?.description || 'Frontend application';

  const pkg = {
    name: `${appName}-frontend`,
    version,
    description,
    private: true,
    type: "module",
    scripts: {
      dev: "vite",
      build: "tsc && vite build",
      preview: "vite preview",
      test: "echo 'No tests configured for frontend'",
      lint: "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
    },
    dependencies: {
      "react": "^18.2.0",
      "react-dom": "^18.2.0",
      "@tanstack/react-query": "^5.0.0",
      "@specverse/runtime": "^4.1.0",
      "js-yaml": "^4.1.0",
      "react-hook-form": "^7.48.0",
      "zod": "^3.22.0",
      "@hookform/resolvers": "^3.3.0"
    },
    devDependencies: {
      "@types/react": "^18.2.0",
      "@types/react-dom": "^18.2.0",
      "@types/js-yaml": "^4.0.9",
      "@vitejs/plugin-react": "^4.2.0",
      "autoprefixer": "^10.4.20",
      "postcss": "^8.4.47",
      "tailwindcss": "^3.4.13",
      "typescript": "^5.2.0",
      "vite": "^5.0.0",
      "eslint": "^8.53.0",
      "@typescript-eslint/eslint-plugin": "^6.10.0",
      "@typescript-eslint/parser": "^6.10.0",
      "eslint-plugin-react-hooks": "^4.6.0",
      "eslint-plugin-react-refresh": "^0.4.4"
    }
  };

  return JSON.stringify(pkg, null, 2);
}
