# -*- coding: utf-8 -*-
"""Small GUI formatting helpers."""

import re

def node_host_only(value: str) -> str:
    """Return the host part for Erlang node strings like name@ip."""
    text = str(value or '').strip().strip("'\"")
    if '@' in text:
        return text.rsplit('@', 1)[1].strip()
    return text


def _server_id_sort_key(server_id) -> tuple:
    """服务器 ID 的稳定排序键，优先按数值升序。"""
    text = str(server_id or "").strip()
    try:
        return (0, int(text), text)
    except ValueError:
        match = re.search(r"\d+", text)
        if match:
            return (0, int(match.group(0)), text)
        return (1, 0, text)
