import { __assign, __rest } from "tslib";
/* eslint-disable jsx-a11y/control-has-associated-label */
// @ts-nocheck
/* eslint-disable jsx-a11y/anchor-has-content */
import './DefaultCard.css';
import React, { useMemo } from 'react';
import { NavLink } from 'react-router-dom';
import { IconArrowRight } from '../../icons/IconArrowRight/IconArrowRight';
import { cn } from '../../utils/bem';
import { getSizeByMap } from '../../utils/getSizeByMap';
import { forwardRefWithAs } from '../../utils/types/PropsWithAsAttributes';
import { Button } from '../Button/Button';
import { usePropsHandler } from '../EventInterceptor/usePropsHandler';
import { Picture } from '../Picture/Picture';
import { Tag } from '../Tag/Tag';
import * as Typography from '../Typography/Typography';
export var cardPropSize = ['s', 'm', 'l'];
export var cardPropSizeDefault = cardPropSize[0];
export var cardPropView = ['feed', 'filled', 'small_post', 'slider', 'text', 'text2'];
export var cardPropViewDefault = cardPropView[0];
export var cardPropDirection = ['column', 'row'];
export var cardPropSizeDirection = cardPropDirection[0];
var sizeMap = {
    s: 'tiny',
    m: 'sm',
    l: 'md'
};
export var cnDefaultCard = cn('DefaultCard');
export var DefaultCard = forwardRefWithAs(function (props) {
    var _a = usePropsHandler(cnDefaultCard(), props), _b = _a.view, view = _b === void 0 ? cardPropViewDefault : _b, _c = _a.direction, direction = _c === void 0 ? cardPropSizeDirection : _c, _d = _a.size, size = _d === void 0 ? cardPropSizeDefault : _d, data = __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 : _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 = useMemo(function () { return (React.createElement(React.Fragment, null,
        React.createElement("div", { className: cnDefaultCard('Tags') },
            hrvTags && (React.createElement(React.Fragment, null, hrvTags.map(function (tag) { return (React.createElement("div", { key: tag.id, className: cnDefaultCard('Tag') },
                React.createElement(Tag, { mode: "link", label: tag.title, size: "s" }))); }))),
            tagsList && (React.createElement(React.Fragment, null, tagsList.map(function (tag) { return (React.createElement("div", { key: tag.id, className: cnDefaultCard('Tag') },
                React.createElement(Tag, { mode: "link", label: tag.title, size: "s" }))); })))))); }, [hrvTags, tagsList]);
    var onClickButtonHandler = function () {
        if (url) {
            window.open(url, '_blank');
        }
    };
    return (React.createElement("div", { className: cnDefaultCard({
            view: view,
            size: size,
            direction: direction
        }), style: style },
        path && React.createElement(NavLink, { className: cnDefaultCard('Link'), to: path }),
        redirectTo && (React.createElement("a", { href: redirectTo, className: cnDefaultCard('Link'), target: "_blank", rel: "noreferrer noopener" })),
        view !== 'text' && view !== 'text2' && defaultPicture && (React.createElement("div", { className: cnDefaultCard('Photo') },
            React.createElement(Picture, __assign({}, defaultPicture)))),
        React.createElement("div", { className: cnDefaultCard('Body') },
            view !== 'text' && postDate && (React.createElement("div", { className: cnDefaultCard('Date') },
                React.createElement(Typography.Typography.Text, { weight: "semibold", size: "xs" }, postDate))),
            descriptionSmall && (React.createElement("div", { className: cnDefaultCard('DescriptionSmall') },
                React.createElement(Typography.Typography.Text, { weight: "semibold", size: "xs", transform: "uppercase" }, descriptionSmall))),
            React.createElement("div", { className: cnDefaultCard('Title') },
                React.createElement(Typography.Typography.Title, { weight: "bold", size: getSizeByMap(sizeMap, size) }, title)),
            view !== 'text' && view !== 'filled' && tags,
            view !== 'text' && view !== 'text2' && linkTitle && (React.createElement("div", { style: {
                    pointerEvents: 'none'
                }, className: cnDefaultCard('Button') },
                React.createElement(Button, { view: "link-secondary", iconRight: currentIcon, iconSize: iconSize, label: linkTitle, onClick: onClickButton ? onClickButton : onClickButtonHandler }))))));
});
