"""Style key/description utilities."""

from __future__ import annotations

import json


def get_style_key(style: dict) -> str:
    """Deterministic string key from a style dict for grouping."""
    if not style:
        return ''
    return '|'.join(
        f'{k}:{json.dumps(v) if isinstance(v, dict) else v}'
        for k, v in sorted(style.items())
        if v is not None and v != ''
    )


def get_style_description(style: dict) -> str:
    """Human-readable description of a style dict."""
    if not style:
        return 'Default style'
    parts = []
    for k, v in sorted(style.items()):
        if v is None or v == '':
            continue
        parts.append(f'{k}:{json.dumps(v) if isinstance(v, dict) else v}')
    return ', '.join(parts) if parts else 'Default style'
