var _excluded = ["disabled", "caption", "error", "layout", "qa"],
  _excluded2 = ["caption", "error", "disabled", "layout", "qa"],
  _excluded3 = ["layout", "disabled", "error", "caption", "hasCaptionPlaceholder", "multiline", "qa"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import React from 'react';
import { Tooltip } from '../Tooltip';
import { useOverflowObserver } from '../_hooks/OverflowObserver';
import { parseFilename } from '../_utils/filename';
import { StyledCaptionText, StyledMultilineCaption, StyledPlaceholderCaption, StyledSingleLineCaption, StyledSinglelineCaptionBody, StyledSinglelineCaptionEnding } from './Thumbnail.styles';
function CaptionTooltip(_ref) {
  var children = _ref.children,
    overlay = _ref.overlay,
    isVisible = _ref.isVisible;
  return /*#__PURE__*/React.createElement(Tooltip, {
    overlay: /*#__PURE__*/React.createElement(Tooltip.Content, null, overlay),
    placement: "bottom",
    trigger: isVisible ? 'hover' : 'none'
  }, children);
}
function MultilineCaption(_ref2) {
  var disabled = _ref2.disabled,
    caption = _ref2.caption,
    error = _ref2.error,
    layout = _ref2.layout,
    qa = _ref2.qa,
    props = _objectWithoutProperties(_ref2, _excluded);
  var _useOverflowObserver = useOverflowObserver(),
    ref = _useOverflowObserver.ref,
    isOverflowing = _useOverflowObserver.isOverflowing;
  return /*#__PURE__*/React.createElement(CaptionTooltip, {
    overlay: caption,
    isVisible: isOverflowing
  }, /*#__PURE__*/React.createElement("span", {
    "data-qa": qa
  }, /*#__PURE__*/React.createElement(StyledMultilineCaption, _extends({
    ref: ref,
    $disabled: disabled,
    $error: error,
    $layout: layout
  }, props), /*#__PURE__*/React.createElement(StyledCaptionText, null, caption))));
}
function SinglelineCaption(_ref3) {
  var caption = _ref3.caption,
    error = _ref3.error,
    disabled = _ref3.disabled,
    layout = _ref3.layout,
    qa = _ref3.qa,
    props = _objectWithoutProperties(_ref3, _excluded2);
  var _useOverflowObserver2 = useOverflowObserver(),
    ref = _useOverflowObserver2.ref,
    isOverflowing = _useOverflowObserver2.isOverflowing;
  var _parseFilename = parseFilename(caption),
    filename = _parseFilename.filename,
    extension = _parseFilename.extension,
    isFilename = _parseFilename.isFilename;
  return /*#__PURE__*/React.createElement(CaptionTooltip, {
    overlay: caption,
    isVisible: isOverflowing
  }, /*#__PURE__*/React.createElement(StyledSingleLineCaption, _extends({
    $error: error,
    $disabled: disabled,
    $layout: layout,
    "data-qa": qa
  }, props), /*#__PURE__*/React.createElement(StyledSinglelineCaptionBody, {
    ref: ref
  }, isFilename ? "".concat(filename, ".") : caption), isFilename && /*#__PURE__*/React.createElement(StyledSinglelineCaptionEnding, null, extension)));
}
export function ThumbnailCaption(_ref4) {
  var layout = _ref4.layout,
    _ref4$disabled = _ref4.disabled,
    disabled = _ref4$disabled === void 0 ? false : _ref4$disabled,
    _ref4$error = _ref4.error,
    error = _ref4$error === void 0 ? false : _ref4$error,
    caption = _ref4.caption,
    hasCaptionPlaceholder = _ref4.hasCaptionPlaceholder,
    multiline = _ref4.multiline,
    _ref4$qa = _ref4.qa,
    qa = _ref4$qa === void 0 ? '' : _ref4$qa,
    props = _objectWithoutProperties(_ref4, _excluded3);
  if (!caption) {
    var captionPlaceholder = hasCaptionPlaceholder && '- -';
    if (captionPlaceholder) {
      return /*#__PURE__*/React.createElement(StyledPlaceholderCaption, {
        $disabled: disabled,
        $error: error,
        $layout: layout,
        "data-qa": qa
      }, /*#__PURE__*/React.createElement(StyledCaptionText, null, captionPlaceholder));
    }
    return null;
  }
  if (multiline) {
    return /*#__PURE__*/React.createElement(MultilineCaption, _extends({
      disabled: disabled,
      caption: caption,
      error: error,
      layout: layout,
      qa: qa
    }, props));
  }
  return /*#__PURE__*/React.createElement(SinglelineCaption, _extends({
    caption: caption,
    disabled: disabled,
    error: error,
    layout: layout,
    qa: qa
  }, props));
}
//# sourceMappingURL=ThumbnailCaption.js.map