import React from 'react';
import { connect } from 'react-redux';
import Collapse from 'antd/es/collapse';
import 'antd/es/collapse/style';
import Alert from 'antd/es/alert';
import 'antd/es/alert/style';
import { getSource, getSourceUserChoice, getDependenciesUserChoice } from '../../../../core/dataBus/selectors';
import Code from '../Code';
import { filterImportedDependencies, findFileNode, extractExportsForImports } from '../shared/utils';
import './index.less';
var Panel = Collapse.Panel;

var DependenciesTab = function DependenciesTab(props) {
  var language = props.language,
      selectedNode = props.selectedNode,
      filesMap = props.filesMap,
      foldersMap = props.foldersMap,
      selectedDependencyEdgeNodes = props.selectedDependencyEdgeNodes;
  var importedDependencies = filterImportedDependencies(selectedNode.importedDependencies, selectedDependencyEdgeNodes);
  return React.createElement("div", {
    className: 'DependenciesTab'
  }, importedDependencies.length ? React.createElement(Collapse, {
    bordered: false,
    defaultActiveKey: ['0', '1']
  }, React.createElement(Panel, {
    header: selectedNode.path,
    key: "0"
  }, React.createElement(Code, {
    language: language,
    limitedHeight: true,
    code: selectedNode.fileCode,
    dependenciesLines: importedDependencies.map(function (_ref) {
      var importNodeLines = _ref.importNodeLines;
      return importNodeLines;
    })
  })), importedDependencies.map(function (file, i) {
    // TODO: extract code from server before
    var fileNode = findFileNode(file.sourceFile, filesMap, foldersMap);

    if (!fileNode) {
      return null;
    } // TODO: move to BE

    /*
    const exportedDependencies = extractExportsForImports(
      fileNode.fileCode,
      file.specifiers,
      file.sourceFile
    );*/


    return React.createElement(Panel, {
      header: fileNode.path,
      key: i + 1
    }, React.createElement(Code, {
      language: language,
      limitedHeight: true,
      code: fileNode.fileCode || ''
    }));
  })) : React.createElement(Alert, {
    message: "C-mon, my dear friend, select dependency connection, what are you waiting for?",
    type: "info",
    showIcon: true
  }));
};

var mapStateToProps = function mapStateToProps(state, props) {
  var _getSource = getSource(state, props),
      filesMap = _getSource.filesMap,
      foldersMap = _getSource.foldersMap;

  var _getSourceUserChoice = getSourceUserChoice(state, props),
      selectedNode = _getSourceUserChoice.selectedNode;

  var _getDependenciesUserC = getDependenciesUserChoice(state, props),
      selectedDependencyEdgeNodes = _getDependenciesUserC.selectedDependencyEdgeNodes;

  return {
    selectedNode: selectedNode,
    selectedDependencyEdgeNodes: selectedDependencyEdgeNodes,
    filesMap: filesMap,
    foldersMap: foldersMap
  };
};

export default connect(mapStateToProps)(DependenciesTab);