"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const uikit_1 = require("@gravity-ui/uikit");
const components_1 = require("../../components/index.js");
const theme_1 = require("../../gravity-blocks/context/theme/index.js");
const utils_1 = require("../../utils/index.js");
const microdata_1 = require("../../utils/microdata.js");
const Content_1 = tslib_1.__importDefault(require("../Content/Content.js"));
const utils_2 = require("./utils.js");
const b = (0, utils_1.block)('layout-item');
const LayoutItem = ({ content: { links = [], ...content } = {}, contentMargin = 'm', metaInfo, media, border, fullscreen, icon, className, analyticsEvents, controlPosition = 'content', }) => {
    const normalizedLinks = React.useMemo(() => (0, utils_2.getLayoutItemLinks)(links), [links]);
    const areControlsInFooter = controlPosition === 'footer';
    const theme = (0, theme_1.useTheme)();
    const themedIcon = (0, utils_1.getThemedValue)(icon, theme);
    const contentProps = {
        controlPosition: areControlsInFooter ? 'bottom' : 'default',
        ...content,
        links: normalizedLinks,
        size: content.size || 's',
        colSizes: { all: 12, md: 12 },
    };
    const titleId = (0, uikit_1.useUniqId)();
    const renderMedia = () => {
        if (!media) {
            return null;
        }
        const themedMedia = (0, utils_1.getThemedValue)(media, theme);
        const { title } = content;
        const mediaWithMicrodata = (0, microdata_1.mergeVideoMicrodata)(themedMedia, {
            name: typeof title === 'string' ? title : title?.text,
            description: content.text,
        });
        return fullscreen && (0, utils_2.hasFullscreen)(themedMedia) ? ((0, jsx_runtime_1.jsx)(components_1.FullscreenMedia, { showFullscreenIcon: (0, utils_2.showFullscreenIcon)(themedMedia), children: ({ className: mediaClassName, fullscreen: _fullscreen, ...fullscreenMediaProps } = {}) => ((0, jsx_runtime_1.jsx)(components_1.Media, { ...mediaWithMicrodata, ...fullscreenMediaProps, className: b('media', { border }, mediaClassName), analyticsEvents: analyticsEvents })) })) : ((0, jsx_runtime_1.jsx)(components_1.Media, { ...themedMedia, className: b('media', { border }), analyticsEvents: analyticsEvents }));
    };
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), children: [renderMedia(), metaInfo && (0, jsx_runtime_1.jsx)(components_1.MetaInfo, { items: metaInfo, className: b('meta-info') }), (0, jsx_runtime_1.jsx)("div", { className: b('content', { 'no-media': !media, margin: contentMargin }), children: (0, jsx_runtime_1.jsx)(components_1.IconWrapper, { icon: themedIcon, className: b('wrapper'), size: contentProps.size, children: (0, jsx_runtime_1.jsx)(Content_1.default, { ...contentProps, titleId: titleId }) }) })] }));
};
exports.default = LayoutItem;
//# sourceMappingURL=LayoutItem.js.map
