package main

import (
	"fmt"
	"os"
	"woke/db"
	"woke/player"
	"woke/scheduler"
	"woke/ui"

	tea "github.com/charmbracelet/bubbletea"
)

func main() {
	store, err := db.Open()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to open database: %v\n", err)
		os.Exit(1)
	}
	defer store.Close()

	pl := player.New()
	sched := scheduler.New(store)
	sched.Start()
	defer sched.Stop()

	model := ui.NewModel(store, sched, pl)
	p := tea.NewProgram(model, tea.WithAltScreen())

	if _, err := p.Run(); err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
}
