"use client"; import { useMemo, useState } from "react"; import Link from "next/link"; import type { BillingPosition, RepeatDownloadPosition } from "@/modules/billing/queries"; import { formatCents } from "@/modules/billing/format"; type BillingSelectionProps = { editorialId: string; positions: BillingPosition[]; repeatDownloads: RepeatDownloadPosition[]; year: number; month: number | null; quarter: number | null; isQuarter: boolean; periodLabel: string; }; const MONTHS = [ "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", ]; const STATUS_LABELS: Record = { open: "Offen", billed: "Abgerechnet", reopened: "Wiedereröffnet", }; export function BillingSelection({ editorialId, positions, repeatDownloads, year, month, quarter, isQuarter, periodLabel, }: BillingSelectionProps) { const [selectedIds, setSelectedIds] = useState>(new Set()); const selectablePositions = useMemo( () => positions.filter((p) => p.selectable), [positions], ); const selectedCount = selectedIds.size; const selectedTotalCents = useMemo( () => positions.reduce( (sum, p) => (selectedIds.has(p.id) ? sum + p.priceCents : sum), 0, ), [positions, selectedIds], ); function togglePosition(id: string) { setSelectedIds((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); } function selectAllOpen() { setSelectedIds(new Set(selectablePositions.map((p) => p.id))); } function clearSelection() { setSelectedIds(new Set()); } const quarterParam = isQuarter ? null : Math.ceil((month ?? 1) / 3); const quarterHref = quarter ? `/admin/abrechnungen/${editorialId}?year=${year}&quarter=${quarter}` : `/admin/abrechnungen/${editorialId}?year=${year}&quarter=${quarterParam}`; const monthHref = `/admin/abrechnungen/${editorialId}?year=${year}&month=${month ?? (quarter ? (quarter - 1) * 3 + 1 : new Date().getUTCMonth() + 1)}`; return ( <>
{isQuarter ? ( Monatsansicht ) : ( Ganzes Quartal )}

Zeitraum: {periodLabel}

{positions.length === 0 ? (

Keine abrechenbaren Nutzungen in diesem Zeitraum.

) : ( {positions.map((position) => ( ))}
Abrechenbare Nutzungen
Auswahl Datei Album Zweck Referenz Preis Status
togglePosition(position.id)} disabled={!position.selectable} aria-label={`${position.filename} auswählen`} /> {position.filename} {position.albumName} {position.purpose} {position.reference ?? "—"} {formatCents(position.priceCents)} {STATUS_LABELS[position.status]} {position.status === "billed" && position.reportNumber !== null && ( {" "}· Bericht Nr. {position.reportNumber} {position.invoiceNumber ? ` · ${position.invoiceNumber}` : ""} )}
)} {repeatDownloads.length > 0 && (

Kostenlose Wiederabrufe

Wiederholte Downloads rufen bereits abgerechnete Nutzungen erneut ab und sind nicht abrechenbar.

{repeatDownloads.map((download) => ( ))}
Wiederabrufe im Zeitraum
Datei Datum Status Notiz
{download.assetId} {download.status} {download.repeatDownloadNote ?? "—"}
)}

{selectedCount} {selectedCount === 1 ? "Nutzung" : "Nutzungen"} ausgewählt

Summe: {formatCents(selectedTotalCents)}

); } type PeriodSelectorProps = { year: number; month: number | null; quarter: number | null; isQuarter: boolean; }; function PeriodSelector({ year, month, quarter, isQuarter }: PeriodSelectorProps) { const years = [2025, 2026, 2027]; return (
{isQuarter ? ( ) : ( )}
); }