File size: 2,948 Bytes
7fabf33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
export function formatDate(value?: string | null) {
  if (!value) return "Sem data";
  return new Intl.DateTimeFormat("pt-BR", {
    day: "2-digit",
    month: "2-digit",
    year: "numeric",
  }).format(new Date(`${value}T12:00:00`));
}

export function formatMonth(value?: string | null) {
  if (!value) return "Sem mês";
  return new Intl.DateTimeFormat("pt-BR", {
    month: "2-digit",
    year: "numeric",
  }).format(new Date(`${value}T12:00:00`));
}

export function dateValueToMonthInput(value?: string | null) {
  if (!value) return "";
  return value.slice(0, 7);
}

export function monthInputToDateValue(value?: string | null) {
  if (!value) return null;
  return `${value}-01`;
}

export function formatDateTime(value?: string | null) {
  if (!value) return "Sem data";
  return new Intl.DateTimeFormat("pt-BR", {
    day: "2-digit",
    month: "2-digit",
    year: "numeric",
    hour: "2-digit",
    minute: "2-digit",
  }).format(new Date(value));
}

export function formatNumber(value: number) {
  return new Intl.NumberFormat("pt-BR", {
    minimumFractionDigits: value % 1 === 0 ? 0 : 1,
    maximumFractionDigits: 2,
  }).format(value);
}

export function statusLabel(status: string) {
  const normalized = status.replace(/_/g, " ").trim().toLowerCase();
  const labels: Record<string, string> = {
    sem_atribuicao: "Sem atribuição",
    "sem atribuicao": "Sem atribuição",
    com_avaliador: "Com avaliador",
    "com avaliador": "Com avaliador",
    pendente_revisao: "Pendente de revisão",
    "pendente revisao": "Pendente de revisão",
    em_ajuste: "Em ajuste",
    "em ajuste": "Em ajuste",
    revisado: "Revisado",
    pronto: "Pronto",
    enviado: "Enviado",
    pendente: "Pendente",
    ativa: "Ativa",
    planejada: "Planejada",
    concluido: "Concluído",
    concluida: "Concluída",
    "sem dado": "Sem dado",
  };

  return labels[normalized] ?? normalized.charAt(0).toUpperCase() + normalized.slice(1);
}

export function hasPriority(value?: string | null) {
  const normalized = (value ?? "").trim().toLowerCase();
  return Boolean(normalized) && !normalized.startsWith("sem prioridade");
}

export function goalDifferenceText(planned: number, capacity: number) {
  const difference = capacity - planned;
  if (difference === 0) return "Carga igual à capacidade";
  if (difference > 0) return `${formatNumber(difference)} dia(s) livres no período`;
  return `${formatNumber(Math.abs(difference))} dia(s) acima da capacidade`;
}

export function goalReadingText(planned: number, capacity: number, rawStatus?: string | null) {
  const normalized = (rawStatus ?? "").toLowerCase();
  if (normalized.includes("treinamento")) return "Período de treinamento";
  if (!capacity) return "Sem capacidade registrada";
  if (planned > capacity) return "Planejamento acima da capacidade";
  if (planned < capacity) return "Planejamento abaixo da capacidade";
  return "Planejamento igual à capacidade";
}