2025-11-13 14:53:37 +07:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
2025-11-13 18:00:51 +07:00
|
|
|
import { IDropAct, IStateDrop, IActData } from '../../interfaces/dashboard.interface';
|
2025-11-13 14:53:37 +07:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class DashboardStateService {
|
|
|
|
|
// ประกาศ BehaviorSubject ด้วย Interface
|
2025-11-13 15:37:50 +07:00
|
|
|
private dashboardState = new BehaviorSubject<IStateDrop | null>(null);
|
2025-11-13 18:00:51 +07:00
|
|
|
private accountting = new BehaviorSubject<IActData[] | null>(null);
|
2025-11-13 14:53:37 +07:00
|
|
|
|
|
|
|
|
// ส่ง Observable ไปให้ components subscribe
|
2025-11-13 15:37:50 +07:00
|
|
|
getStateResult(): Observable<IStateDrop | null> {
|
|
|
|
|
return this.dashboardState.asObservable();
|
2025-11-13 14:53:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// เซ็ท state
|
2025-11-13 18:00:51 +07:00
|
|
|
setStateResult(dashboard: IStateDrop): void {
|
|
|
|
|
this.dashboardState.next(dashboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setStateAccountResult(dashboard: IActData[]): void {
|
|
|
|
|
this.accountting.next(dashboard);
|
2025-11-13 14:53:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// เคลียร์ state
|
|
|
|
|
clearState(): void {
|
2025-11-13 15:37:50 +07:00
|
|
|
this.dashboardState.next(null);
|
2025-11-13 14:53:37 +07:00
|
|
|
}
|
|
|
|
|
|
2025-11-13 18:00:51 +07:00
|
|
|
getStateAccountResult(): Observable<IActData[] | null> {
|
|
|
|
|
return this.accountting.asObservable();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-13 14:53:37 +07:00
|
|
|
// ดึงค่า current state (ไม่ใช่ observable)
|
|
|
|
|
// getCurrentState(): IDropAct | null {
|
2025-11-13 18:00:51 +07:00
|
|
|
// return this.dashboardState.value;
|
2025-11-13 14:53:37 +07:00
|
|
|
// }
|
|
|
|
|
}
|