Spaces:
Runtime error
Runtime error
| 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, | |
| }); | |
| } | |