import { vt as __exportAll } from "./PortalTenantClientProvider-BmRtQAbi.mjs";
import { n as useWidgetInteraction } from "./WidgetInteractionContext-BWH7njU7.mjs";
import { a as getBorderRadiusCompositeField, c as getButtonSizeField, i as getBorderColorField, m as getPaddingField, n as borderWidthClasses, s as getBorderWidthField, t as borderColorClasses, u as getFontSizeField } from "./registries-59Barbhg.mjs";
import { wn as Button } from "./src-CJw6JbdS.mjs";
import { useCallback } from "react";
import { jsx } from "react/jsx-runtime";
import { AlignCenter, AlignLeft, AlignRight } from "lucide-react";
//#region ../widgets/src/widgets/LinkWidget.tsx
var LinkWidget_exports = /* @__PURE__ */ __exportAll({
	LinkWidget: () => LinkWidget,
	linkWidgetPropertySchema: () => linkWidgetPropertySchema
});
const borderRadiusTLClasses = {
	none: "rounded-tl-none",
	sm: "rounded-tl-sm",
	md: "rounded-tl-md",
	lg: "rounded-tl-lg",
	xl: "rounded-tl-xl",
	full: "rounded-tl-full"
};
const borderRadiusTRClasses = {
	none: "rounded-tr-none",
	sm: "rounded-tr-sm",
	md: "rounded-tr-md",
	lg: "rounded-tr-lg",
	xl: "rounded-tr-xl",
	full: "rounded-tr-full"
};
const borderRadiusBLClasses = {
	none: "rounded-bl-none",
	sm: "rounded-bl-sm",
	md: "rounded-bl-md",
	lg: "rounded-bl-lg",
	xl: "rounded-bl-xl",
	full: "rounded-bl-full"
};
const borderRadiusBRClasses = {
	none: "rounded-br-none",
	sm: "rounded-br-sm",
	md: "rounded-br-md",
	lg: "rounded-br-lg",
	xl: "rounded-br-xl",
	full: "rounded-br-full"
};
function sanitizeHref(url) {
	if (!url) return void 0;
	if (/^(https?:|mailto:|tel:|\/)/i.test(url)) return url;
}
const alignmentClasses = {
	left: "justify-start",
	center: "justify-center",
	right: "justify-end"
};
function LinkWidget({ text = "Click Here", linkType = "url", href = "", openInNewTab = true, screenSlug, shareSource, shareResource, shareUrl, variant = "default", size = "default", fontSize = "sm", alignment = "center", fullWidth = false, padding = 0, borderRadius, borderRadiusTL, borderRadiusTR, borderRadiusBL, borderRadiusBR, borderWidth = "none", borderColor = "muted", underline = false, previewMode = false, editMode = false, className, ...props }) {
	const { onNavigate, buildHref } = useWidgetInteraction();
	const handleShareClick = useCallback(async () => {
		const isResourceMode = shareSource === "resource" || shareSource == null;
		const url = isResourceMode ? shareResource?.share_link ?? void 0 : shareUrl ?? void 0;
		if (!url) return;
		if (navigator.share) try {
			await navigator.share({
				url,
				...isResourceMode && shareResource?.title ? { title: shareResource.title } : {}
			});
			return;
		} catch (e) {
			if (e instanceof DOMException && e.name === "AbortError") return;
		}
		try {
			await navigator.clipboard.writeText(url);
		} catch {}
	}, [
		shareSource,
		shareUrl,
		shareResource
	]);
	const handleScreenClick = useCallback((e) => {
		if (onNavigate && screenSlug) {
			e.preventDefault();
			onNavigate(screenSlug);
		}
	}, [onNavigate, screenSlug]);
	const screenHref = screenSlug ? buildHref?.(screenSlug) ?? screenSlug : void 0;
	if (previewMode) return /* @__PURE__ */ jsx("div", {
		className: `flex justify-center p-4 ${className ?? ""}`,
		...props,
		children: /* @__PURE__ */ jsx("span", {
			style: {
				display: "inline-flex",
				alignItems: "center",
				justifyContent: "center",
				height: "36px",
				padding: "0 16px",
				borderRadius: "6px",
				backgroundColor: "#18181b",
				color: "#ffffff",
				fontSize: "14px",
				fontWeight: 500
			},
			children: text
		})
	});
	const fallback = borderRadius ?? "md";
	const tl = borderRadiusTL ?? fallback;
	const tr = borderRadiusTR ?? fallback;
	const bl = borderRadiusBL ?? fallback;
	const br = borderRadiusBR ?? fallback;
	const buttonClasses = `text-${fontSize} ${`rounded-none ${borderRadiusTLClasses[tl]} ${borderRadiusTRClasses[tr]} ${borderRadiusBLClasses[bl]} ${borderRadiusBRClasses[br]}`} ${fullWidth ? "w-full" : ""} ${underline ? "underline" : ""}`;
	return /* @__PURE__ */ jsx("div", {
		className: `flex ${alignmentClasses[alignment]} p-${padding} ${borderWidthClasses[borderWidth]} ${borderWidth !== "none" ? borderColorClasses[borderColor] : ""} ${className ?? ""}`,
		...props,
		children: /* @__PURE__ */ jsx(Button, {
			asChild: true,
			variant,
			size,
			className: buttonClasses,
			children: editMode ? /* @__PURE__ */ jsx("span", {
				className: "cursor-default",
				children: text
			}) : linkType === "share" ? /* @__PURE__ */ jsx("button", {
				type: "button",
				onClick: handleShareClick,
				children: text
			}) : linkType === "screen" ? screenSlug ? /* @__PURE__ */ jsx("a", {
				href: screenHref,
				onClick: handleScreenClick,
				children: text
			}) : /* @__PURE__ */ jsx("span", {
				className: "cursor-default",
				children: text
			}) : /* @__PURE__ */ jsx("a", {
				href: sanitizeHref(href),
				...openInNewTab ? {
					target: "_blank",
					rel: "noopener noreferrer"
				} : {},
				children: text
			})
		})
	});
}
const linkWidgetPropertySchema = {
	widgetType: "LinkWidget",
	displayName: "Link Button",
	fields: [
		{
			key: "linkType",
			label: "Link Type",
			type: "buttonGroup",
			options: [
				{
					label: "URL",
					value: "url"
				},
				{
					label: "Screen",
					value: "screen"
				},
				{
					label: "Share",
					value: "share"
				}
			],
			defaultValue: "url",
			group: "Link"
		},
		{
			key: "text",
			label: "Text",
			type: "text",
			description: "The button label text",
			defaultValue: "Click Here",
			group: "Link"
		},
		{
			key: "href",
			label: "URL",
			type: "text",
			description: "The destination URL",
			defaultValue: "",
			group: "Link",
			requiresKeyValue: {
				key: "linkType",
				value: "url"
			}
		},
		{
			key: "openInNewTab",
			label: "Open in New Tab",
			type: "boolean",
			description: "Whether to open the link in a new tab",
			defaultValue: true,
			group: "Link",
			requiresKeyValue: {
				key: "linkType",
				value: "url"
			}
		},
		{
			key: "screenSlug",
			label: "Screen",
			type: "screenPicker",
			description: "Select a screen to navigate to",
			includeSystemItems: true,
			group: "Link",
			requiresKeyValue: {
				key: "linkType",
				value: "screen"
			}
		},
		{
			key: "shareSource",
			label: "Share Source",
			type: "buttonGroup",
			options: [{
				label: "Resource",
				value: "resource"
			}, {
				label: "URL",
				value: "url"
			}],
			defaultValue: "resource",
			group: "Link",
			requiresKeyValue: {
				key: "linkType",
				value: "share"
			}
		},
		{
			key: "shareResource",
			label: "Shareable Content",
			type: "resource",
			description: "Select content to share",
			allowedTypes: [
				"Product",
				"Medium",
				"Library",
				"Page",
				"EnrollmentPack"
			],
			group: "Link",
			requiresKeyValue: [{
				key: "linkType",
				value: "share"
			}, {
				key: "shareSource",
				value: "resource"
			}]
		},
		{
			key: "shareUrl",
			label: "Share URL",
			type: "text",
			description: "The URL to share",
			defaultValue: "",
			group: "Link",
			requiresKeyValue: [{
				key: "linkType",
				value: "share"
			}, {
				key: "shareSource",
				value: "url"
			}]
		},
		{
			key: "variant",
			label: "Variant",
			type: "select",
			description: "The visual style of the button",
			options: [
				{
					label: "Default",
					value: "default"
				},
				{
					label: "Outline",
					value: "outline"
				},
				{
					label: "Secondary",
					value: "secondary"
				},
				{
					label: "Ghost",
					value: "ghost"
				},
				{
					label: "Destructive",
					value: "destructive"
				}
			],
			defaultValue: "default",
			group: "Button Style"
		},
		getButtonSizeField({
			key: "size",
			label: "Size",
			description: "The size of the button",
			defaultValue: "default",
			group: "Button Style"
		}),
		getFontSizeField({
			key: "fontSize",
			label: "Text Size",
			description: "The font size of the button text",
			defaultValue: "sm",
			group: "Button Style"
		}),
		{
			key: "underline",
			label: "Underline",
			type: "boolean",
			description: "Underline the button text",
			defaultValue: false,
			group: "Button Style"
		},
		{
			key: "alignment",
			label: "Alignment",
			type: "buttonGroup",
			description: "Horizontal alignment of the button",
			options: [
				{
					icon: AlignLeft,
					ariaLabel: "Align left",
					value: "left"
				},
				{
					icon: AlignCenter,
					ariaLabel: "Align center",
					value: "center"
				},
				{
					icon: AlignRight,
					ariaLabel: "Align right",
					value: "right"
				}
			],
			defaultValue: "center",
			group: "Layout"
		},
		{
			key: "fullWidth",
			label: "Full Width",
			type: "boolean",
			description: "Makes the button stretch to full container width",
			defaultValue: false,
			group: "Layout"
		},
		getPaddingField({
			key: "padding",
			label: "Padding",
			description: "Outer container padding",
			defaultValue: 0,
			group: "Layout"
		}),
		getBorderRadiusCompositeField({
			key: "borderRadiusGroup",
			label: "Border Radius",
			defaultValue: "md",
			group: "Design"
		}),
		getBorderWidthField({
			key: "borderWidth",
			label: "Border Width",
			description: "Border width for the widget",
			defaultValue: "none",
			group: "Design"
		}),
		getBorderColorField({
			key: "borderColor",
			label: "Border Color",
			description: "Border color for the widget",
			defaultValue: "muted",
			group: "Design"
		})
	]
};
//#endregion
export { LinkWidget_exports as n, linkWidgetPropertySchema as r, LinkWidget as t };

//# sourceMappingURL=LinkWidget-fPowKN73.mjs.map