DEFAULT_PAPER_SIZE = "58mm"
THERMAL_DPI = 203
PREVIEW_HEIGHT_MM = 297.0
ROLL_HEIGHT_MM = 1000.0
PAPER_OPTIONS = ("56mm", "58mm", "80mm", "100x150mm")

_PAPER_WIDTH_MM = {
    "56mm": 56.0,
    "58mm": 58.0,
    "80mm": 80.0,
    "100x150mm": 100.0,
}

_PAPER_ALIASES = {
    "56": "56mm",
    "56mm": "56mm",
    "58": "58mm",
    "58mm": "58mm",
    "80": "80mm",
    "80mm": "80mm",
    "100x150": "100x150mm",
    "100x150mm": "100x150mm",
}


def normalize_paper_label(label: str) -> str:
    key = str(label or "").strip().lower()
    if not key:
        return DEFAULT_PAPER_SIZE
    return _PAPER_ALIASES.get(key, DEFAULT_PAPER_SIZE)


def get_paper_width_mm(label: str) -> float:
    normalized = normalize_paper_label(label)
    return float(_PAPER_WIDTH_MM.get(normalized, _PAPER_WIDTH_MM[DEFAULT_PAPER_SIZE]))


def estimate_cols_by_mm(width_mm: float) -> int:
    if width_mm <= 58.0:
        return 32
    if width_mm <= 80.0:
        return 48
    return 42
