/** 递归合并（用于 i18n 按模块覆盖） */
export function deepMerge<T>(base: T, patch: unknown): T {
  if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
    return base
  }
  const out = { ...(base as Record<string, unknown>) }
  const src = patch as Record<string, unknown>
  for (const key of Object.keys(src)) {
    const pv = src[key]
    const bv = out[key]
    if (
      pv !== null &&
      typeof pv === 'object' &&
      !Array.isArray(pv) &&
      bv !== null &&
      typeof bv === 'object' &&
      !Array.isArray(bv)
    ) {
      out[key] = deepMerge(bv, pv)
    } else if (pv !== undefined) {
      out[key] = pv
    }
  }
  return out as T
}
