Spaces:
Running

File size: 2,929 Bytes
03608f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use client";

import { AlertCircleIcon, type LucideIcon } from "lucide-react";
import type { ReactNode } from "react";

import { Button } from "@/components/ui/button";
import { ApiError } from "@/lib/api";
import { useI18n } from "@/lib/i18n";
import { cn } from "@/lib/utils";

export function PageHeader({

  title,

  subtitle,

  actions,

}: {

  title: string;

  subtitle?: string;

  actions?: ReactNode;

}) {
  return (
    <div className="flex flex-wrap items-end justify-between gap-3">

      <div className="space-y-1">

        <h1 className="text-xl font-semibold tracking-tight">{title}</h1>

        {subtitle && <p className="max-w-2xl text-sm text-muted-foreground">{subtitle}</p>}

      </div>

      {actions && <div className="flex items-center gap-2">{actions}</div>}

    </div>
  );
}

export function EmptyState({

  icon: Icon,

  title,

  hint,

  className,

  children,

}: {

  icon: LucideIcon;

  title: string;

  hint?: string;

  className?: string;

  children?: ReactNode;

}) {
  return (
    <div

      className={cn(

        "flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-card/50 px-6 py-14 text-center",

        className,

      )}

      data-testid="empty-state"

    >

      <div className="mb-1 rounded-full bg-muted p-3 text-muted-foreground">

        <Icon className="size-5" aria-hidden />

      </div>

      <p className="font-medium">{title}</p>

      {hint && <p className="max-w-sm text-sm text-muted-foreground">{hint}</p>}

      {children}

    </div>
  );
}

export function ErrorState({ error, onRetry }: { error: Error; onRetry?: () => void }) {
  const { t } = useI18n();
  const msg =
    error instanceof ApiError
      ? error.status === 403
        ? t("errors.forbidden")
        : error.detail
      : error.message === "Failed to fetch"
        ? t("errors.network")
        : error.message;
  return (
    <div

      role="alert"

      className="flex items-center gap-3 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm"

    >

      <AlertCircleIcon className="size-4 shrink-0 text-destructive" aria-hidden />

      <span className="flex-1">{msg || t("common.error")}</span>

      {onRetry && (

        <Button size="sm" variant="outline" onClick={onRetry}>

          {t("common.retry")}

        </Button>

      )}

    </div>
  );
}

export function StatTile({

  label,

  value,

  hint,

  testId,

}: {

  label: string;

  value: ReactNode;

  hint?: ReactNode;

  testId?: string;

}) {
  return (
    <div className="rounded-lg border bg-card px-4 py-3" data-testid={testId}>

      <p className="text-xs text-muted-foreground">{label}</p>

      <p className="tabular mt-1 text-2xl font-semibold tracking-tight">{value}</p>

      {hint && <p className="mt-0.5 text-xs text-muted-foreground">{hint}</p>}

    </div>
  );
}