"use client";
import { ListVideo } from "lucide-react";
import { useWatchQueue } from "./WatchQueueProvider";
import { useQueuePanel } from "./QueuePanelProvider";
import { cn } from "@/lib/utils";

export function QueueIndicator() {
  const q = useWatchQueue();
  const { open, toggle } = useQueuePanel();
  const count = q.ids.length;
  return (
    <button
      type="button"
      onClick={toggle}
      aria-label="Watch queue"
      aria-pressed={open}
      title={count > 0 ? `Watch queue · ${count} cover${count === 1 ? "" : "s"}` : "Watch queue"}
      className={cn(
        "relative w-9 h-9 grid place-items-center rounded-lg border transition-colors shrink-0",
        open
          ? "bg-[var(--color-cyan)]/15 border-[var(--color-cyan)]/40 text-[var(--color-cyan)]"
          : count > 0
          ? "bg-[var(--color-cyan)]/15 border-[var(--color-cyan)]/40 text-[var(--color-cyan)]"
          : "border-[var(--color-glass-border)] text-[var(--color-fg-dim)] hover:text-[var(--color-fg)] hover:bg-[var(--color-glass)]",
      )}
    >
      <ListVideo className="w-4 h-4" />
      {count > 0 && (
        <span className="absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full bg-[var(--color-cyan)] text-black text-[10px] font-mono font-bold grid place-items-center">
          {count > 99 ? "99+" : count}
        </span>
      )}
    </button>
  );
}
