import{a as $}from"./chunk-3BUU6LNF.js";import{b as M}from"./chunk-5DQKN4SL.js";import{a as v}from"./chunk-D4RZOGGF.js";import{a as f,b as l,c as P,e as G}from"./chunk-5KCUTXXV.js";import"./chunk-LAJI7RPC.js";import{Hc as A,Ic as F,ee as j}from"./chunk-NVJ2ZZFT.js";import{Aa as c,Ba as I,Nc as w,Pd as _,Qd as O,Qf as z,Se as N,Te as V,Ue as R,_a as k,ab as p,bb as C,bh as U,cb as u,db as g,dc as D,dd as h,fb as S,gb as T,ha as x,ng as m,wa as y,wc as E,ya as d}from"./chunk-SKPDQO4E.js";var B=`<div class="row justify-content-center">
    <div class="col-xl-8 col-lg-12 col-md-12">
        <div class="row">
            <div class="col-12 mb-3">
                <span class="text-md">{{sessionService.currentOrganizationName}}</span>
            </div>
        </div>
        <div class="row" [@listAnimation]="definedListItems.length">
            <div class="col-12" *ngFor="let definedListItem of definedListItems">
                <armon-management-defined-list-editor [definedListItem]="definedListItem"></armon-management-defined-list-editor>
            </div>
        </div>
    </div>
</div>`;var q=`.justify-content-center{-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}.justify-content-flex-end{-webkit-box-pack:end;-moz-box-pack:end;-webkit-flex-pack:end;-ms-flex-pack:end;-moz-justify-content:flex-end;-webkit-justify-content:flex-end;justify-content:flex-end}.card-footer{padding:.28rem .7rem}.alert{font-size:.756rem}@media screen and (min-width: 992px){.modal-xxl{max-width:1640px}}@media screen and (min-width: 1200px){.modal-xxxl{max-width:1860px}}.modal-fs{max-width:none;position:absolute;margin:auto;inset:16px;height:100vh;display:flex}.btn-link{text-decoration:none}.btn-link:hover{text-decoration:underline}.invalid-feedback{margin-top:0!important;font-size:.672rem!important}.section-title{width:100%;padding:6px;border-bottom:solid 1px rgba(102,102,102,.2);color:#666}
`;var J=`<ng-container *ngIf="visibleComponent">
    <div class="card mb-3">
        <div class="card-header p-3 d-flex align-items-center">
            <span class="text-md flex-grow-1">{{definedListItem.title|translate}}<span
                    *ngIf="definedList?.values?.length" class="ms-2">({{definedList?.values?.length}})</span></span>
            <button class="btn btn-sm btn-outline-primary ms-auto" (click)="onAddClicked($event)"
                [disabled]="definedListItem.relatedType && !selectedRelated">
                <cds-icon shape="plus-circle" solid class="cds-icon-18 me-1"></cds-icon>
                {{'BUTTON.ADD'|translate}}
            </button>
        </div>
        <div class="card-body p-3">
            <div class="row" *ngIf="definedListItem && definedListItem.relatedType">
                <div class="col-xl-4 col-lg-4 col-md-6 col-12 mb-4 d-flex align-items-baseline">
                    <label class="me-2 mb-1">{{definedListItem.relatedTypeTitle | translate}}</label>
                    <armon-user-defined-list-input [type]="definedListItem.relatedType" class="flex-grow-1"
                        autoSelectFirstValue="true" [(ngModel)]="selectedRelated"
                        (ngModelChange)="onSelectedRelatedChanged($event)">
                    </armon-user-defined-list-input>
                </div>
            </div>
            <div class="row mhs-10 align-content-start" *ngIf="definedList && definedList.values.length > 0"
                [@listAnimationFastest]="definedList.values.length">
                <ng-container *ngFor="let listValue of definedList.values">
                    <div class="col-xl-3 col-lg-4 col-md-6 col-sm-12 mb-2">
                        <armon-management-defined-list-editor-item [listValue]="listValue" [definedList]="definedList"
                            [definedListItem]="definedListItem" (clicked)="onItemClicked($event, listValue)"
                            (deleteClicked)="onDeleteItemClicked($event, listValue)">
                        </armon-management-defined-list-editor-item>
                    </div>
                </ng-container>
            </div>
            <div class="row" *ngIf="definedList && definedList.values.length ==0">
                <div class="col-12">
                    <nz-empty nzNotFoundImage="simple" [nzNotFoundContent]="null"></nz-empty>
                </div>
            </div>
        </div>
    </div>
</ng-container>

<ng-template #formDrawerTemplate let-data let-drawerRef="formDrawerRef">
    <div class="row my-3">
        <div class="col-12">
            <span class="text-lg">{{definedListItem.title|translate}}</span>
        </div>
    </div>
    <form [formGroup]="form" (keyup.enter)="onFormSaveClicked($event)">
        <ng-container [ngSwitch]="definedListItem.valueType">
            <!-- STRING -->
            <ng-container *ngSwitchCase="1">
                <div class="row">
                    <div class="col-12">
                        <label class="report-form-label">{{'COMMON.VALUE'|translate}}</label>
                        <input [formControl]="form.get('stringValue')" type="text"
                            [ngClass]="{'is-invalid': form.get('stringValue').invalid}"
                            class="form-control form-control-sm">
                        <ng-template
                            *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('stringValue'), isArray:false}">
                        </ng-template>
                    </div>
                </div>
            </ng-container>
            <!-- JSON -->
            <ng-container *ngSwitchCase="5">
                <ng-container [ngSwitch]="definedListItem.type">
                    <!-- ORG UNIT TYPE -->
                    <ng-container *ngSwitchCase="6">
                        <div class="row">
                            <div class="col-12 mb-2">
                                <label class="report-form-label">{{'COMMON.VALUE'|translate}}
                                    ({{'LANGUAGE.TURKISH'|translate}})</label>
                                <input [formControl]="form.get('caption_tr')" type="text"
                                    [ngClass]="{'is-invalid': form.get('caption_tr').invalid}"
                                    class="form-control form-control-sm">
                                <ng-template
                                    *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('caption_tr'), isArray:false}">
                                </ng-template>
                            </div>
                            <div class="col-12 mb-2">
                                <label class="report-form-label">{{'COMMON.VALUE'|translate}}
                                    ({{'LANGUAGE.ENGLISH'|translate}})</label>
                                <input [formControl]="form.get('caption_en')" type="text"
                                    [ngClass]="{'is-invalid': form.get('caption_en').invalid}"
                                    class="form-control form-control-sm">
                                <ng-template
                                    *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('caption_en'), isArray:false}">
                                </ng-template>
                            </div>
                            <div class="col-12 mb-2">
                                <label class="report-form-label w-100">{{'USERGROUP.COLOR'|translate}}</label>
                                <nz-color-picker id="hexcode-input" [formControl]="form.get('color')" class="mb-3" nzShowText nzDisabledAlpha="true"
                                nzFormat="hex"></nz-color-picker>
                                <ng-template
                                    *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('color'), isArray:false}">
                                </ng-template>
                            </div>
                        </div>
                    </ng-container>
                </ng-container>
            </ng-container>
        </ng-container>
    </form>
    <div class="row mt-3">
        <div class="col-12 d-flex justify-content-end">
            <button class="btn btn-sm btn-danger me-auto" *ngIf="selectedListValue"
                (click)="onFormDeleteClicked($event)">{{'BUTTON.DELETE'|translate}}</button>
            <button class="btn btn-sm btn-outline-primary me-2"
                (click)="onFormCancelClicked($event)">{{'BUTTON.CANCEL'|translate}}</button>
            <button class="btn btn-sm btn-primary" [disabled]="form.invalid"
                (click)="onFormSaveClicked($event)">{{'BUTTON.SAVE'|translate}}</button>
        </div>
    </div>
</ng-template>


<!-- FORM FIELD VALIDATION -->
<ng-template #controlValidationTemplate let-form let-control="control" let-isArray="isArray">
    <ng-container *ngIf="control.errors">
        <div class="invalid-feedback" style="display: initial;">
            <span
                *ngIf="control.errors.required">{{(isArray?'VALIDATION.MIN_ONE_SELECTED':'VALIDATION.REQUIRED')|translate}}</span>
            <span *ngIf="control.errors.ip">{{'VALIDATION.IP_V4_OR_V6'|translate}}</span>
            <span *ngIf="control.errors.numeric">{{'VALIDATION.POSITIVE_NUMBER'|translate}}</span>
            <span *ngIf="control.errors.minNumber" [translate]="'VALIDATION.MIN_VALUE'"
                [translateParams]="{min: control.errors.minNumber.refValues[1]}"></span>
            <span *ngIf="control.errors.maxNumber" [translate]="'VALIDATION.MAX_VALUE'"
                [translateParams]="{max: control.errors.maxNumber.refValues[1]}"></span>
            <span *ngIf="control.errors.unique">{{'VALIDATION.UNIQUE'|translate}}</span>
        </div>
    </ng-container>
</ng-template>`;var H=`.justify-content-center{-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}.justify-content-flex-end{-webkit-box-pack:end;-moz-box-pack:end;-webkit-flex-pack:end;-ms-flex-pack:end;-moz-justify-content:flex-end;-webkit-justify-content:flex-end;justify-content:flex-end}.card-footer{padding:.28rem .7rem}.alert{font-size:.756rem}@media screen and (min-width: 992px){.modal-xxl{max-width:1640px}}@media screen and (min-width: 1200px){.modal-xxxl{max-width:1860px}}.modal-fs{max-width:none;position:absolute;margin:auto;inset:16px;height:100vh;display:flex}.btn-link{text-decoration:none}.btn-link:hover{text-decoration:underline}.invalid-feedback{margin-top:0!important;font-size:.672rem!important}
`;var Q=`<div class="list-value-container d-flex align-items-center b-1 p-2 cursor-pointer" (click)="onClicked($event)">
    <ng-container [ngSwitch]="definedListItem.valueType">
        <!-- STRING -->
        <ng-container *ngSwitchCase="1">
            <span class="text-sm line-height-sm">{{listValue.value}}</span>
        </ng-container>
        <ng-container *ngSwitchCase="5">
            <ng-container [ngSwitch]="definedListItem.type">
                <!-- ORG UNIT TYPE -->
                <ng-container *ngSwitchCase="6">
                    <span class="text-sm line-height-sm">
                        <cds-icon shape="stop" solid class="cds-icon-18 me-1" [ngStyle]="{'color': listValue.value.color}">
                        </cds-icon>{{listValue.value.caption_tr}} - {{listValue.value.caption_en}}
                    </span>
                </ng-container>
            </ng-container>
        </ng-container>
    </ng-container>
    <div class="delete-button p-1">
        <cds-icon shape="times-circle" solid class="cds-icon-18 color-error cursor-pointer" click-stop-propagation
            title="{{'BUTTON.DELETE'|translate}}" (click)="onDeleteClicked($event)" click-stop-propagation></cds-icon>
    </div>
</div>`;var W=`.justify-content-center{-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}.justify-content-flex-end{-webkit-box-pack:end;-moz-box-pack:end;-webkit-flex-pack:end;-ms-flex-pack:end;-moz-justify-content:flex-end;-webkit-justify-content:flex-end;justify-content:flex-end}.card-footer{padding:.28rem .7rem}.alert{font-size:.756rem}@media screen and (min-width: 992px){.modal-xxl{max-width:1640px}}@media screen and (min-width: 1200px){.modal-xxxl{max-width:1860px}}.modal-fs{max-width:none;position:absolute;margin:auto;inset:16px;height:100vh;display:flex}.btn-link{text-decoration:none}.btn-link:hover{text-decoration:underline}.invalid-feedback{margin-top:0!important;font-size:.672rem!important}.list-value-container{position:relative;background-color:initial;-webkit-border-radius:.375rem;-moz-border-radius:.375rem;border-radius:.375rem}.list-value-container:hover{background-color:#e1f1f6}.list-value-container:hover .delete-button{visibility:initial}.list-value-container .delete-button{visibility:hidden;position:absolute;right:-.7rem;top:-.7rem}
`;var ne=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},b=class{listValue;definedListItem;definedList;clicked=new x;deleteClicked=new x;constructor(){}ngOnInit(){}ngOnDestroy(){}onClicked(e){this.clicked.emit(e)}onDeleteClicked(e){this.deleteClicked.emit(e)}static ctorParameters=()=>[];static propDecorators={listValue:[{type:c}],definedListItem:[{type:c}],definedList:[{type:c}],clicked:[{type:I}],deleteClicked:[{type:I}]}};b=ne([d({selector:"armon-management-defined-list-editor-item",template:Q,standalone:!0,imports:[u,g,S,O,h],styles:[W]})],b);var oe=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},L=class{organizationUnitService;drawerService;interactionService;formBuilder;visibleComponent=!1;definedListItem;definedList;selectedRelated;editMode=!1;form;formDrawerTemplate;formDrawer;selectedListValue;constructor(e,t,n,o){this.organizationUnitService=e,this.drawerService=t,this.interactionService=n,this.formBuilder=o}ngOnInit(){this.definedListItem.relatedType||this.getList(),this.visibleComponent=!0}ngOnDestroy(){}getList(){let e=new A;e.type=this.definedListItem.type,this.selectedRelated&&(e.relatedValueId=this.selectedRelated.id),this.organizationUnitService.getUserDefinedList(e).subscribe(t=>{this.selectedRelated&&(t.relatedListValue=this.selectedRelated,t.relatedListId=this.selectedRelated.id),this.definedList=t})}upsertListValue(e){let t=new F;this.editMode&&(t.id=this.selectedListValue.id),t.value=e,this.definedList.relatedListId&&(t.relatedValueId=this.definedList.relatedListId),this.organizationUnitService.upsertUserDefinedListValue(this.definedList.id,t).subscribe(n=>{this.editMode&&this.selectedListValue&&(this.selectedListValue.value=e),this.interactionService.showMessage("DEFINED_LIST.UPSERT_COMPLETED",null,w.Success),this.formDrawer.close(),this.getList()})}onSelectedRelatedChanged(){this.selectedRelated&&this.getList()}onAddClicked(e){this.editMode=!1,this.selectedListValue=null,this.setFormValue(this.getEmptyFormValue()),this.showFormDrawer()}onItemClicked(e,t){this.selectedListValue=t,this.editMode=!0,this.setFormValue(this.getFormValue(t)),this.showFormDrawer()}onDeleteItemClicked(e,t){let n;switch(this.definedListItem.valueType){case l.JSON:n=t.value.caption_tr+"/"+t.value.caption_en;break;default:n=t.value;break}this.interactionService.showDialog("DEFINED_LIST.DELETE","DEFINED_LIST.DELETE_VALUE",null,{value:n},!0,"BUTTON.DELETE","",!0,()=>{this.organizationUnitService.deleteUserDefinedListValue(this.definedList.id,t.id).subscribe(o=>{this.interactionService.showMessage("DEFINED_LIST.DELETE_COMPLETED",null,w.Success),this.getList()})})}createForm(){if(!this.form)switch(this.definedListItem.valueType){case l.String:this.form=this.formBuilder.group({stringValue:[null,m.required()]});break;case l.JSON:switch(this.definedListItem.type){case f.OrganizationUnitType:this.form=this.formBuilder.group({caption_tr:[null,m.required()],caption_en:[null,m.required()],color:[null,m.required()]});break}break}}getEmptyFormValue(){switch(this.definedListItem.valueType){case l.String:return{stringValue:null};case l.JSON:switch(this.definedListItem.type){case f.OrganizationUnitType:return{caption_tr:null,caption_en:null,color:"#996600"}}break}}getFormValue(e){switch(this.definedListItem.valueType){case l.String:return{stringValue:e.value};case l.JSON:switch(this.definedListItem.type){case f.OrganizationUnitType:return e.value}break}}setFormValue(e){this.createForm(),this.form.setValue(e)}showFormDrawer(){this.formDrawer=this.drawerService.create({nzContent:this.formDrawerTemplate,nzClosable:!1,nzWidth:E(!1),nzContentParams:{value:""}})}onFormDeleteClicked(e){this.formDrawer.close(),setTimeout(()=>{this.onDeleteItemClicked(null,this.selectedListValue)},300)}onFormCancelClicked(e){this.formDrawer.close()}onFormSaveClicked(e){if(!this.form.invalid)switch(this.definedListItem.valueType){case l.String:this.upsertListValue(this.form.get("stringValue").value);break;case l.JSON:switch(this.definedListItem.type){case f.OrganizationUnitType:this.upsertListValue(this.form.value);break}break}}static ctorParameters=()=>[{type:j},{type:M},{type:z},{type:N}];static propDecorators={definedListItem:[{type:c}],formDrawerTemplate:[{type:y,args:["formDrawerTemplate"]}]}};L=oe([d({selector:"armon-management-defined-list-editor",template:J,animations:v,standalone:!0,imports:[C,G,V,p,b,U,R,u,g,$,k,T,h],styles:[H]})],L);var re=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},Y=class{sessionService;subscriptionLoginState;definedListItems=[];constructor(e){this.sessionService=e}ngOnInit(){this.initializeSubscriptions(),this.definedListItems=D(P)}ngOnDestroy(){this.subscriptionLoginState.unsubscribe()}initializeSubscriptions(){this.subscriptionLoginState=this.sessionService.onLoginStatusChanged.subscribe(e=>{})}static ctorParameters=()=>[{type:_}]};Y=re([d({selector:"armon-management-defined-list",template:B,animations:v,standalone:!0,imports:[p,L],styles:[q]})],Y);export{Y as ManageDefinedListComponent};
