package main

import (
	"fmt"
	"os"

	tea "charm.land/bubbletea/v2"
)

func main() {
	cfg, err := LoadConfig()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err)
		os.Exit(1)
	}

	theme := LoadTheme(cfg.Theme, themesDir())
	sty := BuildStyles(theme)

	sessions, err := ListSessions()
	if err != nil {
		sessions = nil
	}

	cb, err := newChatbot(cfg.Providers, sessions, sty)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to init: %v\n", err)
		os.Exit(1)
	}

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