const fs = require('fs');
const path = require('path');

// 定义需要检查的页面列表
const pages = [
  {
    name: '首页（武术赛事通）',
    path: 'pages/home/home.vue',
    description: '包含轮播图、精品赛事列表'
  },
  {
    name: '个人中心',
    path: 'pages/profile/profile.vue',
    description: '用户信息、我的报名、常用信息等功能入口'
  },
  {
    name: '常用信息',
    path: 'pages/common-info/common-info.vue',
    description: '选手/集体/联系人信息管理（含Tab切换）'
  },
  {
    name: '新增选手',
    path: 'pages/add-player/add-player.vue',
    description: '表单页面，包含证件类型、姓名、证件号码、队伍'
  },
  {
    name: '编辑选手',
    path: 'pages/edit-player/edit-player.vue',
    description: '编辑选手信息'
  },
  {
    name: '新增联系人',
    path: 'pages/add-contact/add-contact.vue',
    description: '包含手机号码、邮箱、地址、设置为默认联系人'
  },
  {
    name: '我的报名',
    path: 'pages/my-registration/my-registration.vue',
    description: '全部/待开始/进行中/已结束四个Tab，显示报名的赛事'
  },
  {
    name: '全部赛事列表',
    path: 'pages/event-list/event-list.vue',
    description: '搜索框、日期和地区筛选'
  },
  {
    name: '赛事详情',
    path: 'pages/event-detail/event-detail.vue',
    description: '赛事信息、信息发布、赛事规程等功能入口'
  },
  {
    name: '选择报名类型',
    path: 'pages/register-type/register-type.vue',
    description: '单人赛/集体赛选择'
  },
  {
    name: '选择报名项目',
    path: 'pages/select-event/select-event.vue',
    description: '列表形式选择报名项目'
  },
  {
    name: '赛事报名流程',
    path: 'pages/event-register/event-register.vue',
    description: '三步骤：选择选手信息、订单支付、报名成功'
  }
];

// 定义需要检查的组件列表
const components = [
  {
    name: '自定义导航栏',
    path: 'components/custom-navbar/custom-navbar.vue'
  },
  {
    name: 'Tab切换组件',
    path: 'components/custom-tabs/custom-tabs.vue'
  },
  {
    name: '确认弹窗组件',
    path: 'components/confirm-modal/confirm-modal.vue'
  }
];

// 定义需要检查的配置文件
const configs = [
  {
    name: 'pages.json',
    path: 'pages.json'
  },
  {
    name: 'manifest.json',
    path: 'manifest.json'
  },
  {
    name: 'App.vue',
    path: 'App.vue'
  },
  {
    name: 'main.js',
    path: 'main.js'
  },
  {
    name: 'uni.scss',
    path: 'uni.scss'
  },
  {
    name: 'index.html',
    path: 'index.html'
  },
  {
    name: 'package.json',
    path: 'package.json'
  }
];

function checkFile(filePath) {
  const fullPath = path.join(__dirname, filePath);
  return fs.existsSync(fullPath);
}

function generateReport() {
  console.log('========================================');
  console.log('  武术赛事报名系统 - 页面完成度检查报告');
  console.log('========================================\n');

  let totalItems = 0;
  let completedItems = 0;

  // 检查配置文件
  console.log('【配置文件检查】');
  configs.forEach(config => {
    totalItems++;
    const exists = checkFile(config.path);
    if (exists) {
      completedItems++;
      console.log(`✓ ${config.name}`);
    } else {
      console.log(`✗ ${config.name} [缺失]`);
    }
  });

  console.log('\n【公共组件检查】');
  components.forEach(component => {
    totalItems++;
    const exists = checkFile(component.path);
    if (exists) {
      completedItems++;
      console.log(`✓ ${component.name}`);
    } else {
      console.log(`✗ ${component.name} [缺失]`);
    }
  });

  console.log('\n【页面检查】');
  pages.forEach((page, index) => {
    totalItems++;
    const exists = checkFile(page.path);
    if (exists) {
      completedItems++;
      console.log(`✓ ${index + 1}. ${page.name}`);
      console.log(`   描述: ${page.description}`);
      console.log(`   路径: ${page.path}\n`);
    } else {
      console.log(`✗ ${index + 1}. ${page.name} [缺失]`);
      console.log(`   描述: ${page.description}`);
      console.log(`   路径: ${page.path}\n`);
    }
  });

  const completionRate = ((completedItems / totalItems) * 100).toFixed(2);

  console.log('========================================');
  console.log('【统计信息】');
  console.log(`总计项目: ${totalItems}`);
  console.log(`已完成: ${completedItems}`);
  console.log(`未完成: ${totalItems - completedItems}`);
  console.log(`完成度: ${completionRate}%`);
  console.log('========================================\n');

  if (completedItems === totalItems) {
    console.log('🎉 恭喜！所有页面和组件都已完成！');
    console.log('\n【后续步骤】');
    console.log('1. 运行 npm install 安装依赖');
    console.log('2. 运行 npm run dev:h5 启动H5开发环境');
    console.log('3. 运行 npm run dev:mp-weixin 启动微信小程序开发环境');
  } else {
    console.log('⚠️  还有未完成的项目，请继续完善。');
  }

  console.log('\n【项目特点】');
  console.log('✓ 支持H5和微信小程序');
  console.log('✓ 基于uniapp框架开发');
  console.log('✓ 完整的赛事报名流程');
  console.log('✓ 选手和联系人信息管理');
  console.log('✓ 响应式设计，一比一还原设计稿');
  console.log('✓ 使用rpx单位，自适应不同屏幕尺寸');
}

// 执行检查
try {
  generateReport();
} catch (error) {
  console.error('检查过程中出现错误:', error);
}
