import { Component, OnInit , Input, Output, EventEmitter } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { SmsPage} from '../sms.page';
import { SMSService } from '../service/smsservice';
import { SMSPopModel } from 'src/app/hmg-common/ui/sms/service/model/SmsModel';
import { SharedDataService } from "src/app/hmg-common/services/shared-data-service/shared-data.service";
@Component({
  selector: 'sms-pop',
  templateUrl: './sms-pop.component.html',
  styleUrls: ['./sms-pop.component.scss'],
})
export class SmsPopComponent implements OnInit {
  
  countr_code: string;
  mobile_no: string;
  id_number : string;
  private dialoginfo = new SMSPopModel();
  @Output() dismiss = new EventEmitter();
  @Output() cancelled = new EventEmitter();
  constructor(
    public modalController: ModalController,
    public sharedData: SharedDataService) { 
    }

  ngOnInit() {
    SMSService.modal_success = false;
  }

  ngAfterViewInit() {
  }

  public async presentModal() {
    // this.dialoginfo = this.sharedData.getSharedData( "smsdata",true);
    // this.countr_code = this.dialoginfo.CountryCode;
    // this.mobile_no = this.dialoginfo.MobileNo;
    // this.id_number = this.dialoginfo.IdentificationNo;
    const modal = await this.modalController.create({
      component: SmsPage,
      backdropDismiss : false
    //   componentProps: {
    //     id : this.id_number,
    //     mobile : this.mobile_no,
    //     c_code : this.countr_code
    //  }
    });  
    modal.cssClass = 'sms-modal'; 
    modal.onDidDismiss().then((d: any) => this.handleModalDismiss(d));
    return await modal.present();
  }


  public dismissModal()
  {
    this.dismiss.emit();
  }

handleModalDismiss = ({ data }) => {
      if (SMSService.modal_success == false) {
        // alert that user cancelled
        this.cancelled.emit();
      } else {
        //save the data
        this.dismiss.emit();
      
      }


}
}
