import os, re
base_dir = r'd:\personal\src-code\ejobs360\job-portal\frontend_mono\src'
app_dir = os.path.join(base_dir, 'app')
routes = set()
for root, dirs, files in os.walk(app_dir):
    for f in files:
        if f in ('page.tsx', 'page.jsx', 'route.ts', 'route.js'):
            rel = os.path.relpath(root, app_dir).replace(os.sep, '/')
            parts = [p for p in rel.split('/') if not (p.startswith('(') and p.endswith(')'))]
            route = '/' + '/'.join(parts) if parts and parts != ['.'] else '/'
            routes.add(route)
print('Valid routes:', len(routes))
href_pat = re.compile(r'href=[\"\'`](/[a-zA-Z0-9_\-/?&=#]*)[\"\'`]')
missing = set()
for root, dirs, files in os.walk(base_dir):
    for f in files:
        if f.endswith(('.tsx', '.ts')):
            path = os.path.join(root, f)
            with open(path, 'r', encoding='utf-8', errors='ignore') as fo:
                for line in fo:
                    for m in href_pat.finditer(line):
                        t = m.group(1).split('?')[0].split('#')[0]
                        if not t.startswith('/') or t.startswith('/api/'): continue
                        matched = t in routes
                        if not matched:
                            for r in routes:
                                pat = '^' + re.sub(r'\[[a-zA-Z0-9_]+\]', r'[^/]+', r) + '$'
                                if re.match(pat, t): matched = True; break
                        if not matched: missing.add((t, os.path.relpath(path, base_dir)))
print('Total missing targets:', len(missing))
for t, p in sorted(missing):
    print('MISSING: ' + t + ' in ' + p)
