import { create } from 'zustand'
import { TracklistEntry } from '../types'

interface TracklistState {
  rawText: string
  entries: TracklistEntry[]
  errors: { line: number; message: string }[]
  isValid: boolean
  isDragging: boolean

  setRawText: (text: string) => void
  setEntries: (entries: TracklistEntry[]) => void
  setErrors: (errors: { line: number; message: string }[]) => void
  setIsValid: (isValid: boolean) => void
  setIsDragging: (isDragging: boolean) => void
  reset: () => void
}

export const useTracklistStore = create<TracklistState>((set) => ({
  rawText: '',
  entries: [],
  errors: [],
  isValid: false,
  isDragging: false,

  setRawText: (rawText) => set({ rawText }),
  setEntries: (entries) => set({ entries }),
  setErrors: (errors) => set({ errors }),
  setIsValid: (isValid) => set({ isValid }),
  setIsDragging: (isDragging) => set({ isDragging }),
  reset: () =>
    set({
      rawText: '',
      entries: [],
      errors: [],
      isValid: false,
      isDragging: false,
    }),
}))