import { getEventCallbacks } from "./eventBus"
import { navigate } from "../../../../vendor/svelte-routing"

export function navigateWrapper(path: string, props: any = null) {
    if (getEventCallbacks("navigate")) {
        let callbacks = Object.values(getEventCallbacks("navigate"))
        for (let i = 0; i < callbacks?.length; i++) {
            // do not navigate if false is returned
            if ((callbacks[i] as Function)(path, props) === false) return
        }
    }
    if (props) navigate(path, props)
    else navigate(path)
}
