import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { useMemo } from 'react';
import { MoreTrigger } from '../MoreTrigger/MoreTrigger.js';
import { CellUI } from '../Cell/Cell.js';
import { StyledDropdown } from './Dropdown.styles.js';
import { getFilenameParts } from '../../utils/getFilenameParts.js';
import { getFileIcon } from '../../utils/getFileicon.js';

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 = _objectWithoutProperties(_ref, _excluded);
  var parsedItems = useMemo(function () {
    return Object.entries(filesInfo).filter(function (_ref2) {
      var _ref3 = _slicedToArray(_ref2, 2),
        isVisible = _ref3[1].isVisible;
      return !isVisible;
    }).map(function (_ref4) {
      var _ref5 = _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.createElement(StyledDropdown, _extends({
    items: parsedItems,
    renderItem: function renderItem(_ref6) {
      var value = _ref6.value,
        label = _ref6.label;
      var _getFilenameParts = getFilenameParts(String(value)),
        filenameWithoutExtension = _getFilenameParts.filenameWithoutExtension,
        extension = _getFilenameParts.extension;
      return /*#__PURE__*/React__default.createElement(Root, null, /*#__PURE__*/React__default.createElement(CellUI, {
        size: size,
        filenameWithoutExtension: filenameWithoutExtension,
        extension: extension,
        cellContentLeft: customIcon || getFileIcon(extension, size),
        onClick: function onClick() {
          return handleClear(label);
        },
        isInsideDropdown: true
      }));
    }
  }, rest, {
    closeOnSelect: false
  }), /*#__PURE__*/React__default.createElement(MoreTrigger, {
    size: size
  }));
};

export { DropdownUI };
