import VectorType from '../enum/VectorType.js'
import SelectState from '../enum/SelectState.js'
import { signService } from './SignService.js'

export default class StateService {
    constructor() {
        this.eventName = null
        this.selectItem = null
        this.focusItem = null
        this.draggingItem = null
    }

    getEventName() {
        return this.eventName
    }

    setEventName(eventName) {
        this.eventName = eventName
    }

    clearEventName() {
        this.eventName = null
    }

    // type表示类型，state默认是select，但是有的元素需要知道选中的是哪个顶点
    setSelectItem(vectorId, type, state, index) {
        this.selectItem = {}
        this.selectItem.vectorId = vectorId
        this.selectItem.type = type

        if (type == VectorType.Tag) {
            if (state == SelectState.Select) {
                this.selectItem.selectIndex = SelectState.All
            } else {
                this.selectItem.selectIndex = state
            }
        } else if (signService.isSign(type)) {
            if (state == SelectState.Select) {
                this.selectItem.selectIndex = SelectState.All
            }
        } else if(type == VectorType.Rectangle){
            if(state == SelectState.All){
                this.selectItem.selectIndex = SelectState.All
            }
            else if(state == SelectState.Side){
                this.selectItem.selectIndex = SelectState.Side +'_'+index
            }
            else if(state == SelectState.Vertex){
                this.selectItem.selectIndex = SelectState.Vertex +'_'+index
            }
        } else if(type == VectorType.Circle){
            if(state == SelectState.All){
                this.selectItem.selectIndex = SelectState.All
            }
            else if(state == SelectState.Vertex){
                this.selectItem.selectIndex = SelectState.Vertex +'_'+index
            }
        } else if(type == VectorType.Icon){
            if(state == SelectState.All){
                this.selectItem.selectIndex = SelectState.All
            }
            else if(state == SelectState.Vertex){
                this.selectItem.selectIndex = SelectState.Vertex +'_'+index
            }
        } else if(type == VectorType.Arrow){
            this.selectItem.selectIndex = state
        } else if (type == VectorType.CustomImage) {
            if (state == SelectState.Select) {
                this.selectItem.selectIndex = SelectState.All
            }
        } else if (type == VectorType.BgImage) {
            if (state == SelectState.Select) {
                this.selectItem.selectIndex = SelectState.All
            }
        }
    }

    getSelectItem() {
        return this.selectItem
    }

    clearSelectItem() {
        this.selectItem = null
    }

    getDraggingItem() {
        return this.draggingItem
    }

    setDraggingItem(draggingItem) {
        this.draggingItem = draggingItem
    }

    clearDraggingItem() {
        this.draggingItem = null
    }

    getFocusItem() {
        return this.focusItem
    }

    setFocusItem(focusItem) {
        this.focusItem = focusItem
    }

    clearFocusItem() {
        this.focusItem = null
    }

    clearItems() {
        this.selectItem = null
        this.focusItem = null
        this.draggingItem = null
    }
}

const stateService = new StateService()
export { stateService }
