namespace Bliku.Tui.Collapsible

/-- Collapsible section state indexed by Nat key. -/
structure State where
  collapsed : Array Nat := #[]
  deriving Inhabited, Repr

def State.isCollapsed (s : State) (k : Nat) : Bool :=
  s.collapsed.contains k

def State.toggle (s : State) (k : Nat) : State :=
  match s.collapsed.findIdx? (fun x => x == k) with
  | some _ => { s with collapsed := s.collapsed.filter (fun x => x != k) }
  | none => { s with collapsed := s.collapsed.push k }

end Bliku.Tui.Collapsible