const fs = require('fs');
const path = 'D:\\project\\zhizhu\\components\\PhotoUploadForm.vue';
const content = fs.readFileSync(path, 'utf8');
const lines = content.split('\n');

// 检查是否有重复的方法声明
console.log('=== Checking for duplicate method declarations ===\n');
const methodDeclarations = new Map();

for (let i = 0; i < lines.length; i++) {
  const line = lines[i];
  const match = line.match(/^\s+(async\s+)?(\w+)\s*\([^)]*\)\s*{/);
  if (match && !line.includes('if (') && !line.includes('if(') && 
      !line.includes('for (') && !line.includes('for(') && 
      !line.includes('while (') && !line.includes('while(') &&
      !line.includes('switch (') && !line.includes('switch(') &&
      !line.includes('catch (') && !line.includes('catch(')) {
    const methodName = match[2];
    if (!methodDeclarations.has(methodName)) {
      methodDeclarations.set(methodName, []);
    }
    methodDeclarations.get(methodName).push(i + 1);
  }
}

// 找出重复声明
let hasDuplicates = false;
for (const [name, lineNumbers] of methodDeclarations) {
  if (lineNumbers.length > 1) {
    hasDuplicates = true;
    console.log(`DUPLICATE: ${name} declared at lines: ${lineNumbers.join(', ')}`);
  }
}

if (!hasDuplicates) {
  console.log('No duplicate method declarations found.');
}

// 检查 data() 返回的对象是否完整
console.log('\n=== Checking data() section ===');
let inData = false;
let dataStart = -1;
let braceCount = 0;
for (let i = 0; i < lines.length; i++) {
  if (lines[i].includes('data()') || lines[i].includes('data ()')) {
    inData = true;
    dataStart = i;
  }
  if (inData) {
    braceCount += (lines[i].match(/{/g) || []).length;
    braceCount -= (lines[i].match(/}/g) || []).length;
    if (braceCount === 0 && i > dataStart) {
      console.log(`data() section: lines ${dataStart + 1} to ${i + 1}`);
      // 检查是否有 return 语句
      let hasReturn = false;
      for (let j = dataStart; j <= i; j++) {
        if (lines[j].includes('return {') || lines[j].includes('return{')) {
          hasReturn = true;
          break;
        }
      }
      if (!hasReturn) {
        console.log('WARNING: data() section may be missing return statement');
      }
      break;
    }
  }
}

// 检查 export default 结构
console.log('\n=== Checking export default structure ===');
let exportStart = -1;
for (let i = 0; i < lines.length; i++) {
  if (lines[i].includes('export default {')) {
    exportStart = i;
    break;
  }
}

if (exportStart >= 0) {
  console.log(`export default starts at line ${exportStart + 1}`);
  
  // 检查关键属性
  const keyProps = ['name', 'components', 'props', 'computed', 'data', 'watch', 'methods'];
  for (const prop of keyProps) {
    let found = false;
    for (let i = exportStart; i < lines.length; i++) {
      if (lines[i].includes(`${prop}:`) || lines[i].includes(`${prop} :`)) {
        console.log(`  ${prop}: found at line ${i + 1}`);
        found = true;
        break;
      }
    }
    if (!found && prop !== 'props') { // props 可能是可选的
      console.log(`  ${prop}: NOT FOUND`);
    }
  }
}

// 检查文件末尾结构
console.log('\n=== Checking file end structure ===');
const lastLines = lines.slice(-30);
for (let i = lines.length - 30; i < lines.length; i++) {
  if (lines[i].includes('</script>') || lines[i].includes('</style>') ||
      lines[i].includes('};') || lines[i].includes('},') ||
      lines[i].trim() === '}') {
    console.log(`Line ${i + 1}: ${lines[i]}`);
  }
}
