package ui

import (
	"icdb/internal/ui/styling"
	"icdb/pkg/layouts"

	"gioui.org/app"
	"gioui.org/op"
)

// run takes a window as parameter and runs the UI on it.
func run(window *app.Window) error {
	theme := styling.GlobalTheme()
	var ops op.Ops
	for {
		switch e := window.Event().(type) {
		case app.DestroyEvent:
			return e.Err
		case app.FrameEvent:
			gtx := app.NewContext(&ops, e)

			layouts.SplitRatio{Ratio: -0.8}.Layout(gtx,
				renderSidebar(theme),
				renderView(theme),
			)

			e.Frame(gtx.Ops)
		}
	}
}
