2025-08-28 18:27:07 +02:00
|
|
|
import { type ClassValue, clsx } from "clsx";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
|
|
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return twMerge(clsx(inputs));
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 17:12:33 +01:00
|
|
|
export const Capitalize = (str: string | null | undefined) => {
|
|
|
|
|
if (!str) return "";
|
|
|
|
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
|
|
|
};
|
2026-03-17 18:44:53 +01:00
|
|
|
export const redirectTo500 = {
|
|
|
|
|
redirect: {
|
|
|
|
|
destination: "/500",
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
} as const;
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
export function getInitials(name: string) {
|
2025-08-28 18:27:07 +02:00
|
|
|
name = name.trim();
|
|
|
|
|
|
|
|
|
|
if (name.includes(" ")) {
|
|
|
|
|
const [firstName, lastName] = name.split(" ");
|
|
|
|
|
if (firstName && lastName) {
|
|
|
|
|
return (firstName.charAt(0) + lastName.charAt(0)).toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name.slice(0, 2).toUpperCase();
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 19:17:54 +02:00
|
|
|
// export function getHexColorFromString(str: string): string {
|
|
|
|
|
// let hash = 0;
|
|
|
|
|
// if (str.length === 0) return "#000000"; // Return black for empty string
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2026-04-22 19:17:54 +02:00
|
|
|
// for (let i = 0; i < str.length; i++) {
|
|
|
|
|
// hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
|
// hash = hash & 0xffffffff; // Ensure hash is a 32-bit integer
|
|
|
|
|
// }
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2026-04-22 19:17:54 +02:00
|
|
|
// let color = "#";
|
|
|
|
|
// for (let i = 0; i < 3; i++) {
|
|
|
|
|
// const value = (hash >> (i * 8)) & 255;
|
|
|
|
|
// color += value.toString(16).padStart(2, "0");
|
|
|
|
|
// }
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2026-04-22 19:17:54 +02:00
|
|
|
// return color;
|
|
|
|
|
// }
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
export function formatCurrency(amount: number): string {
|
2025-08-28 18:27:07 +02:00
|
|
|
return new Intl.NumberFormat("it-IT", {
|
|
|
|
|
currency: "EUR",
|
|
|
|
|
maximumFractionDigits: 2,
|
2025-08-29 16:18:32 +02:00
|
|
|
minimumFractionDigits: 2,
|
|
|
|
|
style: "currency",
|
2025-08-28 18:27:07 +02:00
|
|
|
}).format(amount);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
2025-12-29 19:10:46 +01:00
|
|
|
|
|
|
|
|
export const debounce = <T extends unknown[]>(
|
|
|
|
|
callback: (...args: T) => void,
|
|
|
|
|
delay: number,
|
|
|
|
|
) => {
|
|
|
|
|
let timeoutTimer: ReturnType<typeof setTimeout>;
|
|
|
|
|
|
|
|
|
|
return (...args: T) => {
|
|
|
|
|
clearTimeout(timeoutTimer);
|
|
|
|
|
|
|
|
|
|
timeoutTimer = setTimeout(() => {
|
|
|
|
|
callback(...args);
|
|
|
|
|
}, delay);
|
|
|
|
|
};
|
|
|
|
|
};
|