#include "pw/scene/transform.hpp"
#include "pw/scene/node.hpp"

#include "pw/core/debug.hpp"

namespace pw {

node::node()
	: _transform(*this)
{
}

node::node(const node &node)
	: _children(node.children())
	, _components(node.components())
	, _name(node._name)
	, _transform(*this)
{
//	_components.push_back(std::make_unique<transform>(*this));
}

node::ref node::clone(const unsigned short &copymode) const
{
	return nullptr;
}

std::string node::name() const
{
	return _name;
}

void node::set_name(const std::string &name)
{
	_name = name;
}

void node::add_child(node::ref c)
{
	// take parent nodepath ...
	c->_path = this->_path;

	// add current node
	c->_path.push_back(this);

	// add as child
	_children.push_back(c);
}

void node::remove_child(ref child_node)
{
    for (node::ref_array::iterator it = _children.begin();
         it != _children.end();
         it++)
    {
		if (child_node == *it) it = _children.erase(it);
    }
//    auto it = _children.end();

//    while (it = std::find(_children.begin(),_children.end(),child_node) != _children.end()) {
//		it = _children.erase(it);
//	}
}

node::~node()
{
	_children.clear();
}

//
// components
//
void node::add_component(component new_component)
{
	// assumption is that only transform is a "singular" node
	_components.push_back(new_component);
}

void node::remove_component(component c)
{
//	component::array::iterator it = _components.end();

	for (component::array::iterator it = _components.begin();
         it != _components.end();
         it++)
    {
//        if (*it == c) it = _components.erase(it);
    }
}

const node::ptr_array &node::path() const
{
	return _path;
}

void node::traversal()
{

}


const component::array &node::components() const
{
	return _components;
}




}
