import SwiftUI

struct ContentView: View {
	@State private var viewModel: MailViewModel

	init() {
		let baseURL = URL(string: "http://localhost:3000")!
		let client = APIClient(baseURL: baseURL)
		_viewModel = State(initialValue: MailViewModel(apiClient: client))
	}

	var body: some View {
		NavigationSplitView {
			SidebarView(viewModel: viewModel)
		} content: {
			ThreadListView(viewModel: viewModel)
		} detail: {
			ThreadDetailView(
				thread: viewModel.selectedThread,
				messages: viewModel.selectedMessages
			)
		}
		.task {
			await viewModel.loadThreads(accountId: "personal")
			viewModel.connectToEvents(
				baseURL: URL(string: "http://localhost:3000")!,
				accountId: "personal"
			)
		}
	}
}
