package app

// Condition represents a control structure for conditionally displaying UI
// elements. It extends the UI interface to include methods for handling
// conditional logic.
type Condition interface {
	UI

	// ElseIf sets a UI element to be displayed when the given boolean
	// expression is true and all previous conditions have been false.
	//
	// expr: Boolean expression to evaluate.
	// elem: Function that returns the UI element to display.
	ElseIf(expr bool, elem func() UI) Condition

	// ElseIfSlice sets multiple UI elements to be displayed when the given
	// boolean expression is true and all previous conditions have been false.
	//
	// expr: Boolean expression to evaluate.
	// elems: Function that returns a slice of UI elements to display.
	ElseIfSlice(expr bool, elems func() []UI) Condition

	// Else sets a UI element to be displayed as a fallback when all previous
	// conditions have been false.
	//
	// elem: Function that returns the UI element to display.
	Else(elem func() UI) Condition

	// ElseSlice sets multiple UI elements to be displayed as a fallback when
	// all previous conditions have been false.
	//
	// expr: Boolean expression to evaluate.
	// elems: Function that returns a slice of UI elements to display.
	ElseSlice(elems func() []UI) Condition

	body() []UI
}

// If returns a Condition that will display the given UI element based on the
// evaluation of the provided boolean expression.
func ( bool,  func() UI) Condition {
	return IfSlice(, func() []UI {
		return []UI{()}
	})
}

// IfSlice returns a Condition that will display the given slice of UI elements
// based on the evaluation of the provided boolean expression.
func ( bool,  func() []UI) Condition {
	if ! {
		return condition{}
	}
	return condition{
		children: FilterUIElems(()...),
		matched:  true,
	}
}

type condition struct {
	children []UI
	matched  bool
}

func ( condition) ( bool,  func() UI) Condition {
	return .ElseIfSlice(, func() []UI {
		return []UI{()}
	})
}

func ( condition) ( bool,  func() []UI) Condition {
	if .matched || ! {
		return 
	}

	.children = FilterUIElems(()...)
	.matched = true
	return 
}

func ( condition) ( func() UI) Condition {
	return .ElseSlice(func() []UI {
		return []UI{()}
	})
}

func ( condition) ( func() []UI) Condition {
	return .ElseIfSlice(true, )
}

func ( condition) () Value {
	return nil
}

func ( condition) () bool {
	return false
}

func ( condition) () []UI {
	return .children
}

func ( condition) () UI {
	return nil
}

func ( condition) (UI) UI {
	return nil
}