import { clsx, type ClassValue } from "clsx";

/**
 * Tailwind Classes Merge
 */
export function cn(...inputs: ClassValue[]) {
  return clsx(inputs);
}

/**
 * Format Date
 * Example:
 * 2026-06-14 => June 14, 2026
 */
export function formatDate(dateString: string) {
  return new Date(dateString).toLocaleDateString("en-IN", {
    day: "numeric",
    month: "long",
    year: "numeric",
  });
}

/**
 * Generate Slug
 */
export function slugify(text: string) {
  return text
    .toLowerCase()
    .trim()
    .replace(/[^\w\s-]/g, "")
    .replace(/\s+/g, "-")
    .replace(/-+/g, "-");
}

/**
 * Truncate Text
 */
export function truncate(text: string, length = 140) {
  if (text.length <= length) return text;

  return `${text.substring(0, length)}...`;
}

/**
 * Absolute URL
 */
export function absoluteUrl(path = "") {
  return `https://www.rajvisocialwelfare.org${path}`;
}

/**
 * Read Time Calculator
 */
export function calculateReadTime(content: string) {
  const wordsPerMinute = 200;
  const words = content.trim().split(/\s+/).length;

  return Math.max(1, Math.ceil(words / wordsPerMinute));
}

/**
 * Random Array Items
 */
export function shuffleArray<T>(array: T[]): T[] {
  return [...array].sort(() => Math.random() - 0.5);
}

/**
 * Capitalize First Letter
 */
export function capitalize(text: string) {
  return text.charAt(0).toUpperCase() + text.slice(1);
}

/**
 * Get Current Year
 */
export function currentYear() {
  return new Date().getFullYear();
}

/**
 * Remove HTML Tags
 */
export function stripHtml(html: string) {
  return html.replace(/<[^>]*>?/gm, "");
}