"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return _default;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _useThumbnail = /*#__PURE__*/ _interop_require_default(require("../../../hooks/useThumbnail"));
const _File = /*#__PURE__*/ _interop_require_default(require("../../graphics/File"));
require("./index.scss");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {};
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const baseClass = 'thumbnail';
const Thumbnail = (props)=>{
    const { className = '', collection, doc: { filename } = {}, doc, fileSrc, imageCacheTag, size } = props;
    const thumbnailSRC = collection && doc ? (0, _useThumbnail.default)(collection, doc) : fileSrc;
    const [src, setSrc] = (0, _react.useState)(thumbnailSRC);
    const classes = [
        baseClass,
        `${baseClass}--size-${size || 'medium'}`,
        className
    ].join(' ');
    (0, _react.useEffect)(()=>{
        if (doc && collection && thumbnailSRC) {
            setSrc(`${thumbnailSRC}${imageCacheTag ? `?${imageCacheTag}` : ''}`);
        }
        if (fileSrc) {
            setSrc(fileSrc);
        }
    }, [
        doc,
        collection,
        thumbnailSRC,
        fileSrc,
        imageCacheTag
    ]);
    return /*#__PURE__*/ _react.default.createElement("div", {
        className: classes
    }, src && /*#__PURE__*/ _react.default.createElement("img", {
        alt: filename,
        src: src
    }), !src && /*#__PURE__*/ _react.default.createElement(_File.default, null));
};
const _default = Thumbnail;

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hZG1pbi9jb21wb25lbnRzL2VsZW1lbnRzL1RodW1ibmFpbC9pbmRleC50c3giXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFJlYWN0LCB7IHVzZUVmZmVjdCwgdXNlU3RhdGUgfSBmcm9tICdyZWFjdCdcblxuaW1wb3J0IHR5cGUgeyBQcm9wcyB9IGZyb20gJy4vdHlwZXMnXG5cbmltcG9ydCB1c2VUaHVtYm5haWwgZnJvbSAnLi4vLi4vLi4vaG9va3MvdXNlVGh1bWJuYWlsJ1xuaW1wb3J0IEZpbGVHcmFwaGljIGZyb20gJy4uLy4uL2dyYXBoaWNzL0ZpbGUnXG5pbXBvcnQgJy4vaW5kZXguc2NzcydcblxuY29uc3QgYmFzZUNsYXNzID0gJ3RodW1ibmFpbCdcblxuY29uc3QgVGh1bWJuYWlsOiBSZWFjdC5GQzxQcm9wcz4gPSAocHJvcHMpID0+IHtcbiAgY29uc3Qge1xuICAgIGNsYXNzTmFtZSA9ICcnLFxuICAgIGNvbGxlY3Rpb24sXG4gICAgZG9jOiB7IGZpbGVuYW1lIH0gPSB7fSxcbiAgICBkb2MsXG4gICAgZmlsZVNyYyxcbiAgICBpbWFnZUNhY2hlVGFnLFxuICAgIHNpemUsXG4gIH0gPSBwcm9wc1xuXG4gIGNvbnN0IHRodW1ib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