import type { Project, SessionInfo, BranchInfo } from "../lib/types"

const now = Date.now()
const hour = 3_600_000
const day = 86_400_000

export function generateMockProjects(): Project[] {
  return [
    {
      path: "/Users/demo/projects/acme-api",
      name: "acme-api",
      branch: "main",
      commitAge: "2h ago",
      commitMsg: "fix: rate limiter edge case",
      commitEpoch: (now - 2 * hour) / 1000,
      dirty: "~2 ?1",
      ahead: 1,
      behind: 0,
      claudeAgo: "25m ago",
      claudeLastMs: now - 25 * 60_000,
      sessionCount: 14,
      totalMessages: 342,
      tags: "ts bun hono",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/quantum-dashboard",
      name: "quantum-dashboard",
      branch: "feat/cha",
      commitAge: "5h ago",
      commitMsg: "add chart tooltip comp",
      commitEpoch: (now - 5 * hour) / 1000,
      dirty: "+3 ~1",
      ahead: 3,
      behind: 0,
      claudeAgo: "1h ago",
      claudeLastMs: now - 1 * hour,
      sessionCount: 8,
      totalMessages: 187,
      tags: "ts react vite",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/pixel-engine",
      name: "pixel-engine",
      branch: "develop",
      commitAge: "1d ago",
      commitMsg: "perf: batch draw calls",
      commitEpoch: (now - 1 * day) / 1000,
      dirty: "",
      ahead: 0,
      behind: 0,
      claudeAgo: "3h ago",
      claudeLastMs: now - 3 * hour,
      sessionCount: 22,
      totalMessages: 891,
      tags: "rust wgpu",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/infractl",
      name: "infractl",
      branch: "main",
      commitAge: "3d ago",
      commitMsg: "docs: update deploy guide",
      commitEpoch: (now - 3 * day) / 1000,
      dirty: "?2",
      ahead: 0,
      behind: 2,
      claudeAgo: "2d ago",
      claudeLastMs: now - 2 * day,
      sessionCount: 5,
      totalMessages: 78,
      tags: "go docker k8s",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/notely-mobile",
      name: "notely-mobile",
      branch: "release",
      commitAge: "6h ago",
      commitMsg: "bump version to 2.4.1",
      commitEpoch: (now - 6 * hour) / 1000,
      dirty: "",
      ahead: 0,
      behind: 0,
      claudeAgo: "5h ago",
      claudeLastMs: now - 5 * hour,
      sessionCount: 11,
      totalMessages: 256,
      tags: "ts rn expo",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/blog-engine",
      name: "blog-engine",
      branch: "main",
      commitAge: "7d ago",
      commitMsg: "feat: RSS feed generation",
      commitEpoch: (now - 7 * day) / 1000,
      dirty: "~1",
      ahead: 0,
      behind: 0,
      claudeAgo: "5d ago",
      claudeLastMs: now - 5 * day,
      sessionCount: 3,
      totalMessages: 45,
      tags: "ts astro mdx",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/ml-pipeline",
      name: "ml-pipeline",
      branch: "exp/bert",
      commitAge: "12h ago",
      commitMsg: "tune hyperparams batch 3",
      commitEpoch: (now - 12 * hour) / 1000,
      dirty: "+1 ~4",
      ahead: 7,
      behind: 0,
      claudeAgo: "just now",
      claudeLastMs: now - 60_000,
      sessionCount: 19,
      totalMessages: 523,
      tags: "py torch",
      expanded: false,
      sessions: null,
      branches: null,
    },
    {
      path: "/Users/demo/projects/auth-service",
      name: "auth-service",
      branch: "main",
      commitAge: "14d ago",
      commitMsg: "chore: dep updates",
      commitEpoch: (now - 14 * day) / 1000,
      dirty: "",
      ahead: -1,
      behind: -1,
      claudeAgo: "12d ago",
      claudeLastMs: now - 12 * day,
      sessionCount: 2,
      totalMessages: 31,
      tags: "ts express pg",
      expanded: false,
      sessions: null,
      branches: null,
    },
  ]
}

const mockSessionData: Record<string, SessionInfo[]> = {
  "acme-api": [
    {
      id: "demo-acme-1",
      timestamp: now - 25 * 60_000,
      title: "Fix rate limiter to handle burst traffic correctly",
      lastUserPrompt: "The rate limiter lets through 2x the limit when requests arrive simultaneously",
      lastAssistantMsg: "Found the race condition in the sliding window counter. Fixed by using atomic increment.",
      branch: "main",
      sizeBytes: 48200,
    },
    {
      id: "demo-acme-2",
      timestamp: now - 4 * hour,
      title: "Add pagination to /api/users endpoint",
      lastUserPrompt: "Add cursor-based pagination to the users list endpoint",
      lastAssistantMsg: "Implemented cursor-based pagination using the user ID as cursor. Added limit param with max 100.",
      branch: "main",
      sizeBytes: 31400,
    },
    {
      id: "demo-acme-3",
      timestamp: now - 2 * day,
      title: "Set up OpenTelemetry tracing",
      lastUserPrompt: "Configure otel tracing with jaeger exporter for all HTTP handlers",
      lastAssistantMsg: "Added @opentelemetry/sdk-node with Jaeger exporter. Wrapped all Hono routes with span creation.",
      branch: "feat/observability",
      sizeBytes: 67800,
    },
  ],
  "quantum-dashboard": [
    {
      id: "demo-quantum-1",
      timestamp: now - 1 * hour,
      title: "Build interactive chart tooltip component",
      lastUserPrompt: "Create a tooltip that shows data point details on hover with smooth transitions",
      lastAssistantMsg: "Created ChartTooltip with Framer Motion transitions. Uses portal to avoid clipping.",
      branch: "feat/charts",
      sizeBytes: 52100,
    },
    {
      id: "demo-quantum-2",
      timestamp: now - 1 * day,
      title: "Implement dark mode theme switching",
      lastUserPrompt: "Add dark mode toggle that persists in localStorage",
      lastAssistantMsg: "Added ThemeProvider with CSS variables approach. Toggle syncs to localStorage and system preference.",
      branch: "main",
      sizeBytes: 38900,
    },
  ],
  "pixel-engine": [
    {
      id: "demo-pixel-1",
      timestamp: now - 3 * hour,
      title: "Batch draw calls for sprite rendering",
      lastUserPrompt: "Sprite rendering is too slow with individual draw calls, need batching",
      lastAssistantMsg: "Implemented instanced rendering with a shared vertex buffer. 60fps stable at 10k sprites now.",
      branch: "develop",
      sizeBytes: 89300,
    },
    {
      id: "demo-pixel-2",
      timestamp: now - 3 * day,
      title: "Add tilemap collision detection",
      lastUserPrompt: "Need AABB collision against tilemap layers with slope support",
      lastAssistantMsg: "Added spatial hash grid for broad phase, then precise AABB vs tile shape. Slopes use SAT.",
      branch: "develop",
      sizeBytes: 112400,
    },
    {
      id: "demo-pixel-3",
      timestamp: now - 5 * day,
      title: "Implement ECS architecture",
      lastUserPrompt: "Refactor the game objects into an ECS pattern with archetypes",
      lastAssistantMsg: "Built archetype-based ECS with sparse sets. Component queries use bitmasked signature matching.",
      branch: "feat/ecs",
      sizeBytes: 156700,
    },
    {
      id: "demo-pixel-4",
      timestamp: now - 8 * day,
      title: "WebGPU compute shader for particles",
      lastUserPrompt: "Move particle simulation to a compute shader",
      lastAssistantMsg: "Particle update runs in compute shader now. 100k particles at 60fps. Uses ping-pong buffers.",
      branch: "develop",
      sizeBytes: 73200,
    },
  ],
  "infractl": [
    {
      id: "demo-infra-1",
      timestamp: now - 2 * day,
      title: "Add rollback command for deployments",
      lastUserPrompt: "Need a rollback subcommand that reverts to the previous deployment version",
      lastAssistantMsg: "Added `infractl rollback` with --revision flag. Tracks deployment history in etcd.",
      branch: "main",
      sizeBytes: 41200,
    },
    {
      id: "demo-infra-2",
      timestamp: now - 6 * day,
      title: "Implement health check polling",
      lastUserPrompt: "After deploy, poll the health endpoint until ready or timeout",
      lastAssistantMsg: "Added exponential backoff health polling with configurable timeout and retries.",
      branch: "main",
      sizeBytes: 28700,
    },
  ],
  "notely-mobile": [
    {
      id: "demo-notely-1",
      timestamp: now - 5 * hour,
      title: "Fix offline sync conflict resolution",
      lastUserPrompt: "Notes edited offline are overwriting server changes on sync",
      lastAssistantMsg: "Switched to CRDT-based merge for note content. Conflicts now auto-resolve with last-write-wins for metadata.",
      branch: "release",
      sizeBytes: 64500,
    },
    {
      id: "demo-notely-2",
      timestamp: now - 1 * day,
      title: "Add biometric auth for app lock",
      lastUserPrompt: "Implement FaceID/fingerprint unlock when opening the app",
      lastAssistantMsg: "Used expo-local-authentication for biometrics. Falls back to PIN. Configurable in settings.",
      branch: "feat/security",
      sizeBytes: 35800,
    },
    {
      id: "demo-notely-3",
      timestamp: now - 4 * day,
      title: "Optimize list rendering for large notebooks",
      lastUserPrompt: "The notes list stutters when you have 500+ notes",
      lastAssistantMsg: "Replaced FlatList with FlashList and added virtualization. Smooth scrolling at 1000 notes.",
      branch: "main",
      sizeBytes: 29100,
    },
  ],
  "blog-engine": [
    {
      id: "demo-blog-1",
      timestamp: now - 5 * day,
      title: "Generate RSS feed from MDX posts",
      lastUserPrompt: "Add an RSS 2.0 feed at /feed.xml built from the MDX content collection",
      lastAssistantMsg: "Added RSS generation in the Astro build pipeline. Extracts frontmatter for title, date, description.",
      branch: "main",
      sizeBytes: 22300,
    },
  ],
  "ml-pipeline": [
    {
      id: "demo-ml-1",
      timestamp: now - 60_000,
      title: "Hyperparameter tuning batch 3 results",
      lastUserPrompt: "Run the next batch of hyperparameter configs and log results to wandb",
      lastAssistantMsg: "Batch 3 complete. Best config: lr=2e-5, warmup=500, dropout=0.1. F1 improved to 0.847.",
      branch: "exp/bert",
      sizeBytes: 94600,
    },
    {
      id: "demo-ml-2",
      timestamp: now - 8 * hour,
      title: "Add data augmentation pipeline",
      lastUserPrompt: "Implement text augmentation with synonym replacement and back-translation",
      lastAssistantMsg: "Added augmentation transforms: synonym swap, back-translation via MarianMT, random insertion.",
      branch: "exp/bert",
      sizeBytes: 71200,
    },
    {
      id: "demo-ml-3",
      timestamp: now - 2 * day,
      title: "Set up DVC for dataset versioning",
      lastUserPrompt: "Configure DVC with S3 remote for versioning the training datasets",
      lastAssistantMsg: "Initialized DVC with S3 backend. Added .dvc files for train/val/test splits. Pipeline stages defined.",
      branch: "main",
      sizeBytes: 45300,
    },
    {
      id: "demo-ml-4",
      timestamp: now - 5 * day,
      title: "Implement model evaluation dashboard",
      lastUserPrompt: "Create a streamlit dashboard showing model metrics across experiments",
      lastAssistantMsg: "Built Streamlit app with confusion matrix, per-class metrics, and experiment comparison charts.",
      branch: "main",
      sizeBytes: 58100,
    },
  ],
  "auth-service": [
    {
      id: "demo-auth-1",
      timestamp: now - 12 * day,
      title: "Update JWT refresh token rotation",
      lastUserPrompt: "Implement refresh token rotation to prevent token reuse attacks",
      lastAssistantMsg: "Added one-time-use refresh tokens with family tracking. Reuse detection invalidates the whole family.",
      branch: "main",
      sizeBytes: 37400,
    },
  ],
}

const mockBranchData: Record<string, BranchInfo[]> = {
  "acme-api": [
    { name: "main", isCurrent: true, lastCommitAge: "2h ago", lastCommitMsg: "fix: rate limiter edge case", ahead: 1, behind: 0 },
    { name: "feat/observability", isCurrent: false, lastCommitAge: "2d ago", lastCommitMsg: "add jaeger tracing config", ahead: 4, behind: 0 },
    { name: "feat/webhooks", isCurrent: false, lastCommitAge: "5d ago", lastCommitMsg: "webhook retry with backoff", ahead: 2, behind: 3 },
  ],
  "quantum-dashboard": [
    { name: "feat/charts", isCurrent: true, lastCommitAge: "5h ago", lastCommitMsg: "add chart tooltip comp", ahead: 3, behind: 0 },
    { name: "main", isCurrent: false, lastCommitAge: "2d ago", lastCommitMsg: "merge: auth flow redesign", ahead: 0, behind: 0 },
    { name: "fix/memory-leak", isCurrent: false, lastCommitAge: "4d ago", lastCommitMsg: "dispose chart instances on unmount", ahead: 1, behind: 5 },
  ],
  "pixel-engine": [
    { name: "develop", isCurrent: true, lastCommitAge: "1d ago", lastCommitMsg: "perf: batch draw calls", ahead: 0, behind: 0 },
    { name: "feat/ecs", isCurrent: false, lastCommitAge: "5d ago", lastCommitMsg: "archetype-based ECS impl", ahead: 12, behind: 2 },
    { name: "main", isCurrent: false, lastCommitAge: "10d ago", lastCommitMsg: "v0.3.0 release", ahead: 0, behind: 0 },
  ],
  "infractl": [
    { name: "main", isCurrent: true, lastCommitAge: "3d ago", lastCommitMsg: "docs: update deploy guide", ahead: 0, behind: 2 },
    { name: "feat/canary", isCurrent: false, lastCommitAge: "8d ago", lastCommitMsg: "canary deploy strategy WIP", ahead: 3, behind: 4 },
  ],
  "notely-mobile": [
    { name: "release", isCurrent: true, lastCommitAge: "6h ago", lastCommitMsg: "bump version to 2.4.1", ahead: 0, behind: 0 },
    { name: "feat/security", isCurrent: false, lastCommitAge: "1d ago", lastCommitMsg: "biometric auth integration", ahead: 5, behind: 0 },
    { name: "main", isCurrent: false, lastCommitAge: "3d ago", lastCommitMsg: "merge: offline sync fixes", ahead: 0, behind: 0 },
  ],
  "blog-engine": [
    { name: "main", isCurrent: true, lastCommitAge: "7d ago", lastCommitMsg: "feat: RSS feed generation", ahead: 0, behind: 0 },
    { name: "feat/search", isCurrent: false, lastCommitAge: "12d ago", lastCommitMsg: "pagefind integration WIP", ahead: 2, behind: 1 },
  ],
  "ml-pipeline": [
    { name: "exp/bert", isCurrent: true, lastCommitAge: "12h ago", lastCommitMsg: "tune hyperparams batch 3", ahead: 7, behind: 0 },
    { name: "main", isCurrent: false, lastCommitAge: "3d ago", lastCommitMsg: "merge: DVC setup", ahead: 0, behind: 0 },
    { name: "exp/t5", isCurrent: false, lastCommitAge: "6d ago", lastCommitMsg: "T5-small baseline results", ahead: 5, behind: 3 },
  ],
  "auth-service": [
    { name: "main", isCurrent: true, lastCommitAge: "14d ago", lastCommitMsg: "chore: dep updates", ahead: -1, behind: -1 },
  ],
}

export function generateMockSessions(projectPath: string): SessionInfo[] {
  const name = projectPath.split("/").pop() || ""
  return mockSessionData[name] || []
}

export function generateMockBranches(projectPath: string): BranchInfo[] {
  const name = projectPath.split("/").pop() || ""
  return mockBranchData[name] || []
}
