"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styles_1 = require("@mui/material/styles");
const material_1 = require("@mui/material");
const react_intl_1 = require("react-intl");
const types_1 = require("@selfcommunity/types");
const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon"));
const CommentActivity_1 = tslib_1.__importDefault(require("./CommentActivity"));
const VoteUpActivity_1 = tslib_1.__importDefault(require("./VoteUpActivity"));
const FollowActivity_1 = tslib_1.__importDefault(require("./FollowActivity"));
const PollVoteActivity_1 = tslib_1.__importDefault(require("./PollVoteActivity"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const constants_1 = require("../../constants");
const classes = {
    root: `${constants_1.PREFIX}-relevant-activities-root`,
    activity: `${constants_1.PREFIX}-relevant-activities-activity`
};
const Root = (0, styles_1.styled)(material_1.Box, {
    name: constants_1.PREFIX,
    slot: 'RelevantActivitiesRoot'
})(() => ({}));
function RelevantActivities(props) {
    //PROPS
    const { className = null, activities = [], showMaxRelevantActivities = 5 } = props, rest = tslib_1.__rest(props, ["className", "activities", "showMaxRelevantActivities"]);
    // STATE
    const [openOtherActivities, setOpenOtherActivities] = (0, react_1.useState)(false);
    /**
     * Renders single relevant activity
     * @param a
     * @param i
     */
    function renderActivity(a, i) {
        if (a.type === types_1.SCFeedUnitActivityTypologyType.COMMENT) {
            return (0, jsx_runtime_1.jsx)(CommentActivity_1.default, { activityObject: a, elevation: 0 }, i);
        }
        else if (a.type === types_1.SCFeedUnitActivityTypologyType.FOLLOW) {
            return (0, jsx_runtime_1.jsx)(FollowActivity_1.default, { activityObject: a, elevation: 0 }, i);
        }
        else if (a.type === types_1.SCFeedUnitActivityTypologyType.VOTE) {
            return (0, jsx_runtime_1.jsx)(VoteUpActivity_1.default, { activityObject: a, elevation: 0 }, i);
        }
        else if (a.type === types_1.SCFeedUnitActivityTypologyType.POLLVOTE) {
            return (0, jsx_runtime_1.jsx)(PollVoteActivity_1.default, { activityObject: a, elevation: 0 }, i);
        }
        return null;
    }
    /**
     * Renders root object
     */
    return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: activities.length <= 0 ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.feedObject.relevantActivities.noResults", defaultMessage: "ui.feedObject.relevantActivities.noResults" }) }))) : ((0, jsx_runtime_1.jsxs)(material_1.List, { children: [activities.slice(0, showMaxRelevantActivities).map((a, i) => ((0, jsx_runtime_1.jsx)(material_1.ListItem, Object.assign({ className: classes.activity }, { children: renderActivity(a, i) }), i))), !openOtherActivities && activities.length > showMaxRelevantActivities && ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, Object.assign({ onClick: () => setOpenOtherActivities((prev) => !prev) }, { children: [(0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'ui.feedObject.relevantActivities.showOthers', defaultMessage: 'ui.feedObject.relevantActivities.showOthers' }) }), openOtherActivities ? (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "expand_less" }) : (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "expand_more" })] }))), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ in: openOtherActivities, timeout: "auto", unmountOnExit: true }, { children: activities.slice(showMaxRelevantActivities).map((a, i) => ((0, jsx_runtime_1.jsx)(material_1.ListItem, Object.assign({ className: classes.activity }, { children: renderActivity(a, i) }), i))) }))] })) })));
}
exports.default = RelevantActivities;
