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 DocumentItemSkeleton() {
  return (
    <div className="flex items-start gap-3 p-3 sm:p-4">
      <Skeleton className="w-9 h-9 rounded-lg shrink-0" />
      <div className="flex-1 min-w-0">
        <div className="flex items-center gap-2 mb-1">
          <Skeleton className="flex-1 h-4" />
          <Skeleton className="w-16 h-5 shrink-0" />
        </div>
        <Skeleton className="w-full h-3 mb-1" />
        <Skeleton className="w-32 h-3" />
      </div>
    </div>
  );
}

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

          {/* Recent Documents Carousel */}
          <div className="space-y-3 mb-6">
            <Skeleton className="w-32 h-4" />
            <div className="flex gap-3 overflow-x-auto pb-2">
              {Array.from({ length: 5 }).map((_, i) => (
                <Skeleton key={i} className="w-48 h-16 rounded-lg shrink-0" />
              ))}
            </div>
          </div>

          {/* Main Content Grid */}
          <div className="grid grid-cols-1 lg:grid-cols-4 gap-4 sm:gap-6">
            {/* Sidebar */}
            <div className="lg:col-span-1 space-y-4">
              {/* Folders */}
              <Card>
                <CardHeader className="pb-3">
                  <div className="flex items-center justify-between">
                    <Skeleton className="w-16 h-5" />
                    <Skeleton className="w-6 h-6" />
                  </div>
                </CardHeader>
                <CardContent className="space-y-1">
                  {Array.from({ length: 5 }).map((_, i) => (
                    <Skeleton key={i} className="w-full h-9" />
                  ))}
                </CardContent>
              </Card>

              {/* Tags */}
              <Card>
                <CardHeader className="pb-3">
                  <Skeleton className="w-12 h-5" />
                </CardHeader>
                <CardContent>
                  <div className="flex flex-wrap gap-2">
                    {Array.from({ length: 8 }).map((_, i) => (
                      <Skeleton key={i} className="w-16 h-6 rounded-md" />
                    ))}
                  </div>
                </CardContent>
              </Card>

              {/* Storage */}
              <Card>
                <CardHeader className="pb-3">
                  <Skeleton className="w-16 h-5" />
                </CardHeader>
                <CardContent>
                  <div className="space-y-2">
                    <div className="flex justify-between">
                      <Skeleton className="w-24 h-3" />
                      <Skeleton className="w-12 h-3" />
                    </div>
                    <Skeleton className="w-full h-2" />
                    <Skeleton className="w-32 h-3" />
                  </div>
                </CardContent>
              </Card>
            </div>

            {/* Document List */}
            <div className="lg:col-span-3 space-y-4">
              {/* Toolbar */}
              <div className="flex flex-col sm:flex-row gap-3">
                <Skeleton className="flex-1 h-10" />
                <div className="flex items-center gap-2">
                  <Skeleton className="w-24 h-9" />
                  <Skeleton className="w-20 h-9" />
                </div>
              </div>

              {/* Tabs */}
              <Skeleton className="w-32 h-9" />

              {/* Document List */}
              <Card>
                <CardContent className="p-0">
                  <div className="divide-y">
                    {Array.from({ length: 8 }).map((_, i) => (
                      <DocumentItemSkeleton key={i} />
                    ))}
                  </div>
                </CardContent>
              </Card>
            </div>
          </div>
        </div>
      </main>
    </div>
  );
}
