'use client';

import { Skeleton } from '@/components/ui/skeleton';

function StatSkeleton() {
  return (
    <div className="flex flex-col items-center rounded-lg border border-muted bg-muted/30 p-4 text-center">
      <Skeleton className="mb-2 size-9 rounded-lg" />
      <Skeleton className="h-6 w-12" />
      <Skeleton className="mt-2 h-3 w-20" />
    </div>
  );
}

function DetectionLogSkeleton() {
  return (
    <div className="rounded-lg border bg-card p-3">
      <div className="flex gap-3">
        <Skeleton className="size-20 shrink-0 rounded-lg" />
        <div className="min-w-0 flex-1 space-y-2">
          <div className="flex items-start justify-between gap-3">
            <div className="space-y-2">
              <Skeleton className="h-5 w-28" />
              <Skeleton className="h-3 w-20" />
            </div>
            <div className="space-y-2">
              <Skeleton className="h-3 w-12" />
              <Skeleton className="h-3 w-10" />
            </div>
          </div>
          <Skeleton className="h-3 w-32" />
          <Skeleton className="h-3 w-44" />
        </div>
      </div>
    </div>
  );
}

export function VideoResultsSkeleton() {
  return (
    <div className="space-y-8">
      <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <div className="flex min-w-0 items-start gap-3">
          <Skeleton className="size-10 rounded-lg" />
          <div className="min-w-0 space-y-2">
            <Skeleton className="h-7 w-60 max-w-full" />
            <Skeleton className="h-3 w-80 max-w-full" />
          </div>
        </div>
        <Skeleton className="h-8 w-20" />
      </div>

      <section className="overflow-hidden rounded-lg border bg-card">
        <div className="border-b p-6 pb-4">
          <div className="flex items-center gap-3">
            <Skeleton className="size-10 rounded-lg" />
            <div className="space-y-2">
              <Skeleton className="h-5 w-44" />
              <Skeleton className="h-3 w-64" />
            </div>
          </div>
        </div>

        <div className="p-6">
          <div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
            <div className="space-y-6 lg:col-span-2">
              <Skeleton className="aspect-video w-full rounded-lg border" />

              <section className="overflow-hidden rounded-lg border bg-card/80">
                <div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
                  <div className="space-y-2">
                    <Skeleton className="h-4 w-48" />
                    <Skeleton className="h-3 w-72 max-w-full" />
                  </div>
                  <Skeleton className="h-8 w-48" />
                </div>
                <div className="grid grid-cols-1 gap-2 p-3 sm:grid-cols-3">
                  {Array.from({ length: 3 }).map((_, index) => (
                    <Skeleton key={index} className="h-16 w-full rounded-lg" />
                  ))}
                </div>
              </section>
            </div>

            <div className="space-y-4">
              <div className="flex items-center justify-between">
                <Skeleton className="h-5 w-36" />
              </div>
              <div className="h-107.5 rounded-lg border bg-muted/20 p-4">
                <div className="space-y-3">
                  {Array.from({ length: 5 }).map((_, index) => (
                    <DetectionLogSkeleton key={index} />
                  ))}
                </div>
              </div>
            </div>
          </div>

          <div className="mt-6 grid grid-cols-2 gap-3 md:grid-cols-5">
            {Array.from({ length: 5 }).map((_, index) => (
              <StatSkeleton key={index} />
            ))}
          </div>
        </div>
      </section>
    </div>
  );
}
