import React from 'react';
import { connect } from 'react-redux';
import Icon from 'antd/es/icon';
import 'antd/es/icon/style';
import Breadcrumb from 'antd/es/breadcrumb';
import 'antd/es/breadcrumb/style';
import { FILE_NODE_TYPE } from '../../../core/constants/index';
import { Copy } from '../controls/Copy/index';
import { getActiveNamespace } from '../../../core/namespaceIntegration/selectors';
import { getSourceUserChoice, getProjectMetadata } from '../../../core/dataBus/selectors';
import './SubPanelContainer.less';

var SubPanelContainer = function SubPanelContainer(_ref) {
  var selectedNode = _ref.selectedNode,
      platformPathSeparator = _ref.platformPathSeparator;
  if (!selectedNode) return React.createElement("div", {
    className: "SubPanelContainer"
  }, React.createElement(Breadcrumb, null, React.createElement(Breadcrumb.Item, null, React.createElement(Icon, {
    type: "home"
  })), React.createElement(Breadcrumb.Item, null, " ")));
  var pathParts = selectedNode.path.split(platformPathSeparator);
  var lastNode = selectedNode.type === FILE_NODE_TYPE ? pathParts.pop() : null; // TODO: close folder on click

  return React.createElement("div", {
    className: "SubPanelContainer"
  }, React.createElement(Breadcrumb, null, React.createElement(Breadcrumb.Item, null, React.createElement(Icon, {
    type: "home"
  })), pathParts.map(function (part, i) {
    return React.createElement(Breadcrumb.Item, {
      key: part + i
    }, React.createElement("a", {
      href: "#",
      onClick: function onClick() {
        return console.log("close folder ".concat(pathParts.slice(0, i).join(platformPathSeparator)));
      }
    }, part));
  }), lastNode && React.createElement(Breadcrumb.Item, null, lastNode)), React.createElement("div", {
    className: 'copyIcon'
  }, React.createElement(Copy, {
    copyText: selectedNode.path
  })));
};

var mapStateToProps = function mapStateToProps(state, props) {
  var namespace = getActiveNamespace(state);

  if (!namespace) {
    return {};
  }

  var namespaceProps = {
    namespace: namespace
  };

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

  var _getProjectMetadata = getProjectMetadata(state, namespaceProps),
      platformPathSeparator = _getProjectMetadata.platformPathSeparator;

  return {
    selectedNode: selectedNode,
    platformPathSeparator: platformPathSeparator
  };
};

export default connect(mapStateToProps)(SubPanelContainer);