import sys, re
sys.stdout.reconfigure(encoding='utf-8')
from generate_catalog import ENTRIES

locales = ['vi', 'en', 'zh', 'ja', 'ko', 'th', 'de', 'ru', 'es']

short_ui_prefixes = ('modal_', 'vault_tab_', 'shop_tab_', 'skill_', 'agent_stance_')
explicit_short_keys = {
    'char_name', 'dodge', 'buyout', 'agent_btn_revoke',
    'interaction_step_through_portal', 'interaction_dialogue', 'dialogue_select',
    'dialogue_btn_close', 'dialogue_btn_leave', 'telemetry_agent_orb'
}

failures = []
for row in ENTRIES:
    k = row[0]
    is_short_ui = (
        any(k.startswith(p) for p in short_ui_prefixes) or
        (k.startswith('npc_') and (k.endswith('_name') or k.endswith('_title') or k.endswith('_service'))) or
        (k.startswith('tooltip_') and k.endswith('_title')) or
        k in explicit_short_keys
    )
    if is_short_ui and not k.endswith('_desc') and not k.endswith('_subtitle'):
        for i, loc in enumerate(locales):
            val = row[i+1]
            clean = re.sub(r'[\U00010000-\U0010ffff\u2600-\u27ff\ufe00-\ufe0f]', '', val).strip()
            if loc in ['vi', 'en', 'de', 'ru', 'es', 'ko']:
                words = clean.split()
                if len(words) > 2:
                    failures.append((loc, k, val, len(words)))
            elif loc == 'zh':
                chars = len([c for c in clean if not c.isspace()])
                if chars > 4:
                    failures.append((loc, k, val, chars))
            elif loc == 'ja':
                chars = len([c for c in clean if not c.isspace()])
                if chars > 6:
                    failures.append((loc, k, val, chars))
            elif loc == 'th':
                chars = len(clean)
                if chars > 12:
                    failures.append((loc, k, val, chars))

print('Short UI Failures:', len(failures))
for f in failures:
    print(f)
