'use strict';

var tslib_es6 = require('./tslib.es6-2c2ed574.js');
var React = require('react');
var index = require('./index-3643ff1b.js');
var index$3 = require('./index-4e13f8c3.js');
require('./index-1e5e2223.js');
var core = require('@mantine/core');
require('@mantine/dates');
var index$4 = require('./index-6ce6e395.js');
require('./index-da3b86cd.js');
require('./index-b0ce6f8f.js');
require('./index-024542ed.js');
var index$2 = require('./index-a31ed3e1.js');
require('./index-3d563586.js');
var miscTheme = require('./miscTheme.js');
require('./index-59a9827e.js');
require('./index.styles-691de58f.js');
require('@mantine/hooks');
var utils = require('./utils-b92a8b1c.js');
require('./index-eba09ec0.js');
var index$1 = require('./index-af9c3c64.js');
var togetherComponentGlobalContext = require('./utils-302bc65c.js');
var dateFns = require('date-fns');
var Locale = require('./Locale-fbe01177.js');
var styled = require('@emotion/styled');
var index$6 = require('./index-d54fe628.js');
var index$5 = require('./index-2e0b951e.js');

function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var styled__default = /*#__PURE__*/_interopDefault(styled);

const CardReactionsContext = React.createContext({});

var styles$1 = {"wrapper":"vvR-m49"};

const LikeWrapper = (_a) => {
    var { children, className = '' } = _a, boxProps = tslib_es6.__rest(_a, ["children", "className"]);
    const { isReplied, trackingCategory, trackingLabel, onLikeClick } = React.useContext(CardReactionsContext);
    return (React__default["default"].createElement(core.Box, Object.assign({ className: `${styles$1.wrapper} ${className}`, "data-event-category": trackingCategory, "data-event-action": isReplied ? 'Like Comment Click' : 'Like Post Click', "data-event-label": trackingLabel }, boxProps, { onClick: () => {
            onLikeClick === null || onLikeClick === void 0 ? void 0 : onLikeClick();
        } }), children));
};
const ShareWrapper = (_a) => {
    var { children, className = '' } = _a, boxProps = tslib_es6.__rest(_a, ["children", "className"]);
    const { trackingCategory, trackingLabel, onShareClick } = React.useContext(CardReactionsContext);
    return (React__default["default"].createElement(core.Box, Object.assign({ className: `${styles$1.wrapper} ${className}`, "data-event-category": trackingCategory, "data-event-action": "Share Icon Click", "data-event-label": trackingLabel }, boxProps, { onClick: () => {
            onShareClick === null || onShareClick === void 0 ? void 0 : onShareClick();
        } }), children));
};
const CommentWrapper = (_a) => {
    var { children, className = '' } = _a, boxProps = tslib_es6.__rest(_a, ["children", "className"]);
    const { isReplied, trackingCategory, trackingLabel, onCommentClick } = React.useContext(CardReactionsContext);
    return (React__default["default"].createElement(core.Box, Object.assign({ className: `${styles$1.wrapper} ${className}`, "data-event-category": trackingCategory, "data-event-action": isReplied ? 'Reply Comment Click' : 'Comment Text Click', "data-event-label": trackingLabel }, boxProps, { onClick: (e) => {
            e.preventDefault();
            e.stopPropagation();
            onCommentClick === null || onCommentClick === void 0 ? void 0 : onCommentClick();
        } }), children));
};
const SaveWrapper = (_a) => {
    var { children, className = '' } = _a, boxProps = tslib_es6.__rest(_a, ["children", "className"]);
    const { trackingCategory, trackingLabel, onSaveClick } = React.useContext(CardReactionsContext);
    return (React__default["default"].createElement(core.Box, Object.assign({ className: `${styles$1.wrapper} ${className}`, "data-event-category": trackingCategory, "data-event-action": "Save Post Click", "data-event-label": trackingLabel }, boxProps, { onClick: (e) => {
            e.preventDefault();
            e.stopPropagation();
            onSaveClick === null || onSaveClick === void 0 ? void 0 : onSaveClick();
        } }), children));
};

var styles = {"wrapper":"UhiT4m5","inner":"oEfeTkV","column":"OlbikxJ","iconTxt":"_9GXHCn3","clickableIcon":"HCsrR0N","count":"MV3lNuh","labelReaction":"Ierg-Fq","actions":"_674BTR4","statistical":"XlkglSM","releatedStatistical":"KyekKc3","statisticalNoAction":"TTfvZpR"};

exports.CardReactionType = void 0;
(function (CardReactionType) {
    CardReactionType[CardReactionType["post"] = 1] = "post";
    CardReactionType[CardReactionType["reply"] = 2] = "reply";
})(exports.CardReactionType || (exports.CardReactionType = {}));
const CardReactions = (_a) => {
    var { type, viewCount = 0, loveCount = 0, replyCount = 0, replyPadding, liked, isReplied, isSaved, onCommentClick, onLikeClick, onShareClick, onSaveClick, onGoToUrl, className, style, 
    // hideCommentIcon,
    showingMostEngaging, isMarryBaby: isMarryBabyInit, hasShare = true, hasSave = true, hasActionStatistical = true, hasShowAction = true, isReleatedPost = false, isVertical = false, trackingCategory = 'Together', trackingLabel = '', children } = _a, rest = tslib_es6.__rest(_a, ["type", "viewCount", "loveCount", "replyCount", "replyPadding", "liked", "isReplied", "isSaved", "onCommentClick", "onLikeClick", "onShareClick", "onSaveClick", "onGoToUrl", "className", "style", "showingMostEngaging", "isMarryBaby", "hasShare", "hasSave", "hasActionStatistical", "hasShowAction", "isReleatedPost", "isVertical", "trackingCategory", "trackingLabel", "children"]);
    const { data: { env: { isMarryBaby: isMarryBabyEnv }, }, } = React.useContext(togetherComponentGlobalContext.TogetherComponentGlobalContext);
    const isMarryBaby = Boolean(isMarryBabyInit)
        ? isMarryBabyInit
        : isMarryBabyEnv;
    const { t } = index.useTranslations();
    const { isMobile } = index$1.useScreenSize();
    const hasStatisticalReleated = React.useMemo(() => {
        return viewCount > 0 || replyCount > 0;
    }, [viewCount, replyCount]);
    const hasStatistical = React.useMemo(() => {
        return viewCount > 0 || loveCount > 0 || replyCount > 0;
    }, [viewCount, loveCount, replyCount]);
    const statisticalReleatedPost = React.useCallback(() => {
        return (React__default["default"].createElement("div", { className: `${styles.releatedStatistical} ${hasActionStatistical ? '' : styles.statisticalNoAction} session-statistical` },
            React__default["default"].createElement("div", { className: "releated-post-statistical" },
                React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                        }
                    } }, viewCount > 0 && (React__default["default"].createElement(React__default["default"].Fragment, null,
                    React__default["default"].createElement(index$3.Icon.Eye, { size: 18, isMarryBaby: isMarryBaby }),
                    React__default["default"].createElement("div", { className: styles.labelReaction }, viewCount)))),
                React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl(replyCount > 0 ? '' : '?action=comment');
                        }
                    } },
                    React__default["default"].createElement("div", { className: styles.labelReaction }, replyCount > 0
                        ? t('comment.count', { count: replyCount })
                        : t('comment.now'))))));
    }, [
        hasStatisticalReleated,
        hasActionStatistical,
        isMarryBaby,
        viewCount,
        replyCount,
    ]);
    const statisticalCommonPost = React.useCallback(() => {
        if (!hasStatistical)
            return '';
        return (React__default["default"].createElement("div", { className: `${styles.statistical} ${hasActionStatistical ? '' : styles.statisticalNoAction} session-statistical` },
            React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div", onClick: () => {
                    if (hasActionStatistical) {
                        onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                    }
                } }, viewCount > 0 && (React__default["default"].createElement(React__default["default"].Fragment, null,
                React__default["default"].createElement(index$3.Icon.Eye, { size: 18, isMarryBaby: isMarryBaby }),
                React__default["default"].createElement("div", { className: styles.labelReaction }, viewCount)))),
            isMobile || isVertical ? (React__default["default"].createElement("div", { className: "wrapper-list-statistical" },
                loveCount > 0 ? (React__default["default"].createElement(index$2.Text, { className: styles.iconTxt, size: "p3", as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                        }
                    } },
                    React__default["default"].createElement("div", { className: styles.labelReaction },
                        loveCount,
                        " ",
                        t('cardReactions.like')))) : (React__default["default"].createElement("div", null)),
                replyCount > 0 && (React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                        }
                    } },
                    React__default["default"].createElement("div", { className: styles.labelReaction },
                        replyCount,
                        " ",
                        t('cardReactions.comment')))))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
                loveCount > 0 ? (React__default["default"].createElement(index$2.Text, { className: styles.iconTxt, size: "p3", as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                        }
                    } },
                    React__default["default"].createElement(index$3.Icon.Heart, { isMarryBaby: isMarryBaby, isSolid: false, size: 18, color: '#737373' }),
                    React__default["default"].createElement("div", { className: styles.labelReaction }, loveCount))) : (React__default["default"].createElement("div", null)),
                replyCount > 0 && (React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div", onClick: () => {
                        if (hasActionStatistical) {
                            onGoToUrl === null || onGoToUrl === void 0 ? void 0 : onGoToUrl();
                        }
                    } },
                    React__default["default"].createElement(index$3.Icon.Comment, { size: 18, className: "txt-icon", isMarryBaby: isMarryBaby }),
                    React__default["default"].createElement("div", { className: styles.labelReaction }, replyCount)))))));
    }, [
        hasStatistical,
        hasActionStatistical,
        isMarryBaby,
        isMobile,
        viewCount,
        loveCount,
        replyCount,
    ]);
    return (React__default["default"].createElement(CardReactionsContext.Provider, { value: {
            liked,
            loveCount,
            trackingCategory,
            trackingLabel,
            isReplied,
            onLikeClick,
            onShareClick,
            onCommentClick,
            onSaveClick,
        } }, children || (React__default["default"].createElement("div", Object.assign({ className: `${styles.wrapper} ${className}`, "data-show-most-engaging": showingMostEngaging, "data-type": type === exports.CardReactionType.post ? 'post' : 'reply', "data-reply-padding": type === exports.CardReactionType.reply && replyPadding, "data-is-marrybaby": isMarryBaby, style: style }, rest),
        React__default["default"].createElement("div", { className: `${styles.inner} ${isVertical ? 'direction-vertical' : ''}` },
            hasShowAction && (React__default["default"].createElement("div", { className: `${styles.actions} session-action` },
                React__default["default"].createElement(LikeWrapper, { className: `${styles.clickableIcon} wrapper-action` },
                    React__default["default"].createElement(index$2.Text, { className: styles.iconTxt, size: "p3", as: "div" },
                        React__default["default"].createElement(index$3.Icon.Heart, { isMarryBaby: isMarryBaby, isSolid: liked, size: 18, color: liked
                                ? isMarryBaby
                                    ? miscTheme.theme.mbColors.pink
                                    : miscTheme.theme.colors.red800
                                : '#737373' }),
                        React__default["default"].createElement("div", { className: styles.labelReaction }, t('cardReactions.like')))),
                hasShare && (React__default["default"].createElement(ShareWrapper, { className: `${styles.clickableIcon} wrapper-action` },
                    React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div" },
                        React__default["default"].createElement(index$3.Icon.Share, { size: 18, isMarryBaby: isMarryBaby }),
                        React__default["default"].createElement("div", { className: styles.labelReaction }, t('share.title'))))),
                hasSave && (React__default["default"].createElement(SaveWrapper, { className: `${styles.clickableIcon} wrapper-action` },
                    React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div" },
                        isSaved ? (React__default["default"].createElement(index$3.Icon.Bookmark, { size: 18, isMarryBaby: isMarryBaby, color: isMarryBaby ? '#3E3F58' : '#737373' })) : (React__default["default"].createElement(index$3.Icon.Save, { size: 18, isMarryBaby: isMarryBaby, color: isMarryBaby ? '#3E3F58' : '#737373' })),
                        React__default["default"].createElement("div", { className: styles.labelReaction }, isSaved
                            ? t('cardReactions.unSave')
                            : t('cardReactions.save'))))),
                React__default["default"].createElement(CommentWrapper, { className: `${styles.clickableIcon} wrapper-action` },
                    React__default["default"].createElement(index$2.Text, { size: "p3", className: styles.iconTxt, as: "div" },
                        React__default["default"].createElement(index$3.Icon.Comment, { size: 18, className: "txt-icon", isMarryBaby: isMarryBaby }),
                        React__default["default"].createElement("div", { className: styles.labelReaction }, t('cardReactions.comment')))))),
            isReleatedPost
                ? statisticalReleatedPost()
                : statisticalCommonPost())))));
};
CardReactions.LikeWrapper = LikeWrapper;
CardReactions.ShareWrapper = ShareWrapper;
CardReactions.CommentWrapper = CommentWrapper;

const useStyles = core.createStyles((theme) => ({
    wrapper: {
        display: 'flex',
        flexWrap: 'wrap',
        width: '100%',
        padding: '0.5rem 0',
        gap: '0.5rem',
    },
    item: {
        position: 'relative',
        whiteSpace: 'nowrap',
        padding: '5px 12px',
        // border: '1px solid #e4e8ec',
        background: theme.colors.gray[0],
        borderRadius: '2rem',
        cursor: 'pointer',
        '-webkit-user-drag': 'none',
        userSelect: 'none',
        textDecoration: 'none',
        '*': {
            pointerEvents: 'none',
        },
        '&:first-child': {
            marginLeft: 0,
        },
    },
    text: {},
}));
const TagTopic = (_a) => {
    var { topics = [], onClick, className, style, trackingCategory = 'Together', locale = 'vi-VN', classNames, styles, unstyled, shortenedNumber = 3, shortenedStyle } = _a, rest = tslib_es6.__rest(_a, ["topics", "onClick", "className", "style", "trackingCategory", "locale", "classNames", "styles", "unstyled", "shortenedNumber", "shortenedStyle"]);
    const { t } = index.useTranslations();
    const { classes } = useStyles(undefined, {
        name: 'TagTopic',
        classNames,
        styles,
        unstyled,
    });
    const { data: { env: { togetherBasePath }, }, action: { sanitizeFunction }, } = React.useContext(togetherComponentGlobalContext.TogetherComponentGlobalContext);
    const [showAll, setShowAll] = React.useState(!shortenedStyle);
    return (React__default["default"].createElement("div", Object.assign({ onClick: onClick, className: `${classes.wrapper} ${className}`, style: style }, rest),
        (showAll ? topics : topics.slice(0, shortenedNumber)).map((topic, index) => {
            const isMonthTopic = (topic === null || topic === void 0 ? void 0 : topic.dueDateMonth) &&
                (topic === null || topic === void 0 ? void 0 : topic.dueDateMonth) !== 0 &&
                (topic === null || topic === void 0 ? void 0 : topic.dueDateYear) &&
                (topic === null || topic === void 0 ? void 0 : topic.dueDateYear) !== 0;
            return (React__default["default"].createElement("a", { className: classes.item, key: index, "data-event-category": trackingCategory, "data-event-action": "Topic in Post Click", "data-event-label": `${togetherComponentGlobalContext.getCurrentBaseUrl(locale)}${togetherBasePath}${topic.url}`, href: topic.isActive && !topic.isHidden
                    ? `${togetherBasePath}${topic.url}/`
                    : undefined },
                React__default["default"].createElement(index$2.Text, { size: "p4" },
                    React__default["default"].createElement("span", { style: Object.assign({}, (isMonthTopic && {
                            textTransform: 'capitalize',
                        })), dangerouslySetInnerHTML: {
                            __html: isMonthTopic
                                ? `${dateFns.format(new Date(2020, Number(topic.dueDateMonth) - 1, 1), 'MMMM', {
                                    locale: index$4.DATE_FNS_LOCALE[locale],
                                })}${locale === Locale.LOCALE.Vietnam ? '/' : ' '}${topic === null || topic === void 0 ? void 0 : topic.dueDateYear}`
                                : (sanitizeFunction === null || sanitizeFunction === void 0 ? void 0 : sanitizeFunction(topic.name)) || topic.name,
                        } }))));
        }),
        !showAll && topics.length > shortenedNumber && (React__default["default"].createElement("a", { className: classes.item, href: "#", onClick: (e) => {
                e.preventDefault();
                setShowAll(true);
            } },
            React__default["default"].createElement(index$2.Text, { size: "p4" },
                "+",
                t('tagTopic.moreTopics', {
                    number: topics.length - shortenedNumber,
                }))))));
};

const StyledLabelSortPin = styled__default["default"].div `
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  cursor: pointer;
  &[data-color='gray'] {
    background: ${miscTheme.theme.colors.neutral50};
  }
  &[data-color='white'] {
    border-bottom: 1px solid #e4e8ec;
    background: ${miscTheme.theme.colors.white};
  }

  .popover-menu__btn {
    display: flex;
    min-width: 2rem;
    height: 2rem;
    align-items: center;
    padding: 8px 0 !important;
    border: none;
    margin-left: 0.5rem;
    background: transparent;
    > span {
      display: flex;
      align-items: center;
    }

    &:hover {
      background: transparent !important;
    }
  }

  &.label-pinned {
    border-radius: ${miscTheme.theme.borderRadius} 6px 0 0;
    .label-sort-pin-icon {
      width: 16px;
      height: 16px;
      vertical-align: middle;
    }
  }

  &[data-is-marrybaby='true'] {
    padding: 0.75rem 1rem;
    border-radius: 16px 16px 0px 0px;
    &[data-color='white'] {
      border-bottom: none;
    }
    &[data-color='gray'] {
      background: #f3f3f3;
    }
    .popover-menu__btn {
      width: unset;
    }

    &.label-pinned {
      border-bottom: none;
      background: #fff9eb;
      border-radius: 1rem 1rem 0 0;
      .label-sort-pin-icon {
        margin-right: 8px;
      }
      .label-sort-pin-heading {
        color: #fb8c00;
      }
    }
    &.label-sorting {
      ${utils.MediaQueries.tdUp} {
        padding-bottom: 1.5rem;
        margin-bottom: -0.75rem;
      }
    }
  }
`;

const LabelSortPin = ({ label, rightLabel, onClick, color, className, style, }) => {
    const { data: { env: { isMarryBaby }, }, } = React.useContext(togetherComponentGlobalContext.TogetherComponentGlobalContext);
    return (React__default["default"].createElement(StyledLabelSortPin, { "data-is-marrybaby": isMarryBaby, "data-color": color, onClick: onClick, className: className, style: style },
        React__default["default"].createElement(index$2.Text, { className: "label-sort-pin-heading", size: isMarryBaby ? 'p4' : 'p3', weight: "bold" }, label),
        rightLabel));
};

var img$4 = "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='none'%3e%3cpath stroke='%23FB8C00' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m3.5 20 4.37-4.37'/%3e%3cpath stroke='%23FB8C00' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M4.956 11.294a1 1 0 0 0 0 1.414l2.918 2.918 2.918 2.918a1 1 0 0 0 1.414 0l1.175-1.175a1 1 0 0 0 .293-.707v-3.936l2.9-2.9 2.31.123c.282.015.56-.091.76-.291l.573-.574a1 1 0 0 0 0-1.414l-4.386-4.386a1 1 0 0 0-1.414 0l-.574.574a1 1 0 0 0-.29.76l.122 2.309-2.9 2.9H6.838a1 1 0 0 0-.707.293z' clip-rule='evenodd'/%3e%3cpath stroke='%23FB8C00' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m16.57 9.83-2.9-2.9'/%3e%3c/svg%3e";
var MBPinOrange = img$4;

var img$3 = "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3e%3cpath stroke='%23FEA21E' stroke-linecap='round' d='m7.186 7.682-3.504 6.132'/%3e%3cpath fill='%23FEA21E' stroke='%23FEA21E' stroke-linejoin='round' stroke-width='.5' d='M3.246 7.784a.25.25 0 0 0 .091.342l5.447 3.145a.25.25 0 0 0 .342-.092 3.39 3.39 0 0 0 .11-3.186l1.622-2.808a2.66 2.66 0 0 0 1.606-1.239.25.25 0 0 0-.092-.341l-4.19-2.42a.25.25 0 0 0-.341.092 2.66 2.66 0 0 0-.27 2.01L5.949 6.095a3.39 3.39 0 0 0-2.703 1.69Z'/%3e%3c/svg%3e";
var IconPinYellow = img$3;

const LabelPin = ({ onClick, color, className, style }) => {
    const { data: { env: { isMarryBaby }, }, } = React.useContext(togetherComponentGlobalContext.TogetherComponentGlobalContext);
    const { t } = index.useTranslations();
    return (React__default["default"].createElement(LabelSortPin, { label: React__default["default"].createElement(React__default["default"].Fragment, null,
            isMarryBaby && (React__default["default"].createElement("img", { className: "label-sort-pin-icon", src: MBPinOrange, loading: "lazy" })),
            ' ',
            t('label.pinnedPost')), rightLabel: !isMarryBaby && (React__default["default"].createElement("img", { className: "label-sort-pin-icon", src: IconPinYellow, loading: "lazy" })), onClick: onClick, color: 'white' , className: `label-pinned ${className}`, style: style }));
};

var img$2 = "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3e%3cpath stroke='%238C8C8C' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M13.333 4 6 11.333 2.667 8'/%3e%3c/svg%3e";
var IconCheckGray = img$2;

var img$1 = "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='none'%3e%3cpath stroke='%23262626' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.75' d='m15 18-6-6 6-6'/%3e%3c/svg%3e";
var IconChevronLeftDark = img$1;

var img = "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3e%3cpath stroke='%23595959' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 12 4-4-4-4'/%3e%3c/svg%3e";
var IconChevronRightDark = img;

const TreePopoverMenu = (_a) => {
    var { data } = _a, popoverProps = tslib_es6.__rest(_a, ["data"]);
    return (React__default["default"].createElement(index$5.PopoverMenu, Object.assign({}, popoverProps), ({ setShow }) => React__default["default"].createElement(Tree, { data: data, setShow: setShow })));
};
const getCurrentDataFromPath = (data, path) => {
    const pathItems = path.split('.');
    let currentData = data;
    pathItems.forEach((pathItem) => {
        var _a, _b;
        if (!pathItem || !currentData || (currentData === null || currentData === void 0 ? void 0 : currentData.type) !== 'list')
            return;
        currentData = (_b = (_a = currentData === null || currentData === void 0 ? void 0 : currentData.list) === null || _a === void 0 ? void 0 : _a[Number(pathItem)]) === null || _b === void 0 ? void 0 : _b.subTree;
    });
    return currentData;
};
const Tree = ({ data, setShow }) => {
    var _a;
    const [path, setPath] = React.useState('');
    const currentData = React.useMemo(() => data && getCurrentDataFromPath(data, path), [data, path]);
    if (!data)
        return null;
    if (!currentData)
        return null;
    const handleItemClick = (index, { subTree, onClick = () => null }) => {
        if (onClick)
            onClick();
        if (!subTree)
            setShow && setShow(false);
        else
            setPath((p) => p.split('.').concat(String(index)).join('.'));
    };
    return (React__default["default"].createElement(index$5.StyledTree, null,
        currentData.isShowheader ? (React__default["default"].createElement("div", { className: "__header" },
            path ? (React__default["default"].createElement("img", { className: "__back-btn", src: IconChevronLeftDark, onClick: () => setPath((p) => p.split('.').slice(0, -1).join('.')), loading: "lazy" })) : null,
            currentData.title ? (React__default["default"].createElement(index$6.Heading, { className: "__title", tag: "h6" }, currentData.title)) : null)) : null,
        currentData.description ? (React__default["default"].createElement(index$2.Text, { className: "tree-text-description", color: miscTheme.theme.colors.gray600, size: "p3", weight: "regular" }, currentData.description)) : null,
        React__default["default"].createElement("div", { className: "__content" },
            currentData.type === 'jsx'
                ? (_a = currentData === null || currentData === void 0 ? void 0 : currentData.jsxRenderer) === null || _a === void 0 ? void 0 : _a.call(currentData, setShow)
                : null,
            currentData.type === 'list' ? (React__default["default"].createElement("ul", { className: "__list" }, Array.isArray(currentData.list)
                ? currentData.list.map((item, index) => (React__default["default"].createElement("li", { key: index, style: item.style, className: `__item ${item.className}` },
                    ' ',
                    React__default["default"].createElement("div", { className: `__btn ${item.selected ? '--checked' : ''}`, onClick: () => handleItemClick(index, item), "data-event-category": item.dataEventCategory, "data-event-action": item.dataEventAction, "data-event-label": item.dataEventLabel },
                        item.icon && (React__default["default"].createElement("img", { className: "__icon", src: item.icon, loading: "lazy" })),
                        React__default["default"].createElement("span", null, item.label)),
                    item.subTree ? (React__default["default"].createElement("img", { className: "__toggle", src: IconChevronRightDark, loading: "lazy" })) : null,
                    item.selected ? (React__default["default"].createElement("img", { className: "__toggle", src: IconCheckGray, loading: "lazy" })) : null)))
                : null)) : null)));
};

exports.CardReactions = CardReactions;
exports.LabelPin = LabelPin;
exports.LabelSortPin = LabelSortPin;
exports.TagTopic = TagTopic;
exports.TreePopoverMenu = TreePopoverMenu;
