'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var MoreTrigger = require('../MoreTrigger/MoreTrigger.js');
var Cell = require('../Cell/Cell.js');
var Dropdown_styles = require('./Dropdown.styles.js');
var getFilenameParts = require('../../utils/getFilenameParts.js');
var getFileicon = require('../../utils/getFileicon.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["rootWrapper", "size", "filesInfo", "customIcon", "handleClear"];
var DropdownUI = function DropdownUI(_ref) {
  var Root = _ref.rootWrapper,
    size = _ref.size,
    filesInfo = _ref.filesInfo,
    customIcon = _ref.customIcon,
    handleClear = _ref.handleClear,
    rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
  var parsedItems = React.useMemo(function () {
    return Object.entries(filesInfo).filter(function (_ref2) {
      var _ref3 = _rollupPluginBabelHelpers.slicedToArray(_ref2, 2),
        isVisible = _ref3[1].isVisible;
      return !isVisible;
    }).map(function (_ref4) {
      var _ref5 = _rollupPluginBabelHelpers.slicedToArray(_ref4, 2),
        key = _ref5[0],
        _ref5$ = _ref5[1],
        filenameWithoutExtension = _ref5$.filenameWithoutExtension,
        extension = _ref5$.extension;
      return {
        value: "".concat(filenameWithoutExtension, ".").concat(extension),
        label: key
      };
    });
  }, [filesInfo]);
  return /*#__PURE__*/React__default.default.createElement(Dropdown_styles.StyledDropdown, _rollupPluginBabelHelpers.extends({
    items: parsedItems,
    renderItem: function renderItem(_ref6) {
      var value = _ref6.value,
        label = _ref6.label;
      var _getFilenameParts = getFilenameParts.getFilenameParts(String(value)),
        filenameWithoutExtension = _getFilenameParts.filenameWithoutExtension,
        extension = _getFilenameParts.extension;
      return /*#__PURE__*/React__default.default.createElement(Root, null, /*#__PURE__*/React__default.default.createElement(Cell.CellUI, {
        size: size,
        filenameWithoutExtension: filenameWithoutExtension,
        extension: extension,
        cellContentLeft: customIcon || getFileicon.getFileIcon(extension, size),
        onClick: function onClick() {
          return handleClear(label);
        },
        isInsideDropdown: true
      }));
    }
  }, rest, {
    closeOnSelect: false
  }), /*#__PURE__*/React__default.default.createElement(MoreTrigger.MoreTrigger, {
    size: size
  }));
};

exports.DropdownUI = DropdownUI;
