import { getBasicConfig } from './basicConfig'
import { isValidNumber } from './math'

export const getStrokeStyle = (borderStyle, borderWidth) => {
  switch (borderStyle) {
    case 'solid':
      return '0'
    case 'dashed':
      return `${1.5 * borderWidth} ${3 * borderWidth}`
    case 'dotted':
      return `0 ${2.5 * borderWidth}`
    default:
      return '0'
  }
}

export const getStrokeConfig = (
  properties,
  theme,
  svgWidth,
  canvasWidth,
  type
) => {
  const {
    custom: {
      borderStyle,
      borderRadius,
    }
  } = properties

  const {
    borderColor,
    borderWidth
  } = getBasicConfig(properties, theme, type)

  // 计算实际边线比例
  const strokeWidth = canvasWidth * borderWidth / svgWidth
  // 边线样式 
  const strokeDasharray = getStrokeStyle(borderStyle, strokeWidth)
  // radius
  const strokeRadius = borderRadius ? canvasWidth * borderRadius / svgWidth : 0
  return {
    strokeDasharray,
    strokeLinecap: "square",
    stroke: borderColor,
    strokeWidth: isValidNumber(strokeWidth) ? strokeWidth : 0,
    strokeRadius: isValidNumber(strokeRadius) ? strokeRadius : 0,
  }
}