import { CODE } from 'core/app'
import type { Note } from 'src/types/note'
import type { Chat } from 'src/types/chat'
import { defineWorkspaceStore } from 'core/workspace/workspace-store-factory'

export const useNoteStore = defineWorkspaceStore('note', {
  state: () => ({
    currentNote: {} as Note,
    notes: [] as Note[],
    favoriteTop: true,
    chatToNote: {} as Chat,
    chatWidth: 0,
  }),
  getters: {
    noteId: (state) => state.currentNote.id,
  },
  actions: {
    setCurrentNote(note: Note) {
      this.currentNote = note
    },
    setNotes(notes: Note[]) {
      this.notes = notes
    },
    setFavoriteTop(value: boolean) {
      this.favoriteTop = value
    },
    setChatToNote(value: Chat) {
      this.chatToNote = value
    },
    resetChatToNote() {
      this.chatToNote = {} as Chat
    },
    setChatWidth(value: number) {
      this.chatWidth = value
    },
  },
  persist: {
    key: `${CODE}.note`
  }
})

