"""
imgsearch_api.py — Image-guided search interface
"""
import sys
import os
from Core.env_loader import PROJECT_ROOT

_img_searcher = None


def init_imgsearch(get_frame_fn, send_vel_fn, gradual_stop_fn,
                   llava_fn, yolo_sees_fn, model):
    """Wire up the ImageSearch module."""
    global _img_searcher

    vision_dir = os.path.join(PROJECT_ROOT, "Vision")
    if vision_dir not in sys.path:
        sys.path.insert(0, vision_dir)

    try:
        from marcus_imgsearch import ImageSearch
        _img_searcher = ImageSearch(
            get_frame_fn=get_frame_fn,
            send_vel_fn=send_vel_fn,
            gradual_stop_fn=gradual_stop_fn,
            llava_fn=llava_fn,
            yolo_sees_fn=yolo_sees_fn,
            model=model,
        )
        print("Image search ready")
    except ImportError:
        print("marcus_imgsearch.py not found — image search disabled")
    except Exception as e:
        print(f"Image search error: {e}")


def get_searcher():
    return _img_searcher
