import { atom } from 'nanostores'
import { persistentAtom } from '@nanostores/persistent'
import type { SynthesisParams, WindowType } from '../spectral-synthesis'

export type GeneratorType = 'tixy' | 'picsum' | 'art-institute' | 'geometric-tiles'

export interface GeneratedImage {
  id: string
  canvas: HTMLCanvasElement
  imageData: ImageData
  generator: GeneratorType
  params: any
}

export interface AppSettings {
  selectedGenerator: GeneratorType
  gridSize: number
  imageSize: number
  backgroundColor: string
  foregroundColor: string
}

export const appSettings = atom<AppSettings>({
  selectedGenerator: 'tixy',
  gridSize: 20,
  imageSize: 64,
  backgroundColor: '#000000',
  foregroundColor: '#ffffff'
})

export const generatedImages = atom<GeneratedImage[]>([])

export const selectedImage = atom<GeneratedImage | null>(null)

export const isGenerating = atom<boolean>(false)

export const panelOpen = atom<boolean>(false)

export const synthesisParams = atom<SynthesisParams>({
  duration: 5,
  minFreq: 20,
  maxFreq: 20000,
  sampleRate: 44100,
  frequencyResolution: 1,
  timeResolution: 1,
  amplitudeThreshold: 0.01,
  maxPartials: 100,
  windowType: 'rectangular'
})