
import { arrowService } from '../Service/ArrowService'
import { coordinate } from '../Coordinate'
import { floorplanService } from '../Service/FloorplanService'
import { mathUtil } from '../MathUtil';
import SelectState from '../enum/SelectState';

//独立的，不会和线条以及其他构件融合
export default class AddArrow {
    constructor() {
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }

    execute(position){
        if(this.end == null){
            this.end = coordinate.getXYFromScreen(position)
        }
        else if(this.currentVectorId == null){
            this.start = {
                x:position.x,
                y:position.y
            };
            const arrow = arrowService.createArrow(this.start,this.end)
            this.currentVectorId = arrow.vectorId
        }
        else {
            const arrow = floorplanService.getArrow(this.currentVectorId)
            arrow.updatePoint(position,SelectState.Start)
        }
    }

    clear(){
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }
}

const addArrow = new AddArrow()
export { addArrow }