import { existsSync, readFileSync } from 'node:fs'

const requiredFiles = [
  'src/app/App.tsx',
  'src/pages/login.tsx',
  'src/pages/workspace.tsx',
  'src/pages/project.tsx',
  'src/pages/projects/project-overview.tsx',
  'src/pages/projects/project-data.tsx',
  'src/pages/projects/project-rail.tsx',
  'src/pages/projects/project-sidebar.tsx',
  'src/pages/projects/project-topbar.tsx',
  'src/pages/projects/project-inspector.tsx',
  'src/pages/projects/project-statusbar.tsx',
  'src/pages/projects/project-types.ts',
]

const failures = requiredFiles.filter((file) => !existsSync(file)).map((file) => `missing ${file}`)

if (existsSync('src/App.tsx')) {
  failures.push('legacy src/App.tsx should be removed after page split')
}

if (existsSync('src/app/App.tsx')) {
  const appSource = readFileSync('src/app/App.tsx', 'utf8')
  for (const forbidden of ['function LoginPage', 'function Workbench', 'function OverviewContent']) {
    if (appSource.includes(forbidden)) {
      failures.push(`src/app/App.tsx still contains ${forbidden}`)
    }
  }
}

if (failures.length) {
  console.error(failures.join('\n'))
  process.exit(1)
}

console.log('structure ok')
