import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { IPrjMst } from '../../interfaces/main.interface';

@Injectable({
  providedIn: 'root'
})
export class ProjectStateService {
  // ประกาศ BehaviorSubject ด้วย Interface
  private projectState = new BehaviorSubject<IPrjMst[] | null>(null);

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

  // เซ็ท state
  setProjectState(projects: IPrjMst[]): void {
    this.projectState.next(projects);
  }

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