package main

import (
	"fmt"
	"learngo/tree"
)

/*
包扩展
1、定义别名
2、使用组合
*/
// 组合 TreeMenuNode
type myTreeNode struct {
	node *tree.TreeMenuNode
}

func (myNode *myTreeNode) postOrder() {

	node := myTreeNode{myNode.node.Child}
	node.postOrder()
	treeNode := myTreeNode{myNode.node.Perent}
	treeNode.postOrder()
	myNode.node.Print()
}

func main() {

	var menu tree.TreeMenuNode

	menu = tree.TreeMenuNode{Name: "角色管理"}
	menu.Perent = &tree.TreeMenuNode{}
	menu.Child = &tree.TreeMenuNode{"增加用户", nil, nil}
	menu.Child.Child = new(tree.TreeMenuNode)

	org := tree.TreeMenuNode{Name: "xx研发中心"}
	org.Child = &tree.TreeMenuNode{"A组", nil, nil}

	nodes := []tree.TreeMenuNode{
		{Name: "xxx系统"},
		{Name: "测试"},
		{"系统管理", &menu, &org},
	}
	fmt.Println(nodes)

	fmt.Println("调用自定义方法： ")

	menu.Print()
	menu.Child.Child.SetName("自定义名称")
	menu.Child.Child.Print()

	var xMenu *tree.TreeMenuNode
	xMenu.SetName("测试参数")
	xMenu = &org
	xMenu.SetName("测试参数2")
	xMenu.Print()

	fmt.Println("  遍历菜单树")
	menu.Traverse()
	org.Traverse()

	// 通过工厂获取
	root := tree.CraeteTreeMenuNode("测试")
	fmt.Println(root.Name)

	root.Perent = tree.CraeteTreeMenuNode("1")

	root.Child = tree.CraeteTreeMenuNode("2")

	root.Perent.Perent = tree.CraeteTreeMenuNode("01")

	root.Child.Child = tree.CraeteTreeMenuNode("02")

	root.Perent.Print()

}
