"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.graphStatus = void 0;
exports.graphStatus = (state, action) => {
    switch (action.type) {
        case 'SET_SCHEDULER':
            return {
                services: [...state.services],
                packages: [...state.packages],
                nodeSelected: state.nodeSelected,
                scheduler: action.scheduler,
            };
        case 'SET_GRAPH':
            return {
                packages: action.graph.getPackages().map((pkg) => ({
                    enabled: pkg.isEnabled(),
                    version: pkg.getVersion(),
                    name: pkg.getName(),
                    compilationStatus: pkg.getTranspilingStatus(),
                })),
                services: action.graph.getServices().map((pkg) => ({
                    enabled: pkg.isEnabled(),
                    name: pkg.getName(),
                    version: pkg.getVersion(),
                    compilationStatus: pkg.getTranspilingStatus(),
                    status: pkg.getStatus(),
                    port: action.graph.getPort(pkg.getName()),
                })),
                nodeSelected: state.nodeSelected,
                scheduler: state.scheduler,
            };
        case 'UPDATE_PACKAGE_STATUS':
            const packages = [...state.packages];
            const toUpdate = packages.find((pkg) => pkg.name === action.node.getName());
            if (toUpdate) {
                toUpdate.compilationStatus = action.node.getTranspilingStatus();
                toUpdate.enabled = action.node.isEnabled();
            }
            return {
                services: [...state.services],
                packages,
                nodeSelected: state.nodeSelected,
                scheduler: state.scheduler,
            };
        case 'UPDATE_SERVICE_STATUS':
            const services = [...state.services];
            const serviceToUpdate = services.find((pkg) => pkg.name === action.service.getName());
            if (serviceToUpdate) {
                serviceToUpdate.compilationStatus = action.service.getTranspilingStatus();
                serviceToUpdate.status = action.service.getStatus();
                serviceToUpdate.enabled = action.service.isEnabled();
            }
            return {
                packages: [...state.packages],
                services,
                nodeSelected: state.nodeSelected,
                scheduler: state.scheduler,
            };
        default:
            return state;
    }
};
//# sourceMappingURL=graph-status.js.map