"""Formatting utilities for verification display"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/utils.ipynb.

# %% auto #0
__all__ = ['format_duration_mmss', 'format_duration_seconds', 'format_time_range', 'truncate_text']

# %% ../nbs/utils.ipynb #verify-utils-imports
from typing import Optional

# %% ../nbs/utils.ipynb #format-duration-mmss
def format_duration_mmss(
    seconds: Optional[float]  # Duration in seconds
) -> str:  # Formatted string (mm:ss)
    """Format duration in seconds as mm:ss for summary display."""
    if seconds is None:
        return "--:--"
    minutes = int(seconds // 60)
    secs = int(seconds % 60)
    return f"{minutes}:{secs:02d}"

# %% ../nbs/utils.ipynb #format-duration-seconds
def format_duration_seconds(
    seconds: Optional[float]  # Duration in seconds
) -> str:  # Formatted string (e.g., "10.3s")
    """Format duration in seconds as Xs or X.Xs for average display."""
    if seconds is None:
        return "-.-s"
    return f"{seconds:.1f}s"

# %% ../nbs/utils.ipynb #format-time-range
def format_time_range(
    start: Optional[float],  # Start time in seconds
    end: Optional[float]  # End time in seconds
) -> str:  # Formatted range (e.g., "0.0s - 2.1s")
    """Format time range for sample segment display."""
    if start is None or end is None:
        return "-.-s - -.-s"
    return f"{start:.1f}s - {end:.1f}s"

# %% ../nbs/utils.ipynb #truncate-text
def truncate_text(
    text: Optional[str],  # Full text to truncate
    max_length: int = 60  # Maximum length before truncation
) -> str:  # Truncated text with ellipsis if needed
    """Truncate text for sample segment display."""
    if text is None:
        return ""
    if len(text) <= max_length:
        return text
    return f"{text[:max_length-3]}..."
