/* @author yanjun.zsj
 * @date 2018.11
*/
import React from 'react';
import { LineProps } from './types';

const iconSize = [12, 12];
class Line extends React.Component<LineProps, null> {
  constructor(props) {
    super(props);
  }

  removeHandle = (edit): void => {
    if (edit) {
      this.props.removeRelation(this.props.data);
    }
  }

  mouseOver = (edit): void => {
    if (edit) {
      this.props.toTop(this.props.data);
    }
  }

  render(): React.ReactElement {
    const {
      startX = 0,
      startY = 0,
      endX = 0,
      endY = 0,
      currentRelation,
      data,
      edit,
      closeIcon
    } = this.props;
    return <g
      className={`path-end ${currentRelation === data ? "active" : ""} ${edit ? '' : 'disabled'}`}
      onMouseOver={this.mouseOver.bind(edit)}
      onClick={this.removeHandle.bind(edit)}
    >
      <path
        className="line"
        d={`M${startX}, ${startY} L${endX}, ${endY}`}
        markerEnd="url(#markerArrow)"
      />
      <image
        className="icon-remove"
        x={(endX + startX - iconSize[0]) / 2}
        y={(endY + startY - iconSize[1]) / 2}
        width={iconSize[0]}
        height={iconSize[1]}
        xlinkHref={closeIcon || "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADIBAMAAABfdrOtAAAAJ1BMVEVHcEwAosoAossAosoAosoAosoAosr///+y4+/d8vgir9FZw92J1OfP8mV+AAAABnRSTlMAlSthvOSmceEMAAAF/0lEQVR42sWcPXMbNxCGyVOYOopj1kxiuWa+VGtiRbXixKojk8RQOtaBbKvOuXAtZvQDRHPS6zL5AaZn8qdCHinyPoDdd3E4BJ1t0i8fLLDYXXy0WoL29f7+8U8v1Ivj4/1HX7UaaNF3X5ypfPv10be+Jb4vKqzb8HOfEt+YJDIZbzRWiVX72YvM3mNFt2f1Nb5UbBv2a2r8oIA2qjUAoscKazVUoq5C27MAGkr9GEDDVeVQydpnDhoHQg01ko/kJ0rchj3pPD+Ti6hzodFPlEv7RSTSVW7tqFmDbIyPm2VPObfzxjtL0mFPamigHRad1RFRg0bciYt72aupAdm+W1cEsH27toYaBgDhUT7xoKFGjMiJDxH1vHkQzipdPyKkVdq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