All files / app/(dashboard)/developer page.tsx

82.39% Statements 440/534
81.33% Branches 61/75
50% Functions 3/6
82.39% Lines 440/534

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 6691x                                                                     24x 24x 24x 24x 24x 24x 24x     24x 23x 23x   23x                                               23x                                         24x   24x 23x   23x 23x 23x 23x 23x 1x 1x 1x   21x 21x 21x 21x 21x   23x 1x 1x 1x   20x 20x 20x 20x 20x   23x 3x 3x 3x 3x   17x 17x 17x 17x 17x   17x 17x 17x 23x 23x 23x 23x   23x 24x   24x                                                                 24x 11x 11x 11x 11x 11x 11x 11x   11x     24x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x   2x 2x 2x 2x 2x   2x   10x 10x 10x   10x 10x   10x 10x 10x 10x 10x 10x 10x 10x 10x   10x 10x 10x 10x 10x   10x 10x 10x 10x     10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 9x 24x 24x 24x 24x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   9x 9x 9x   9x 9x   24x 24x 24x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x   24x     24x 24x 24x 24x 24x 24x 24x 24x 10x 10x 10x 10x 13x 13x 13x 10x 10x 10x   24x 10x 10x 10x 10x 13x 13x 13x 10x 10x 10x   24x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x   24x 24x 24x     24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 2x 3x 3x 3x 2x   8x   24x 24x 24x 24x 24x 24x 2x 8x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x     24x 1x 1x                 1x     1x 1x 1x 4x 1x 1x 1x 1x 1x 1x   1x 1x 1x                                                                 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x   1x   1x     24x 24x 24x 24x 24x 24x 24x 24x 24x   24x 24x 24x 24x 24x 24x 24x 9x 9x 9x 9x 9x 9x 9x   9x 9x 9x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   24x 24x 24x   24x   2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 1x     2x 2x 2x 3x 3x 3x 2x 2x 1x 1x 1x   2x   2x 2x 1x 1x 1x 1x   2x 1x 1x 1x 1x   2x 2x   2x 1x 1x 1x 1x 1x   1x 1x   1x 1x 1x 1x 1x 1x   1x   1x 1x   1x   2x   2x  
'use client';
 
import { useState, useEffect } from 'react';
import Link from 'next/link';
import { useRouter, useSearchParams } from 'next/navigation';
import { motion } from 'framer-motion';
import {
  Github,
  Code2,
  Star,
  GitFork,
  Plus,
  ExternalLink,
  RefreshCw,
  Globe,
  ChevronRight,
  Loader2,
  Settings,
  Sparkles,
  Users,
  FolderGit2,
} from 'lucide-react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { createClient } from '@/lib/supabase/client';
import { useToast } from '@/hooks/use-toast';
import type { DeveloperProfile, CodeProject, Profile } from '@/types/database';
 
interface DeveloperDashboardData {
  developerProfile: DeveloperProfile | null;
  profile: Profile | null;
  projects: CodeProject[];
}
 
export default function DeveloperDashboardPage() {
  const [data, setData] = useState<DeveloperDashboardData | null>(null);
  const [loading, setLoading] = useState(true);
  const [syncing, setSyncing] = useState(false);
  const router = useRouter();
  const searchParams = useSearchParams();
  const { toast } = useToast();
 
  // Handle OAuth callback messages
  useEffect(() => {
    const github = searchParams.get('github');
    const error = searchParams.get('error');
 
    if (github === 'connected') {
      toast({
        title: 'GitHub Connected',
        description: 'Your GitHub account has been connected successfully. Syncing repositories...',
      });
      // Clean URL and trigger sync
      router.replace('/developer');
      // Auto-sync after connection
      setTimeout(() => {
        fetch('/api/auth/github/sync', { method: 'POST' })
          .then((res) => res.json())
          .then((result) => {
            if (result.success) {
              toast({
                title: 'Repositories Synced',
                description: `Imported ${result.stats.reposImported} repositories.`,
              });
              window.location.reload();
            }
          })
          .catch(console.error);
      }, 500);
    }
 
    if (error) {
      const errorMessages: Record<string, string> = {
        github_not_configured: 'GitHub integration is not configured. Please contact support.',
        oauth_failed: 'Failed to connect to GitHub. Please try again.',
        missing_params: 'Invalid OAuth response. Please try again.',
        invalid_state: 'Security validation failed. Please try again.',
        state_expired: 'Connection timed out. Please try again.',
        token_exchange_failed: 'Failed to authenticate with GitHub. Please try again.',
        user_fetch_failed: 'Failed to fetch your GitHub profile. Please try again.',
        update_failed: 'Failed to save GitHub connection. Please try again.',
        create_failed: 'Failed to create developer profile. Please try again.',
        access_denied: 'GitHub access was denied. Please try again and allow access.',
      };
 
      toast({
        variant: 'destructive',
        title: 'GitHub Connection Failed',
        description: errorMessages[error] || 'An unexpected error occurred. Please try again.',
      });
      router.replace('/developer');
    }
  }, [searchParams, router, toast]);
 
  useEffect(() => {
    const supabase = createClient();
 
    async function fetchData() {
      const {
        data: { user },
      } = await supabase.auth.getUser();
      if (!user) {
        router.push('/login');
        return;
      }
 
      const { data: profile } = await supabase
        .from('profiles')
        .select('*')
        .eq('user_id', user.id)
        .single();
 
      if (!profile) {
        router.push('/profile');
        return;
      }
 
      const { data: developerProfile } = await supabase
        .from('developer_profiles')
        .select('*')
        .eq('profile_id', profile.id)
        .single();
 
      if (!developerProfile) {
        setData({ developerProfile: null, profile, projects: [] });
        setLoading(false);
        return;
      }
 
      const { data: projects } = await supabase
        .from('code_projects')
        .select('*')
        .eq('developer_profile_id', developerProfile.id)
        .order('display_order', { ascending: true });
 
      setData({
        developerProfile,
        profile,
        projects: projects || [],
      });
      setLoading(false);
    }
 
    fetchData();
  }, [router]);
 
  const syncGitHub = async () => {
    if (!data?.developerProfile?.github_connected) return;
    setSyncing(true);
 
    try {
      const response = await fetch('/api/auth/github/sync', {
        method: 'POST',
      });
 
      const result = await response.json();
 
      if (!response.ok) {
        throw new Error(result.error || 'Failed to sync GitHub');
      }
 
      toast({
        title: 'GitHub Synced',
        description: `Imported ${result.stats.reposImported} repositories with ${result.stats.totalStars} total stars.`,
      });
 
      // Reload to show updated data
      window.location.reload();
    } catch (error) {
      console.error('GitHub sync error:', error);
      toast({
        variant: 'destructive',
        title: 'Sync Failed',
        description: error instanceof Error ? error.message : 'Failed to sync GitHub repositories.',
      });
      setSyncing(false);
    }
  };
 
  if (loading) {
    return (
      <div className="flex min-h-[400px] items-center justify-center">
        <div className="flex flex-col items-center gap-4">
          <Loader2 className="h-8 w-8 animate-spin text-primary" />
          <p className="text-sm text-muted-foreground">Loading developer dashboard...</p>
        </div>
      </div>
    );
  }
 
  // No developer profile - show setup prompt
  if (!data?.developerProfile) {
    return (
      <div className="space-y-8">
        <div>
          <h1 className="text-3xl font-bold">Developer Dashboard</h1>
          <p className="text-muted-foreground">Showcase your code and technical skills</p>
        </div>
 
        <Card className="border-dashed">
          <CardContent className="flex flex-col items-center justify-center py-16">
            <div className="mb-4 rounded-full bg-primary/10 p-4">
              <Code2 className="h-12 w-12 text-primary" />
            </div>
            <h2 className="mb-2 text-xl font-semibold">Set Up Your Developer Profile</h2>
            <p className="mb-6 max-w-md text-center text-muted-foreground">
              Connect your GitHub, showcase your projects, and highlight your technical skills to
              potential employers and clients.
            </p>
            <Button asChild size="lg">
              <Link href="/developer/setup">
                <Plus className="mr-2 h-4 w-4" />
                Create Developer Profile
              </Link>
            </Button>
          </CardContent>
        </Card>
      </div>
    );
  }
 
  const { developerProfile, projects } = data;
  const totalStars = projects.reduce((sum, p) => sum + (p.stars || 0), 0);
  const totalForks = projects.reduce((sum, p) => sum + (p.forks || 0), 0);
 
  return (
    <div className="space-y-8">
      {/* Header */}
      <div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
        <div>
          <h1 className="text-3xl font-bold">Developer Dashboard</h1>
          <p className="text-muted-foreground">Manage your technical portfolio and projects</p>
        </div>
        <div className="flex gap-2">
          <Button variant="outline" asChild>
            <Link href="/developer/settings">
              <Settings className="mr-2 h-4 w-4" />
              Settings
            </Link>
          </Button>
          <Button asChild>
            <Link href="/developer/projects/new">
              <Plus className="mr-2 h-4 w-4" />
              Add Project
            </Link>
          </Button>
        </div>
      </div>
 
      {/* GitHub Connection Card */}
      <Card>
        <CardHeader>
          <div className="flex items-center justify-between">
            <div className="flex items-center gap-3">
              <div className="flex h-10 w-10 items-center justify-center rounded-full bg-[#24292e]">
                <Github className="h-5 w-5 text-white" />
              </div>
              <div>
                <CardTitle className="text-lg">GitHub</CardTitle>
                <CardDescription>
                  {developerProfile.github_connected
                    ? `Connected as @${developerProfile.github_username}`
                    : 'Connect your GitHub to import projects'}
                </CardDescription>
              </div>
            </div>
            {developerProfile.github_connected ? (
              <div className="flex items-center gap-2">
                <Button variant="outline" size="sm" onClick={syncGitHub} disabled={syncing}>
                  <RefreshCw className={`mr-2 h-4 w-4 ${syncing ? 'animate-spin' : ''}`} />
                  {syncing ? 'Syncing...' : 'Sync'}
                </Button>
                <Button variant="outline" size="sm" asChild>
                  <Link
                    href={`https://github.com/${developerProfile.github_username}`}
                    target="_blank"
                  >
                    <ExternalLink className="h-4 w-4" />
                  </Link>
                </Button>
              </div>
            ) : (
              <Button asChild>
                <Link href="/api/auth/github">
                  <Github className="mr-2 h-4 w-4" />
                  Connect GitHub
                </Link>
              </Button>
            )}
          </div>
        </CardHeader>
        {developerProfile.github_connected && (
          <CardContent>
            {(() => {
              const githubData = developerProfile.github_data as {
                followers?: number;
                following?: number;
                public_repos?: number;
              } | null;
              return (
                <div className="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-6">
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <FolderGit2 className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">
                      {githubData?.public_repos ?? projects.filter((p) => p.is_from_github).length}
                    </p>
                    <p className="text-xs text-muted-foreground">Public Repos</p>
                  </div>
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <Users className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">{githubData?.followers ?? 0}</p>
                    <p className="text-xs text-muted-foreground">Followers</p>
                  </div>
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <Users className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">{githubData?.following ?? 0}</p>
                    <p className="text-xs text-muted-foreground">Following</p>
                  </div>
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <Star className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">{totalStars}</p>
                    <p className="text-xs text-muted-foreground">Total Stars</p>
                  </div>
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <GitFork className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">{totalForks}</p>
                    <p className="text-xs text-muted-foreground">Total Forks</p>
                  </div>
                  <div className="rounded-lg bg-muted/50 p-3 text-center">
                    <div className="mb-1 flex justify-center">
                      <Code2 className="h-4 w-4 text-muted-foreground" />
                    </div>
                    <p className="text-2xl font-bold">
                      {developerProfile.open_source_contributions}
                    </p>
                    <p className="text-xs text-muted-foreground">Contributions</p>
                  </div>
                </div>
              );
            })()}
          </CardContent>
        )}
      </Card>
 
      {/* Skills Overview */}
      <Card>
        <CardHeader>
          <CardTitle>Technical Skills</CardTitle>
          <CardDescription>Your programming languages, frameworks, and tools</CardDescription>
        </CardHeader>
        <CardContent>
          <div className="space-y-4">
            {developerProfile.primary_languages.length > 0 && (
              <div>
                <p className="mb-2 text-sm font-medium">Languages</p>
                <div className="flex flex-wrap gap-2">
                  {developerProfile.primary_languages.map((lang) => (
                    <Badge key={lang} variant="secondary">
                      {lang}
                    </Badge>
                  ))}
                </div>
              </div>
            )}
            {developerProfile.frameworks.length > 0 && (
              <div>
                <p className="mb-2 text-sm font-medium">Frameworks</p>
                <div className="flex flex-wrap gap-2">
                  {developerProfile.frameworks.map((fw) => (
                    <Badge key={fw} variant="outline">
                      {fw}
                    </Badge>
                  ))}
                </div>
              </div>
            )}
            {developerProfile.tools.length > 0 && (
              <div>
                <p className="mb-2 text-sm font-medium">Tools & Platforms</p>
                <div className="flex flex-wrap gap-2">
                  {developerProfile.tools.map((tool) => (
                    <Badge key={tool} variant="outline">
                      {tool}
                    </Badge>
                  ))}
                </div>
              </div>
            )}
          </div>
        </CardContent>
      </Card>
 
      {/* Availability Card */}
      <Card>
        <CardHeader>
          <CardTitle>Work Availability</CardTitle>
        </CardHeader>
        <CardContent>
          <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
            <div className="space-y-1">
              <p className="text-sm text-muted-foreground">Status</p>
              <Badge variant={developerProfile.open_to_work ? 'default' : 'secondary'}>
                {developerProfile.open_to_work ? 'Open to Work' : 'Not Looking'}
              </Badge>
            </div>
            <div className="space-y-1">
              <p className="text-sm text-muted-foreground">Work Types</p>
              <div className="flex flex-wrap gap-1">
                {developerProfile.work_types.length > 0 ? (
                  developerProfile.work_types.map((type) => (
                    <Badge key={type} variant="outline" className="text-xs">
                      {type.replace('_', ' ')}
                    </Badge>
                  ))
                ) : (
                  <span className="text-sm text-muted-foreground">Not specified</span>
                )}
              </div>
            </div>
            <div className="space-y-1">
              <p className="text-sm text-muted-foreground">Hourly Rate</p>
              <p className="font-semibold">
                {developerProfile.hourly_rate_usd
                  ? `$${developerProfile.hourly_rate_usd}/hr`
                  : 'Not set'}
              </p>
            </div>
            <div className="space-y-1">
              <p className="text-sm text-muted-foreground">Remote Work</p>
              <Badge variant={developerProfile.remote_only ? 'default' : 'secondary'}>
                {developerProfile.remote_only ? 'Remote Only' : 'Open to On-site'}
              </Badge>
            </div>
          </div>
        </CardContent>
      </Card>
 
      {/* Contribution Stats */}
      {developerProfile.github_connected &&
        (() => {
          const githubData = developerProfile.github_data as {
            contributions?: {
              totalCommits?: number;
              pullRequests?: number;
              issues?: number;
              reviews?: number;
              activeRepos?: number;
            };
          } | null;
          const contribs = githubData?.contributions;
 
          // Language breakdown from projects
          const langCounts: Record<string, number> = {};
          projects.forEach((p) => {
            p.technologies.forEach((tech) => {
              langCounts[tech] = (langCounts[tech] || 0) + 1;
            });
          });
          const sortedLangs = Object.entries(langCounts)
            .sort((a, b) => b[1] - a[1])
            .slice(0, 8);
          const maxLangCount = sortedLangs[0]?.[1] || 1;
 
          return (
            <>
              {contribs && (
                <Card>
                  <CardHeader>
                    <CardTitle>Recent Activity</CardTitle>
                    <CardDescription>Contribution stats from GitHub (last 90 days)</CardDescription>
                  </CardHeader>
                  <CardContent>
                    <div className="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-5">
                      <div className="rounded-lg bg-muted/50 p-3 text-center">
                        <p className="text-2xl font-bold">{contribs.totalCommits || 0}</p>
                        <p className="text-xs text-muted-foreground">Commits</p>
                      </div>
                      <div className="rounded-lg bg-muted/50 p-3 text-center">
                        <p className="text-2xl font-bold">{contribs.pullRequests || 0}</p>
                        <p className="text-xs text-muted-foreground">Pull Requests</p>
                      </div>
                      <div className="rounded-lg bg-muted/50 p-3 text-center">
                        <p className="text-2xl font-bold">{contribs.issues || 0}</p>
                        <p className="text-xs text-muted-foreground">Issues</p>
                      </div>
                      <div className="rounded-lg bg-muted/50 p-3 text-center">
                        <p className="text-2xl font-bold">{contribs.reviews || 0}</p>
                        <p className="text-xs text-muted-foreground">Reviews</p>
                      </div>
                      <div className="rounded-lg bg-muted/50 p-3 text-center">
                        <p className="text-2xl font-bold">{contribs.activeRepos || 0}</p>
                        <p className="text-xs text-muted-foreground">Active Repos</p>
                      </div>
                    </div>
                  </CardContent>
                </Card>
              )}
 
              {sortedLangs.length > 0 && (
                <Card>
                  <CardHeader>
                    <CardTitle>Language Breakdown</CardTitle>
                    <CardDescription>Technologies used across your projects</CardDescription>
                  </CardHeader>
                  <CardContent>
                    <div className="space-y-3">
                      {sortedLangs.map(([lang, count]) => (
                        <div key={lang} className="flex items-center gap-3">
                          <span className="w-24 text-sm font-medium">{lang}</span>
                          <div className="flex-1">
                            <div className="h-3 rounded-full bg-muted">
                              <div
                                className="h-3 rounded-full bg-primary transition-all"
                                style={{ width: `${(count / maxLangCount) * 100}%` }}
                              />
                            </div>
                          </div>
                          <span className="w-8 text-right text-sm text-muted-foreground">
                            {count}
                          </span>
                        </div>
                      ))}
                    </div>
                  </CardContent>
                </Card>
              )}
            </>
          );
        })()}
 
      {/* Projects */}
      <Card>
        <CardHeader>
          <div className="flex items-center justify-between">
            <div>
              <CardTitle>Projects</CardTitle>
              <CardDescription>Showcase your best work</CardDescription>
            </div>
            <Button variant="outline" size="sm" asChild>
              <Link href="/developer/projects">
                View All
                <ChevronRight className="ml-1 h-4 w-4" />
              </Link>
            </Button>
          </div>
        </CardHeader>
        <CardContent>
          {projects.length === 0 ? (
            <div className="py-12 text-center text-muted-foreground">
              <Code2 className="mx-auto mb-4 h-12 w-12 opacity-50" />
              <p>No projects yet</p>
              <p className="text-sm">Add your first project to showcase your work</p>
              <Button className="mt-4" asChild>
                <Link href="/developer/projects/new">
                  <Plus className="mr-2 h-4 w-4" />
                  Add Project
                </Link>
              </Button>
            </div>
          ) : (
            <div className="grid gap-4 sm:grid-cols-2">
              {projects.slice(0, 4).map((project, index) => (
                <motion.div
                  key={project.id}
                  initial={{ opacity: 0, y: 20 }}
                  animate={{ opacity: 1, y: 0 }}
                  transition={{ delay: index * 0.1 }}
                >
                  <ProjectCard project={project} />
                </motion.div>
              ))}
            </div>
          )}
        </CardContent>
      </Card>
    </div>
  );
}
 
function ProjectCard({ project }: { project: CodeProject }) {
  return (
    <Link
      href={`/developer/projects/${project.id}`}
      className="group block rounded-lg border p-4 transition-colors hover:bg-muted/50"
    >
      <div className="mb-2 flex items-start justify-between">
        <div className="flex items-center gap-2">
          <Code2 className="h-5 w-5 text-primary" />
          <h3 className="font-semibold transition-colors group-hover:text-primary">
            {project.title}
          </h3>
          {project.is_featured && <Sparkles className="h-4 w-4 text-yellow-500" />}
        </div>
        {project.github_repo_url && <Github className="h-4 w-4 text-muted-foreground" />}
      </div>
 
      {project.description && (
        <p className="mb-3 line-clamp-2 text-sm text-muted-foreground">{project.description}</p>
      )}
 
      <div className="flex items-center justify-between">
        <div className="flex flex-wrap gap-1">
          {project.technologies.slice(0, 3).map((tech) => (
            <Badge key={tech} variant="secondary" className="text-xs">
              {tech}
            </Badge>
          ))}
          {project.technologies.length > 3 && (
            <Badge variant="outline" className="text-xs">
              +{project.technologies.length - 3}
            </Badge>
          )}
        </div>
 
        <div className="flex items-center gap-3 text-sm text-muted-foreground">
          {project.stars > 0 && (
            <span className="flex items-center gap-1">
              <Star className="h-3.5 w-3.5" />
              {project.stars}
            </span>
          )}
          {project.forks > 0 && (
            <span className="flex items-center gap-1">
              <GitFork className="h-3.5 w-3.5" />
              {project.forks}
            </span>
          )}
        </div>
      </div>
 
      {(project.live_demo_url || project.github_repo_url) && (
        <div className="mt-3 flex gap-2 border-t pt-3">
          {project.live_demo_url && (
            <Button variant="outline" size="sm" className="h-7 text-xs" asChild>
              <a href={project.live_demo_url} target="_blank" onClick={(e) => e.stopPropagation()}>
                <Globe className="mr-1 h-3 w-3" />
                Demo
              </a>
            </Button>
          )}
          {project.github_repo_url && (
            <Button variant="outline" size="sm" className="h-7 text-xs" asChild>
              <a
                href={project.github_repo_url}
                target="_blank"
                onClick={(e) => e.stopPropagation()}
              >
                <Github className="mr-1 h-3 w-3" />
                Code
              </a>
            </Button>
          )}
        </div>
      )}
    </Link>
  );
}