import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { useUniqId } from '@gravity-ui/uikit';
import { FullscreenMedia, IconWrapper, Media, MetaInfo } from "../../components/index.js";
import { useTheme } from "../../gravity-blocks/context/theme/index.js";
import { block, getThemedValue } from "../../utils/index.js";
import { mergeVideoMicrodata } from "../../utils/microdata.js";
import Content from "../Content/Content.js";
import { getLayoutItemLinks, hasFullscreen, showFullscreenIcon } from "./utils.js";
import './LayoutItem.css';
const b = block('layout-item');
const LayoutItem = ({ content: { links = [], ...content } = {}, contentMargin = 'm', metaInfo, media, border, fullscreen, icon, className, analyticsEvents, controlPosition = 'content', }) => {
    const normalizedLinks = React.useMemo(() => getLayoutItemLinks(links), [links]);
    const areControlsInFooter = controlPosition === 'footer';
    const theme = useTheme();
    const themedIcon = getThemedValue(icon, theme);
    const contentProps = {
        controlPosition: areControlsInFooter ? 'bottom' : 'default',
        ...content,
        links: normalizedLinks,
        size: content.size || 's',
        colSizes: { all: 12, md: 12 },
    };
    const titleId = useUniqId();
    const renderMedia = () => {
        if (!media) {
            return null;
        }
        const themedMedia = getThemedValue(media, theme);
        const { title } = content;
        const mediaWithMicrodata = mergeVideoMicrodata(themedMedia, {
            name: typeof title === 'string' ? title : title?.text,
            description: content.text,
        });
        return fullscreen && hasFullscreen(themedMedia) ? (_jsx(FullscreenMedia, { showFullscreenIcon: showFullscreenIcon(themedMedia), children: ({ className: mediaClassName, fullscreen: _fullscreen, ...fullscreenMediaProps } = {}) => (_jsx(Media, { ...mediaWithMicrodata, ...fullscreenMediaProps, className: b('media', { border }, mediaClassName), analyticsEvents: analyticsEvents })) })) : (_jsx(Media, { ...themedMedia, className: b('media', { border }), analyticsEvents: analyticsEvents }));
    };
    return (_jsxs("div", { className: b(null, className), children: [renderMedia(), metaInfo && _jsx(MetaInfo, { items: metaInfo, className: b('meta-info') }), _jsx("div", { className: b('content', { 'no-media': !media, margin: contentMargin }), children: _jsx(IconWrapper, { icon: themedIcon, className: b('wrapper'), size: contentProps.size, children: _jsx(Content, { ...contentProps, titleId: titleId }) }) })] }));
};
export default LayoutItem;
//# sourceMappingURL=LayoutItem.js.map
