var _excluded = ["items", "downloadAllUrl", "getDownloadUrl", "getViewUrl", "getName", "qa"],
  _excluded2 = ["name", "viewUrl", "downloadUrl"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { Archive, Download } from '@procore/core-icons/dist';
import React from 'react';
import { Box } from '../Box/Box';
import { Link } from '../Link/Link';
import { Tooltip } from '../Tooltip/Tooltip';
import { Typography } from '../Typography/Typography';
import { useI18nContext } from '../_hooks/I18n';
import { StyledFileListDownloadAll, StyledFileListItem, StyledFileListItemDownloadIcon, StyledFileListItemTextInactive } from './FileList.styles';
/**

 @since 10.19.0

 @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-filelist--demo)

 @see [Design Guidelines](https://design.procore.com/file-list)

 */

export var defaultGetViewUrl = function defaultGetViewUrl(item) {
  return item.viewUrl;
};
export var defaultGetDownloadUrl = function defaultGetDownloadUrl(item) {
  return item.downloadUrl;
};
export var defaultGetName = function defaultGetName(item) {
  return item.name;
};
export var FileList = /*#__PURE__*/React.forwardRef(function FileList(_ref, ref) {
  var items = _ref.items,
    downloadAllUrl = _ref.downloadAllUrl,
    _ref$getDownloadUrl = _ref.getDownloadUrl,
    getDownloadUrl = _ref$getDownloadUrl === void 0 ? defaultGetDownloadUrl : _ref$getDownloadUrl,
    _ref$getViewUrl = _ref.getViewUrl,
    getViewUrl = _ref$getViewUrl === void 0 ? defaultGetViewUrl : _ref$getViewUrl,
    _ref$getName = _ref.getName,
    getName = _ref$getName === void 0 ? defaultGetName : _ref$getName,
    qa = _ref.qa,
    props = _objectWithoutProperties(_ref, _excluded);
  var I18n = useI18nContext();
  var length = items.length;
  var isDownloadAllVisible = length > 1 && downloadAllUrl;
  if (length === 0) {
    return null;
  }
  return /*#__PURE__*/React.createElement(Box, _extends({
    ref: ref
  }, props), isDownloadAllVisible && /*#__PURE__*/React.createElement(StyledFileListDownloadAll, {
    variant: "tertiary",
    size: "sm",
    icon: /*#__PURE__*/React.createElement(Archive, null),
    href: downloadAllUrl,
    tabIndex: 0
  }, I18n.t('core.fileList.downloadAll')), /*#__PURE__*/React.createElement(Box, {
    as: "ul"
  }, items.map(function (item, i) {
    var _qa$item;
    var name = getName(item);
    var downloadUrl = getDownloadUrl(item);
    return /*#__PURE__*/React.createElement(Item, {
      name: name,
      downloadUrl: getDownloadUrl(item),
      viewUrl: getViewUrl(item),
      "data-qa": qa === null || qa === void 0 ? void 0 : (_qa$item = qa.item) === null || _qa$item === void 0 ? void 0 : _qa$item.call(qa, item),
      key: "".concat(name, "-").concat(downloadUrl)
    });
  })));
});
export function Item(_ref2) {
  var name = _ref2.name,
    viewUrl = _ref2.viewUrl,
    downloadUrl = _ref2.downloadUrl,
    props = _objectWithoutProperties(_ref2, _excluded2);
  var I18n = useI18nContext();
  return /*#__PURE__*/React.createElement(StyledFileListItem, props, viewUrl ? /*#__PURE__*/React.createElement(Typography, {
    intent: "body",
    weight: "semibold"
  }, /*#__PURE__*/React.createElement(Link, {
    href: viewUrl,
    target: "_blank",
    tabIndex: 0
  }, name)) : /*#__PURE__*/React.createElement(Tooltip, {
    overlay: I18n.t('core.fileList.noPreview')
  }, /*#__PURE__*/React.createElement(Typography, {
    intent: "body",
    color: "gray15"
  }, /*#__PURE__*/React.createElement(StyledFileListItemTextInactive, {
    tabIndex: 0
  }, name))), downloadUrl && /*#__PURE__*/React.createElement(Tooltip, {
    overlay: I18n.t('core.fileList.download')
  }, /*#__PURE__*/React.createElement(StyledFileListItemDownloadIcon, {
    "aria-label": I18n.t('core.fileList.download'),
    href: downloadUrl,
    icon: /*#__PURE__*/React.createElement(Download, {
      size: "sm"
    }),
    size: "sm",
    variant: "tertiary"
  })));
}
//# sourceMappingURL=FileList.js.map