File size: 1,504 Bytes
14fdc5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { CandidateCardData } from "@/lib/types";

type CandidateCardProps = {
  card: CandidateCardData;
  onAction?: (actionMessage: string, actionLabel: string) => void;
};

export function CandidateCard({ card, onAction }: CandidateCardProps) {
  const tags = Array.isArray(card.tags) ? card.tags : [];
  const actions = Array.isArray(card.actions) ? card.actions : [];

  return (
    <article className="candidate-card">
      <h4>{card.title}</h4>
      {card.subtitle ? <p className="candidate-meta">{card.subtitle}</p> : null}

      {tags.length ? (
        <div className="tag-list">
          {tags.map((tag) => (
            <span key={tag} className="tag">
              {tag}
            </span>
          ))}
        </div>
      ) : null}

      {card.meta ? (
        <p className="candidate-meta" style={{ marginTop: 8 }}>
          {Object.entries(card.meta)
            .filter(([, value]) => value !== null && value !== undefined && value !== "")
            .map(([key, value]) => `${key}: ${String(value)}`)
            .join(" | ")}
        </p>
      ) : null}

      {actions.length ? (
        <div className="action-row">
          {actions.slice(0, 2).map((action) => (
            <button
              key={`${action.label}-${action.action}`}
              type="button"
              onClick={() => onAction?.(action.action, action.label)}
            >
              {action.label}
            </button>
          ))}
        </div>
      ) : null}
    </article>
  );
}