import { vt as __exportAll } from "./PortalTenantClientProvider-BmRtQAbi.mjs";
import { n as useDataSourceRegistryConfig } from "./registry-context-BKvTiuXB.mjs";
import { r as useWidgetsApi, t as ErrorState } from "./error-state-DvzIn9Tz.mjs";
import { i as getBorderColorField, l as getColorField, m as getPaddingField, n as borderWidthClasses, o as getBorderRadiusField, s as getBorderWidthField, t as borderColorClasses, u as getFontSizeField } from "./registries-59Barbhg.mjs";
import { t as useWidgetPreviewContext } from "./preview-context-D9ZzEfWh.mjs";
import { useQuery } from "@tanstack/react-query";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { Loader2, Sparkles } from "lucide-react";
//#region ../widgets/src/hooks/use-catchups.preview.ts
const PREVIEW_DATA = [
	{
		id: 1,
		suggestionTitle: "Check in with Sarah about her recent order"
	},
	{
		id: 2,
		suggestionTitle: "Follow up with Mike on product samples"
	},
	{
		id: 3,
		suggestionTitle: "Reconnect with Lisa — last contact 30 days ago"
	},
	{
		id: 4,
		suggestionTitle: "Thank Alex for their referral last week"
	},
	{
		id: 5,
		suggestionTitle: "Share new catalog with Jordan"
	}
];
//#endregion
//#region ../widgets/src/hooks/use-catchups.ts
function useCatchUps() {
	const widgetsApi = useWidgetsApi();
	const { isPreview } = useWidgetPreviewContext();
	const { baseUrl } = useDataSourceRegistryConfig();
	return useQuery({
		queryKey: [
			"portal-widget-use",
			"catchups",
			isPreview ? "preview" : baseUrl
		],
		queryFn: ({ signal }) => widgetsApi.fetchCatchUps(signal),
		enabled: !isPreview,
		...isPreview && { placeholderData: PREVIEW_DATA }
	});
}
//#endregion
//#region ../widgets/src/widgets/CatchUpWidget.tsx
var CatchUpWidget_exports = /* @__PURE__ */ __exportAll({
	CatchUpWidget: () => CatchUpWidget,
	catchUpWidgetPropertySchema: () => catchUpWidgetPropertySchema
});
const fontSizeClasses = {
	"2xl": "text-2xl",
	xl: "text-xl",
	lg: "text-lg",
	md: "text-base",
	sm: "text-sm",
	xs: "text-xs"
};
function CatchUpWidget({ titleEnabled = true, titleText = "Catch Ups", titleFontSize = "xl", titleColor = "foreground", background = {
	type: "solid",
	color: "background"
}, textColor = "foreground", accentColor = "primary", padding = 4, borderRadius = "md", borderWidth = "none", borderColor = "muted", maxItems = 5, className, ...props }) {
	const backgroundColor = background.color || "background";
	const backgroundImage = (background.resource?.image_url || background.resource?.imageUrl) && background.type === "image" ? `url(${background.resource.image_url || background.resource.imageUrl})` : "none";
	const { data = [], isLoading, isError } = useCatchUps();
	const catchUpsToShow = data.slice(0, maxItems);
	const moreCatchUps = data.length - catchUpsToShow.length;
	return /* @__PURE__ */ jsxs("div", {
		className: `flex flex-col rounded-${borderRadius} ${borderWidthClasses[borderWidth]} ${borderWidth !== "none" ? borderColorClasses[borderColor] : ""} bg-${backgroundColor} p-${padding} text-${textColor} ${className || ""}`,
		style: { backgroundImage },
		...props,
		children: [/* @__PURE__ */ jsxs("div", {
			className: "flex items-center justify-between",
			children: [titleEnabled && /* @__PURE__ */ jsx("h3", {
				className: `${fontSizeClasses[titleFontSize]} font-header font-semibold text-${titleColor}`,
				children: titleText
			}), !isLoading && !isError && data.length > 0 && /* @__PURE__ */ jsx("span", {
				className: `text-3xl font-bold text-${accentColor}`,
				children: data.length
			})]
		}), isLoading ? /* @__PURE__ */ jsx("div", {
			className: "flex min-h-[150px] flex-1 items-center justify-center",
			children: /* @__PURE__ */ jsx(Loader2, { className: `h-8 w-8 animate-spin text-${accentColor}` })
		}) : isError ? /* @__PURE__ */ jsx(ErrorState, {}) : data.length === 0 ? /* @__PURE__ */ jsxs("div", {
			className: "flex min-h-[150px] flex-1 flex-col items-center justify-center gap-2",
			children: [
				/* @__PURE__ */ jsx(Sparkles, { className: `h-8 w-8 text-${accentColor}` }),
				/* @__PURE__ */ jsx("p", {
					className: "text-center font-semibold",
					children: "You're all caught up."
				}),
				/* @__PURE__ */ jsx("p", {
					className: "text-sm opacity-60",
					children: "See you next time!"
				})
			]
		}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
			className: "mt-3 flex-1",
			children: catchUpsToShow.map((catchUp, index) => /* @__PURE__ */ jsx("div", {
				className: `py-2 ${index !== catchUpsToShow.length - 1 ? "border-b border-current/10" : ""}`,
				children: /* @__PURE__ */ jsx("p", {
					className: "line-clamp-1 text-sm",
					children: catchUp.suggestionTitle
				})
			}, catchUp.id || index))
		}), moreCatchUps > 0 && /* @__PURE__ */ jsxs("p", {
			className: "mt-2 text-sm opacity-60",
			children: [
				moreCatchUps,
				" more catch up",
				moreCatchUps > 1 ? "s" : ""
			]
		})] })]
	});
}
const catchUpWidgetPropertySchema = {
	widgetType: "CatchUpWidget",
	displayName: "Catch Up Widget",
	tabsConfig: [{
		id: "styling",
		label: "Styling"
	}],
	fields: [
		{
			key: "titleEnabled",
			label: "Widget Title",
			type: "boolean",
			description: "Enable the title displayed above the catch ups",
			defaultValue: true,
			tab: "styling",
			group: "Title"
		},
		{
			key: "titleText",
			label: "Title",
			type: "text",
			description: "Title text displayed above the catch ups",
			defaultValue: "Catch Ups",
			tab: "styling",
			group: "Title",
			requiresKeyToBeTrue: "titleEnabled"
		},
		getFontSizeField({
			key: "titleFontSize",
			label: "Title Font Size",
			description: "Font size for the widget title",
			defaultValue: "xl",
			tab: "styling",
			group: "Title",
			requiresKeyToBeTrue: "titleEnabled"
		}),
		getColorField({
			key: "titleColor",
			label: "Title Color",
			description: "Color for the widget title",
			defaultValue: "foreground",
			tab: "styling",
			group: "Title",
			requiresKeyToBeTrue: "titleEnabled"
		}),
		{
			type: "background",
			key: "background",
			label: "Background",
			description: "Background for the container",
			defaultValue: "background",
			tab: "styling",
			group: "Design"
		},
		getColorField({
			key: "textColor",
			label: "Text Color",
			description: "Default text color for catch up items",
			defaultValue: "foreground",
			tab: "styling",
			group: "Design"
		}),
		getColorField({
			key: "accentColor",
			label: "Accent Color",
			description: "Color used for count display and icons",
			defaultValue: "primary",
			tab: "styling",
			group: "Design"
		}),
		{
			key: "separator",
			type: "separator",
			label: "Separator",
			tab: "styling",
			group: "Design"
		},
		{
			key: "maxItems",
			label: "Max Items",
			type: "number",
			description: "Maximum number of catch ups to display",
			defaultValue: 5,
			min: 1,
			max: 10,
			tab: "styling",
			group: "Design"
		},
		getPaddingField({
			key: "padding",
			label: "Padding",
			description: "Padding around the container",
			defaultValue: 4,
			tab: "styling",
			group: "Design"
		}),
		getBorderRadiusField({
			key: "borderRadius",
			label: "Border Radius",
			description: "Border radius for the container",
			defaultValue: "md",
			tab: "styling",
			group: "Design"
		}),
		getBorderWidthField({
			key: "borderWidth",
			label: "Border Width",
			description: "Border width for the widget",
			defaultValue: "none",
			tab: "styling",
			group: "Design"
		}),
		getBorderColorField({
			key: "borderColor",
			label: "Border Color",
			description: "Border color for the widget",
			defaultValue: "muted",
			tab: "styling",
			group: "Design"
		})
	]
};
//#endregion
export { CatchUpWidget_exports as n, catchUpWidgetPropertySchema as r, CatchUpWidget as t };

//# sourceMappingURL=CatchUpWidget-B_in7Bjq.mjs.map