<template>
  <pop-menu ref="popMenu" :menu="menu" />
</template>

<script>
import PopMenu from '@/components/PopMenu';
import { mapGetters } from 'vuex';
import { DeviceMenu, OperateMode } from '@/scripts/ConstDic';

export default {
    name: 'StationControlMenu',
    components: {
        PopMenu
    },
    props: {
        selected: {
            type: Object,
            default() {
                return null;
            }
        }
    },
    data() {
        return {
            menu: [],
            menuNormal: [
            ],
            menuForce: [
            ]
        };
    },
    computed: {
        ...mapGetters('training', [
            'mode',
            'operatemode'
        ]),
        ...mapGetters('menuOperation', [
            'buttonOperation'
        ])
    },
    watch: {
        '$store.state.menuOperation.menuCount': function (val) {
            if (this.$store.getters['menuOperation/checkDialogIsOpen'](DeviceMenu.StationControl) && !this.buttonOperation) {
                this.doShow(this.$store.state.menuOperation.menuPosition);
            } else {
                this.doClose();
            }
        }
    },
    methods: {
        clickEvent() {
            const self = this;
            window.onclick = function (e) {
                self.doClose();
            };
        },
        doShow(point) {
            if (this.$refs && this.$refs.popMenu) {
                this.$refs.popMenu.close();
            }
        },
        doClose() {
            if (this.$refs && this.$refs.popMenu) {
                this.$refs.popMenu.close();
            }
        }
    }
};
</script>
