package app

// HTML provides an interface for representing HTML elements within the
// application.
type HTML interface {
	UI

	// Tag retrieves the name of the HTML tag that the element represents.
	Tag() string

	// XMLNamespace fetches the XML namespace associated with the HTML element.
	// This is relevant for elements like SVG which might have a different
	// namespace.
	XMLNamespace() string

	// SelfClosing determines whether the HTML element is self-closing.
	// For elements like <img> or <br> which don't have closing tags, this
	// method returns true. Otherwise, it returns false.
	SelfClosing() bool

	depth() uint
	attrs() attributes
	setAttrs(attributes) HTML
	// SetAttr sets an HTML attribute.
	SetAttr(name string, value any)
	events() eventHandlers
	setEvents(eventHandlers) HTML
	setDepth(uint) UI
	setJSElement(Value) HTML
	parent() UI
	body() []UI
	setBody([]UI) HTML
}

type htmlElement struct {
	tag           string
	xmlns         string
	treeDepth     uint
	isSelfClosing bool
	jsElement     Value
	attributes    attributes
	eventHandlers eventHandlers
	parentElement UI
	children      []UI
}

func ( *htmlElement) () Value {
	return .jsElement
}

func ( *htmlElement) () bool {
	return .jsElement != nil
}

func ( *htmlElement) () string {
	return .tag
}

func ( *htmlElement) () string {
	return .xmlns
}

func ( *htmlElement) () bool {
	return .isSelfClosing
}

func ( *htmlElement) () uint {
	return .treeDepth
}

func ( *htmlElement) () attributes {
	return .attributes
}

func ( *htmlElement) ( string,  any) {
	if .attributes == nil {
		.attributes = make(attributes)
	}
	.attributes.Set(, )
}

// SetAttr sets an HTML attribute.
func ( *htmlElement) ( string,  any) {
	.setAttr(, )
}

func ( *htmlElement) () eventHandlers {
	return .eventHandlers
}

func ( *htmlElement) ( string,  EventHandler,  ...EventOption) {
	if .eventHandlers == nil {
		.eventHandlers = make(eventHandlers)
	}
	.eventHandlers.Set(, , ...)
}

func ( *htmlElement) () UI {
	return .parentElement
}

func ( *htmlElement) () []UI {
	return .children
}