"""Image primitives: icon, avatar, cover_image."""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.tokens.theme import Theme, default_theme


def icon(
    url: str,
    *,
    size: int = 24,
    tint_color: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivImage:
    """Small icon image with fixed square dimensions."""
    kwargs: dict = {
        "image_url": url,
        "width": dk.DivFixedSize(value=size),
        "height": dk.DivFixedSize(value=size),
        "scale": dk.DivImageScale.FIT,
    }
    if tint_color:
        kwargs["tint_color"] = tint_color
    return dk.DivImage(**kwargs)


def avatar(
    url: str,
    *,
    size: int = 40,
    border_radius: int | None = None,
    theme: Theme = default_theme,
) -> dk.DivImage:
    """Circular avatar image."""
    radius = border_radius if border_radius is not None else size // 2
    return dk.DivImage(
        image_url=url,
        width=dk.DivFixedSize(value=size),
        height=dk.DivFixedSize(value=size),
        border=dk.DivBorder(corner_radius=radius),
        scale=dk.DivImageScale.FILL,
    )


def cover_image(
    url: str,
    *,
    height: int = 200,
    corner_radius: int = 0,
    theme: Theme = default_theme,
) -> dk.DivImage:
    """Full-width cover / hero image."""
    kwargs: dict = {
        "image_url": url,
        "width": dk.DivMatchParentSize(),
        "height": dk.DivFixedSize(value=height),
        "scale": dk.DivImageScale.FILL,
    }
    if corner_radius > 0:
        kwargs["border"] = dk.DivBorder(corner_radius=corner_radius)
    return dk.DivImage(**kwargs)
