import { Component, OnInit } from '@angular/core';
import {ConfFeeDetailComponent} from '../conf-fee-detail/conf-fee-detail.component';
import {DomSanitizer} from '@angular/platform-browser';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FuncService } from '../../../../../core/service/func.service';
import { VarService } from '../../../../../core/service/var.service';

@Component({
  selector: 'app-conf-fee-page',
  templateUrl: './conf-fee-page.component.html',
  styleUrls: ['./conf-fee-page.component.scss']
})
export class ConfFeePageComponent extends FramePageComponent implements OnInit {

  constructor(private modalService: BsModalService, private san: DomSanitizer) {
    super(modalService, san);
    this.modalComponent = ConfFeeDetailComponent;
  }

  ngOnInit() {
  }
  getFeeConfig(v) {
    return ConfFeePageComponent.getFeeConfig(v);
  }
  public static getFeeConfig(v, exam_batchs?: any) {
    if (exam_batchs === undefined) {
      exam_batchs = 3;
    }
    let fee_type = '专业:';
    if (v.fee_type === 'Subject') {
      fee_type = '每科目：';
    }
    // 没有复试
    let value = '';
    if (v.amount_2 === undefined) {
      if (v.out_amount_1 === undefined) {
        // 省内外配置一致
        value =  fee_type + FuncService.formatCurrency(v.amount_1 / 100) ;
      } else {
        // 本部考点和省外考点收费不一样
        value =  fee_type + `本部【${FuncService.formatCurrency(v.amount_1 / 100)}】，外省【${FuncService.formatCurrency(v.out_amount_1 / 100)}】`;
      }
      return value;
    }

    if (exam_batchs < 2) {
      return value;
    }
    // 有复试
    if (v.out_amount_1 === undefined) {
      // 省内外配置一致
      value =  fee_type + `初试【${FuncService.formatCurrency(v.amount_1 / 100)}】，复试【${FuncService.formatCurrency(v.amount_2 / 100)}】`;
      if (exam_batchs > 2) {
        value = value + (v.amount_3 === undefined ? '' : `，三试【${FuncService.formatCurrency(v.amount_3 / 100)}】`);
      }
      return value;
    }
    value =  fee_type + `本部初试【${FuncService.formatCurrency(v.amount_1 / 100)}】，本部复试【${FuncService.formatCurrency(v.amount_2 / 100)}】` ;
    if (exam_batchs > 2 ) {
      value = value + (v.amount_3 === undefined ? '' : `，本部三试【${FuncService.formatCurrency(v.amount_3 / 100)}】`);
    }
    value = value + '<br/>' + `省外初试【${FuncService.formatCurrency(v.out_amount_1 / 100)}】`;
    if (v.out_amount_2 !== undefined) {
      value = value  + `，省外复试【${FuncService.formatCurrency(v.out_amount_2 / 100)}】`;
    }
    if (exam_batchs > 2 ) {
      if (v.out_amount_3 !== undefined) {
        value = value + `，省外三试【${FuncService.formatCurrency(v.out_amount_3 / 100)}】`;
      }
    }
    // return AjaxService.sanitizer.bypassSecurityTrustHtml(value);
    return VarService.DOM_SANITIZER.bypassSecurityTrustHtml(value);
  }
}
