import { copyStyles } from '@angular/animations/browser/src/util';
import { Component, ElementRef, OnInit } from '@angular/core';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { MenuResponse } from 'src/app/hmg-common/services/menu/models/menu-response';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { ReportServiceService } from '../report-service.service';

@Component({
  selector: 'app-transaction-list',
  templateUrl: './transaction-list.component.html',
  styleUrls: ['./transaction-list.component.scss'],
})
export class TransactionListComponent implements OnInit {
  transactionList: any = [];
  selectedMenu: any;
  template: any;
  constructor(public cs: CommonService, private elementRef: ElementRef, public reports: ReportServiceService, public ts: TranslatorService,) { }

  ngOnInit() {
    this.selectedMenu = this.cs.sharedService.getSharedData(MenuResponse.SELECTED_MENU, false);
    this.transactionList = this.cs.sharedService.getSharedData(ReportServiceService.TRANSACTION_LIST, false);
    this.template = this.cs.sharedService.getSharedData(ReportServiceService.TEMPLATE, false);
  }
  getDate(date) {
    return this.cs.evaluteDate(date);
  }
  getCppOutput(transaction) {
    var request: any = {
      P_REQUEST_ID: transaction['REQUEST_ID']
    };
    this.cs.startLoading();
    this.reports.getCppOutput(request, {}, this.ts.trPK('general', 'retry')).subscribe((result: any) => {

      console.log(result);
      this.cs.stopLoading();

    });
  }
  refresh(transaction) {
    var request: any = {
      P_REQUEST_ID: transaction['REQUEST_ID']
    };
    this.cs.startLoading();
    var request: any = {};
    request.P_MENU_TYPE = this.selectedMenu.MENU_TYPE;
    request.P_SELECTED_RESP_ID = -999;
    request.P_FUNCTION_NAME = this.selectedMenu.FUNCTION_NAME;
    request.P_DESC_FLEX_NAME = this.template.CONCURRENT_PROGRAM_NAME;

    this.reports.getTransaction(request, {}, this.ts.trPK('general', 'retry')).subscribe((result: any) => {
      this.cs.stopLoading();
      this.transactionList = result['GetCcpTransactionsList_New'];
    });
  }
}
