import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";

/* eslint-disable react/forbid-prop-types, react/require-default-props */
import React from 'react';
import { Permission } from '@choerodon/boot';
import isEmpty from 'lodash/isEmpty';
import "./index.less";
export default function ClickText(props) {
  var value = props.value,
      clickAble = props.clickAble,
      onClick = props.onClick,
      record = props.record,
      permissionCode = props.permissionCode,
      showToolTip = props.showToolTip,
      getClickEvent = props.getClickEvent;
  var text = clickAble && onClick ? /*#__PURE__*/React.createElement("a", {
    className: "c7ncd-click-text",
    onClick: handleClick,
    role: "none"
  }, value) : /*#__PURE__*/React.createElement("span", null, value);

  function handleClick(e) {
    onClick(record, getClickEvent ? e : null);
  }

  if (isEmpty(permissionCode)) {
    return showToolTip ? /*#__PURE__*/React.createElement(_Tooltip, {
      title: value
    }, text) : text;
  }

  return /*#__PURE__*/React.createElement(Permission, {
    service: permissionCode,
    noAccessChildren: value,
    defaultChildren: value
  }, showToolTip ? /*#__PURE__*/React.createElement(_Tooltip, {
    title: value
  }, text) : text);
}
ClickText.defaultProps = {
  clickAble: false,
  permissionCode: [],
  showToolTip: false,
  getClickEvent: false
};