import React from 'react'
import { useMeasure } from 'react-use'
import { AppProps, ExtensionType } from 'src/types'
import 'src/style.css'
import {
  getBasicConfig,
  getStrokeConfig,
  getShadowConfig
} from 'src/utils'
import {
  Small_Canvas_Width
} from 'src/contants'


const PlusSign: React.FC<AppProps> = (props) => {

  const {
    properties,
    theme
  } = props
  const [containerRef, { width: offsetWidth, height: offsetHeight }] = useMeasure()

  const {
    backgroundColor,
  } = React.useMemo(() => {
    return getBasicConfig(properties, theme, ExtensionType.PlusSign)
  }, [properties, theme])

  const shadow = React.useMemo(() => {
    return getShadowConfig(properties, theme)
  }, [properties, theme])

  const {
    strokeDasharray,
    strokeLinecap,
    stroke,
    strokeWidth
  } = React.useMemo(() => {
    return getStrokeConfig(properties, theme, offsetWidth, Small_Canvas_Width, ExtensionType.PlusSign)
  }, [properties, theme, offsetWidth])

  return (
    <div className='graphicsContainer' ref={containerRef}>
      <svg
        className="graphics"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        fill-rule="evenodd"
        clip-rule="evenodd"
        height="40"
        width="40"
        viewBox="0 0 40 40"
        style={{ filter: shadow }}
      >
        {/* 加号 */}
        <path
          fill-rule="evenodd"
          clip-rule="evenodd"
          d="M17.5 0C16.6716 0 16 0.671574 16 1.5V16H1.5C0.671573 16 0 16.6716 0 17.5V22.5C0 23.3284 0.671574 24 1.5 24H16V38.5C16 39.3284 16.6716 40 17.5 40H22.5C23.3284 40 24 39.3284 24 38.5V24H38.5C39.3284 24 40 23.3284 40 22.5V17.5C40 16.6716 39.3284 16 38.5 16H24V1.5C24 0.671573 23.3284 0 22.5 0H17.5Z"
          strokeDasharray={strokeDasharray}
          strokeLinecap={strokeLinecap}
          stroke={stroke}
          fill={backgroundColor}
          strokeWidth={strokeWidth}
        />
      </svg>
    </div>
  )
}

export default PlusSign
