import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import "./style.scss";
import PersonViewExperienceCard from "../PersonViewExperienceCard";
import clsx from "clsx";
import PersonViewEducationCard from "../PersonViewEducationCard";
import { ClickableText, Loader, SkillIndustryBadge, Tooltip } from "../..";
import { detectEntitiesInDescription, detectEntitiesInDescriptionWithSlop, highlightRichTextWithSlop, splitTruncatedTextByKeyWordsWithSlop, } from "../../../utils";
import { useEffect, useState, useRef } from "react";
const PersonViewSummary = ({ about = "", experience = [], totalExperience = "", education = [], onCompanyNameClick, industries, isIndustryLoading = false, filterIndustries, filterSkills, filterProducts, isExpIndustriesLoading = false, scrollToEducation = false, dataCy, isSummaryView, productsObject, }) => {
    const [hoveredPill, setHoveredPill] = useState(null);
    const [showMore, setShowMore] = useState(false);
    const educationRef = useRef(null);
    const getClasses = (phraseIds) => clsx({
        ["highlight"]: true,
        ["hover"]: hoveredPill !== null && phraseIds.includes(hoveredPill.toLowerCase()),
    });
    const isAboutNA = clsx({
        "personViewSummary-About": about.toLowerCase() !== "not available",
        "personViewSummary-AboutNA": about.toLowerCase() === "not available",
    });
    const aboutSectionSkills = detectEntitiesInDescriptionWithSlop(about.trim(), filterSkills);
    const aboutSectionProducts = detectEntitiesInDescription(about.trim(), filterProducts);
    const shouldShowMatchedKeywords = industries.length !== 0 ||
        aboutSectionSkills.length !== 0 ||
        aboutSectionProducts.length !== 0 ||
        isIndustryLoading;
    const keyWords = [...aboutSectionSkills, ...industries];
    const aboutWords = about.trim().split(/\s+/);
    const wordLimit = 30;
    const isTruncated = aboutWords.length > wordLimit;
    const splittedText = splitTruncatedTextByKeyWordsWithSlop(about, keyWords, aboutSectionProducts);
    const highlightedText = highlightRichTextWithSlop(splittedText.filter((sentence) => sentence.trim() !== "\n" && sentence.trim() !== ""), keyWords, getClasses, about, aboutSectionProducts);
    const truncatedTextHighlighted = highlightRichTextWithSlop(splitTruncatedTextByKeyWordsWithSlop(aboutWords.slice(0, wordLimit).join(" "), keyWords, aboutSectionProducts), keyWords, getClasses, aboutWords.slice(0, wordLimit).join(" "), aboutSectionProducts);
    const handleHoverPill = (text, _type, action) => {
        if (action === "enter") {
            setHoveredPill(text);
        }
        else if (action === "leave") {
            setHoveredPill(null);
        }
    };
    const handleToggleShowMore = () => {
        setShowMore(!showMore);
    };
    useEffect(() => {
        if (scrollToEducation && educationRef.current) {
            educationRef.current.scrollIntoView({
                behavior: "smooth",
                block: "start",
            });
        }
    }, [scrollToEducation]);
    const showExperience = !isSummaryView &&
        filterIndustries &&
        onCompanyNameClick &&
        experience?.length !== 0;
    return (_jsx("div", { className: "personViewSummary--Generic", children: _jsxs("div", { className: isAboutNA, children: [about.toLowerCase() !== "not available" && !isSummaryView && (_jsx("h2", { children: "About" })), about.toLowerCase() !== "not available" && (_jsxs("div", { id: "personViewSummary-About-Text", "data-cy": `${dataCy}-about-section`, children: [_jsxs("span", { children: [showMore ? highlightedText : truncatedTextHighlighted, !showMore && isTruncated && "..."] }), isTruncated && (_jsx("div", { className: "clickableTextWrapper", children: _jsx(ClickableText, { text: showMore ? "‎ See less" : "See more", onClick: handleToggleShowMore, sizeVariant: "base" }) })), shouldShowMatchedKeywords && (_jsx("div", { className: "personViewExperienceDetails--MatchedKeywordsAbout", children: isIndustryLoading ? (_jsx(Loader, { width: "24", height: "24" })) : (_jsxs(_Fragment, { children: [aboutSectionProducts.length > 0 && (_jsxs("span", { className: "personViewExperienceDetails--SkillsAndIndustries", children: [_jsx("h2", { children: "COMPANY PRODUCT:" }), _jsx("span", { children: aboutSectionProducts.map((product, key) => (_jsx(Tooltip, { content: 'Extracted from "About"', toolTipPosition: "bottom", children: _jsx(SkillIndustryBadge, { highlight: handleHoverPill, highlightPill: false, text: product }) }, `industry-${key}`))) })] })), industries.length > 0 && (_jsxs("span", { className: "personViewExperienceDetails--SkillsAndIndustries", children: [_jsx("h2", { children: "INDUSTRIES MATCHED:" }), _jsx("span", { children: industries.map((industry, key) => (_jsx(Tooltip, { content: 'Extracted from "About"', toolTipPosition: "bottom", children: _jsx(SkillIndustryBadge, { highlight: handleHoverPill, highlightPill: true, text: industry, type: "industry" }) }, `industry-${key}`))) })] })), aboutSectionSkills.length > 0 && (_jsxs("span", { className: "personViewExperienceDetails--SkillsAndIndustries", children: [_jsx("h2", { children: "KEYWORDS/SKILLS:" }), _jsx("span", { children: aboutSectionSkills.map((skill, key) => (_jsx(Tooltip, { content: 'Extracted from "About"', toolTipPosition: "bottom", children: _jsx(SkillIndustryBadge, { highlight: handleHoverPill, highlightPill: true, text: skill, type: "skill" }) }, `skill-${key}`))) })] }))] })) }))] })), showExperience && (_jsxs("div", { className: "personViewSummary-Experience", "data-cy": `${dataCy}-experience-section`, children: [_jsx("h2", { children: "Work Experience" }), totalExperience && (_jsxs("span", { className: "totalExperience", children: ["Total: ", totalExperience] })), experience?.map((companyExp, key) => {
                            return (_jsx(PersonViewExperienceCard, { companyLogo: companyExp?.companyLogo, experienceDetails: companyExp?.experienceDetails, onCompanyNameClick: onCompanyNameClick, filterIndustries: filterIndustries, filterSkills: filterSkills, filterProducts: filterProducts, isExpIndustriesLoading: isExpIndustriesLoading, companyExp: companyExp, isNoSkillsOrIndustries: false, dataCy: `${dataCy}-experience-section`, productsObject: productsObject }, key));
                        })] })), !isSummaryView && education?.length !== 0 && (_jsxs("div", { ref: educationRef, className: "personViewSummary-Education", "data-cy": `${dataCy}-education-section`, children: [_jsx("h2", { children: "Education" }), education?.map((edu) => {
                            return (_jsx(PersonViewEducationCard, { education: edu }, edu?.index));
                        })] }))] }) }));
};
export default PersonViewSummary;
