import { clsx, type ClassValue } from "clsx" import { twMerge } from "tailwind-merge" export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } export function generateSlug(text: string): string { const slug = text .toString() .toLowerCase() .trim() .replace(/\s+/g, '-') // Replace spaces with - .replace(/[^\w\-]+/g, '') // Remove all non-word chars .replace(/\-\-+/g, '-') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, '') // Trim - from end of text // Add cryptographically random suffix for uniqueness (8 chars) const array = new Uint8Array(6) crypto.getRandomValues(array) const random = Array.from(array, b => b.toString(36).padStart(2, '0')).join('').slice(0, 8) return `${slug}-${random}` } export function fillTemplate(template: string, variables: Record): string { return template.replace(/\{\{([^}]+)\}\}/g, (match, key) => { return variables[key.trim()] || match }) } export function extractVariables(template: string): string[] { const matches = template.match(/\{\{([^}]+)\}\}/g) || [] return Array.from(new Set(matches.map(match => match.slice(2, -2).trim()))) }