"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlImage = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
/* eslint-disable @typescript-eslint/no-namespace */
var react_1 = require("react");
var theme_1 = require("../theme");
var powerhooks_1 = require("powerhooks");
exports.GlImage = react_1.memo(function (props) {
    var className = props.className, url = props.url, alt = props.alt, height = props.height, width = props.width, hasShadow = props.hasShadow, imageSources = props.imageSources;
    var _a = __read(react_1.useState(false), 2), isImageLoaded = _a[0], setIsImageLoaded = _a[1];
    var onLoad = powerhooks_1.useConstCallback(function () {
        setIsImageLoaded(true);
    });
    var _b = useStyles({
        isImageLoaded: isImageLoaded,
        "hasShadow": hasShadow !== null && hasShadow !== void 0 ? hasShadow : false,
    }), classes = _b.classes, cx = _b.cx;
    return !url.endsWith(".mp4") ? (jsx_runtime_1.jsxs("picture", { children: [imageSources !== undefined &&
                imageSources.map(function (source) { return jsx_runtime_1.jsx("source", __assign({}, source), void 0); }),
            jsx_runtime_1.jsx("img", { onLoad: onLoad, className: cx(classes.root, className), src: url, alt: alt, width: width, height: height }, void 0)] }, void 0)) : (jsx_runtime_1.jsxs("video", __assign({ width: width, height: height, className: cx(classes.root, className), autoPlay: true, muted: true, loop: true }, { children: [jsx_runtime_1.jsx("source", { src: url, type: "video/mp4" }, void 0), "Your browser does not support HTML video."] }), void 0));
});
var useStyles = theme_1.makeStyles()(function (theme, _a) {
    var isImageLoaded = _a.isImageLoaded, hasShadow = _a.hasShadow;
    return ({
        "root": {
            "position": "relative",
            "width": isImageLoaded ? "100%" : undefined,
            "height": isImageLoaded ? "auto" : undefined,
            "objectFit": "cover",
            "verticalAlign": "middle",
            "boxShadow": !hasShadow ? undefined : theme.customShadow,
        },
    });
});
//# sourceMappingURL=GlImage.js.map