"""
Shared UI utilities for the Palladium Streamlit app.

Kept in a separate module so that ``app.main`` and ``app.views.*`` can both
import from here without creating a circular dependency.
"""

from __future__ import annotations

import streamlit as st

# ---------------------------------------------------------------------------
# Bootstrap Icons — injected once at the top of every page render.
# Using the CDN stylesheet so no npm/build step is needed.
# ---------------------------------------------------------------------------
_BI_CSS = """
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"
/>
<style>
  /* Tighten up the default Streamlit header spacing */
  .block-container { padding-top: 1.5rem; }
  /* Make BI icons align nicely with surrounding text */
  .bi { vertical-align: -0.125em; }
</style>
"""


def inject_icons() -> None:
    """Inject Bootstrap Icons CSS (idempotent — Streamlit deduplicates identical HTML)."""
    st.markdown(_BI_CSS, unsafe_allow_html=True)


def icon(name: str, *, cls: str = "") -> str:
    """Return an inline Bootstrap Icon ``<i>`` tag.

    Usage::

        st.markdown(icon("bar-chart") + " Financial Summary", unsafe_allow_html=True)

    See the full icon catalogue at https://icons.getbootstrap.com/
    """
    extra = f" {cls}" if cls else ""
    return f'<i class="bi bi-{name}{extra}"></i>'
