import { Component, forwardRef, OnInit,Output, ViewChild, ElementRef, EventEmitter } from '@angular/core';
import * as moment from 'moment';
import { HyperService } from '../../core/services/http.service';
import { Router } from "@angular/router";
import { LocalStorage } from '../../core/services/local_storage.service';
import{EnquirypopupComponent} from '../../leadmodule/enquirypopup/enquirypopup.component';

@Component({
  selector: 'app-confirm-popup',
  templateUrl: './confirm-popup.component.html',
  styleUrls: ['./confirm-popup.component.scss']
})
export class ConfirmPopupComponent implements OnInit {
  // @ViewChild(EnquirypopupComponent) child:any;
 // @ViewChild(forwardRef(() => EnquirypopupComponent))
 // public child: EnquirypopupComponent;



  confirm_delete_modal_visible: boolean = false;
  confirm_modal_visible: boolean = false;
  confirm_logout_visible: boolean = false;
  screen_callback: any;
  success_modal_visible: boolean = false;
  success_content_modal_visible:boolean=false;
  success_addplanmodal_visible:Boolean=false;
  displaytext:any;
  message:any;
  error_modal_visible: boolean = false;
  idvalue:any='';
  confirm_delete_nonsyncmodal: boolean = false;
  

  constructor(private server: HyperService, private router: Router) { }
  @Output() sendCount = new EventEmitter();
  ngOnInit() {
  }
  public showconfirmModal(url: string = "", data: any = {}, callBack: any = null) {
    this.confirm_modal_visible = true;
  }
  public showconfirmModalLogout(url: string = "", data: any = {}, callBack: any = null) {
    this.confirm_logout_visible = true;
  }
  onType(type) {
    this.confirm_modal_visible = false;
    if (type == 1) {
      this.server.get("redeem/wallet")
        .then((data) => {
          if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
            this.router.navigateByUrl('wallet');
          } else if (data.result.status == 401 && data.result.response == 'failed') {
            this.router.navigateByUrl('');
          }
        });

    } else {
    }

  }
  onLogType(type){
    if(type==1){
      LocalStorage.createJWT();
      this.router.navigateByUrl('/');
    }else{
      this.confirm_logout_visible = false;
    }
  }
  onCloseModal() {
    this.success_modal_visible = false;
    this.success_addplanmodal_visible = false;
    this.message='close';
      this.sendCount.emit('list');
    this.error_modal_visible = false;
  }


  onCloseErrorModal() {
    this.success_modal_visible = false;
    this.success_addplanmodal_visible = false;
    this.message='close';
      this.sendCount.emit('');
    this.error_modal_visible = false;
  }


  onCloseContentModal(){
    this.success_content_modal_visible = false;
    this.message='close';
      this.sendCount.emit('list');
    //this.error_modal_visible = false;
  }

  public showsuccessModal(tempvar) {
    console.log("tempvar--->",tempvar);
   // this.sendCount.emit('list');
   this.displaytext=tempvar.result.data.enq_num;
    this.success_modal_visible = true;
    
  }
  public showaddplansuccessModal(tempvar) {
    console.log("tempvar--->",tempvar);
   // this.sendCount.emit('list');
   this.displaytext=tempvar.result.message;
    this.success_addplanmodal_visible = true;
    
  }
  public showerrormodal(tempvar) {
    this.sendCount.emit('');
    this.displaytext=tempvar.result.message;
     this.error_modal_visible = true;
  }

  public displaysuccessModal(tempvar) {
    console.log("tempvar--->",tempvar);
   // this.sendCount.emit('list');
   this.displaytext=tempvar.result.message;
    this.success_content_modal_visible = true;
  }
  //==> ram----
  deletenonsyncmodal(temp1){
    console.log("temp1-->",temp1);
    this.idvalue=temp1;
    this.confirm_delete_nonsyncmodal=true;
  
  }

  deletenonsync(){  
    this.server.delete("enquiry/deleteunsave/"+this.idvalue)
    .then((data) => {
      if (data.status == 200 && data.result.response != 'failed') {
        console.log("data--->",data)
        this.confirm_delete_nonsyncmodal=false;
        this.sendCount.emit('list');
      } else if (data.result.status == 401 && data.result.response == 'failed') {
        this.router.navigateByUrl('');
      }
    });
  }

  cancelnonsyncmodal(){
    this.confirm_delete_nonsyncmodal=false;
  }
  
  //==> ram----

  deleterowmodal(temp1){
    console.log("temp1-->",temp1);
    this.idvalue=temp1;
    this.confirm_delete_modal_visible=true;
  }
  //==
  deletemodal(){
    this.server.delete("enquiry/plannerdelete/"+this.idvalue)
        .then((data) => {
          if (data.status == 200 && data.result.response != 'failed') {
            console.log("data--->",data)
            this.confirm_delete_modal_visible=false;
            this.sendCount.emit('list');
          } else if (data.result.status == 401 && data.result.response == 'failed') {
            this.router.navigateByUrl('');
          }
        });
   
  }
  //==
  canceldeletemodal(){
    this.confirm_delete_modal_visible=false;
    this.sendCount.emit('list');
  }




  

  
}
