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 EqualSign: React.FC<AppProps> = (props) => {
  const {
    properties,
    theme
  } = props
  const [containerRef, { width: offsetWidth, height: offsetHeight }] = useMeasure()

  const {
    shadowX, shadowY, shadowB, shadowS
  } = properties

  const {
    backgroundColor,
  } = React.useMemo(() => {
    return getBasicConfig(properties, theme, ExtensionType.EqualSign)
  }, [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.EqualSign)
  }, [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="M1.5 8C0.671573 8 0 8.67157 0 9.5V14.5C0 15.3284 0.671574 16 1.5 16H38.5C39.3284 16 40 15.3284 40 14.5V9.5C40 8.67157 39.3284 8 38.5 8H1.5ZM1.5 25C0.671573 25 0 25.6716 0 26.5V31.5C0 32.3284 0.671574 33 1.5 33H38.5C39.3284 33 40 32.3284 40 31.5V26.5C40 25.6716 39.3284 25 38.5 25H1.5Z"
          strokeDasharray={strokeDasharray}
          strokeLinecap={strokeLinecap}
          stroke={stroke}
          fill={backgroundColor}
          strokeWidth={strokeWidth}
        />
      </svg>
    </div>
  )
}

export default EqualSign
