import { computed, ref } from 'vue'

export function useKbxDirtyState() {
  const revision = ref(0)
  const savedRevision = ref(0)
  const dirty = computed(() => revision.value !== savedRevision.value)

  function touch() { revision.value++ }
  function markSaved() { savedRevision.value = revision.value }
  function reset() { revision.value = 0; savedRevision.value = 0 }

  return { dirty, touch, markSaved, reset }
}
