import { logger } from './chunk-KQGP6BTS.mjs';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';

// src/utils/time.ts
var formatTime = {
  /**
   * 将秒数转换为 MM:SS 格式
   */
  toMinutesSeconds(seconds) {
    const minutes = Math.floor(seconds / 60);
    const remainingSeconds = Math.floor(seconds % 60);
    return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`;
  },
  /**
   * 将秒数转换为 HH:MM:SS 格式
   */
  toHoursMinutesSeconds(seconds) {
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor(seconds % 3600 / 60);
    const remainingSeconds = Math.floor(seconds % 60);
    if (hours > 0) {
      return `${hours}:${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
    }
    return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`;
  },
  /**
   * 格式化日期为用户友好的格式
   */
  formatDate(date, locale = "zh-CN") {
    const d = new Date(date);
    const now = /* @__PURE__ */ new Date();
    const diffMs = now.getTime() - d.getTime();
    const diffDays = Math.floor(diffMs / (1e3 * 60 * 60 * 24));
    if (diffDays === 0) {
      return locale === "zh-CN" ? "\u4ECA\u5929" : "Today";
    } else if (diffDays === 1) {
      return locale === "zh-CN" ? "\u6628\u5929" : "Yesterday";
    } else if (diffDays < 7) {
      return locale === "zh-CN" ? `${diffDays}\u5929\u524D` : `${diffDays} days ago`;
    } else {
      return d.toLocaleDateString(locale);
    }
  }
};

// src/utils/japanese.ts
var japaneseUtils = {
  /**
   * 提取文本中的汉字
   */
  extractKanji(text) {
    return text.match(/[\u4E00-\u9FAF]/g) || [];
  },
  /**
   * 提取文本中的假名
   */
  extractKana(text) {
    return text.match(/[\u3040-\u309F\u30A0-\u30FF]/g) || [];
  },
  /**
   * 清理文本，移除特殊字符但保留日语字符
   */
  cleanText(text) {
    return text.replace(/[^\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FAF\w\s]/g, "");
  }
};

// src/utils/validators.ts
var validators = {
  /**
   * 验证邮箱格式
   */
  isValidEmail(email) {
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return emailRegex.test(email);
  },
  /**
   * 验证密码强度
   */
  isValidPassword(password) {
    const errors = [];
    if (password.length < 6) {
      errors.push("Password must be at least 6 characters");
    }
    if (password.length > 50) {
      errors.push("Password must not exceed 50 characters");
    }
    if (!/[a-zA-Z]/.test(password)) {
      errors.push("Password must contain at least one letter");
    }
    if (!/[0-9]/.test(password)) {
      errors.push("Password must contain at least one number");
    }
    return {
      isValid: errors.length === 0,
      errors
    };
  },
  /**
   * 验证用户名格式
   */
  isValidUsername(username) {
    const usernameRegex = /^[a-zA-Z0-9_]{3,20}$/;
    return usernameRegex.test(username);
  },
  /**
   * 验证文件大小
   */
  isValidFileSize(size, maxSize) {
    return size > 0 && size <= maxSize;
  },
  /**
   * 验证文件类型
   */
  isValidFileType(type, supportedTypes) {
    return supportedTypes.includes(type);
  },
  /**
   * 验证 URL 格式
   */
  isValidUrl(url) {
    try {
      new URL(url);
      return true;
    } catch {
      return false;
    }
  }
};

// src/utils/file.ts
var fileUtils = {
  /**
   * 格式化文件大小
   */
  formatFileSize(bytes) {
    if (bytes === 0) return "0 Bytes";
    const k = 1024;
    const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
  },
  /**
   * 获取文件扩展名
   */
  getFileExtension(filename) {
    return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
  },
  /**
   * 生成唯一文件名
   */
  generateUniqueFileName(originalName) {
    const timestamp = Date.now();
    const random = Math.random().toString(36).substring(2, 15);
    const extension = this.getFileExtension(originalName);
    const baseName = originalName.replace(`.${extension}`, "");
    return extension ? `${baseName}_${timestamp}_${random}.${extension}` : `${baseName}_${timestamp}_${random}`;
  },
  /**
   * 验证文件名是否有效
   */
  isValidFilename(filename) {
    const invalidChars = /[<>:"/\\|?*\x00-\x1F]/g;
    return !invalidChars.test(filename) && filename.length > 0 && filename.length <= 255;
  }
};

// src/utils/array.ts
var arrayUtils = {
  /**
   * 数组去重
   */
  unique(array) {
    return [...new Set(array)];
  },
  /**
   * 数组分组
   */
  groupBy(array, key) {
    return array.reduce(
      (groups, item) => {
        const groupKey = String(item[key]);
        const group = groups[groupKey] || [];
        group.push(item);
        groups[groupKey] = group;
        return groups;
      },
      {}
    );
  },
  /**
   * 数组分页
   */
  paginate(array, page, limit) {
    const total = array.length;
    const pages = Math.ceil(total / limit);
    const start = (page - 1) * limit;
    const end = start + limit;
    const data = array.slice(start, end);
    return {
      data,
      total,
      page,
      pages,
      hasNext: page < pages,
      hasPrev: page > 1
    };
  },
  /**
   * 数组随机排序
   */
  shuffle(array) {
    const shuffled = [...array];
    for (let i = shuffled.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
    }
    return shuffled;
  }
};

// src/utils/string.ts
var stringUtils = {
  /**
   * 截断文本
   */
  truncate(text, length, suffix = "...") {
    if (text.length <= length) return text;
    return text.substring(0, length - suffix.length) + suffix;
  },
  /**
   * 首字母大写
   */
  capitalize(text) {
    if (!text) return "";
    return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
  },
  /**
   * 驼峰转下划线
   */
  camelToSnake(text) {
    return text.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
  },
  /**
   * 下划线转驼峰
   */
  snakeToCamel(text) {
    return text.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
  },
  /**
   * 生成随机字符串
   */
  generateRandom(length) {
    const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    let result = "";
    for (let i = 0; i < length; i++) {
      result += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    return result;
  }
};

// src/utils/debug.ts
var debugUtils = {
  /**
   * 安全的 JSON 序列化
   */
  safeStringify(obj) {
    try {
      return JSON.stringify(obj, null, 2);
    } catch (error) {
      return `[Circular Reference or Invalid JSON: ${error}]`;
    }
  },
  /**
   * 性能计时器
   */
  createTimer(label) {
    const start = typeof performance !== "undefined" ? performance.now() : Date.now();
    return {
      end: () => {
        const end = typeof performance !== "undefined" ? performance.now() : Date.now();
        const duration = end - start;
        const message = `${label || "Timer"}: ${duration.toFixed(2)}ms`;
        logger.info(message);
        return duration;
      }
    };
  },
  /**
   * 内存使用情况（仅在 Node.js 环境）
   */
  getMemoryUsage() {
    if (typeof process !== "undefined" && process.memoryUsage) {
      const usage = process.memoryUsage();
      return {
        rss: fileUtils.formatFileSize(usage.rss),
        heapTotal: fileUtils.formatFileSize(usage.heapTotal),
        heapUsed: fileUtils.formatFileSize(usage.heapUsed),
        external: fileUtils.formatFileSize(usage.external)
      };
    }
    return null;
  }
};

// src/utils/error.ts
var errorUtils = {
  /**
   * 创建标准化的错误对象
   */
  createError(code, message, details) {
    const error = new Error(message);
    error.code = code;
    if (details) {
      error.details = details;
    }
    return error;
  },
  /**
   * 安全的错误信息提取
   */
  extractErrorMessage(error) {
    if (error instanceof Error) {
      return error.message;
    }
    if (typeof error === "string") {
      return error;
    }
    if (error && typeof error === "object" && "message" in error) {
      return String(error.message);
    }
    return "Unknown error";
  },
  /**
   * 错误重试机制
   */
  async retry(fn, maxAttempts = 3, delay = 1e3) {
    let lastError;
    for (let attempt = 1; attempt <= maxAttempts; attempt++) {
      try {
        return await fn();
      } catch (error) {
        lastError = error instanceof Error ? error : new Error(String(error));
        if (attempt === maxAttempts) {
          throw lastError;
        }
        await new Promise((resolve) => setTimeout(resolve, delay * Math.pow(2, attempt - 1)));
      }
    }
    throw lastError;
  }
};
function cn(...inputs) {
  return twMerge(clsx(inputs));
}

export { arrayUtils, cn, debugUtils, errorUtils, fileUtils, formatTime, japaneseUtils, stringUtils, validators };
//# sourceMappingURL=chunk-3BGPZN4X.mjs.map
//# sourceMappingURL=chunk-3BGPZN4X.mjs.map