"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.GlProjectCard = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
/* eslint-disable @typescript-eslint/no-namespace */
var react_1 = require("react");
var GlButton_1 = require("../utils/GlButton");
var theme_1 = require("../theme");
var GlCard_1 = require("./GlCard");
var theme_2 = require("../theme");
var useDomRect_1 = require("powerhooks/useDomRect");
exports.GlProjectCard = (0, react_1.memo)(function (props) {
    var className = props.className, text = props.text, projectImageUrl = props.projectImageUrl, subtitle = props.subtitle, title = props.title, badgeLabel = props.badgeLabel, link = props.link, badgeBackgroundColor = props.badgeBackgroundColor, badgeColor = props.badgeColor;
    var _a = __read((0, react_1.useState)(undefined), 2), imgAspectRatio = _a[0], setImgAspectRatio = _a[1];
    var _b = (0, useDomRect_1.useDomRect)(), headerRef = _b.ref, headerWidth = _b.domRect.width;
    var img = new Image();
    (0, react_1.useEffect)(function () {
        img.src = projectImageUrl;
        img.onload = function () {
            setImgAspectRatio(img.height / img.width);
        };
    }, [projectImageUrl]);
    var _c = useStyles({
        badgeColor: badgeColor,
        badgeBackgroundColor: badgeBackgroundColor,
        projectImageUrl: projectImageUrl,
        headerWidth: headerWidth,
        imgAspectRatio: imgAspectRatio,
    }, { props: props }), classes = _c.classes, cx = _c.cx;
    return ((0, jsx_runtime_1.jsxs)(GlCard_1.GlCard, __assign({ link: link, className: cx(classes.root, className) }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ ref: headerRef, className: classes.header }, { children: badgeLabel !== undefined && ((0, jsx_runtime_1.jsx)(GlButton_1.GlButton, __assign({ type: "submit", className: classes.button, variant: "ternary", href: link === null || link === void 0 ? void 0 : link.href, onClick: link === null || link === void 0 ? void 0 : link.onClick }, { children: badgeLabel }))) })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: classes.footer }, { children: [(0, jsx_runtime_1.jsx)(theme_1.Text, __assign({ typo: "object heading", className: classes.footerTitle }, { children: title })), subtitle !== undefined && ((0, jsx_runtime_1.jsx)(theme_1.Text, __assign({ typo: "label 2", className: classes.footerSubtitle }, { children: subtitle }))), text !== undefined && ((0, jsx_runtime_1.jsx)(theme_1.Text, __assign({ className: classes.footerText, typo: "label 2" }, { children: text })))] }))] })));
});
var useStyles = (0, theme_1.makeStyles)()(function (theme, _a) {
    var badgeBackgroundColor = _a.badgeBackgroundColor, badgeColor = _a.badgeColor, projectImageUrl = _a.projectImageUrl, headerWidth = _a.headerWidth, imgAspectRatio = _a.imgAspectRatio;
    return ({
        "root": {
            "transition": "opacity 300ms",
            "opacity": headerWidth === 0 || imgAspectRatio === undefined ? 0 : 1,
            "display": "flex",
            "flexDirection": "column",
            "overflow": "hidden",
            "margin": (function () {
                if (theme.windowInnerWidth >= theme_2.breakpointsValues.lg) {
                    return undefined;
                }
                return theme.spacing(1);
            })(),
        },
        "footer": {
            "flex": 1,
            "backgroundColor": theme.isDarkModeEnabled
                ? theme.colors.palette.dark.greyVariant1
                : theme.colors.palette.light.light,
            "padding": [4, 5, 4, 5]
                .map(function (spacing) { return "".concat(theme.spacing(spacing), "px"); })
                .join(" "),
        },
        "footerTitle": {
            "marginBottom": theme.spacing(1),
        },
        "footerSubtitle": {
            "marginBottom": theme.spacing(1),
        },
        "header": {
            "width": "100%",
            "margin": 0,
            "background": "url(\"".concat(projectImageUrl, "\")"),
            "minHeight": imgAspectRatio === undefined
                ? undefined
                : headerWidth * imgAspectRatio,
            "backgroundSize": "cover",
            "backgroundPosition": "center",
            "display": "flex",
            "justifyContent": "flex-end",
            "alignItems": "flex-start",
            "padding": theme.spacing(3),
        },
        "button": {
            "marinLeft": theme.spacing(7),
            "border": "none",
            "backgroundColor": badgeBackgroundColor !== null && badgeBackgroundColor !== void 0 ? badgeBackgroundColor : undefined,
            "color": (function () {
                if (badgeColor !== undefined) {
                    return "".concat(badgeColor, " !important");
                }
                return undefined;
            })(),
        },
        "footerText": {},
    });
});
//# sourceMappingURL=GlProjectCard.js.map