!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("@angular/material/button"),require("@angular/material/card"),require("@angular/material/dialog"),require("@angular/material/icon"),require("@iapps/ngx-dhis2-data-filter"),require("@iapps/ngx-dhis2-org-unit-filter"),require("@iapps/ngx-dhis2-period-filter"),require("@iapps/ngx-dhis2-validation-rule-group-filter"),require("@ngx-translate/core"),require("lodash"),require("@angular/material/tooltip"),require("@angular/material/tabs")):"function"==typeof define&&define.amd?define("@iapps/ngx-dhis2-selection-filters",["exports","@angular/common","@angular/core","@angular/material/button","@angular/material/card","@angular/material/dialog","@angular/material/icon","@iapps/ngx-dhis2-data-filter","@iapps/ngx-dhis2-org-unit-filter","@iapps/ngx-dhis2-period-filter","@iapps/ngx-dhis2-validation-rule-group-filter","@ngx-translate/core","lodash","@angular/material/tooltip","@angular/material/tabs"],e):e(((t=t||self).iapps=t.iapps||{},t.iapps["ngx-dhis2-selection-filters"]={}),t.ng.common,t.ng.core,t.ng.material.button,t.ng.material.card,t.ng.material.dialog,t.ng.material.icon,t["@iapps/ngx-dhis2-data-filter"],t["@iapps/ngx-dhis2-org-unit-filter"],t["@iapps/ngx-dhis2-period-filter"],t["@iapps/ngx-dhis2-validation-rule-group-filter"],t["@ngx-translate/core"],t._,t.ng.material.tooltip,t.ng.material.tabs)}(this,(function(t,e,i,n,a,o,r,l,s,d,c,u,p,f,g){"use strict";
/*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */var m=function(){return(m=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var a in e=arguments[i])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};function h(t,e,i,n){var a,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(a=t[l])&&(r=(o<3?a(r):o>3?a(e,i,r):a(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r}Object.create;function x(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,a,o=i.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)r.push(n.value)}catch(t){a={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(a)throw a.error}}return r}function b(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(x(arguments[e]));return t}Object.create;function y(t){switch(t){case"ou":return"filters";case"pe":return"rows";case"dx":return"columns";default:return"filters"}}var v={showDataFilter:!0,showPeriodFilter:!0,showValidationRuleGroupFilter:!0,showOrgUnitFilter:!0,showLayout:!1,showDynamicDimension:!0,orgUnitFilterConfig:{singleSelection:!0}};function F(t,e){var i=m(m({},v),t||{});if(i.allowStepSelection){var n=t.stepSelections||[];p.each(n,(function(t,a){var o;if(a>0){var r=p.find(e,["dimension",n[a-1]]),l=function(t){switch(t){case"dx":return"disableDataFilter";case"pe":return"disablePeriodFilter";case"vrg":return"disableValidationRuleGroupFilter";case"ou":return"disableOrgUnitFilter";default:return}}(t);l&&(i=m(m({},i),((o={})[l]=!r||0===(r.items||[]).length,o)))}}))}return i}function O(t,e){var i=p.find(t,["dimension",e.dimension]),n=i?t.indexOf(i):-1;return i?b(t.slice(0,n),[m(m({},i),e)],t.slice(n+1)):t?b(t,[e]):[e]}var S=function(){function t(t,e){this.dialogRef=t,this.data=e}var e,n;return t.prototype.ngOnInit=function(){this._setSelectionParameters()},t.prototype.onFilterUpdate=function(t,e){var i=this;if("LAYOUT"===e){var n=p.flatten(p.map(p.keys(t),(function(e){return p.map(t[e]||[],(function(t,i){return m(m({},t),{layout:e,layoutOrder:i})}))})));this.data.dataSelections=p.sortBy(p.map(this.data.dataSelections||[],(function(t){var e=p.find(n,["value",t.dimension]);return m(m({},t),e?{changed:!0,layout:e.layout,layoutOrder:e.layoutOrder}:{changed:!0})})),"layoutOrder")}else p.isArray(t)?(this.data.dataSelections=p.filter(this.data.dataSelections||[],(function(t){return-1!==["ou","pe","dx","co","dy"].indexOf(t.dimension)})),p.each(t,(function(t){i.data.dataSelections=p.find(i.data.dataSelections,["dimension",t.dimension])?b(O(i.data.dataSelections||[],t)):b(i.data.dataSelections||[],[m(m({},t),{layout:t.layout||y(t.dimension)})])}))):this.data.dataSelections=p.find(this.data.dataSelections,["dimension",t.dimension])?b(O(this.data.dataSelections||[],t)):b(this.data.dataSelections||[],[m(m({},t),{layout:t.layout||y(t.dimension)})]);this._setSelectionParameters()},t.prototype.onUpdate=function(t){t.stopPropagation(),this.dialogRef.close(this.data.dataSelections)},t.prototype._setSelectionParameters=function(){this.data.selectionFilterConfig=F(this.data.selectionFilterConfig,this.data.dataSelections);var t=p.find(this.data.dataSelections,["dimension","dx"]);this.data.selectedData=t?t.items:[],this.data.selectedDynamicDimensions=p.filter(this.data.dataSelections||[],(function(t){return-1===["ou","pe","dx","co","dy"].indexOf(t.dimension)})),this.data.selectedDataGroups=t?t.groups:[];var e=p.find(this.data.dataSelections,["dimension","vrg"]);this.data.selectedValidationRuleGroups=e?e.items:[];var i=p.find(this.data.dataSelections,["dimension","pe"]);this.data.selectedPeriods=i?i.items:[];var n,a=p.find(this.data.dataSelections,["dimension","ou"]);this.data.selectedOrgUnits=a?a.items:[],this.data.selectedValidationDataElements=(n=t?t.items:[],p.uniq(p.flatten((n||[]).map((function(t){return(t.dataElements||[]).filter((function(t){return"dataElement"===t.metadataType})).map((function(t){return t.id.split(".")[0]}))})).filter((function(t){return t})))));var o=p.find(this.data.dataSelections,["dimension","vrg"]);this.data.lowestPeriodType=o&&o.periodType?o.periodType.id:""},t.ctorParameters=function(){return[{type:o.MatDialogRef},{type:void 0,decorators:[{type:i.Inject,args:[o.MAT_DIALOG_DATA]}]}]},t=h([i.Component({selector:"lib-selection-dialog",template:'<mat-dialog-content *ngIf="data">\n    <mat-tab-group dynamicHeight="true">\n        <mat-tab *ngIf="data?.selectionFilterConfig?.showDataFilter">\n            <ng-template mat-tab-label>\n                <mat-icon class="tab-icon">dns</mat-icon>\n                <span>Data</span>\n            </ng-template>\n            <div class="selection-filter-content">\n                <ngx-dhis2-data-filter [selectedItems]="data.selectedData"\n                    [dataFilterConfig]="data?.selectionFilterConfig?.dataFilterConfig"\n                    (close)="onFilterUpdate($event, \'DATA\')" (update)="onFilterUpdate($event, \'DATA\')">\n                </ngx-dhis2-data-filter>\n            </div>\n        </mat-tab>\n        <mat-tab *ngIf="data?.selectionFilterConfig?.showValidationRuleGroupFilter">\n            <ng-template mat-tab-label>\n                <mat-icon class="tab-icon">warning</mat-icon>\n                <span class="button-text">Validation</span>\n            </ng-template>\n            <div class="selection-filter-content">\n                <lib-ngx-dhis2-validation-rule-filter [dataSelection]="data.selectedValidationDataElements"\n                    [selectedVRGs]=\'data.selectedValidationRuleGroups\'\n                    (update)="onFilterUpdate($event, \'VALIDATIONRULEGROUP\')"\n                    (close)="onFilterUpdate($event, \'VALIDATIONRULEGROUP\')">\n                </lib-ngx-dhis2-validation-rule-filter>\n            </div>\n        </mat-tab>\n        <mat-tab *ngIf="data?.selectionFilterConfig?.showPeriodFilter">\n            <ng-template mat-tab-label>\n                <mat-icon class="tab-icon">watch_later</mat-icon>\n                <span class="button-text">Period</span>\n            </ng-template>\n            <div class="selection-filter-content">\n                <ngx-dhis2-period-filter [selectedPeriods]="data.selectedPeriods"\n                    [selectedPeriodType]="data.selectionFilterConfig.selectedPeriodType"\n                    [periodFilterConfig]="data.selectionFilterConfig.periodFilterConfig"\n                    (close)="onFilterUpdate($event, \'PERIOD\')" (update)="onFilterUpdate($event, \'PERIOD\')">\n                </ngx-dhis2-period-filter>\n            </div>\n        </mat-tab>\n        <mat-tab *ngIf="data?.selectionFilterConfig?.showOrgUnitFilter">\n            <ng-template mat-tab-label>\n                <mat-icon class="tab-icon">device_hub</mat-icon>\n                <span class="button-text">Organisation unit</span>\n            </ng-template>\n            <div class="selection-filter-content">\n                <ngx-dhis2-org-unit-filter [orgUnitFilterConfig]="data.selectionFilterConfig?.orgUnitFilterConfig"\n                    [selectedOrgUnitItems]="data.selectedOrgUnits" (orgUnitUpdate)="onFilterUpdate($event, \'ORG_UNIT\')"\n                    (orgUnitClose)="onFilterUpdate($event, \'ORG_UNIT\')">\n                </ngx-dhis2-org-unit-filter>\n            </div>\n        </mat-tab>\n    </mat-tab-group>\n</mat-dialog-content>\n<mat-dialog-actions align="end">\n    <button mat-stroked-button (click)="onUpdate($event)">\n        <mat-icon>close</mat-icon>\n        <span class="button-text">Close</span>\n    </button>\n    <button mat-flat-button color="primary" (click)="onUpdate($event)">\n        <mat-icon>refresh</mat-icon>\n        <span class="button-text">Update</span>\n    </button>\n</mat-dialog-actions>\n',styles:[".button-text{margin-left:5px}.tab-icon{margin-right:15px}::ng-deep .mat-tab-label{justify-content:space-between!important;padding:0 10px!important}.selection-filter-content{padding-top:15px}"]}),(e=1,n=i.Inject(o.MAT_DIALOG_DATA),function(t,i){n(t,i,e)})],t)}(),U=function(){function t(t){this.dialog=t,this.selectionFilterUpdate=new i.EventEmitter}return t.prototype.ngOnInit=function(){this.dataSelections&&p.isArray(this.dataSelections)||(this.dataSelections=[])},t.prototype.onOpenFilter=function(t){var e=this;t.stopPropagation(),this.dialog.open(S,{width:"50%",data:{dataSelections:this.dataSelections,layout:this.layout,selectionFilterConfig:this.selectionFilterConfig}}).afterClosed().subscribe((function(t){e.selectionFilterUpdate.emit(t)}))},t.ctorParameters=function(){return[{type:o.MatDialog}]},h([i.Input()],t.prototype,"dataSelections",void 0),h([i.Input()],t.prototype,"layout",void 0),h([i.Input()],t.prototype,"selectionFilterConfig",void 0),h([i.Output()],t.prototype,"selectionFilterUpdate",void 0),t=h([i.Component({selector:"ngx-dhis2-selection-filters",template:'<div class="selection-filter-container">\n  \x3c!--selection filter header--\x3e\n  <div class="selection-filter-header">\n    <button mat-stroked-button (click)="onOpenFilter($event)"\n      [matTooltip]="\'Filter by Different dimensions\' | translate">\n      <mat-icon [style.color]="\'gray\'">filter_alt</mat-icon>\n      <span class="filter-button-title">Filter</span>\n    </button>\n  </div>\n  \x3c!--end of selection filter header--\x3e\n</div>\n',styles:[".selection-filter-container{position:relative}.selection-filter-header{display:flex}.filter-button-title{margin-left:5px;margin-right:5px}.selection-filter-btn{outline:0;display:flex;align-items:center}.selection-filter-btn:disabled{cursor:not-allowed;opacity:.4}.selection-filter-btn img{height:13px}.filter-control-btn{width:50px;padding-left:10px}.selection-filter-name{font-size:12px;margin-left:3px;margin-right:3px;display:flex;align-items:center;height:30px}.selection-filter-btn-list{display:flex;justify-content:space-around;margin-left:3px}.selection-filter-btn-list>button{margin-left:3px}.selection-filter-btn-list>button>img{height:13px}.selection-filter-btn-list>button:first-child{margin-left:0}.active-filter{background-color:#f1f1f1}.selection-filter-body{position:absolute;top:45px;padding:5px;width:600px;min-height:350px;z-index:1000}.arrow-up{transform:rotate(180deg)}.summary-selection{margin-left:5px;margin-right:5px;font-size:9px}@media (max-width:500px){.selection-filter-body{width:95%}}"]})],t)}(),D=function(){function t(){}return t.prototype.transform=function(t,e,i){switch(void 0===i&&(i=2),e){case"ou":var n=this._getSelectionNames(this._getLevelOrGroupList(t)).join(", "),a=this._updateWithMaxToShow(this._getSelectionNames(this._getOrgUnitList(t)),i);return""!==n?n+" in "+a:a;default:return this._updateWithMaxToShow(this._getSelectionNames(t),i)}},t.prototype._getLevelOrGroupList=function(t){return(t||[]).filter((function(t){return-1!==t.type.indexOf("LEVEL")||-1!==t.type.indexOf("GROUP")}))},t.prototype._getOrgUnitList=function(t){return(t||[]).filter((function(t){return-1===t.type.indexOf("LEVEL")&&-1===t.type.indexOf("GROUP")}))},t.prototype._getSelectionNames=function(t){return(t||[]).map((function(t){return t.name||""}))},t.prototype._updateWithMaxToShow=function(t,e){if(void 0===e&&(e=-1),-1===e||t.length<=e)return t.join(", ");var i=" and "+(t.length-e)+" more";return(t||[]).slice(0,e).join(", ")+i},t=h([i.Pipe({name:"summarizeSelection"})],t)}(),w=function(){function t(){}return t=h([i.NgModule({imports:[e.CommonModule,u.TranslateModule.forChild(),s.NgxDhis2OrgUnitFilterModule,l.NgxDhis2DataFilterModule,d.NgxDhis2PeriodFilterModule,c.NgxDhis2ValidationRuleFilterModule,n.MatButtonModule,a.MatCardModule,o.MatDialogModule,r.MatIconModule,f.MatTooltipModule,g.MatTabsModule],declarations:[U,D,S],entryComponents:[S],exports:[U]})],t)}();t.NgxDhis2SelectionFiltersModule=w,t.ɵa=U,t.ɵb=D,t.ɵc=S,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=iapps-ngx-dhis2-selection-filters.umd.min.js.map