import { onBeforeUnmount, onMounted, watch, type Ref } from 'vue'
import { useRoute } from 'vue-router'
import { useKbxWorkspaceStore } from './workspaceStore'
import { registerWorkspaceLifecycle } from './workspaceLifecycleRegistry'
export function useKbxWorkspaceBinding(dirty:Ref<boolean>, save?:()=>boolean|Promise<boolean>){const route=useRoute();const store=useKbxWorkspaceStore();let unregister:(()=>void)|undefined;onMounted(()=>{unregister=registerWorkspaceLifecycle(route.fullPath,{save});store.setActiveDirty(dirty.value)});watch(dirty,value=>store.setActiveDirty(value));onBeforeUnmount(()=>unregister?.())}
