from __future__ import annotations
from typing import Any, Mapping

def _deep_merge(dst: dict, src: Mapping) -> dict:
    out = dict(dst)
    for k, v in src.items():
        if isinstance(v, Mapping) and isinstance(out.get(k), Mapping):
            out[k] = _deep_merge(out[k], v)  # type: ignore[arg-type]
        else:
            out[k] = v
    return out
def register(app):
    @app.template_filter("combine")
    def combine_filter(a: Any, b: Any, deep: bool = False, drop_none: bool = False) -> Any:
        """
        Jinja filter: merge two dict-like objects.

        - Non-dict inputs: returns `a` unchanged.
        - If drop_none=True, keys in `b` with value None are ignored.
        - If deep=True, nested dicts are merged recursively.
        """
        if not isinstance(a, Mapping) or not isinstance(b, Mapping):
            return a
        b2 = {k: v for k, v in b.items() if not (drop_none and v is None)}
        return _deep_merge(a, b2) if deep else {**a, **b2}