import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { WorklistMainService } from '../service/work-list.main.service';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { TextAreaInput } from 'src/app/uI-elements/text-area.input';

@Component({
  selector: 'app-apply-action-modal',
  templateUrl: './apply-action-modal.component.html',
  styleUrls: ['./apply-action-modal.component.scss'],
})
export class ApplyActionModalComponent implements OnInit {
  private textArea: TextAreaInput;
  getpassResAttr: any;
  getPassNotificationDetails: any;
  getPassNotification: any;

  constructor( private ts: TranslatorService,private modalCtrl: ModalController, private cs: CommonService,public worklistMainService: WorklistMainService,
    ) {
      
      this.getPassNotificationDetails = this.cs.sharedService.getSharedData('passNotificationInfo');
      this.getpassResAttr = this.cs.sharedService.getSharedData('passResAttr');
      this.getPassNotification = this.cs.sharedService.getSharedData('ApplyActionModalPage');

      
     }

  ngOnInit() {
    document.getElementById("notificationDynamicFields").innerHTML="";
    console.log(this.getPassNotificationDetails);
    //this.applyAction(this.getPassNotificationDetails);
    this.notificationDynamicFields(this.getpassResAttr);
  }

  applyAction() {
    this.worklistMainService
      .actionButton(this.getPassNotification)
      .subscribe((result: any) => {
        this.handleApplayActionResult(result);
      });
  }

  handleApplayActionResult(result) {
    if (this.cs.validResponse(result)) {
      if (result.MessageStatus == 1) {
        // this.navCtrl.push("HomePage");
        //this.common.openHome();
        //this.common.openNotificationPage();
        //   for( var i = 0; i < this.notificationArray.length; i++){ 
        //     if ( this.notificationArray[i].ROW_NUM === this.getPassNotificationDetails.ROW_NUM) {
        //       this.notificationArray.splice(i, 1); 
        //     }
        //  }
      //////////////  this.getNotificationCountAfterSubmit();
      /////////////   this.nextNotfification();
      }
    } // valid it
  }

  notificationDynamicFields(notificationAttr){
    const containerId = 'notificationDynamicFields';
    for(let i=0;i<notificationAttr.length;i++){
      if(notificationAttr[i].ATTRIBUTE_TYPE=="VARCHAR2"){
        this.textArea = new TextAreaInput(notificationAttr[i].ATTRIBUTE_DISPLAY_NAME, notificationAttr[i].ATTRIBUTE_NAME, "", containerId,"","","");
      }else if(notificationAttr[i].ATTRIBUTE_TYPE=="ROLE"){
        
      }else if(notificationAttr[i].ATTRIBUTE_TYPE=="DATE"){
        
      }else if(notificationAttr[i].ATTRIBUTE_TYPE=="NUMBER"){
        
      }
    }
  }

  closeModel() {
    this.modalCtrl.dismiss();

  }

}
