"use client";

import { Button } from "@mcpengine/ui";
import { ProjectGrid } from "../../components/project/ProjectGrid";

const mockProjects = [
  {
    id: "1",
    name: "Trello MCP Server",
    status: "deployed" as const,
    toolCount: 24,
    updatedAt: new Date(Date.now() - 1000 * 60 * 30), // 30 min ago
  },
  {
    id: "2",
    name: "Stripe Payments",
    status: "tested" as const,
    toolCount: 18,
    updatedAt: new Date(Date.now() - 1000 * 60 * 60 * 2), // 2 hrs ago
  },
  {
    id: "3",
    name: "Internal CRM",
    status: "draft" as const,
    toolCount: 0,
    updatedAt: new Date(Date.now() - 1000 * 60 * 60 * 24), // 1 day ago
  },
];

const recentActivity = [
  { action: "Deployed", target: "Trello MCP Server", time: "30 minutes ago", icon: "🚀" },
  { action: "Tests passed", target: "Stripe Payments", time: "2 hours ago", icon: "✅" },
  { action: "Created", target: "Internal CRM", time: "1 day ago", icon: "📄" },
];

export default function DashboardPage() {
  return (
    <div className="flex-1 overflow-y-auto">
      <div className="p-8 max-w-6xl mx-auto">
        {/* Header */}
        <div className="flex items-center justify-between mb-8">
          <div>
            <h1 className="text-2xl font-bold text-white">My Projects</h1>
            <p className="text-gray-400 text-sm mt-1">
              {mockProjects.length} project{mockProjects.length !== 1 ? "s" : ""}
            </p>
          </div>
          <Button className="bg-indigo-600 hover:bg-indigo-500 text-white px-5 py-2.5 rounded-lg font-semibold flex items-center gap-2">
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
            </svg>
            New Project
          </Button>
        </div>

        {/* Project Grid */}
        <ProjectGrid projects={mockProjects} />

        {/* Quick Actions */}
        <div className="mt-12">
          <h2 className="text-lg font-semibold text-white mb-4">Quick Actions</h2>
          <div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
            {[
              {
                label: "Upload Spec",
                desc: "Import an OpenAPI or Swagger file",
                icon: (
                  <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
                  </svg>
                ),
              },
              {
                label: "Browse Templates",
                desc: "Start from 37 production templates",
                icon: (
                  <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm10 0a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zm10 0a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
                  </svg>
                ),
              },
              {
                label: "View Docs",
                desc: "Read the MCPEngine documentation",
                icon: (
                  <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
                  </svg>
                ),
              },
            ].map((action) => (
              <button
                key={action.label}
                className="flex items-start gap-4 p-5 bg-gray-900 border border-gray-800 rounded-xl hover:border-gray-700 hover:bg-gray-800/50 transition-all text-left group"
              >
                <div className="text-indigo-400 group-hover:text-indigo-300 transition-colors">
                  {action.icon}
                </div>
                <div>
                  <p className="font-semibold text-white">{action.label}</p>
                  <p className="text-sm text-gray-400 mt-0.5">{action.desc}</p>
                </div>
              </button>
            ))}
          </div>
        </div>

        {/* Recent Activity */}
        <div className="mt-12">
          <h2 className="text-lg font-semibold text-white mb-4">Recent Activity</h2>
          <div className="bg-gray-900 border border-gray-800 rounded-xl divide-y divide-gray-800">
            {recentActivity.map((item, i) => (
              <div key={i} className="flex items-center gap-4 px-5 py-4">
                <span className="text-xl">{item.icon}</span>
                <div className="flex-1">
                  <p className="text-sm text-white">
                    <span className="font-medium">{item.action}</span>{" "}
                    <span className="text-gray-400">{item.target}</span>
                  </p>
                </div>
                <span className="text-xs text-gray-500">{item.time}</span>
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}
