/**
 * ID generation. Uses crypto.randomUUID when available with a fallback
 * for older environments (and SSR bundles that may not have crypto).
 */

let counter = 0;

export function createId(prefix = 'm'): string {
  if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
    return `${prefix}_${crypto.randomUUID()}`;
  }
  counter += 1;
  return `${prefix}_${Date.now().toString(36)}_${counter.toString(36)}_${Math.random()
    .toString(36)
    .slice(2, 8)}`;
}
