"use client"

// Delt "Skriv ut"-meny -- lenker til de tre rundekoblede utskriftssidene
// (ADR-097). Brukt fra RoundGroupsPanel (individuell) og økt-visningene
// (Cup) -- ekte gjenbruk, ikke en tidlig abstraksjon.

import Link from "next/link"
import { Printer } from "lucide-react"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

export function PrintMenu({
  organizationId,
  tournamentId,
  roundId,
  sessionId,
  includeCartTags = true,
}: {
  organizationId: string
  tournamentId: string
  roundId?: string
  sessionId?: string
  includeCartTags?: boolean
}) {
  const scope = roundId ? `roundId=${roundId}` : `sessionId=${sessionId}`
  const href = (kind: "scorecard" | "startlist" | "cart-tags") =>
    `/tournaments/${tournamentId}/print/${kind}?org=${organizationId}&${scope}`

  return (
    <DropdownMenu>
      <DropdownMenuTrigger
        aria-label="Skriv ut"
        className="inline-flex min-h-11 items-center gap-2 rounded-xl border border-border bg-card px-3 text-sm font-bold text-foreground transition-colors hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
      >
        <Printer aria-hidden="true" className="size-5" />
        <span className="hidden sm:inline">Skriv ut</span>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end">
        <DropdownMenuItem render={<Link href={href("scorecard")}>Scorekort</Link>} />
        <DropdownMenuItem render={<Link href={href("startlist")}>Startliste</Link>} />
        {includeCartTags && <DropdownMenuItem render={<Link href={href("cart-tags")}>Cart-tags</Link>} />}
      </DropdownMenuContent>
    </DropdownMenu>
  )
}
