package tests

import "core:strings"
import "core:testing"
import "../src/core"
import "../src/shared"
import "../src/ui"

@test
ui_render_contains_header_and_status :: proc(t: ^testing.T) {
	state := core.new_initial_state()
	controller := ui.new_controller(state)
	defer ui.dispose_controller(&controller)
	out := ui.render_app_to_string(controller)
	defer delete(out)

	testing.expect(t, strings.contains(out, "[comic-odin]"), "render should contain app header")
	testing.expect(t, strings.contains(out, "jobs=0"), "render should show job count")
	testing.expect(t, strings.contains(out, "Story"), "default screen should be story")
}

@test
ui_runtime_apply_commands_flow :: proc(t: ^testing.T) {
	state := core.new_initial_state()
	pages_dyn: [dynamic]core.Page
	append(&pages_dyn, core.Page{page_number = 1})
	chars_dyn: [dynamic]core.Character
	append(&chars_dyn, core.Character{name = "A"})
	state.script = core.Comic_Script{title = "Script", pages = pages_dyn[:], characters = chars_dyn[:]}
	state.characters = chars_dyn[:]
	state.panel_images = make(map[string]core.Panel_Image)
	state.panel_images["p1"] = core.Panel_Image{url = "u", width = 1, height = 1}

	controller := ui.new_controller(state)
	defer ui.dispose_controller(&controller)
	cmds := [2]ui.UI_Command{
		{kind = .Navigate, screen = .Layout},
		{kind = .Start_Generate, job_type = .Generate_Panel, message = "panel"},
	}

	err := ui.apply_commands(&controller, cmds[:])
	testing.expect(t, shared.is_ok(err), "command sequence should succeed")
	testing.expect(t, controller.active_screen == .Layout, "expected layout screen")
	testing.expect(t, controller.state.workflow.is_generating, "generation should be active")
}
