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 StatCardSkeleton() {
  return (
    <Card>
      <CardContent className="p-4 sm:p-6">
        <div className="flex items-start justify-between gap-3">
          <div className="flex-1 min-w-0">
            <Skeleton className="w-24 h-3 mb-2" />
            <Skeleton className="w-16 h-8 mb-1" />
            <Skeleton className="w-32 h-3" />
          </div>
          <Skeleton className="w-10 h-10 rounded-lg shrink-0" />
        </div>
      </CardContent>
    </Card>
  );
}

function TaskListCardSkeleton() {
  return (
    <Card className="h-full">
      <CardHeader className="pb-3">
        <div className="flex items-center gap-2">
          <Skeleton className="w-4 h-4" />
          <Skeleton className="w-32 h-4" />
        </div>
      </CardHeader>
      <CardContent className="space-y-3">
        {Array.from({ length: 5 }).map((_, i) => (
          <div key={i} className="flex items-start gap-3 py-2">
            <Skeleton className="w-4 h-4 mt-0.5 shrink-0" />
            <div className="flex-1 min-w-0">
              <Skeleton className="w-full h-4 mb-1" />
              <Skeleton className="w-24 h-3" />
            </div>
            <Skeleton className="w-16 h-5 shrink-0" />
          </div>
        ))}
      </CardContent>
    </Card>
  );
}

export default function TasksLoading() {
  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-40 h-8 mb-2" />
              <Skeleton className="w-64 h-4" />
            </div>
            <Skeleton className="w-32 h-9" />
          </div>

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

          {/* Task Lists Grid */}
          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6 mb-6">
            {Array.from({ length: 3 }).map((_, i) => (
              <TaskListCardSkeleton key={i} />
            ))}
          </div>

          {/* Bottom Section */}
          <div className="grid grid-cols-1 lg:grid-cols-3 gap-4 sm:gap-6">
            <Card className="lg:col-span-1">
              <CardHeader className="pb-3">
                <Skeleton className="w-32 h-4" />
              </CardHeader>
              <CardContent className="space-y-4">
                {Array.from({ length: 4 }).map((_, i) => (
                  <div key={i}>
                    <div className="flex justify-between mb-1">
                      <Skeleton className="w-20 h-3" />
                      <Skeleton className="w-8 h-3" />
                    </div>
                    <Skeleton className="w-full h-1.5" />
                  </div>
                ))}
              </CardContent>
            </Card>
            <Card className="lg:col-span-2">
              <CardHeader className="pb-3">
                <Skeleton className="w-32 h-4" />
              </CardHeader>
              <CardContent>
                <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
                  {Array.from({ length: 4 }).map((_, i) => (
                    <Skeleton key={i} className="w-full h-16" />
                  ))}
                </div>
              </CardContent>
            </Card>
          </div>
        </div>
      </main>
    </div>
  );
}
