import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
import { PaymentService } from './service/payment.service';
import { PayRequestInfo } from './service/models/pay-request.info';
import { PaymentInfoModel } from './service/models/payment-info.model';
import { PaymentValidationResponse } from './service/models/payment-validation.response';

@Component({
  selector: 'payment',
  templateUrl: './payment.component.html',
  styleUrls: ['./payment.component.scss'],
})
export class PaymentComponent implements OnInit {


  public methods = [
    {
      icon: 'visa',
      title: 'payment,visa',
      method: PaymentService.VISA
    },
    {
      icon: 'sadad',
      title: 'payment,sadad',
      method: PaymentService.SADAD
    },
    {
      icon: 'mada',
      title: 'payment,mada',
      method: PaymentService.MADA
    },
    {
      icon: 'mastercard',
      title: 'payment,mastercard',
      method: PaymentService.MASTERCARD
    },
    {
      icon: 'instalment',
      title: 'payment,instalment',
      method: PaymentService.INSTALMENT
    }
  ];

  @Output() success = new EventEmitter();
  @Output() faild = new EventEmitter();
  @Output() cancel = new EventEmitter();
  public orderDescription: string;
  public amount: number;
  private requestInfo: PayRequestInfo;
  constructor(
    public ts: TranslatorService,
    public cs: CommonService,
    public paymentService: PaymentService,
    public sharedData: SharedDataService
  ) { }

  ngOnInit() {

  }

  @Input() set payRequestInfo(payRequestInfo: PayRequestInfo) {
    this.requestInfo = payRequestInfo;
    this.amount = payRequestInfo.amount;
    this.orderDescription = payRequestInfo.orderDescription;
  }

  get payRequestInfo(): PayRequestInfo {
    return this.requestInfo;
  }


  public openPayment(method: string) {
    /*this.paymentService.openPayment(this.amount, method, this.orderDescription).subscribe((success) => {
      if (success) {
        this.success.emit(this.requestInfo.data);
      } else {
        this.faild.emit();
      }
    });
    */
  }

  public onComplete(info: PaymentInfoModel) {
   
  }

  public onCancel() {
    this.cancel.emit();
  }


}
