namespace Bliku.Tui.Tabs
/-- Generic tab state. -/
structure State where
active : Nat := 0
total : Nat := 0
deriving Inhabited, Repr
def State.clamp (s : State) : State :=
let maxIdx := if s.total == 0 then 0 else s.total - 1
{ s with active := min s.active maxIdx }
def State.next (s : State) : State :=
let maxIdx := if s.total == 0 then 0 else s.total - 1
{ s with active := min (s.active + 1) maxIdx } |>.clamp
def State.prev (s : State) : State :=
{ s with active := if s.active > 0 then s.active - 1 else 0 } |>.clamp
end Bliku.Tui.Tabs