import { create } from 'zustand'

type SharedTransitionState = {
    byLocationKey:        Record<string, string>
    setForLocationKey:    (locationKey: string, sharedId: string) => void
    clearForLocationKey:  (locationKey: string) => void }


export const useSharedTransitionStore = create<SharedTransitionState> (set => ({
    byLocationKey:      { },
    setForLocationKey:  (locationKey, sharedId) =>
	set (state => ({ byLocationKey: { ...state.byLocationKey,
					  [locationKey]: sharedId } })),
    clearForLocationKey: (locationKey) =>
	set (state => {
	  const next = { ...state.byLocationKey }
	  delete next[locationKey]
	  return { byLocationKey: next }}) }))
