//..............................................................................
//
// Ninja UI - information grid
//

namespace ui {

//! \addtogroup api-ui
//! @{

//..............................................................................

opaque class InformationItem {
	string_t autoget property m_name;
	string_t autoget property m_toolTip;
	bool autoget property m_isEnabled;

	void addChildItem(
		InformationItem* item,
		InformationItem* beforeItem = null
	);

	void removeChildItem(InformationItem* item);
}

//..............................................................................

class InformationGroup: InformationItem {
	construct(string_t name);
}

//..............................................................................

opaque class InformationValue: InformationItem {
	construct(string_t name);

	string_t autoget property m_value;
	string_t autoget property m_disabledValue;
	string_t autoget property m_valueToolTip;
	uint_t autoget property m_valueColor;
	bool autoget property m_isSelectionDependent;
}

//..............................................................................

// when calculating misc stats, we want to delay update of UI as to avoid
// the unnecessary load on the CPU

opaque class InformationStatValue: InformationValue {
	typedef string_t FormatFunc(uint64_t value);

	FormatFunc* m_formatFunc;
	string_t m_formatSpec;

	uint64_t autoget property m_value; // shadows InformationValue.m_value

	construct(string_t name);
	destruct();

	void forceUpdate();
}

//..............................................................................

opaque class InformationGrid {
	void addItem(
		InformationItem* item,
		InformationItem* beforeItem = null
	);

	void removeItem(InformationItem* item);

	InformationGroup* createGroup(
		InformationItem* parentItem = null,
		InformationItem* beforeItem = null,
		string_t name,
		string_t toolTip = null
	);

	InformationGroup* createGroup(
		string_t name,
		string_t toolTip = null
	) {
		return createGroup(,, name, toolTip);
	}

	InformationValue* createValue(
		InformationItem* parentItem = null,
		InformationItem* beforeItem = null,
		bool isSelectionDependent = false,
		string_t name,
		string_t toolTip = null
	);

	 InformationValue* createValue(
		string_t name,
		string_t toolTip = null
	) {
		return createValue(,,, name, toolTip);
	}

	InformationStatValue* createStatValue(
		InformationItem* parentItem = null,
		InformationItem* beforeItem = null,
		bool isSelectionDependent = false,
		string_t name,
		string_t toolTip = null
	);

	 InformationStatValue* createStatValue(
		string_t name,
		string_t toolTip = null
	) {
		return createStatValue(,,, name, toolTip);
	}

	void resizeNameColumnToContents();

protected:
	void addValueImpl(
		InformationValue* item,
		InformationItem* parentItem,
		InformationItem* beforeItem,
		bool isSelectionDependent,
		string_t toolTip
	);
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

InformationGroup* InformationGrid.createGroup(
	InformationItem* parentItem,
	InformationItem* beforeItem,
	string_t name,
	string_t toolTip
) {
	InformationGroup* item = new InformationGroup(name);

	parentItem ?
		parentItem.addChildItem(item, beforeItem) :
		addItem(item, beforeItem);

	return item;
}

InformationValue* InformationGrid.createValue(
	InformationItem* parentItem,
	InformationItem* beforeItem,
	bool isSelectionDependent,
	string_t name,
	string_t toolTip
) {
	InformationValue* item = new InformationValue(name);
	addValueImpl(item, parentItem, beforeItem, isSelectionDependent, toolTip);
	return item;
}

InformationStatValue* InformationGrid.createStatValue(
	InformationItem* parentItem,
	InformationItem* beforeItem,
	bool isSelectionDependent,
	string_t name,
	string_t toolTip
) {
	InformationStatValue* item = new InformationStatValue(name);
	addValueImpl(item, parentItem, beforeItem, isSelectionDependent, toolTip);
	return item;
}

void InformationGrid.addValueImpl(
	InformationValue* item,
	InformationItem* parentItem,
	InformationItem* beforeItem,
	bool isSelectionDependent,
	string_t toolTip
) {
	item.m_toolTip = toolTip;
	item.m_isSelectionDependent = isSelectionDependent;

	parentItem ?
		parentItem.addChildItem(item, beforeItem) :
		addItem(item, beforeItem);
}

//..............................................................................

//! @}

} // namespace ui
