```python
def swap_keys(names: dict) -> dict:
    """
    Given a mapping of names to codes, return the mapping the other way round,
    from each code to a name. When two names share one code, the name that sorts first
    is the one kept. A name whose code is empty text is left out altogether.
    """
    if not names:
        return {}
    
    # Convert the dictionary keys to a sorted list of tuples (code, name)
    sorted_codes = sorted(names.items(), key=lambda item: (item[1], item[0]))
    
    # Create a new dictionary with codes as keys and names as values
    swapped_names = {code: name for code, name in sorted_codes}
    
    return swapped_names
```