import{Component,ViewEncapsulation,ChangeDetectionStrategy,Inject,forwardRef,ChangeDetectorRef,Input,EventEmitter,ElementRef,Output,ContentChildren,NgModule}from"@angular/core";import{trigger,state,style,transition,animate}from"@angular/animations";import{CommonModule}from"@angular/common";import{PrimeTemplate,SharedModule}from"primeng/api";import{Subject}from"rxjs";class OrganizationChartNode{constructor(e,t){this.cd=t,this.chart=e,this.subscription=this.chart.selectionSource$.subscribe(()=>{this.cd.markForCheck()})}get leaf(){return 0!=this.node.leaf&&!(this.node.children&&this.node.children.length)}get colspan(){return this.node.children&&this.node.children.length?2*this.node.children.length:null}onNodeClick(e,t){this.chart.onNodeClick(e,t)}toggleNode(e,t){t.expanded=!t.expanded,t.expanded?this.chart.onNodeExpand.emit({originalEvent:e,node:this.node}):this.chart.onNodeCollapse.emit({originalEvent:e,node:this.node}),e.preventDefault()}isSelected(){return this.chart.isSelected(this.node)}ngOnDestroy(){this.subscription.unsubscribe()}}OrganizationChartNode.decorators=[{type:Component,args:[{selector:"[pOrganizationChartNode]",template:'\n
\n \n \n \n {{node.label}} \n \n \n \n \n \n \n \n | \n
\n \n \n \n | \n
\n \n \n \n \n | \n \n 1">\n \n | \n | \n \n \n
\n \n \n \n | \n
\n \n ',animations:[trigger("childState",[state("in",style({opacity:1})),transition("void => *",[style({opacity:0}),animate(150)]),transition("* => void",[animate(150,style({opacity:0}))])])],encapsulation:ViewEncapsulation.None,changeDetection:ChangeDetectionStrategy.OnPush,styles:[".p-organizationchart-table{border-collapse:separate;border-spacing:0;margin:0 auto}.p-organizationchart-table>tbody>tr>td{padding:0 .75rem;text-align:center;vertical-align:top}.p-organizationchart-node-content{display:inline-block;position:relative}.p-organizationchart-node-content .p-node-toggler{-ms-user-select:none;-webkit-user-select:none;bottom:-.75rem;cursor:pointer;height:1.5rem;left:50%;margin-left:-.75rem;position:absolute;user-select:none;width:1.5rem;z-index:2}.p-organizationchart-node-content .p-node-toggler .p-node-toggler-icon{position:relative;top:.25rem}.p-organizationchart-line-down{height:20px;margin:0 auto;width:1px}.p-organizationchart-line-left,.p-organizationchart-line-right{border-radius:0}.p-organizationchart-selectable-node{cursor:pointer}.p-organizationchart .p-organizationchart-node-hidden{display:none}.p-organizationchart-preservespace .p-organizationchart-node-hidden{display:inherit;visibility:hidden}"]}]}],OrganizationChartNode.ctorParameters=(()=>[{type:void 0,decorators:[{type:Inject,args:[forwardRef(()=>OrganizationChart)]}]},{type:ChangeDetectorRef}]),OrganizationChartNode.propDecorators={node:[{type:Input}],root:[{type:Input}],first:[{type:Input}],last:[{type:Input}]};class OrganizationChart{constructor(e,t){this.el=e,this.cd=t,this.preserveSpace=!0,this.selectionChange=new EventEmitter,this.onNodeSelect=new EventEmitter,this.onNodeUnselect=new EventEmitter,this.onNodeExpand=new EventEmitter,this.onNodeCollapse=new EventEmitter,this.selectionSource=new Subject,this.selectionSource$=this.selectionSource.asObservable()}get selection(){return this._selection}set selection(e){this._selection=e,this.initialized&&this.selectionSource.next()}get root(){return this.value&&this.value.length?this.value[0]:null}ngAfterContentInit(){this.templates.length&&(this.templateMap={}),this.templates.forEach(e=>{this.templateMap[e.getType()]=e.template}),this.initialized=!0}getTemplateForNode(e){return this.templateMap?e.type?this.templateMap[e.type]:this.templateMap.default:null}onNodeClick(e,t){let n=e.target;if((!n.className||-1===n.className.indexOf("p-node-toggler")&&-1===n.className.indexOf("p-node-toggler-icon"))&&this.selectionMode){if(!1===t.selectable)return;let n=this.findIndexInSelection(t),i=n>=0;"single"===this.selectionMode?i?(this.selection=null,this.onNodeUnselect.emit({originalEvent:e,node:t})):(this.selection=t,this.onNodeSelect.emit({originalEvent:e,node:t})):"multiple"===this.selectionMode&&(i?(this.selection=this.selection.filter((e,t)=>t!=n),this.onNodeUnselect.emit({originalEvent:e,node:t})):(this.selection=[...this.selection||[],t],this.onNodeSelect.emit({originalEvent:e,node:t}))),this.selectionChange.emit(this.selection),this.selectionSource.next()}}findIndexInSelection(e){let t=-1;if(this.selectionMode&&this.selection)if("single"===this.selectionMode)t=this.selection==e?0:-1;else if("multiple"===this.selectionMode)for(let n=0;n\n \n \n ',changeDetection:ChangeDetectionStrategy.OnPush}]}],OrganizationChart.ctorParameters=(()=>[{type:ElementRef},{type:ChangeDetectorRef}]),OrganizationChart.propDecorators={value:[{type:Input}],style:[{type:Input}],styleClass:[{type:Input}],selectionMode:[{type:Input}],preserveSpace:[{type:Input}],selection:[{type:Input}],selectionChange:[{type:Output}],onNodeSelect:[{type:Output}],onNodeUnselect:[{type:Output}],onNodeExpand:[{type:Output}],onNodeCollapse:[{type:Output}],templates:[{type:ContentChildren,args:[PrimeTemplate]}]};class OrganizationChartModule{}OrganizationChartModule.decorators=[{type:NgModule,args:[{imports:[CommonModule],exports:[OrganizationChart,SharedModule],declarations:[OrganizationChart,OrganizationChartNode]}]}];export{OrganizationChart,OrganizationChartModule,OrganizationChartNode};