Spaces:
Runtime error

File size: 2,903 Bytes
ad79323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
108
109
110
111
112
113
114
115
116
117
118
import type {
  CalendarViewValue,
  CaseFileRagStatusValue,
  CaseStatusValue,
  CaseTypeValue,
  CustomerGenderValue,
  SessionDatePresetValue,
} from "@/lib/constants";
import { APP_TIME_ZONE } from "@/lib/constants";
import { formatInTimeZone } from "date-fns-tz";

const dateFormatter = new Intl.DateTimeFormat("ar-EG", {
  dateStyle: "medium",
});

const dateTimeFormatter = new Intl.DateTimeFormat("ar-EG", {
  dateStyle: "medium",
  timeStyle: "short",
});

const timeFormatter = new Intl.DateTimeFormat("ar-EG", {
  hour: "numeric",
  minute: "2-digit",
});

export function formatDate(value: Date | string) {
  return dateFormatter.format(new Date(value));
}

export function formatDateTime(value: Date | string) {
  return dateTimeFormatter.format(new Date(value));
}

export function formatTime(value: Date | string) {
  return timeFormatter.format(new Date(value));
}

export function getGenderLabel(value: CustomerGenderValue) {
  return value === "MALE" ? "ذكر" : "أنثى";
}

export function getCaseTypeLabel(value: CaseTypeValue) {
  switch (value) {
    case "CIVIL":
      return "مدنيه";
    case "CRIMINAL":
      return "جنائيه";
    case "PERSONAL_STATUS":
      return "أحوال";
  }
}

export function getCaseStatusLabel(value: CaseStatusValue) {
  return value === "OPEN" ? "مفتوحة" : "مقفولة";
}

export function getCaseFileRagStatusLabel(value: CaseFileRagStatusValue) {
  switch (value) {
    case "PROCESSING":
      return "جارٍ التحضير";
    case "READY":
      return "جاهز للسؤال";
    case "FAILED":
      return "فشل التحضير";
    case "SKIPPED":
      return "غير مدعوم";
    case "PENDING":
      return "في الانتظار";
  }
}

export function getSessionPresetLabel(value: SessionDatePresetValue) {
  switch (value) {
    case "today":
      return "النهارده";
    case "tomorrow":
      return "بكرة";
    case "thisWeek":
      return "الأسبوع ده";
    case "thisMonth":
      return "الشهر ده";
    case "thisYear":
      return "السنة دي";
    case "all":
      return "الكل";
  }
}

export function getCalendarViewLabel(value: CalendarViewValue) {
  return value === "week" ? "الأسبوع" : "الشهر";
}

export function getFullName(parts: Array<string | null | undefined>) {
  return parts.filter(Boolean).join(" ");
}

export function formatCasePublicId(value: string) {
  return `#${value}`;
}

export function formatFileSize(sizeBytes: number) {
  if (sizeBytes < 1024) {
    return `${sizeBytes} بايت`;
  }

  if (sizeBytes < 1024 * 1024) {
    return `${(sizeBytes / 1024).toFixed(1)} ك.ب`;
  }

  return `${(sizeBytes / (1024 * 1024)).toFixed(1)} م.ب`;
}

export function formatMonthYearTitle(value: Date | string) {
  return formatInTimeZone(new Date(value), APP_TIME_ZONE, "MMMM yyyy", {
    locale: undefined,
  });
}