import { createModel } from '@rematch/core'

import { EventRecord, EventsFilter, UIState } from '../..'

import { RootModel } from '.'


const defaultState = (): UIState => ({
  eventsFilter: { query: '', eventTypes: [] },
  selectedEventRecordId: null
})

export const ui = createModel<RootModel>()({
  state: defaultState(),
  reducers: {
    setSelectedEventRecordId(state, payload: EventRecord['id']) {
      state.selectedEventRecordId = payload
      return state
    },
    setEventsFilter(state, payload: EventsFilter) {
      state.eventsFilter = payload
      return state
    }
  },
  effects: {}
})
