"use client";
/**
 * Shared halacha-classification labels + badge (INV-DM7 — two orthogonal axes).
 *
 * rule_type holds the rule ROLE (what KIND of statement). authority (binding vs
 * persuasive) is a SEPARATE, DERIVED axis (where it came from) — rendered as a
 * distinct read-only badge, never mixed into the role label.
 */
import { Badge } from "@/components/ui/badge";

/** rule ROLE labels. Legacy authority values (binding/persuasive) are kept as a
 *  fallback so pre-backfill rows still render a Hebrew word during rollout. */
export const RULE_TYPE_LABELS: Record<string, string> = {
  holding: "עיקרון מהותי",
  interpretive: "פרשני",
  procedural: "פרוצדורלי",
  application: "יישום",
  obiter: "אמרת אגב",
  // legacy (pre-split) — fold to role wording until backfill completes
  binding: "עיקרון מהותי",
  persuasive: "פרשני",
};

export function ruleTypeLabel(t: string | null | undefined): string {
  return (t && RULE_TYPE_LABELS[t]) || t || "—";
}

export const AUTHORITY_LABELS: Record<string, string> = {
  binding: "מחייב",
  persuasive: "משכנע",
};

/** Read-only authority badge — derived from the source, the chair never sets it. */
export function AuthorityBadge({
  authority,
}: {
  authority?: string | null;
}) {
  if (!authority || !AUTHORITY_LABELS[authority]) return null;
  const isBinding = authority === "binding";
  return (
    <Badge
      variant="outline"
      title="דרגת-המחייבות נגזרת אוטומטית מזהות הערכאה"
      className={
        isBinding
          ? "text-[0.65rem] bg-gold/15 text-navy border-gold/50"
          : "text-[0.65rem] bg-muted text-ink-muted border-border"
      }
    >
      {AUTHORITY_LABELS[authority]}
    </Badge>
  );
}
