/**
 * Simple observable implementation for state changes
 */
class SimpleObservable {
    listeners = new Set();
    subscribe(listener) {
        this.listeners.add(listener);
        return () => this.listeners.delete(listener);
    }
    next(value) {
        for (const listener of this.listeners) {
            listener(value);
        }
    }
}
/**
 * Centralized state management for the admin dashboard.
 * Handles cross-view data passing and state synchronization.
 */
export class AdminState {
    // Observable subjects for reactive updates
    monitors$ = new SimpleObservable();
    incidents$ = new SimpleObservable();
    config$ = new SimpleObservable();
    // Current data
    _monitors = [];
    _incidents = [];
    _config = null;
    // Selected items for navigation context
    _selectedMonitor = null;
    _selectedIncident = null;
    // Monitors
    get monitors() {
        return this._monitors;
    }
    set monitors(value) {
        this._monitors = value;
        this.monitors$.next(value);
    }
    // Incidents
    get incidents() {
        return this._incidents;
    }
    set incidents(value) {
        this._incidents = value;
        this.incidents$.next(value);
    }
    // Config
    get config() {
        return this._config;
    }
    set config(value) {
        this._config = value;
        if (value) {
            this.config$.next(value);
        }
    }
    // Selected monitor for edit navigation
    setSelectedMonitor(monitor) {
        this._selectedMonitor = monitor;
    }
    getSelectedMonitor() {
        return this._selectedMonitor;
    }
    clearSelectedMonitor() {
        this._selectedMonitor = null;
    }
    // Selected incident for edit navigation
    setSelectedIncident(incident) {
        this._selectedIncident = incident;
    }
    getSelectedIncident() {
        return this._selectedIncident;
    }
    clearSelectedIncident() {
        this._selectedIncident = null;
    }
    // Helper methods
    getCategories() {
        const categories = new Set();
        for (const monitor of this._monitors) {
            if (monitor.category) {
                categories.add(monitor.category);
            }
        }
        return Array.from(categories).sort();
    }
    getAvailableServices() {
        return [...this._monitors];
    }
    getMonitorById(id) {
        return this._monitors.find(m => m.id === id);
    }
    getIncidentById(id) {
        return this._incidents.find(i => i.id === id);
    }
    getActiveIncidents() {
        return this._incidents.filter(i => !['resolved', 'postmortem'].includes(i.status));
    }
    getPastIncidents() {
        return this._incidents.filter(i => ['resolved', 'postmortem'].includes(i.status));
    }
    // CRUD operations (these would typically call an API)
    addMonitor(monitor) {
        this.monitors = [...this._monitors, monitor];
    }
    updateMonitor(id, data) {
        this.monitors = this._monitors.map(m => m.id === id ? { ...m, ...data } : m);
    }
    deleteMonitor(id) {
        this.monitors = this._monitors.filter(m => m.id !== id);
    }
    addIncident(incident) {
        this.incidents = [...this._incidents, incident];
    }
    updateIncident(id, data) {
        this.incidents = this._incidents.map(i => i.id === id ? { ...i, ...data } : i);
    }
    deleteIncident(id) {
        this.incidents = this._incidents.filter(i => i.id !== id);
    }
}
// Singleton instance
export const adminState = new AdminState();
//# sourceMappingURL=data:application/json;base64,[encoded data, 5012 characters]