# ── Generated by Nexa Transpiler ──────────────────────────────
# This file was auto-generated from a .nexa source file.
# Do not edit directly — regenerate with: nexa compile <file>
# ─────────────────────────────────────────────────────────────
from __future__ import annotations
import asyncio, math, json, os, random, functools, time as _time
import sys as _sys
_sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_sys.path.insert(0, os.path.expanduser('~/.nexa/packages'))
from nexa_lang.builtins import BUILTINS

# ── Nexa runtime stubs ───────────────────────────────────────
_nexa_modules = {}
def _nexa_opt_access(obj, attr):
    if obj is None: return None
    if isinstance(obj, dict): return obj.get(attr)
    return getattr(obj, attr, None)

def _nexa_invoke_method(obj, method, *args, **kwargs):
    if isinstance(obj, list):
        if method == 'push': return obj.append(*args, **kwargs)
        if method == 'join': return (args[0] if args else '').join(str(x) for x in obj)
    if isinstance(obj, dict) and method == 'keys': return list(obj.keys())
    if isinstance(obj, dict) and method == 'values': return list(obj.values())
    return getattr(obj, method)(*args, **kwargs)

sys = BUILTINS['sys']
print('=== Nexa v12 Showcase ===')
print('\n--- 1. String Native Methods ---')
text = ' Hello, Nexa World! '
print('Original:', text)
print('Upper   :', _nexa_invoke_method(text, 'upper'))
print('Lower   :', _nexa_invoke_method(text, 'lower'))
print('Strip   :', _nexa_invoke_method(text, 'strip'))
print('Split   :', _nexa_invoke_method(text, 'split', ','))
print('Replace :', _nexa_invoke_method(text, 'replace', 'Nexa', 'Future'))
print('\n--- 2. List Native Methods ---')
arr = [1, 2, 3]
print('Array Initial:', arr)
_nexa_invoke_method(arr, 'push', 4)
_nexa_invoke_method(arr, 'push', 5)
print('Array after pushes:', arr)
last = _nexa_invoke_method(arr, 'pop')
print('Array popped item:', last, ' | Remaining:', arr)
unsorted = [10, 5, 8, 1, 3]
_nexa_invoke_method(unsorted, 'sort')
print('Array sorted:', unsorted)
print('Array join:', _nexa_invoke_method(arr, 'join', '-'))
print('\n--- 3. Dictionary Native Methods ---')
user = {'name': 'Alice', 'age': 25, 'role': 'admin'}
print('User Dict:', user)
print('Keys:', _nexa_invoke_method(user, 'keys'))
print('Values:', _nexa_invoke_method(user, 'values'))
print("Get existing 'name':", _nexa_invoke_method(user, 'get', 'name'))
print("Get missing 'token':", _nexa_invoke_method(user, 'get', 'token'))
print('\n--- 4. OS Subprocess & Environment ---')
res = _nexa_invoke_method(sys, 'run', 'echo Nexa OS Subprocess OK!')
print('Subprocess stdout:', _nexa_invoke_method(_nexa_invoke_method(res, 'get', 'stdout'), 'strip'))
print('\n✅ All Nexa v12 features successfully verified!')
