import { DashboardStateService } from '../../services/state/dashboard-state.service';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ChartConfiguration, ChartOptions } from 'chart.js';
import { BaseChartDirective } from 'ng2-charts';
import { GeneralService } from '../../services/generalservice';
import { IPrjMst  } from '../../interfaces/main.interface';
import { ProjectStateService } from '../../services/state/project-state.service';


@Component({
  selector: 'app-main-manager-content',
  standalone: false,
  templateUrl: './main-manager-content.component.html',
  styleUrls: ['./main-manager-content.component.css']
})
export class MainManagerContentComponent implements OnInit {
  // @ViewChild(BaseChartDirective) chart?: BaseChartDirective;
  myPrjMst: IPrjMst[]=[];
  // myActData: IActData[] = [];
  // myActSumData: IActSumData = {
  //   summary: {
  //     totalIncome: '',
  //     totalExpense: '',
  //     netProfit: '',
  //     profitRate: '',
  //     adjustedProfitRate: '',
  //     period: ''
  //   },
  //   pie: {
  //     income: [],
  //     expense: []
  //   }
  // };

  constructor(
    private generalService: GeneralService,
    private projectStateService: ProjectStateService
  ) {}

  ngOnInit(): void {
    this.OnSearchPrj({}, true);
  }

  OnSearchPrj(value: any, setupFirst: boolean): void {
    const uri = '/api/ttc/projectsearch';
    let request = {}
    this.generalService.postRequest(uri, request).subscribe({
      next: (result: any) => {
        if (result.code === '200') {
          this.generalService.trowApi(result);
          this.myPrjMst = result.data;
          this.projectStateService.setProjectState(this.myPrjMst);
        }else{
          this.generalService.trowApi(result);
        }
      },
      error: (error: any) => {
        this.generalService.trowApi(error);
      },
      complete: () => {

      }
    });
  }



  // OnSetupDashboard(value: any, setupFirst: boolean): void {
  //   const uri = '/api/web/accountingSetup';
  //   let request = {
  //     token: value
  //   }
  //   this.generalService.postRequest(uri, request).subscribe({
  //     next: (result: any) => {
  //       if (result.code === '200') {
  //         this.generalService.trowApi(result);
  //         this.myDropAct = result.data
  //         this.dashboardStateService.setStateResult(this.myDropAct)
  //       }else{
  //         this.generalService.trowApi(result);
  //       }
  //     },
  //     error: (error: any) => {
  //       this.generalService.trowApi(error);
  //     },
  //     complete: () => {

  //     }
  //   });
  // }

  // OnSearchSum(value: any, setupFirst: boolean): void {
  //   const uri = '/api/web/accountingSum';
  //   let request = {
  //     token: value
  //   }
  //   this.generalService.postRequest(uri, request).subscribe({
  //     next: (result: any) => {
  //       if (result.code === '200') {
  //         this.generalService.trowApi(result);
  //         this.myActSumData = result.data
  //         this.dashboardStateService.setStateSumResult(this.myActSumData);
  //       }else{
  //         this.generalService.trowApi(result);
  //       }
  //     },
  //     error: (error: any) => {
  //       this.generalService.trowApi(error);
  //     },
  //     complete: () => {

  //     }
  //   });
  // }
}
