import { usePage } from '@inertiajs/react';
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
    return twMerge(clsx(inputs));
}

/**
 * Return translation for the given key.
 * @see https://laravel.com/docs/11.x/localization
 * @param key
 */
export function t(key: string): string {
    // eslint-disable-next-line react-hooks/rules-of-hooks -- translation helper used like a hook across the app
    const { props } = usePage();
    return props.translations?.[key] ?? key;
}

/**
 * Return the given string with first letter uppercase.
 * @param value
 */
export function capitalize(value: string): string {
    if (!value) {
        return '';
    }
    return value.charAt(0).toUpperCase() + value.slice(1);
}
