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

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

export function toUrl(url: NonNullable<InertiaLinkProps['href']>): string {
    return typeof url === 'string' ? url : url.url;
}

/**
 * Formats a camelCase/PascalCase product name with proper spacing.
 * e.g. "NaturalAssurance12" → "Natural Assurance 12"
 *      "ClearGuarantee6" → "Clear Guarantee 6"
 *      "ClearGuarantee9Plus" → "Clear Guarantee 9 Plus"
 */
export function productProperName(name: string): string {
    return name.replace(/([a-z])(?=[A-Z0-9])|([0-9])(?=[A-Za-z])/g, '$1$2 ');
}
