import React from 'react';
import { PREFIX_CLS } from '../../config';
import './style';

const prefixCls = `${PREFIX_CLS}-hocs`;
export default ({
  children,
  link = {},
  style,
  onMouseEnter,
  onMouseLeave,
  onClick,
  isAnimated,
}) => {
  const aTag = (
    <a
      target={link.target || '_blank'}
      href={link.href}
      className={prefixCls}
      style={style}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      onClick={onClick}
    >
      {children}
    </a>
  );
  const divTag = (
    <div
      className={prefixCls}
      style={style}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      onClick={onClick}
    >
      {children}
    </div>
  );
  const emptyTag = <>{children}</>;

  const getTag = () => {
    let tag;
    if (isAnimated) {
      tag = link.href ? aTag : divTag;
    } else if (link.href) {
      tag = aTag;
    } else {
      tag = emptyTag;
    }
    return tag;
  };
  return <>{getTag()}</>;
};
