import type { InertiaLinkProps } from '@inertiajs/react';
import { clsx } from 'clsx';
import type { ClassValue } 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;
}

export function prefixUrl(url: string): string {
    const base = (window as any).assetUrl || '/';
    const prefix = base.endsWith('/') ? base.slice(0, -1) : base;
    
    if (url.startsWith(prefix)) {
        return url;
    }
    
    if (url.startsWith('/')) {
        return prefix + url;
    }
    
    return url;
}
