import { init } from "@/common/js/websocket.js";
export default {
    beforeDestroy() {
        this.websocket?.close();
    },
    data() {
        return {
            websocket: null,
            websocketData: {},
            activePhaseId: '',
            runMode: '',
        }
    },
    mounted() {

    },
    methods: {
        getCrossWs() {
            this.websocket = init({
                url: `ws://${window.wsHost}/utc/signalStatus/${this.crossId},${this.wsType}`,
                callBack: (res) => {
                    this.websocketData = res[0];
                    // this.$store.state.crossControl.wsData[this.crossId] = res[0];
                    this.activePhaseId = this.websocketData.phaseId;
                    this.runMode = this.websocketData.runMode;
                    this.websocketData.dirLampGroupMap = {};
                    this.websocketData.dirLampGroupMapList.forEach(item => {
                        const dir = item.dir;
                        this.websocketData.dirLampGroupMap[dir] = {};
                        item.turnList.forEach(turnItem => {
                            this.websocketData.dirLampGroupMap[dir][turnItem.turn] = turnItem.color;
                        });
                    });
                },
            });
        },
    },
};
