'use strict';

var tslib_es6 = require('./tslib.es6-2c2ed574.js');
var React = require('react');
var index$1 = require('./index-eba09ec0.js');
var index = require('./index-992544de.js');
require('./index-da3b86cd.js');
var dataTransform = require('./dataTransform-a2855b2e.js');
var togetherApiPaths = require('./togetherApiPaths.js');
var togetherComponentGlobalContext = require('./utils-302bc65c.js');
var core = require('@hhgtech/icons/core');
var core$1 = require('@mantine/core');
var togetherMoleculesCardAuthor = require('./index-63b0c985.js');
var Locale = require('./Locale-fbe01177.js');
require('@hhgtech/icons/other');
require('./index-3d563586.js');
require('./shared-60ad3e5a.js');
require('./index-59a9827e.js');
require('./index-a31ed3e1.js');
require('./index-3643ff1b.js');
require('./translationsContext-78113889.js');
require('./index-98ac1127.js');
require('./index-3b44943e.js');
require('./miscCookieHelper.js');
require('slugify');
require('./constantsIsProduction.js');
require('string-format');
require('./constants-762249c4.js');
require('dayjs');
require('dayjs/plugin/relativeTime');
require('./utils-b92a8b1c.js');
require('./index-5fc323d7.js');
require('./paths-b2d1698d.js');
require('./constants-3fbd741a.js');
require('./index-6ce6e395.js');
require('date-fns/locale');
require('./constantsSite.js');
require('./constantsDomainLocales.js');
require('./constantsRiskScreener.js');
require('./index-4e13f8c3.js');
require('./miscTheme.js');
require('./WhatsApp-1159dc64.js');
require('./Spinner-84d3cdf0.js');
require('./index-17dd60b9.js');
require('@emotion/styled');
require('./index-af9c3c64.js');
require('./index-b0ce6f8f.js');
require('./index-9747120c.js');
require('@emotion/react');
require('./index-d54fe628.js');
require('./index-16480bf7.js');
require('./index.styles-691de58f.js');

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

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

const ProfileDetailContext = React.createContext({});

var styles$1 = {"container":"_0NhMo6T","faq":"nrZtZ-u"};

const Faqs = ({ faqs }) => {
    const [collapseSelected, setCollapseSelected] = React.useState([]);
    const handleClick = (index) => {
        if (collapseSelected.includes(index)) {
            const newCollapseSelected = collapseSelected.filter((item) => item !== index);
            setCollapseSelected(newCollapseSelected);
        }
        else {
            setCollapseSelected((pre) => {
                return [...pre, index];
            });
        }
    };
    return (React__default["default"].createElement("div", { className: styles$1.container }, faqs.map((faq, index) => {
        const collapsed = collapseSelected.includes(index);
        return (React__default["default"].createElement("div", { className: styles$1.faq, key: index },
            React__default["default"].createElement("div", { className: "faq-item", onClick: () => handleClick(index) },
                React__default["default"].createElement("div", { className: "faq-question", dangerouslySetInnerHTML: { __html: faq.question || '' } }),
                collapsed ? React__default["default"].createElement(core.Minus, null) : React__default["default"].createElement(core.Plus, null)),
            React__default["default"].createElement(core$1.Collapse, { in: collapsed, className: "faq-answer" },
                React__default["default"].createElement("div", { dangerouslySetInnerHTML: { __html: faq.answer || '' } }))));
    })));
};

var styles = {"container":"_2ugC2Ll","info":"_8IDDHjn","body":"CCwRHCd","description":"RF63WXG","cardAuthorWrapper":"PIaeC0v"};

const formatExperience = (data) => {
    if (!data)
        return {};
    return {
        title: data === null || data === void 0 ? void 0 : data.title,
        organization: data === null || data === void 0 ? void 0 : data.organization,
        duration: data.duration,
    };
};
const formatEducation = (data) => {
    if (!data)
        return {};
    return {
        completedYear: data === null || data === void 0 ? void 0 : data.completed_year,
        schoolName: data.school_name,
        study: data.study,
    };
};

exports.TabName = void 0;
(function (TabName) {
    TabName[TabName["About"] = 0] = "About";
    TabName[TabName["Care"] = 1] = "Care";
    TabName[TabName["Answer"] = 2] = "Answer";
    TabName[TabName["Posts"] = 3] = "Posts";
})(exports.TabName || (exports.TabName = {}));
exports.UserType = void 0;
(function (UserType) {
    UserType[UserType["Expert"] = 0] = "Expert";
    UserType[UserType["User"] = 1] = "User";
})(exports.UserType || (exports.UserType = {}));
const TabDataInit = {
    experiences: [],
    relatedPosts: [],
    educations: [],
    awards: [],
    contact: {},
    data: {},
};
const ProfileChatbot = (_a) => {
    var { authorProps, authActionWrapper, onSkipQuestion, onCloseFromPost, onChatWithBot, showSkipQuestionTag, currentPageUrl } = _a, rest = tslib_es6.__rest(_a, ["authorProps", "authActionWrapper", "onSkipQuestion", "onCloseFromPost", "onChatWithBot", "showSkipQuestionTag", "currentPageUrl"]);
    const { data: { locale, userInfo, env: { isMarryBaby }, }, } = React.useContext(togetherComponentGlobalContext.TogetherComponentGlobalContext);
    const id = String(authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId);
    const [countValues, setCountValues] = React.useState();
    const [loading, setLoading] = React.useState(false);
    const [info, setInfo] = React.useState();
    const [faqs, setFaqs] = React.useState([]);
    const [description, setDescription] = React.useState('');
    const isAuthorLogin = (userInfo === null || userInfo === void 0 ? void 0 : userInfo._togetherUserId) === (authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId);
    const [activeTab, setActiveTab] = React.useState(1);
    const tabsProps = {
        value: String(activeTab),
        dataList: [
            {
                value: '1',
                text: 'FAQs',
                content: React__default["default"].createElement(Faqs, { faqs: faqs }),
            },
        ],
        onTabChange: (n) => setActiveTab(Number(n)),
    };
    React.useEffect(() => {
        (() => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
            setLoading(true);
            const res = yield Promise.all([
                togetherComponentGlobalContext.callApi(togetherComponentGlobalContext.getApiPath(togetherApiPaths.PATHS.USER.DETAIL, {
                    _locale: locale,
                    id,
                }), 'GET'),
                togetherComponentGlobalContext.callApi(togetherComponentGlobalContext.getApiPath(togetherApiPaths.PATHS.CHATBOT.PROFILE, {
                    _locale: locale,
                }), 'GET'),
                togetherComponentGlobalContext.callApi(togetherComponentGlobalContext.getApiPath(togetherApiPaths.PATHS.CHATBOT.FAQS_LIST, {
                    _locale: locale,
                }), 'GET'),
            ]);
            const [restDetail, profileRes, faqsRes] = res;
            const resInfo = {
                data: restDetail === null || restDetail === void 0 ? void 0 : restDetail.data,
                experiences: (((_b = (_a = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.experiences) || []).map(formatExperience),
                relatedPosts: (((_c = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _c === void 0 ? void 0 : _c.related_post) || []).map((i) => dataTransform.formatArticle(i.post)),
                educations: (((_e = (_d = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _d === void 0 ? void 0 : _d.fields) === null || _e === void 0 ? void 0 : _e.educations) || []).map(formatEducation),
                awards: ((_g = (_f = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _f === void 0 ? void 0 : _f.fields) === null || _g === void 0 ? void 0 : _g.awards_accreditations) || [],
                contact: ((_j = (_h = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _h === void 0 ? void 0 : _h.fields) === null || _j === void 0 ? void 0 : _j.contact) || {},
            };
            (restDetail === null || restDetail === void 0 ? void 0 : restDetail.status) === 1 && setInfo(resInfo);
            setFaqs(((_k = faqsRes === null || faqsRes === void 0 ? void 0 : faqsRes.data) === null || _k === void 0 ? void 0 : _k.faqs) || []);
            setDescription(((_l = profileRes === null || profileRes === void 0 ? void 0 : profileRes.data) === null || _l === void 0 ? void 0 : _l.description) || '');
            setLoading(false);
        }))();
    }, []);
    return (React__default["default"].createElement(ProfileDetailContext.Provider, { value: {
            isMarryBaby,
            siteType: isMarryBaby ? 'marryBaby' : 'helloSites',
            authorId: String((authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId) || ''),
            authActionWrapper,
            onSkipQuestion,
            info,
            authorProps,
            onCloseFromPost,
            countValues,
            setCountValues,
            isAuthorLogin,
            showSkipQuestionTag,
            currentPageUrl,
        } },
        React__default["default"].createElement("div", Object.assign({}, rest, { className: `${styles.container} ${(rest === null || rest === void 0 ? void 0 : rest.className) || ''}`, "data-is-marrybaby": isMarryBaby }), loading ? (React__default["default"].createElement(index.Loading, null)) : (React__default["default"].createElement(React__default["default"].Fragment, null,
            React__default["default"].createElement("div", { className: styles.cardAuthorWrapper },
                React__default["default"].createElement(togetherMoleculesCardAuthor.CardAuthor, Object.assign({}, authorProps, { className: "card-author", showDetailPopup: false, showChatbotButton: locale === Locale.LOCALE.Vietnam, onChatWithBot: onChatWithBot }))),
            React__default["default"].createElement("div", { className: styles.description, dangerouslySetInnerHTML: { __html: description } }),
            faqs.length > 0 && (React__default["default"].createElement("div", { className: styles.body },
                React__default["default"].createElement(index$1.Tabs, Object.assign({}, tabsProps)))))))));
};

exports.ProfileChatbot = ProfileChatbot;
exports.TabDataInit = TabDataInit;
