import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { IDropAct, IStateDrop, IActData, IActSumData } from '../../interfaces/dashboard.interface';

@Injectable({
  providedIn: 'root'
})
export class DashboardStateService {
  // ประกาศ BehaviorSubject ด้วย Interface
  private dashboardState = new BehaviorSubject<IStateDrop | null>(null);
  private accounttingState = new BehaviorSubject<IActData[] | null>(null);
  private actsumState = new BehaviorSubject<IActSumData | null>(null);

  // ส่ง Observable ไปให้ components subscribe
  getStateResult(): Observable<IStateDrop | null> {
    return this.dashboardState.asObservable();
  }

  // เซ็ท state
  setStateResult(dashboard: IStateDrop): void {
    this.dashboardState.next(dashboard);
  }


  setStateAccountResult(dashboard: IActData[]): void {
    this.accounttingState.next(dashboard);
  }


  setStateSumResult(sumResult: IActSumData): void {
    this.actsumState.next(sumResult);
  }

  // เคลียร์ state
  clearState(): void {
    this.dashboardState.next(null);
  }

  getStateAccountResult(): Observable<IActData[] | null> {
    return this.accounttingState.asObservable();
  }




  getStateSumResult(): Observable<IActSumData | null> {
    return this.actsumState.asObservable();
  }
  // ดึงค่า current state (ไม่ใช่ observable)
  // getCurrentState(): IDropAct | null {
  //   return this.dashboardState.value;
  // }
}
