import { Skeleton } from "@/components/ui/skeleton";
import { Card, CardContent, CardHeader } from "@/components/ui/card";

function SidebarSkeleton() {
  return (
    <div className="hidden lg:flex flex-col fixed inset-y-0 left-0 border-r border-border bg-card w-64 h-screen p-4 space-y-6">
      <div className="flex items-center gap-2">
        <Skeleton className="w-8 h-8 rounded-lg" />
        <Skeleton className="w-32 h-6" />
      </div>
      <Skeleton className="w-full h-12 rounded-lg" />
      <div className="space-y-2 flex-1">
        {Array.from({ length: 8 }).map((_, i) => (
          <Skeleton key={i} className="w-full h-10 rounded-lg" />
        ))}
      </div>
      <div className="flex items-center gap-3 pt-4 border-t">
        <Skeleton className="w-8 h-8 rounded-full" />
        <div className="space-y-1">
          <Skeleton className="w-24 h-4" />
          <Skeleton className="w-16 h-3" />
        </div>
      </div>
    </div>
  );
}

function ProjectCardSkeleton() {
  return (
    <Card>
      <CardHeader className="pb-3">
        <div className="flex items-center justify-between">
          <div className="flex items-center gap-2">
            <Skeleton className="w-3 h-3 rounded-full" />
            <Skeleton className="w-32 h-4" />
          </div>
          <Skeleton className="w-16 h-5" />
        </div>
        <Skeleton className="w-full h-8 mt-2" />
      </CardHeader>
      <CardContent className="space-y-3">
        <div className="space-y-1">
          <div className="flex justify-between">
            <Skeleton className="w-16 h-3" />
            <Skeleton className="w-8 h-3" />
          </div>
          <Skeleton className="w-full h-2" />
        </div>
        <div className="flex justify-between">
          <Skeleton className="w-24 h-3" />
          <Skeleton className="w-16 h-3" />
        </div>
      </CardContent>
    </Card>
  );
}

function StatCardSkeleton() {
  return (
    <Card>
      <CardHeader className="flex flex-row items-center justify-between pb-2 space-y-0">
        <Skeleton className="w-24 h-3" />
        <Skeleton className="w-4 h-4" />
      </CardHeader>
      <CardContent>
        <Skeleton className="w-16 h-7 mb-1" />
        <Skeleton className="w-full h-2 mb-2" />
        <Skeleton className="w-32 h-3" />
      </CardContent>
    </Card>
  );
}

export default function ProjectsLoading() {
  return (
    <div className="h-screen bg-background flex overflow-hidden">
      <SidebarSkeleton />

      <main className="flex-1 h-screen overflow-y-auto lg:pl-64">
        <div className="min-h-full p-4 lg:p-8">
          {/* Mobile header */}
          <div className="lg:hidden flex items-center justify-between gap-4 p-4 mb-4 border-b">
            <div className="flex items-center gap-3">
              <Skeleton className="w-8 h-8" />
              <Skeleton className="w-32 h-6" />
            </div>
            <Skeleton className="w-8 h-8" />
          </div>

          {/* Desktop search */}
          <div className="hidden lg:flex items-center justify-end gap-4 mb-6">
            <Skeleton className="w-64 h-10" />
          </div>

          {/* Header */}
          <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
            <div>
              <Skeleton className="w-48 h-8 mb-2" />
              <Skeleton className="w-64 h-4" />
            </div>
            <Skeleton className="w-32 h-9" />
          </div>

          {/* Stats Cards */}
          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4 mb-8">
            {Array.from({ length: 4 }).map((_, i) => (
              <StatCardSkeleton key={i} />
            ))}
          </div>

          {/* Project Cards */}
          <div className="space-y-4">
            <Skeleton className="w-40 h-6" />
            <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
              {Array.from({ length: 6 }).map((_, i) => (
                <ProjectCardSkeleton key={i} />
              ))}
            </div>
          </div>

          {/* Recent Tasks */}
          <div className="mt-8 space-y-4">
            <Skeleton className="w-32 h-6" />
            <Card>
              <CardContent className="p-0">
                <div className="divide-y">
                  {Array.from({ length: 5 }).map((_, i) => (
                    <div key={i} className="p-4 flex items-center justify-between">
                      <div className="flex items-center gap-3 flex-1">
                        <Skeleton className="w-2 h-2 rounded-full" />
                        <div className="flex-1 min-w-0">
                          <Skeleton className="w-full h-4 mb-1" />
                          <Skeleton className="w-24 h-3" />
                        </div>
                      </div>
                      <Skeleton className="w-16 h-5" />
                    </div>
                  ))}
                </div>
              </CardContent>
            </Card>
          </div>
        </div>
      </main>
    </div>
  );
}
