import { onActivated, onMounted, ref } from 'vue'

/**
 * First visit: onMounted(full load). Re-activation from keep-alive: silent refresh only.
 */
export function usePageActivateRefresh(
  refresh: (silent: boolean) => void | Promise<void>,
) {
  const ready = ref(false)
  onMounted(async () => {
    await refresh(false)
    ready.value = true
  })
  onActivated(() => {
    if (ready.value) void refresh(true)
  })
}
