"use strict";
exports.__esModule = true;
exports.PageCard = void 0;
var tslib_1 = require("tslib");
/* eslint-disable jsx-a11y/control-has-associated-label */
// @ts-nocheck
/* eslint-disable jsx-a11y/anchor-has-content */
require("./PageCard.css");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var IconArrowRight_1 = require("../../icons/IconArrowRight/IconArrowRight");
var bem_1 = require("../../utils/bem");
var getSizeByMap_1 = require("../../utils/getSizeByMap");
var Button_1 = require("../Button/Button");
var Link_1 = require("../Link/Link");
var Picture_1 = require("../Picture/Picture");
var Typography_1 = require("../Typography/Typography");
var cnPageCard = (0, bem_1.cn)('PageCard');
var sizeMapTitle = {
    s: 'tiny',
    m: 'lg',
    l: 'lg'
};
var sizeMapSubTitle = {
    m: 'l'
};
var PageCard = function (_a) {
    var view = _a.view, title = _a.title, titleTag = _a.titleTag, subtitle = _a.subtitle, linkText = _a.linkText, link = _a.link, linkImage = _a.linkImage, _b = _a.linkView, linkView = _b === void 0 ? 'link-secondary' : _b, decor = _a.decor, _c = _a.size, size = _c === void 0 ? 'm' : _c, _d = _a.lineColor, lineColor = _d === void 0 ? '#0F161A' : _d, _e = _a.decorPosition, decorPosition = _e === void 0 ? 'default' : _e, picture = _a.picture, buttonAttrs = _a.buttonAttrs;
    var handleClick = function (link) {
        if (link.includes('http') || (buttonAttrs === null || buttonAttrs === void 0 ? void 0 : buttonAttrs.target) === '_blank') {
            window.open(link, '_blank');
        }
        else {
            window.location = link;
        }
    };
    var LinkImageComponent = (0, react_1.useMemo)(function () { return react_1["default"].createElement(react_1["default"].Fragment, null, linkImage && react_1["default"].createElement("img", { src: linkImage.url, alt: "alt" })); }, [linkImage]);
    return (react_1["default"].createElement("div", { className: cnPageCard({
            decorPosition: decorPosition,
            size: size,
            view: view,
            picture: !!picture,
            hoverState: !!link
        }) },
        link && view !== 'secondary' && (
        // eslint-disable-next-line jsx-a11y/anchor-is-valid
        react_1["default"].createElement("a", { href: link, onClick: function (e) {
                e.preventDefault();
                handleClick(link);
            }, className: cnPageCard('LinkOverlay') })),
        lineColor && react_1["default"].createElement("div", { className: cnPageCard('Line'), style: { backgroundColor: lineColor } }),
        picture && react_1["default"].createElement(Picture_1.Picture, (0, tslib_1.__assign)({ className: cnPageCard('Picture') }, picture)),
        react_1["default"].createElement("div", { className: cnPageCard('Title') },
            react_1["default"].createElement(Typography_1.Typography.Title, { size: view === 'secondary' ? 'xs' : (0, getSizeByMap_1.getSizeByMap)(sizeMapTitle, size), as: titleTag }, title)),
        subtitle && (react_1["default"].createElement("div", { className: cnPageCard('SubTitle') },
            react_1["default"].createElement(Typography_1.Typography.Text, { size: view === 'secondary' ? 'm' : (0, getSizeByMap_1.getSizeByMap)(sizeMapSubTitle, size) }, subtitle))),
        linkText && link && (react_1["default"].createElement("div", { className: cnPageCard('Button') },
            react_1["default"].createElement(Button_1.Button, { view: linkView, iconRight: !linkImage && IconArrowRight_1.IconArrowRight, iconSize: "m", icon: LinkImageComponent, label: linkText, onClick: function () { return handleClick(link); } }))),
        !linkText && link && (react_1["default"].createElement("div", { className: cnPageCard('Link') },
            react_1["default"].createElement(Link_1.Link, { href: link.link, target: link.targetBlank ? '_blank' : null },
                react_1["default"].createElement(Typography_1.Typography.Text, null, link.title)))),
        decor && (react_1["default"].createElement("div", { className: cnPageCard('Decor') },
            react_1["default"].createElement(Picture_1.Picture, { desktop: decor.url, desktopWebp: decor.urlWebp })))));
};
exports.PageCard = PageCard;
