package wasm

import "syscall/js"

const (
	ELEMENTS_PROPERTY_accessKey              = "accessKey"               //Sets or returns the accesskey attribute of an element
	ELEMENTS_METHOD_addEventListener         = "addEventListener"        //Attaches an event handler to an element
	ELEMENTS_METHOD_appendChild              = "appendChild"             //Adds (appends) a new child node to an element
	ELEMENTS_PROPERTY_attributes             = "attributes"              //Returns a NamedNodeMap of an element's attributes
	ELEMENTS_METHOD_blur                     = "blur"                    //Removes focus from an element
	ELEMENTS_PROPERTY_childElementCount      = "childElementCount"       //Returns an elements's number of child elements
	ELEMENTS_PROPERTY_childNodes             = "childNodes"              //Returns a NodeList of an element's child nodes
	ELEMENTS_PROPERTY_children               = "children"                //Returns an HTMLCollection of an element's child elements
	ELEMENTS_PROPERTY_classList              = "classList"               //Returns the class name(s) of an element
	ELEMENTS_PROPERTY_className              = "className"               //Sets or returns the value of the class attribute of an element
	ELEMENTS_METHOD_click                    = "click"                   //Simulates a mouse-click on an element
	ELEMENTS_PROPERTY_clientHeight           = "clientHeight"            //Returns the height of an element, including padding
	ELEMENTS_PROPERTY_clientLeft             = "clientLeft"              //Returns the width of the left border of an element
	ELEMENTS_PROPERTY_clientTop              = "clientTop"               //Returns the width of the top border of an element
	ELEMENTS_PROPERTY_clientWidth            = "clientWidth"             //Returns the width of an element, including padding
	ELEMENTS_METHOD_cloneNode                = "cloneNode"               //Clones an element
	ELEMENTS_METHOD_closest                  = "closest"                 //Searches the DOM tree for the closest element that matches a CSS selector
	ELEMENTS_METHOD_compareDocumentPosition  = "compareDocumentPosition" //Compares the document position of two elements
	ELEMENTS_METHOD_contains                 = "contains"                //Returns true if a node is a descendant of a node
	ELEMENTS_PROPERTY_contentEditable        = "contentEditable"         //Sets or returns whether the content of an element is editable or not
	ELEMENTS_PROPERTY_dir                    = "dir"                     //Sets or returns the value of the dir attribute of an element
	ELEMENTS_PROPERTY_firstChild             = "firstChild"              //Returns the first child node of an element
	ELEMENTS_PROPERTY_firstElementChild      = "firstElementChild"       //Returns the first child element of an element
	ELEMENTS_METHOD_focus                    = "focus"                   //Gives focus to an element
	ELEMENTS_METHOD_getAttribute             = "getAttribute"            //Returns the value of an element's attribute
	ELEMENTS_METHOD_getAttributeNode         = "getAttributeNode"        //Returns an attribute node
	ELEMENTS_METHOD_getBoundingClientRect    = "getBoundingClientRect"   //Returns the size of an element and its position relative to the viewport
	ELEMENTS_METHOD_getElementsByClassName   = "getElementsByClassName"  //Returns a collection of child elements with a given class name
	ELEMENTS_METHOD_getElementsByTagName     = "getElementsByTagName"    //Returns a collection of child elements with a given tag name
	ELEMENTS_METHOD_hasAttribute             = "hasAttribute"            //Returns true if an element has a given attribute
	ELEMENTS_METHOD_hasAttributes            = "hasAttributes"           //Returns true if an element has any attributes
	ELEMENTS_METHOD_hasChildNodes            = "hasChildNodes"           //Returns true if an element has any child nodes
	ELEMENTS_PROPERTY_id                     = "id"                      //Sets or returns the value of the id attribute of an element
	ELEMENTS_PROPERTY_innerHTML              = "innerHTML"               //Sets or returns the content of an element
	ELEMENTS_PROPERTY_innerText              = "innerText"               //Sets or returns the text content of a node and its descendants
	ELEMENTS_METHOD_insertAdjacentElement    = "insertAdjacentElement"   //Inserts a new HTML element at a position relative to an element
	ELEMENTS_METHOD_insertAdjacentHTML       = "insertAdjacentHTML"      //Inserts an HTML formatted text at a position relative to an element
	ELEMENTS_METHOD_insertAdjacentText       = "insertBefore"            //Inserts text into a position relative to an element
	ELEMENTS_METHOD_insertBefore             = ""                        //Inserts a new child node before an existing child node
	ELEMENTS_PROPERTY_isContentEditable      = "isContentEditable"       //Returns true if an element's content is editable
	ELEMENTS_METHOD_isDefaultNamespace       = "isDefaultNamespace"      //Returns true if a given namespaceURI is the default
	ELEMENTS_METHOD_isEqualNode              = "isEqualNode"             //Checks if two elements are equal
	ELEMENTS_METHOD_isSameNode               = "isSameNode"              //Checks if two elements are the same node
	ELEMENTS_PROPERTY_lang                   = "lang"                    //Sets or returns the value of the lang attribute of an element
	ELEMENTS_PROPERTY_lastChild              = "lastChild"               //Returns the last child node of an element
	ELEMENTS_PROPERTY_lastElementChild       = "lastElementChild"        //Returns the last child element of an element
	ELEMENTS_METHOD_matches                  = "matches"                 //Returns true if an element is matched by a given CSS selector
	ELEMENTS_PROPERTY_namespaceURI           = "namespaceURI"            //Returns the namespace URI of an element
	ELEMENTS_PROPERTY_nextSibling            = "nextSibling"             //Returns the next node at the same node tree level
	ELEMENTS_PROPERTY_nextElementSibling     = "nextElementSibling="     //Returns the next element at the same node tree level
	ELEMENTS_PROPERTY_nodeName               = "nodeName"                //Returns the name of a node
	ELEMENTS_PROPERTY_nodeType               = "nodeType"                //Returns the node type of a node
	ELEMENTS_PROPERTY_nodeValue              = "nodeValue"               //Sets or returns the value of a node
	ELEMENTS_METHOD_normalize                = "normalize"               //Joins adjacent text nodes and removes empty text nodes in an element
	ELEMENTS_PROPERTY_offsetHeight           = "offsetHeight"            //Returns the height of an element, including padding, border and scrollbar
	ELEMENTS_PROPERTY_offsetWidth            = "offsetWidth"             //Returns the width of an element, including padding, border and scrollbar
	ELEMENTS_PROPERTY_offsetLeft             = "offsetLeft"              //Returns the horizontal offset position of an element
	ELEMENTS_PROPERTY_offsetParent           = "offsetParent"            //Returns the offset container of an element
	ELEMENTS_PROPERTY_offsetTop              = "offsetTop"               //Returns the vertical offset position of an element
	ELEMENTS_PROPERTY_outerHTML              = "outerHTML"               //Sets or returns the content of an element (including the start tag and the end tag)
	ELEMENTS_PROPERTY_outerText              = "outerText"               //Sets or returns the outer text content of a node and its descendants
	ELEMENTS_PROPERTY_ownerDocument          = "ownerDocument"           //Returns the root element (document object) for an element
	ELEMENTS_PROPERTY_parentNode             = "parentNode"              //Returns the parent node of an element
	ELEMENTS_PROPERTY_parentElement          = "parentElement"           //Returns the parent element node of an element
	ELEMENTS_PROPERTY_previousSibling        = "previousSibling"         //Returns the previous node at the same node tree level
	ELEMENTS_PROPERTY_previousElementSibling = "previousElementSibling"  //Returns the previous element at the same node tree level
	ELEMENTS_METHOD_querySelector            = "querySelector"           //Returns the first child element that matches a CSS selector(s)
	ELEMENTS_METHOD_querySelectorAll         = "querySelectorAll"        //Returns all child elements that matches a CSS selector(s)
	ELEMENTS_METHOD_remove                   = "remove"                  //Removes an element from the DOM
	ELEMENTS_METHOD_removeAttribute          = "removeAttribute"         //Removes an attribute from an element
	ELEMENTS_METHOD_removeAttributeNode      = "removeAttributeNode"     //Removes an attribute node, and returns the removed node
	ELEMENTS_METHOD_removeChild              = "removeChild"             //Removes a child node from an element
	ELEMENTS_METHOD_removeEventListener      = "removeEventListener"     //Removes an event handler that has been attached with the addEventListener() method
	ELEMENTS_METHOD_replaceChild             = "replaceChild"            //Replaces a child node in an element
	ELEMENTS_PROPERTY_scrollHeight           = "scrollHeight"            //Returns the entire height of an element, including padding
	ELEMENTS_METHOD_scrolltoView             = "scrolltoView"            //Scrolls the an element into the visible area of the browser window
	ELEMENTS_PROPERTY_scrollLeft             = "scrollLeft"              //Sets or returns the number of pixels an element's content is scrolled horizontally
	ELEMENTS_PROPERTY_scrollTop              = "scrollTop"               //Sets or returns the number of pixels an element's content is scrolled vertically
	ELEMENTS_PROPERTY_scrollWidth            = "scrollWidth"             //Returns the entire width of an element, including padding
	ELEMENTS_METHOD_setAttribute             = "setAttribute"            //Sets or changes an attribute's value
	ELEMENTS_METHOD_setAttributeNode         = "setAttributeNode"        //Sets or changes an attribute node
	ELEMENTS_PROPERTY_style                  = "style"                   //Sets or returns the value of the style attribute of an element
	ELEMENTS_PROPERTY_tabIndex               = "tabIndex"                //Sets or returns the value of the tabindex attribute of an element
	ELEMENTS_PROPERTY_tagName                = "tagName"                 //Returns the tag name of an element
	ELEMENTS_PROPERTY_textContent            = "textContent"             //Sets or returns the textual content of a node and its descendants
	ELEMENTS_PROPERTY_title                  = "title"                   //Sets or returns the value of the title attribute of an element
	ELEMENTS_METHOD_toString                 = "toString"                //Converts an element to a string
)

const (
	DOCUMENTS_PROPERTY_activeElement        = "activeElement"          //Returns the currently focused element in the document
	DOCUMENTS_METHOD_addEventListener       = "addEventListener"       //Attaches an event handler to the document
	DOCUMENTS_METHOD_adoptNode              = "adoptNode"              //Adopts a node from another document
	DOCUMENTS_PROPERTY_baseURI              = "baseURI"                //Returns the absolute base URI of a document
	DOCUMENTS_PROPERTY_body                 = "body"                   //Sets or returns the document's body (the <body> element)
	DOCUMENTS_PROPERTY_characterSet         = "characterSet"           //Returns the character encoding for the document
	DOCUMENTS_METHOD_close                  = "close"                  //Closes the output stream previously opened with document.open()
	DOCUMENTS_PROPERTY_cookie               = "cookie"                 //Returns all name/value pairs of cookies in the document
	DOCUMENTS_METHOD_createAttribute        = "createAttribute"        //Creates an attribute node
	DOCUMENTS_METHOD_createComment          = "createComment"          //Creates a Comment node with the specified text
	DOCUMENTS_METHOD_createDocumentFragment = "createDocumentFragment" //Creates an empty DocumentFragment node
	DOCUMENTS_METHOD_createElement          = "createElement"          //Creates an Element node
	DOCUMENTS_METHOD_createEvent            = "createEvent"            //Creates a new event
	DOCUMENTS_METHOD_createTextNode         = "createTextNode"         //Creates a Text node
	DOCUMENTS_PROPERTY_defaultView          = "defaultView"            //Returns the window object associated with a document, or null if none is available.
	DOCUMENTS_PROPERTY_designMode           = "designMode"             //Controls whether the entire document should be editable or not.
	DOCUMENTS_PROPERTY_doctype              = "doctype"                //Returns the Document Type Declaration associated with the document
	DOCUMENTS_PROPERTY_documentElement      = "documentElement"        //Returns the Document Element of the document (the <html> element)
	DOCUMENTS_PROPERTY_documentURI          = "documentURI"            //Sets or returns the location of the document
	DOCUMENTS_PROPERTY_domain               = "domain"                 //Returns the domain name of the server that loaded the document
	DOCUMENTS_PROPERTY_embeds               = "embeds"                 //Returns a collection of all <embed> elements the document
	DOCUMENTS_PROPERTY_charset              = "charset"                //Deprecatedforms="" 	//Returns a collection of all <form> elements in the document
	DOCUMENTS_METHOD_getElementById         = "getElementById"         //Returns the element that has the ID attribute with the specified value
	DOCUMENTS_METHOD_getElementsByClassName = "getElementsByClassName" //Returns an HTMLCollection containing all elements with the specified class name
	DOCUMENTS_METHOD_getElementsByName      = "getElementsByName"      //Returns an live NodeList containing all elements with the specified name
	DOCUMENTS_METHOD_getElementsByTagName   = "getElementsByTagName"   //Returns an HTMLCollection containing all elements with the specified tag name
	DOCUMENTS_METHOD_hasFocus               = "hasFocus"               //Returns a Boolean value indicating whether the document has focus
	DOCUMENTS_METHOD_importNode             = "importNode"             //Imports a node from another document
	DOCUMENTS_METHOD_normalize              = "normalize"              //Removes empty Text nodes, and joins adjacent nodes
	DOCUMENTS_METHOD_open                   = "open"                   //Opens an HTML output stream to collect output from document.write()
	DOCUMENTS_METHOD_querySelector          = "querySelector"          //Returns the first element that matches a specified CSS selector(s) in the document
	DOCUMENTS_METHOD_querySelectorAll       = "querySelectorAll"       //Returns a static NodeList containing all elements that matches a specified CSS selector(s) in the document
	DOCUMENTS_METHOD_removeEventListener    = "removeEventListener"    //Removes an event handler from the document (that has been attached with the addEventListener() method)
	DOCUMENTS_METHOD_write                  = "write"                  //Writes HTML expressions or JavaScript code to a document
	DOCUMENTS_METHOD_writeln                = "writeln"                //Same as write(), but adds a newline character after each statement
)

func GetCheckedRadioOrCheckbox(jsObject js.Value) (id, name, value string) {
	for i := 0; true; i++ {
		if tmpObject := jsObject.Index(i); !tmpObject.IsUndefined() {
			if tmpObject.Get("checked").Bool() {
				id, name, value = tmpObject.Get("id").String(), tmpObject.Get("name").String(), tmpObject.Get("value").String()
				break
			}
		} else {
			break
		}

	}
	return
}

type Checkerboard struct {
	Id, Name          string
	Checked, Disabled bool
	Value             string
}

func GetStatusFromBulkOfIds(dombase js.Value, ids []string) (result []Checkerboard) {
	for _, id := range ids {
		tmpObject := dombase.Call(DOCUMENTS_METHOD_getElementById, id)
		result = append(result, Checkerboard{
			Id:       id,
			Name:     tmpObject.Get("name").String(),
			Checked:  tmpObject.Get("checked").Bool(),
			Disabled: tmpObject.Get("disabled").Bool(),
			Value:    tmpObject.Get("value").String()})
	}

	return
}

/*
func IsDefined(o js.Value, attribute string) bool {
	if o.Get(attribute).IsUndefined() {
		return false
	} else {
		return true
	}
}
*/
