"use strict";const e=require("../../common/vendor.js"),d=require("./tool/util.js"),t={name:"LyTreeNode",componentName:"LyTreeNode",components:{lyCheckbox:()=>"./components/ly-checkbox.js"},props:{nodeId:[Number,String],renderAfterExpand:{type:Boolean,default:!0},checkOnlyLeaf:{type:Boolean,default:!1},showCheckbox:{type:Boolean,default:!1},showRadio:{type:Boolean,default:!1},indent:Number,iconClass:String},data:()=>({node:{indeterminate:!1,checked:!1,expanded:!1},expanded:!1,childNodeRendered:!1,oldChecked:null,oldIndeterminate:null,highlightCurrent:!1}),inject:["tree"],computed:{checkboxVisible(){return this.checkOnlyLeaf?this.showCheckbox&&this.node.isLeaf:this.showCheckbox},radioVisible(){return this.checkOnlyLeaf?this.showRadio&&this.node.isLeaf:this.showRadio}},watch:{"node.indeterminate"(e){this.handleSelectChange(this.node.checked,e)},"node.checked"(e){this.handleSelectChange(e,this.node.indeterminate)},"node.expanded"(e){this.$nextTick((()=>this.expanded=e)),e&&(this.childNodeRendered=!0)}},methods:{getNodeKey(e){let t=this.tree.store.root.getChildNodes([e])[0];return d.getNodeKey(this.tree.nodeKey,t.data)},handleSelectChange(e,d){if(this.oldChecked!==e&&this.oldIndeterminate!==d){if(this.checkOnlyLeaf&&!this.node.isLeaf)return;if(this.checkboxVisible){const t=this.tree.store._getAllNodes();this.tree.$emit("check-change",{checked:e,indeterminate:d,node:this.node,data:this.node.data,checkedall:t.every((e=>e.checked))})}else this.tree.$emit("radio-change",{checked:e,node:this.node,data:this.node.data,checkedall:!1})}!this.expanded&&this.tree.expandOnCheckNode&&e&&this.handleExpandIconClick(),this.oldChecked=e,this.indeterminate=d},handleClick(){this.tree.store.setCurrentNode(this.node),this.tree.$emit("current-change",{node:this.node,data:this.tree.store.currentNode?this.tree.store.currentNode.data:null,currentNode:this.tree.store.currentNode}),this.tree.currentNode=this.node,this.tree.expandOnClickNode&&this.handleExpandIconClick(),this.tree.checkOnClickNode&&!this.node.disabled&&(this.checkboxVisible||this.radioVisible)&&this.handleCheckChange(!this.node.checked),this.tree.$emit("node-click",this.node)},handleExpandIconClick(){this.node.isLeaf||(this.expanded?(this.tree.$emit("node-collapse",this.node),this.node.collapse()):(this.node.expand(),this.tree.$emit("node-expand",this.node),this.tree.accordion&&e.index.$emit(`${this.tree.elId}-tree-node-expand`,this.node)))},handleCheckChange(d){this.node.disabled||(this.checkboxVisible?this.node.setChecked(d,!(this.tree.checkStrictly||this.checkOnlyLeaf)):this.node.setRadioChecked(d),this.$nextTick((()=>{this.tree.$emit("check",{node:this.node,data:this.node.data,checkedNodes:this.tree.store.getCheckedNodes(),checkedKeys:this.tree.store.getCheckedKeys(),halfCheckedNodes:this.tree.store.getHalfCheckedNodes(),halfCheckedKeys:this.tree.store.getHalfCheckedKeys()})})),e.index.$emit("updateKey"))},handleImageError(){this.node.icon=this.tree.defaultNodeIcon}},created(){if(!this.tree)throw new Error("Can not find node's tree.");this.node=this.tree.store.nodesMap[this.nodeId],this.highlightCurrent=this.tree.highlightCurrent,this.node.expanded&&(this.expanded=!0,this.childNodeRendered=!0);const d=(this.tree.props||{}).children||"children";this.$watch(`node.data.${d}`,(()=>{this.node.updateChildren()})),this.tree.accordion&&e.index.$on(`${this.tree.elId}-tree-node-expand`,(e=>{this.node.id!==e.id&&this.node.level===e.level&&this.node.collapse()}))},beforeDestroy(){this.$parent=null}};if(!Array){(e.resolveComponent("ly-checkbox")+e.resolveComponent("ly-tree-node"))()}const n=e._export_sfc(t,[["render",function(d,t,n,i,o,h){return e.e({a:e.o(((...e)=>h.handleExpandIconClick&&h.handleExpandIconClick(...e))),b:e.n({"is-leaf":o.node.isLeaf,expanded:!o.node.isLeaf&&o.node.expanded}),c:e.n(n.iconClass?n.iconClass:"ly-iconfont ly-icon-caret-right"),d:h.checkboxVisible||h.radioVisible},h.checkboxVisible||h.radioVisible?{e:e.o((e=>h.handleCheckChange(!o.node.checked))),f:e.p({type:h.checkboxVisible?"checkbox":"radio",checked:o.node.checked,indeterminate:o.node.indeterminate,disabled:!!o.node.disabled})}:{},{g:o.node.loading},(o.node.loading,{}),{h:o.node.icon&&o.node.icon.length>0},o.node.icon&&o.node.icon.length>0?e.e({i:-1!==o.node.icon.indexOf("/")},-1!==o.node.icon.indexOf("/")?{j:o.node.icon,k:e.o(((...e)=>h.handleImageError&&h.handleImageError(...e)))}:{l:e.n(o.node.icon)}):{},{m:e.t(o.node.label),n:o.node.isCurrent&&o.highlightCurrent?1:"",o:(o.node.level-1)*n.indent+"px",p:!n.renderAfterExpand||o.childNodeRendered},!n.renderAfterExpand||o.childNodeRendered?{q:e.f(o.node.childNodesId,((d,t,i)=>({a:h.getNodeKey(d),b:"ae593102-1-"+i,c:e.p({nodeId:d,"render-after-expand":n.renderAfterExpand,"show-checkbox":n.showCheckbox,"show-radio":n.showRadio,"check-only-leaf":n.checkOnlyLeaf,indent:n.indent,"icon-class":n.iconClass})}))),r:o.expanded}:{},{s:o.node.visible,t:o.expanded?1:"",v:o.node.visible?"":1,w:!o.node.disabled&&o.node.checked?1:"",x:e.o(((...e)=>h.handleClick&&h.handleClick(...e)))})}]]);wx.createComponent(n);