import { cn } from "./index3.js";
import { Badge } from "./index13.js";
import { Avatar } from "./index15.js";
import { FileTypeIcon } from "./index383.js";
import { cva } from "class-variance-authority";
import * as React from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
//#region src/components/organisms/content/ActivityFeed/ActivityFeed.tsx
var activityFeedVariants = cva("flex flex-col", {
	variants: { divider: {
		divider: "divide-y divide-border-secondary",
		connector: "px-6 py-4",
		none: "gap-4"
	} },
	defaultVariants: { divider: "divider" }
});
var activityItemVariants = cva("flex gap-3 relative", {
	variants: {
		type: {
			notifications: "",
			messages: ""
		},
		divider: {
			divider: "px-4 py-4",
			connector: "pt-0",
			none: "px-4 py-4"
		}
	},
	defaultVariants: {
		type: "notifications",
		divider: "divider"
	}
});
var ActivityFeedItem = React.memo(React.forwardRef(({ className, user, timestamp, dateTime, activity, content, unread = false, avatarSize = "lg", divider = "divider", feedType = "notifications", userHandle, expanded, isLast = false, ...props }, ref) => {
	const renderContent = () => {
		if (!content || expanded === false) return null;
		switch (content.type) {
			case "file": return /* @__PURE__ */ jsxs("div", {
				className: "group/file flex gap-3 items-start w-full mt-3 rounded-lg transition-[background-color,transform] duration-150 ease-out motion-reduce:transition-none hover:bg-muted/40 active:scale-[0.99] motion-reduce:active:scale-100 cursor-default",
				children: [/* @__PURE__ */ jsx(FileTypeIcon, {
					extension: content.fileExtension,
					size: "md"
				}), /* @__PURE__ */ jsxs("div", {
					className: "flex flex-col min-w-0 flex-1",
					children: [/* @__PURE__ */ jsx("p", {
						className: "text-sm font-medium text-secondary-foreground truncate",
						children: content.fileName
					}), /* @__PURE__ */ jsx("p", {
						className: "text-sm text-muted-foreground",
						children: content.fileSize
					})]
				})]
			});
			case "message": return /* @__PURE__ */ jsx("div", {
				className: "mt-3 border border-border rounded-ee-md rounded-es-md rounded-se-md p-3 shadow-xs w-full transition-shadow duration-200 ease-out hover:shadow-sm motion-reduce:transition-none",
				children: /* @__PURE__ */ jsx("p", {
					className: "text-sm text-secondary-foreground",
					children: content.mentions && content.mentions.length > 0 ? renderMessageWithMentions(content.message, content.mentions) : `"${content.message}"`
				})
			});
			case "labels": return /* @__PURE__ */ jsx("div", {
				className: "flex flex-wrap gap-1 mt-3",
				children: content.labels.map((label, i) => /* @__PURE__ */ jsx(Badge, {
					variant: "outline",
					color: label.color || "primary",
					size: "sm",
					className: "delight-stagger transition-transform duration-150 ease-out motion-reduce:transition-none hover:scale-105 motion-reduce:hover:scale-100",
					style: { "--delight-delay": `${i * 50}ms` },
					children: label.text
				}, label.text))
			});
			default: return null;
		}
	};
	const renderMessageWithMentions = (message, mentions) => {
		const result = [];
		let remainingText = message;
		let key = 0;
		for (const mention of mentions) {
			const mentionPattern = new RegExp(`(@${mention})`, "gi");
			const parts = remainingText.split(mentionPattern);
			for (let i = 0; i < parts.length; i++) {
				const part = parts[i];
				if (part.toLowerCase() === `@${mention.toLowerCase()}`) result.push(/* @__PURE__ */ jsx("span", {
					className: "font-semibold text-primary",
					children: part
				}, key++));
				else if (i === parts.length - 1) remainingText = part;
				else result.push(/* @__PURE__ */ jsx("span", { children: part }, key++));
			}
		}
		if (remainingText) result.push(/* @__PURE__ */ jsx("span", { children: remainingText }, key++));
		return result;
	};
	return /* @__PURE__ */ jsxs("div", {
		ref,
		"data-slot": "activity-feed-item",
		role: "article",
		"aria-label": `${user.name}: ${activity.text}${activity.link ? ` ${activity.link}` : ""}`,
		className: cn(activityItemVariants({
			type: feedType,
			divider
		}), "transition-colors duration-150 ease-out motion-reduce:transition-none", "hover:bg-muted/30", className),
		...props,
		children: [
			/* @__PURE__ */ jsxs("div", {
				className: cn("flex flex-col items-center gap-0.5 self-stretch shrink-0", divider === "connector" && !isLast && "pb-0.5"),
				children: [/* @__PURE__ */ jsx(Avatar, {
					src: user.avatarSrc,
					fallback: user.name,
					size: avatarSize,
					indicator: user.online === true ? "online" : user.online === false ? "offline" : void 0
				}), divider === "connector" && !isLast && /* @__PURE__ */ jsx("div", { className: "flex-1 w-0.5 min-h-4 rounded-sm bg-border-secondary delight-connector-grow" })]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: cn("flex flex-col flex-1 min-w-0", divider === "connector" && "pb-8"),
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex flex-col",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "flex items-center gap-2 flex-wrap",
						children: [
							/* @__PURE__ */ jsx("span", {
								className: "text-sm font-medium text-secondary-foreground",
								children: user.name
							}),
							feedType === "messages" && userHandle && /* @__PURE__ */ jsxs("span", {
								className: "text-sm text-muted-foreground",
								children: ["@", userHandle]
							}),
							dateTime ? /* @__PURE__ */ jsx("time", {
								dateTime,
								className: "text-xs text-muted-foreground",
								children: timestamp
							}) : /* @__PURE__ */ jsx("span", {
								className: "text-xs text-muted-foreground",
								children: timestamp
							})
						]
					}), /* @__PURE__ */ jsxs("p", {
						className: "text-sm text-muted-foreground",
						children: [activity.text, activity.link && /* @__PURE__ */ jsxs(Fragment$1, { children: [" ", activity.linkHref ? /* @__PURE__ */ jsx("a", {
							href: activity.linkHref,
							className: "font-medium text-primary hover:text-primary/80 transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1 rounded-sm",
							children: activity.link
						}) : /* @__PURE__ */ jsx("span", {
							className: "font-medium text-secondary-foreground",
							children: activity.link
						})] })]
					})]
				}), renderContent()]
			}),
			unread && /* @__PURE__ */ jsx("div", {
				className: "absolute top-2 end-1 size-2.5",
				"aria-hidden": "true",
				children: /* @__PURE__ */ jsx("div", { className: "size-2 rounded-full bg-primary delight-unread-pulse" })
			})
		]
	});
}));
ActivityFeedItem.displayName = "ActivityFeedItem";
var ActivityFeed = React.forwardRef(({ className, divider = "divider", items, type = "notifications", loading, children, ...props }, ref) => {
	return /* @__PURE__ */ jsx("div", {
		ref,
		"data-slot": "activity-feed",
		role: "feed",
		"aria-label": "Activity feed",
		"aria-busy": loading || void 0,
		className: cn(activityFeedVariants({ divider }), className),
		...props,
		children: items ? items.map((item, index) => /* @__PURE__ */ jsx(ActivityFeedItem, {
			...item,
			"aria-setsize": items.length,
			"aria-posinset": index + 1,
			divider: divider ?? "divider",
			feedType: type,
			isLast: index === items.length - 1,
			className: cn("delight-stagger", item.className),
			style: {
				"--delight-delay": `${index * 60}ms`,
				...item.style
			}
		}, index)) : children
	});
});
ActivityFeed.displayName = "ActivityFeed";
//#endregion
export { ActivityFeed, ActivityFeedItem, activityFeedVariants, activityItemVariants };

//# sourceMappingURL=index447.js.map