import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { Button, Icon } from '@gravity-ui/uikit';
import { YFMWrapper } from "../../components/index.js";
import { LocationContext } from "../../gravity-blocks/context/locationContext/index.js";
import { useAnalytics } from "../../gravity-blocks/hooks/index.js";
import { Facebook } from "../../gravity-blocks/icons/Facebook.js";
import { Linkedin } from "../../gravity-blocks/icons/Linkedin.js";
import { Telegram } from "../../gravity-blocks/icons/Telegram.js";
import { Twitter } from "../../gravity-blocks/icons/Twitter.js";
import { Vk } from "../../gravity-blocks/icons/Vk.js";
import { DefaultEventNames } from "../../models/index.js";
import { block, getAbsolutePath, getShareLink } from "../../utils/index.js";
import { i18n } from "./i18n/index.js";
import './Share.css';
const icons = {
    facebook: Facebook,
    twitter: Twitter,
    linkedin: Linkedin,
    vk: Vk,
    telegram: Telegram,
};
const b = block('share-block');
const Share = ({ items, title }) => {
    const { pathname, hostname } = React.useContext(LocationContext);
    const handleAnalytics = useAnalytics(DefaultEventNames.ShareButton);
    const handleButtonClick = React.useCallback(() => handleAnalytics(), [handleAnalytics]);
    return (_jsxs("div", { className: b(), children: [title ? (_jsx(YFMWrapper, { content: title, modifiers: {
                    constructor: true,
                }, contentClassName: b('title'), tagName: "h5" })) : (_jsx("h5", { className: b('title'), children: i18n('constructor-share') })), _jsx("div", { className: b('items'), children: items &&
                    items.map((type) => {
                        const url = getAbsolutePath(hostname, pathname);
                        const socialUrl = getShareLink(url, type);
                        const icon = icons[type];
                        const urlTitle = i18n(`${type}-title`);
                        const buttonLabel = i18n(`${type}-label`);
                        return (_jsx(Button, { view: "flat", size: "l", target: "_blank", href: socialUrl, className: b('item', { type: type.toLowerCase() }), onClick: handleButtonClick, title: urlTitle, "aria-label": buttonLabel, children: icon && (_jsx(Icon, { data: icon, size: 24, className: b('icon', { type }) })) }, type));
                    }) })] }));
};
export default Share;
//# sourceMappingURL=Share.js.map
