import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

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

export function getMediaUrl(path?: string | null) {
    if (!path) return ""
    if (path.startsWith("http") || path.startsWith("https")) {
        return path
    }
    // Remove leading slash if exists to avoid double slash if base url has trailing slash
    // But usually base url doesn't have trailing slash.
    // Let's safe join.
    const baseUrl = import.meta.env.VITE_API_BASE_URL?.replace(/\/+$/, "") || ""
    const cleanPath = path.startsWith("/") ? path : `/${path}`
    return `${baseUrl}${cleanPath}`
}

export function formatDate(dateStr: string) {
    if (!dateStr) return "-"
    return new Date(dateStr).toLocaleDateString("tr-TR", {
        year: "numeric",
        month: "long",
        day: "numeric",
        hour: "2-digit",
        minute: "2-digit",
    })
}
