function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["selected", "disabled", "clickable", "focused", "hasCaptionPlaceholder", "src", "filename", "size", "label", "name", "caption", "onChange", "value"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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 { useCheckbox } from '@react-aria/checkbox';
import { useFocusRing } from '@react-aria/focus';
import { useRef } from 'react';
import { useToggleState } from 'react-stately';
import { getIsFilePreviewableAsImage } from './Thumbnail.utils';
var defaultSize = 'lg';
export var useThumbnail = function useThumbnail(_ref) {
  var selected = _ref.selected,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$clickable = _ref.clickable,
    clickable = _ref$clickable === void 0 ? true : _ref$clickable,
    _ref$focused = _ref.focused,
    focused = _ref$focused === void 0 ? false : _ref$focused,
    _ref$hasCaptionPlaceh = _ref.hasCaptionPlaceholder,
    hasCaptionPlaceholder = _ref$hasCaptionPlaceh === void 0 ? false : _ref$hasCaptionPlaceh,
    src = _ref.src,
    filename_ = _ref.filename,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? defaultSize : _ref$size,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? '' : _ref$label,
    name = _ref.name,
    _ref$caption = _ref.caption,
    caption = _ref$caption === void 0 ? '' : _ref$caption,
    onChange = _ref.onChange,
    value = _ref.value,
    props = _objectWithoutProperties(_ref, _excluded);
  var a11yProps = props.role === 'figure' ? {
    as: 'figure'
  } : {
    as: 'div'
  };
  var inputRef = useRef(null);
  var toggleState = useToggleState({
    defaultSelected: selected,
    onChange: onChange
  });
  var layout = size === 'sm' ? 'row' : 'column';
  var isFile = src instanceof File;
  var isImageURL = typeof src === 'string';
  var canPreviewFileAsImage = getIsFilePreviewableAsImage(src);
  var isFileOrNonPreviewableImage = isFile && !canPreviewFileAsImage;
  var shouldUsePlaceholder = isFileOrNonPreviewableImage || !src;
  var filename = filename_ !== null && filename_ !== void 0 ? filename_ : isFileOrNonPreviewableImage ? src.name : caption;
  var ariaLabel = label && caption ? "".concat(label, " ").concat(caption) : caption || label;
  var _useCheckbox = useCheckbox({
      isSelected: selected,
      'aria-label': ariaLabel,
      name: name,
      onChange: onChange,
      value: value
    }, toggleState, inputRef),
    inputProps = _useCheckbox.inputProps;
  var _useFocusRing = useFocusRing(),
    isFocusVisible = _useFocusRing.isFocusVisible,
    focusProps = _useFocusRing.focusProps;
  return _objectSpread(_objectSpread(_objectSpread({
    alt: props.alt || props.alt === '' ? props.alt : caption || label
  }, props), a11yProps), {}, {
    label: label,
    caption: caption,
    selected: toggleState.isSelected,
    disabled: disabled,
    clickable: clickable,
    focused: focused,
    isImageURL: isImageURL,
    hasCaptionPlaceholder: hasCaptionPlaceholder,
    shouldUsePlaceholder: shouldUsePlaceholder,
    src: src,
    filename: filename,
    size: size,
    layout: layout,
    inputRef: inputRef,
    inputProps: inputProps,
    /**
     * Appeared 23-1-18 https://github.com/procore/core/pull/12250
     * Possible issue with types from React Aria during dependency update
     * > The inferred type of 'useThumbnail' cannot be named without a
     * > reference to '@react-aria/focus/node_modules/@react-types/shared'.
     * > This is likely not portable. A type annotation is necessary.
     */
    focusProps: focusProps,
    isFocusVisible: isFocusVisible,
    toggleState: toggleState
  });
};
//# sourceMappingURL=Thumbnail.hooks.js.map