export function createParameterEditSession({
  capture,
  pushUndo,
  clearRedo,
  onChange = () => {},
}) {
  let editing = false;
  let pending = null;
  return {
    begin() {
      editing = true;
      if (pending === null) pending = capture();
      onChange(true);
    },
    end() {
      editing = false;
      if (pending !== null) {
        pushUndo(pending);
        clearRedo();
        pending = null;
      }
      onChange(false);
    },
    cancel() {
      editing = false;
      pending = null;
      onChange(false);
    },
    isEditing: () => editing,
    hasPending: () => pending !== null,
  };
}
