/**
 * 路由工厂：统一默认 meta，页面默认开启 keep-alive
 *
 * @example
 * createPage({
 *   path: '/demo',
 *   name: 'Demo',
 *   component: () => import('@/views/demo/index.vue'),
 *   title: '示例',
 * })
 *
 * // 关闭缓存：
 * createPage({ ..., keepAlive: false })
 */
export function createPage({
  path,
  name,
  component,
  title = "",
  keepAlive = true,
  meta = {},
  ...rest
}) {
  if (!path || !name || !component) {
    throw new Error("[router] createPage 需要 path / name / component");
  }

  return {
    path,
    name,
    component,
    meta: {
      title,
      keepAlive,
      ...meta,
    },
    ...rest,
  };
}

/** 批量应用 createPage（也可直接传已构造好的 route） */
export function defineRoutes(list = []) {
  return list.map((item) => {
    if (item.meta && item.component) return item;
    return createPage(item);
  });
}
