<script>
    import ocAlgorithm from './js/algorithm'
    import TreeSelectDom from './treeSelectDom'

    export default {
        name: 'oc-treeselect',
        mixins: [ TreeSelectDom ],

        props: {
            // 支持属性结构的自动构建，与下面treeNode形成对比，dom节点过多时（>5000个treeitem），应采用treeNode直接构建的形式，性能会好点
            treeData: { type: Object, default: null },
            childKey: { type: String, default: 'items' },
            textKey: { type: String, default: 'name' },
            idKey: { type: String, default: 'id'},

            // //支持直接放入html的构建
            // treeNode: { type: Object, default: null },
        },

        computed: {
            currentTreeNode() {
                let treeNode = null;
                if(this.treeNode) {
                    treeNode = this.treeNode;
                }
                else if(this.treeData) {
                    treeNode = ocAlgorithm.generateTreeNode(this.treeData, true, this.childKey, this.textKey, this.idKey);
                }
                if(treeNode) {
                    treeNode.addClass('ocTreeSelectPop');
                }

                return treeNode;
            }
        },

        beforeDestroy() {
            this.currentTreeNode && this.currentTreeNode.remove();
        }
    }
</script>
