import { applySafeAreaToRoot } from "../safeArea";

export function vkSubscribeInsets(bridge: any) {
    // bridge.subscribe((e) => { ... })
    const unsub = bridge.subscribe((e: any) => {
        if (e?.detail?.type === "VKWebAppUpdateInsets") {
            const insets = e.detail?.data?.insets;
            if (insets) applySafeAreaToRoot(insets);
        }
    });

    // В некоторых обёртках subscribe возвращает ничего — тогда возвращаем no-op
    return typeof unsub === "function" ? unsub : () => {};
}
