import React from 'react';
import classNames from 'classnames';
import { SYMBOL_WIDTH, NODE_NAME_X_SHIFT } from '../constants';
import FileIcon from '../Icons/language/File';
import CppFileIcon from '../Icons/language/CppFile';
import JavaScriptFileIcon from '../Icons/language/JavaScriptFile';
import PythonFileIcon from '../Icons/language/PythonFile';
import DepCirclesIcon from '../Icons/DepCircles';
import './index.less';

var getFileIcon = function getFileIcon(_ref) {
  var position = _ref.position,
      iconSize = _ref.iconSize,
      language = _ref.language;

  switch (language) {
    case 'cpp':
      return React.createElement(CppFileIcon, {
        x: position.x + 2,
        y: position.y - 10,
        height: iconSize + 1,
        width: iconSize + 1
      });

    case 'javascript':
      return React.createElement(JavaScriptFileIcon, {
        x: position.x + 2,
        y: position.y - 10,
        height: iconSize,
        width: iconSize
      });

    case 'python':
      return React.createElement(PythonFileIcon, {
        x: position.x + 2,
        y: position.y - 10,
        height: iconSize + 1,
        width: iconSize + 1
      });

    default:
      return React.createElement(FileIcon, {
        x: position.x + 2,
        y: position.y - 9,
        height: iconSize,
        width: iconSize
      });
  }
};

export var FileName = function FileName(props) {
  var position = props.position,
      name = props.name,
      path = props.path,
      onNodeClick = props.onNodeClick,
      codeCrumbs = props.codeCrumbs,
      purple = props.purple,
      selected = props.selected,
      dependency = props.dependency,
      dependencyImportedOnly = props.dependencyImportedOnly,
      language = props.language;
  var iconSize = 15;
  var nameWidth = name.length * SYMBOL_WIDTH;
  var iconFile = getFileIcon({
    position: position,
    iconSize: iconSize,
    language: language
  });
  var icon = !dependency ? iconFile : React.createElement(DepCirclesIcon, {
    x: position.x,
    y: position.y - 7.5,
    height: iconSize,
    width: iconSize,
    fill: selected ? '#754BC3' : '#1890ff'
  });
  return React.createElement("g", {
    className: 'FileNode',
    onClick: onNodeClick
  }, (dependency || codeCrumbs) && React.createElement(React.Fragment, null, React.createElement("rect", {
    x: position.x + 3,
    y: position.y - 3,
    width: NODE_NAME_X_SHIFT,
    height: 5,
    className: 'NodeText-cover'
  }), React.createElement("rect", {
    x: position.x + NODE_NAME_X_SHIFT,
    y: position.y - 8,
    width: nameWidth,
    height: 16,
    className: 'NodeText-cover'
  })) || null, icon, dependency && dependencyImportedOnly && React.createElement("circle", {
    cx: position.x + 2.5,
    cy: position.y,
    r: 2.5,
    className: 'NodeText-file-dependencyImportedOnly'
  }), React.createElement("g", null, React.createElement("title", null, path), React.createElement("text", {
    x: position.x + NODE_NAME_X_SHIFT,
    y: position.y + 5,
    className: classNames('NodeText-file-name', {
      'NodeText-file-name-purple': purple,
      'NodeText-file-name-selected': dependency && selected && !purple
    })
  }, name)));
};