"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 locationContext_1 = require("../../gravity-blocks/context/locationContext/index.js");
const hooks_1 = require("../../gravity-blocks/hooks/index.js");
const Facebook_1 = require("../../gravity-blocks/icons/Facebook.js");
const Linkedin_1 = require("../../gravity-blocks/icons/Linkedin.js");
const Telegram_1 = require("../../gravity-blocks/icons/Telegram.js");
const Twitter_1 = require("../../gravity-blocks/icons/Twitter.js");
const Vk_1 = require("../../gravity-blocks/icons/Vk.js");
const models_1 = require("../../models/index.js");
const utils_1 = require("../../utils/index.js");
const i18n_1 = require("./i18n/index.js");
const icons = {
    facebook: Facebook_1.Facebook,
    twitter: Twitter_1.Twitter,
    linkedin: Linkedin_1.Linkedin,
    vk: Vk_1.Vk,
    telegram: Telegram_1.Telegram,
};
const b = (0, utils_1.block)('share-block');
const Share = ({ items, title }) => {
    const { pathname, hostname } = React.useContext(locationContext_1.LocationContext);
    const handleAnalytics = (0, hooks_1.useAnalytics)(models_1.DefaultEventNames.ShareButton);
    const handleButtonClick = React.useCallback(() => handleAnalytics(), [handleAnalytics]);
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(), children: [title ? ((0, jsx_runtime_1.jsx)(components_1.YFMWrapper, { content: title, modifiers: {
                    constructor: true,
                }, contentClassName: b('title'), tagName: "h5" })) : ((0, jsx_runtime_1.jsx)("h5", { className: b('title'), children: (0, i18n_1.i18n)('constructor-share') })), (0, jsx_runtime_1.jsx)("div", { className: b('items'), children: items &&
                    items.map((type) => {
                        const url = (0, utils_1.getAbsolutePath)(hostname, pathname);
                        const socialUrl = (0, utils_1.getShareLink)(url, type);
                        const icon = icons[type];
                        const urlTitle = (0, i18n_1.i18n)(`${type}-title`);
                        const buttonLabel = (0, i18n_1.i18n)(`${type}-label`);
                        return ((0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "flat", size: "l", target: "_blank", href: socialUrl, className: b('item', { type: type.toLowerCase() }), onClick: handleButtonClick, title: urlTitle, "aria-label": buttonLabel, children: icon && ((0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icon, size: 24, className: b('icon', { type }) })) }, type));
                    }) })] }));
};
exports.default = Share;
//# sourceMappingURL=Share.js.map
