import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { GeneralService } from '../../services/generalservice';
import { IPrjMst } from '../../interfaces/main.interface'
import { ProjectStateService } from '../../services/state/project-state.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-main-manager',
  standalone: false,
  templateUrl: './main-manager.component.html',
  styleUrl: './main-manager.component.css'
})
export class MainManagerComponent implements OnInit {

  mode: string = 'i';

  myPrjMst:IPrjMst[] = [];

  totalBudget = 200000;     // งบทั้งหมด
  approvedBudget = 65000;   // งบที่อนุมัติแล้ว



  get remainingBudget() {
    return this.totalBudget - this.approvedBudget;
  }

  approveProject(p: any) {
    p.status = 'BAP';
    this.approvedBudget += p.budget;
  }

  rejectProject(p: any) {
    p.status = 'CN';
  }

  openBudgetDetail(idx: IPrjMst) {
    this.router.navigate(['/main/manager/aproval'], {
      state: {
        prjseq: idx.prjseq,
        prjnam: idx.prjnam
      }
    });
  }

  constructor(
    private router: Router,
    private projectStateService: ProjectStateService
  ) {}




  ngOnInit(): void {
    this.setupFormControl();
    this.projectStateService.getStateResult().subscribe(data => {
      if(data){
       this.myPrjMst = data
      }
    });
  }
  setupFormControl(){

  }

  onSaveSubmit(){

  }

  onArrearsSubmit(){

  }
}
