import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { formatBerlinDateTime } from "@/modules/downloads/format";
import type { UsageHistoryAttempt, UsageHistoryPage } from "@/modules/downloads/stream";
const priceFormatter = new Intl.NumberFormat("de-DE", {
style: "currency",
currency: "EUR",
});
const byteFormatter = new Intl.NumberFormat("de-DE", {
style: "unit",
unit: "byte",
unitDisplay: "short",
maximumFractionDigits: 0,
});
export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistoryPage }>) {
return (
{history.items.length === 0 ? (
Noch keine Nutzungen erfasst. Wählen Sie ein Foto aus einem freigegebenen Album.
Zu den Alben
) : (
{history.items.map((usage) => (
-
- Album
- {usage.albumName}
Verwendungszweck
{usage.purpose}
Nutzungspreis
{priceFormatter.format(usage.priceCents / 100)}
Abrechnungsstatus
{billingStatusLabel(usage.billingStatus)}
{usage.reference ? (
Interne Referenz
{usage.reference}
) : null}
))}
)}
Downloadversuche
{history.attempts.length === 0 ? (
Noch keine Downloadversuche erfasst.
) : (
{history.attempts.map((attempt) => (
))}
)}
);
}
function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) {
const displayedAt = attempt.finishedAt ?? attempt.requestedAt;
return (
{attempt.filename}
{attempt.albumName} · {attempt.purpose}
{attempt.reference ? ` · ${attempt.reference}` : ""}
{statusLabel(attempt.status)}
{attempt.repeat ? "Wiederholter Abruf" : "Neue Nutzung"} ·{" "}
{byteFormatter.format(attempt.transferredBytes)}
{priceFormatter.format(attempt.billableCents / 100)}
Nutzungspreis {priceFormatter.format(attempt.priceCents / 100)}
);
}
function HistoryPagination({ history }: Readonly<{ history: UsageHistoryPage }>) {
if (history.page === 1 && !history.hasNext) return null;
return (
);
}
function AttemptPagination({ history }: Readonly<{ history: UsageHistoryPage }>) {
if (!history.attemptCursor && !history.nextAttemptCursor) return null;
return (
);
}
function statusLabel(status: UsageHistoryAttempt["status"]): string {
const labels: Record = {
authorized: "Autorisiert",
streaming: "Wird ausgeliefert",
completed: "Abgeschlossen",
interrupted: "Unterbrochen",
failed_before_delivery: "Vor Auslieferung fehlgeschlagen",
};
return labels[status];
}
function billingStatusLabel(status: UsageHistoryPage["items"][number]["billingStatus"]): string {
const labels: Record = {
open: "Offen",
billed: "Abgerechnet",
reopened: "Wieder geöffnet",
voided: "Storniert",
};
return labels[status];
}