"use strict";
exports.__esModule = true;
exports.DefaultCard = exports.cnDefaultCard = exports.cardPropSizeDirection = exports.cardPropDirection = exports.cardPropViewDefault = exports.cardPropView = exports.cardPropSizeDefault = exports.cardPropSize = 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("./DefaultCard.css");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var react_router_dom_1 = require("react-router-dom");
var IconArrowRight_1 = require("../../icons/IconArrowRight/IconArrowRight");
var bem_1 = require("../../utils/bem");
var getSizeByMap_1 = require("../../utils/getSizeByMap");
var PropsWithAsAttributes_1 = require("../../utils/types/PropsWithAsAttributes");
var Button_1 = require("../Button/Button");
var usePropsHandler_1 = require("../EventInterceptor/usePropsHandler");
var Picture_1 = require("../Picture/Picture");
var Tag_1 = require("../Tag/Tag");
var Typography = (0, tslib_1.__importStar)(require("../Typography/Typography"));
exports.cardPropSize = ['s', 'm', 'l'];
exports.cardPropSizeDefault = exports.cardPropSize[0];
exports.cardPropView = ['feed', 'filled', 'small_post', 'slider', 'text', 'text2'];
exports.cardPropViewDefault = exports.cardPropView[0];
exports.cardPropDirection = ['column', 'row'];
exports.cardPropSizeDirection = exports.cardPropDirection[0];
var sizeMap = {
    s: 'tiny',
    m: 'sm',
    l: 'md'
};
exports.cnDefaultCard = (0, bem_1.cn)('DefaultCard');
exports.DefaultCard = (0, PropsWithAsAttributes_1.forwardRefWithAs)(function (props) {
    var _a = (0, usePropsHandler_1.usePropsHandler)((0, exports.cnDefaultCard)(), props), _b = _a.view, view = _b === void 0 ? exports.cardPropViewDefault : _b, _c = _a.direction, direction = _c === void 0 ? exports.cardPropSizeDirection : _c, _d = _a.size, size = _d === void 0 ? exports.cardPropSizeDefault : _d, data = (0, tslib_1.__rest)(_a, ["view", "direction", "size"]);
    var _e = data || {}, contentType = _e.contentType, postDate = _e.postDate, hrvTags = _e.hrvTags, tagsList = _e.tags, title = _e.title, picture = _e.picture, _f = _e.linkIcon, linkIcon = _f === void 0 ? IconArrowRight_1.IconArrowRight : _f, onClickButton = _e.onClickButton, url = _e.url, path = _e.path, descriptionSmall = _e.descriptionSmall, _g = _e.iconSize, iconSize = _g === void 0 ? 's' : _g, style = _e.style, linkTitle = _e.linkTitle, bannerPicture = _e.bannerPicture, redirectTo = _e.redirectTo;
    var defaultPicture = null;
    var currentIcon = linkIcon;
    switch (contentType) {
        case 6:
            defaultPicture = bannerPicture;
            break;
        default:
            defaultPicture = picture;
            break;
    }
    var tags = (0, react_1.useMemo)(function () { return (react_1["default"].createElement(react_1["default"].Fragment, null,
        react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('Tags') },
            hrvTags && (react_1["default"].createElement(react_1["default"].Fragment, null, hrvTags.map(function (tag) { return (react_1["default"].createElement("div", { key: tag.id, className: (0, exports.cnDefaultCard)('Tag') },
                react_1["default"].createElement(Tag_1.Tag, { mode: "link", label: tag.title, size: "s" }))); }))),
            tagsList && (react_1["default"].createElement(react_1["default"].Fragment, null, tagsList.map(function (tag) { return (react_1["default"].createElement("div", { key: tag.id, className: (0, exports.cnDefaultCard)('Tag') },
                react_1["default"].createElement(Tag_1.Tag, { mode: "link", label: tag.title, size: "s" }))); })))))); }, [hrvTags, tagsList]);
    var onClickButtonHandler = function () {
        if (url) {
            window.open(url, '_blank');
        }
    };
    return (react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)({
            view: view,
            size: size,
            direction: direction
        }), style: style },
        path && react_1["default"].createElement(react_router_dom_1.NavLink, { className: (0, exports.cnDefaultCard)('Link'), to: path }),
        redirectTo && (react_1["default"].createElement("a", { href: redirectTo, className: (0, exports.cnDefaultCard)('Link'), target: "_blank", rel: "noreferrer noopener" })),
        view !== 'text' && view !== 'text2' && defaultPicture && (react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('Photo') },
            react_1["default"].createElement(Picture_1.Picture, (0, tslib_1.__assign)({}, defaultPicture)))),
        react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('Body') },
            view !== 'text' && postDate && (react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('Date') },
                react_1["default"].createElement(Typography.Typography.Text, { weight: "semibold", size: "xs" }, postDate))),
            descriptionSmall && (react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('DescriptionSmall') },
                react_1["default"].createElement(Typography.Typography.Text, { weight: "semibold", size: "xs", transform: "uppercase" }, descriptionSmall))),
            react_1["default"].createElement("div", { className: (0, exports.cnDefaultCard)('Title') },
                react_1["default"].createElement(Typography.Typography.Title, { weight: "bold", size: (0, getSizeByMap_1.getSizeByMap)(sizeMap, size) }, title)),
            view !== 'text' && view !== 'filled' && tags,
            view !== 'text' && view !== 'text2' && linkTitle && (react_1["default"].createElement("div", { style: {
                    pointerEvents: 'none'
                }, className: (0, exports.cnDefaultCard)('Button') },
                react_1["default"].createElement(Button_1.Button, { view: "link-secondary", iconRight: currentIcon, iconSize: iconSize, label: linkTitle, onClick: onClickButton ? onClickButton : onClickButtonHandler }))))));
});
