function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

import * as React from 'react';
import classNames from 'classnames';
import { TYPE_FOLDER, DEFAULT_ROOT } from '../../constants';
import messages from './messages';
import Breadcrumb from '../../components/breadcrumb';
import FolderIcon from '../../icons/folder-icon';
import FileIcon from '../../icons/file-icon';
import getSize from '../../utils/size';
import { getFileExtension } from '../../utils/file';
import baseCellRenderer from './baseCellRenderer';
import './FilePathCell.scss';

var getName = function getName() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      name = _ref.name,
      type = _ref.type,
      isExternal = _ref.isExternal,
      id = _ref.id;

  var intl = arguments.length > 1 ? arguments[1] : undefined;

  if (id === DEFAULT_ROOT) {
    return intl.formatMessage(messages.allFiles);
  }

  if (isExternal) {
    var message = type === TYPE_FOLDER ? messages.externalFolder : messages.externalFile;
    return intl.formatMessage(message);
  }

  return name || id;
};

var fileNameCellRenderer = function fileNameCellRenderer(intl) {
  return function (cellRendererParams) {
    return baseCellRenderer(cellRendererParams, function (cellValue) {
      var id = cellValue.id,
          _cellValue$name = cellValue.name,
          name = _cellValue$name === void 0 ? '' : _cellValue$name,
          size = cellValue.size,
          _cellValue$itemPath = cellValue.itemPath,
          itemPath = _cellValue$itemPath === void 0 ? [] : _cellValue$itemPath,
          itemType = cellValue.itemType,
          isExternal = cellValue.isExternal;
      var extension = getFileExtension(name);
      var icon = itemType === TYPE_FOLDER ? /*#__PURE__*/React.createElement(FolderIcon, null) : /*#__PURE__*/React.createElement(FileIcon, {
        extension: extension
      });
      var path = itemPath.map(function (pathInfo) {
        return getName(pathInfo, intl);
      });
      var displaySize = size ? " (".concat(getSize(size), ")") : '';
      var contentName = getName({
        id: id,
        isExternal: isExternal,
        type: itemType,
        name: name
      }, intl);
      var displayName = "".concat(contentName).concat(displaySize);
      var fullPath = [].concat(_toConsumableArray(path), [displayName]);
      var filePathCellClass = classNames('bdl-FilePathCell', {
        'bdl-is-external': isExternal
      });
      return /*#__PURE__*/React.createElement("span", {
        className: filePathCellClass,
        title: fullPath.join(' > ')
      }, icon, /*#__PURE__*/React.createElement(Breadcrumb, {
        label: "contentPath"
      }, fullPath.map(function (itemPathName) {
        return /*#__PURE__*/React.createElement("span", {
          key: itemPathName,
          className: "bdl-FilePathCell-breadcrumbName"
        }, itemPathName);
      })));
    });
  };
};

export default fileNameCellRenderer;
//# sourceMappingURL=filePathCellRenderer.js.map