package ui

import "core:fmt"
import "core:strings"
import "../core"

render_header :: proc(c: App_Controller) -> string {
	mode := "Casual"
	if c.state.user_mode == .Professional {
		mode = "Professional"
	}
	return fmt.aprintf("[comic-odin] screen=%s step=%v mode=%s", screen_name(c.active_screen), c.state.workflow.current_step, mode)
}

render_progress :: proc(state: core.Comic_State) -> string {
	if !state.workflow.is_generating {
		return "idle"
	}
	return fmt.aprintf("generating %.0f%%", state.workflow.generation_progress)
}

render_story_view :: proc(state: core.Comic_State) -> string {
	idea := state.story_idea
	if len(idea) == 0 {
		idea = "(no story idea yet)"
	}
	return fmt.aprintf("Story\n- idea: %s\n- genre: %s\n- audience: %s", idea, state.story_genre, state.target_audience)
}

render_script_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Script\n- title: %s\n- pages: %d\n- characters: %d", state.script.title, len(state.script.pages), len(state.script.characters))
}

render_characters_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Characters\n- count: %d", len(state.characters))
}

render_panels_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Panels\n- generated images: %d", len(state.panel_images))
}

render_layout_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Layout\n- pages: %d", len(state.page_layouts))
}

render_bubbles_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Speech\n- panels with bubbles: %d", len(state.speech_bubbles))
}

render_export_view :: proc(state: core.Comic_State) -> string {
	return fmt.aprintf("Export\n- page layouts: %d\n- format: %v", len(state.page_layouts), state.export_format)
}

render_screen_body :: proc(c: App_Controller) -> string {
	switch c.active_screen {
	case .Story:
		return render_story_view(c.state)
	case .Script:
		return render_script_view(c.state)
	case .Characters:
		return render_characters_view(c.state)
	case .Panels:
		return render_panels_view(c.state)
	case .Layout:
		return render_layout_view(c.state)
	case .Bubbles:
		return render_bubbles_view(c.state)
	case .Export:
		return render_export_view(c.state)
	case .Community:
		return "Community\n- coming soon"
	}
	return "Unknown screen"
}

render_status_bar :: proc(c: App_Controller) -> string {
	status := render_progress(c.state)
	if len(c.state.workflow.error_message) > 0 {
		status = fmt.aprintf("error: %s", c.state.workflow.error_message)
	}
	return fmt.aprintf("jobs=%d | %s", active_jobs_count(c.jobs), status)
}

render_app_to_string :: proc(c: App_Controller) -> string {
	parts := [3]string{render_header(c), render_screen_body(c), render_status_bar(c)}
	out := strings.join(parts[:], "\n\n", context.allocator)
	for p in parts {
		delete(p)
	}
	return out
}
