import { configOpt } from './toolConfig';

const { line} = configOpt;
import store from "@/vuex/index"

const styleConfig=store.state.sand.styleConfig

/**type--类型  xP--定位点的横坐标 yP--定位点的纵坐标
 * 创建的线条
 * 斜直线无箭头、斜直线单项箭头、斜直线双线箭头
 * 弯折线无箭头、弯折线单项、弯折线双向箭头
 * 圆角弯折线无箭头、圆角弯折线单项、圆角弯折线双向箭头
 */
export const myEdgeOption = (type,xP=0,yP=0) => {
  // 斜直线
  let skewLine={
    source: { x: xP-40, y: yP-40 },
    target: { x: xP+40 ,y: yP+40 },
    router: {
      name: 'normal',
      args: {
        padding: {
          left: 10,
        }
      }
    },
    attrs:{
      line:{
        strokeDasharray:null,
        stroke: styleConfig.lineColor,
        strokeWidth: line.width,
        sourceMarker: '',//起始箭头 
        targetMarker: '',//终止箭头
      }
    }
  }
  //弯折线
  let bendLine={
    source: { x: xP-40, y: yP-40 },
    target: { x: xP+40 ,y: yP+40 },
    vertices:[{x:xP,y:yP-40},{x:xP,y:yP+40}],
    attrs:{
      line:{
        strokeDasharray:null,
        stroke: styleConfig.lineColor,
        strokeWidth: line.width,
        sourceMarker: '',//起始箭头 
        targetMarker: '',//终止箭头
      }
    }
  }
	switch (type) {
		case 'noArrowStraight': 
			return skewLine
		case 'singleArrowStraight': 
			return {
				...skewLine,
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: {},//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
			}
		case 'doubleArrowStraight': 
			return {
				...skewLine,
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: "classic",//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
			}
		case 'noArrowBend': 
			return bendLine
		case 'singleArrowBend': 
			return {
        ...bendLine,
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: {},//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
			}
    case 'doubleArrowBend':
      return {
        ...bendLine,
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: "classic",//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
      }
    case 'noArrowRoundBend': 
			return {
        ...bendLine,
        connector: {
          name: 'rounded',
          args: { radius: 8 },
        },
      }
    case 'singleArrowRoundBend': 
			return {
        ...bendLine,
        connector: {
          name: 'rounded',
          args: { radius: 8 },
        },
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: {},//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
      }
    case 'doubleArrowRoundBend': 
			return {
        ...bendLine,
        connector: {
          name: 'rounded',
          args: { radius: 8 },
        },
        attrs:{
          line:{
            strokeDasharray:null,
            stroke: styleConfig.lineColor,
            strokeWidth: line.width,
            sourceMarker: 'classic',//起始箭头 
            targetMarker: "classic",//终止箭头
          }
        },
      }
  }
}

