from typing import Iterable, Union

from shared.utils import join_url, host_url, _join_url_parts, route_prefix


# --- Register as a Jinja filter (Quart / Flask) ---
def register(app):
    @app.template_filter("urljoin")
    def urljoin_filter(value: Union[str, Iterable[str]]):
        return join_url(value)
    @app.template_filter("urlhost")
    def urlhost_filter(value: Union[str, Iterable[str]]):
        return host_url(value)
    @app.template_filter("urlhost_no_slash")
    def urlhost_no_slash_filter(value: Union[str, Iterable[str]]):
        return host_url(value, True)
    @app.template_filter("host")
    def host_filter(value: str):
        return _join_url_parts([route_prefix(), value])
