import { ft as __exportAll } from "./translation-adapter-RsuBioxm.mjs";
import { a as useActiveLocale, r as useDomainDict } from "./static-dict-adapter-BlNdg7r8.mjs";
import { t as createTranslationContext } from "./translation-api-context-factory-oSEnOBmb.mjs";
import { B as Label, C as Separator, Cn as Button, Ct as CardHeader, In as useZodForm, Ln as cn, Q as Dialog, an as Breadcrumb, bt as CardContent, cn as BreadcrumbList, et as DialogContent, g as Skeleton, j as Input, ln as BreadcrumbPage, nt as DialogFooter, on as BreadcrumbItem, ot as DialogTitle, p as fluidToast, rt as DialogHeader, sn as BreadcrumbLink, un as BreadcrumbSeparator, vt as Card, wt as CardTitle, yt as CardAction } from "./src-v1U7mjgR.mjs";
import { n as mysiteDomain, t as createMysiteTranslationAdapter } from "./translation-adapter-C-L9dSVl.mjs";
import { n as useAppNavigation } from "./AppNavigationContext-CUpMPyMJ.mjs";
import { n as ScreenHeaderBreadcrumbs } from "./ScreenHeaderContext-BA8__sLA.mjs";
import { a as usePortalFavorites, c as usePortalMySiteThemes, d as usePortalUpdateLink, f as usePortalUpdateSettings, i as usePortalDeleteLink, l as usePortalReorderFavorites, n as usePortalCreateLink, o as usePortalLinks, r as usePortalDeleteFavorite, s as usePortalMySiteProfile, u as usePortalReorderLinks } from "./use-mysite-portal-B1lFZMl2.mjs";
import { a as verticalListSortingStrategy, c as PointerSensor, d as useSensors, f as CSS, i as useSortable, l as closestCenter, n as arrayMove, o as DndContext, r as sortableKeyboardCoordinates, s as KeyboardSensor, t as SortableContext, u as useSensor } from "./sortable.esm-B6B4nWkF.mjs";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import "@tanstack/react-query";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
import { z } from "zod";
import { ArrowLeft, Check, ChevronRight, Copy, Eye, GripVertical, LayoutGrid, Link2, LoaderCircle, Palette, Pencil, Plus, Trash2, User, Users } from "lucide-react";
//#region ../../mysite/core/src/translation-api-context.ts
const { Provider: MysiteProvider, useTranslation } = createTranslationContext("Mysite");
const MysiteTranslationProvider = MysiteProvider;
const useMysiteTranslation = useTranslation;
//#endregion
//#region src/providers/MysiteTranslationBridge.tsx
function MysiteTranslationBridge({ children }) {
	const { locale } = useActiveLocale();
	const dict = useDomainDict(mysiteDomain, locale);
	return /* @__PURE__ */ jsx(MysiteTranslationProvider, {
		value: useMemo(() => createMysiteTranslationAdapter(locale, dict), [locale, dict]),
		children
	});
}
//#endregion
//#region ../../mysite/ui/src/portal/components/animation-utils.ts
function getContentClassName(phase) {
	switch (phase) {
		case "idle": return "opacity-100 transition-none";
		case "fade-out": return "opacity-0 transition-opacity duration-300 ease-in-out";
		case "slide": return "opacity-0 2xl:translate-x-[50%] transition-transform duration-500 ease-in-out";
		case "fade-in": return "opacity-100 2xl:translate-x-[50%] transition-opacity duration-300 ease-in-out";
		case "editing": return "opacity-100 2xl:translate-x-[50%] transition-none";
		case "exit-fade-out": return "opacity-0 2xl:translate-x-[50%] transition-opacity duration-300 ease-in-out";
		case "exit-slide": return "opacity-0 transition-transform duration-500 ease-in-out";
		case "exit-fade-in": return "opacity-100 transition-opacity duration-300 ease-in-out";
	}
}
function getPreviewClassName(phase) {
	switch (phase) {
		case "idle":
		case "fade-out":
		case "exit-fade-in": return "transition-none";
		case "slide": return "2xl:-translate-x-[200%] transition-transform duration-500 ease-in-out";
		case "fade-in":
		case "editing":
		case "exit-fade-out": return "2xl:-translate-x-[200%] transition-none";
		case "exit-slide": return "transition-transform duration-500 ease-in-out";
	}
}
//#endregion
//#region ../../mysite/ui/src/portal/components/VisitorDetailsCard.tsx
function MySiteVisitorDetailsCard({ views, leads }) {
	const { t } = useMysiteTranslation();
	return /* @__PURE__ */ jsxs(Card, {
		className: "h-auto gap-0 py-0 shadow-none",
		children: [/* @__PURE__ */ jsx(CardHeader, {
			className: "p-4 pb-3",
			children: /* @__PURE__ */ jsx(CardTitle, {
				className: "text-sm",
				children: t("visitor_details")
			})
		}), /* @__PURE__ */ jsxs(CardContent, {
			className: "flex px-4 pb-4",
			children: [
				/* @__PURE__ */ jsxs("div", {
					className: "flex-1",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "mb-2 flex items-center gap-1.5",
						children: [/* @__PURE__ */ jsx(Eye, { className: "text-muted-foreground size-3.5" }), /* @__PURE__ */ jsx("span", {
							className: "text-muted-foreground text-sm",
							children: t("views")
						})]
					}), /* @__PURE__ */ jsx("p", {
						className: "text-foreground text-2xl font-bold",
						children: views.toLocaleString()
					})]
				}),
				/* @__PURE__ */ jsx(Separator, {
					orientation: "vertical",
					className: "bg-border mx-4 h-auto"
				}),
				/* @__PURE__ */ jsxs("div", {
					className: "flex-1",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "mb-2 flex items-center gap-1.5",
						children: [/* @__PURE__ */ jsx(Users, { className: "text-muted-foreground size-3.5" }), /* @__PURE__ */ jsx("span", {
							className: "text-muted-foreground text-sm",
							children: t("leads")
						})]
					}), /* @__PURE__ */ jsx("p", {
						className: "text-foreground text-2xl font-bold",
						children: leads.toLocaleString()
					})]
				})
			]
		})]
	});
}
//#endregion
//#region ../../mysite/ui/src/portal/components/MySiteLinkCard.tsx
function MySiteLinkCard({ mysiteUrl, displayUrl, onUpdateSlug, onToast }) {
	const { t } = useMysiteTranslation();
	const lastSlashIndex = displayUrl.lastIndexOf("/");
	const urlPrefix = lastSlashIndex >= 0 ? displayUrl.slice(0, lastSlashIndex + 1) : "";
	const currentSlug = lastSlashIndex >= 0 ? displayUrl.slice(lastSlashIndex + 1) : displayUrl;
	const [isEditingLink, setIsEditingLink] = useState(false);
	const [linkSlugInput, setLinkSlugInput] = useState(currentSlug);
	const [isSaving, setIsSaving] = useState(false);
	const handleEditLink = useCallback(() => {
		setLinkSlugInput(currentSlug);
		setIsEditingLink(true);
	}, [currentSlug]);
	const handleCancelEditLink = useCallback(() => {
		setIsEditingLink(false);
		setLinkSlugInput(currentSlug);
	}, [currentSlug]);
	const handleSaveLink = useCallback(async () => {
		const trimmed = linkSlugInput.trim();
		if (!trimmed) {
			onToast?.(t("slug_empty_error"), "error");
			return;
		}
		if (trimmed === currentSlug) {
			setIsEditingLink(false);
			return;
		}
		if (!onUpdateSlug) return;
		setIsSaving(true);
		try {
			await onUpdateSlug(trimmed);
			onToast?.(t("link_updated"), "success");
			setIsEditingLink(false);
		} catch {
			onToast?.(t("link_update_failed"), "error");
		} finally {
			setIsSaving(false);
		}
	}, [
		linkSlugInput,
		currentSlug,
		onUpdateSlug,
		onToast,
		t
	]);
	const handleCopyLink = useCallback(async () => {
		if (!mysiteUrl) return;
		try {
			await navigator.clipboard.writeText(mysiteUrl);
			onToast?.(t("link_copied"), "success");
		} catch {
			onToast?.(t("link_copy_failed"), "error");
		}
	}, [
		mysiteUrl,
		onToast,
		t
	]);
	return /* @__PURE__ */ jsxs(Card, {
		className: "h-auto gap-0 py-0 shadow-none",
		children: [/* @__PURE__ */ jsxs(CardHeader, {
			className: "items-center p-4",
			children: [/* @__PURE__ */ jsx(CardTitle, {
				className: "text-sm",
				children: t("your_mysite_link")
			}), !isEditingLink && onUpdateSlug && /* @__PURE__ */ jsx(CardAction, { children: /* @__PURE__ */ jsx(Button, {
				variant: "link",
				size: "sm",
				onClick: handleEditLink,
				children: t("edit_link")
			}) })]
		}), /* @__PURE__ */ jsxs(CardContent, {
			className: "px-4 pb-4",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "text-foreground flex items-center gap-2 rounded-lg border bg-gradient-to-r from-[rgba(72,187,120,0.2)] via-[rgba(236,72,153,0.15)] to-[rgba(251,146,60,0.15)] px-3 py-2.5",
				children: [isEditingLink ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
					className: "shrink-0 text-sm",
					children: urlPrefix
				}), /* @__PURE__ */ jsx("input", {
					type: "text",
					value: linkSlugInput,
					onChange: (e) => setLinkSlugInput(e.target.value),
					onKeyDown: (e) => {
						if (e.key === "Enter" && !isSaving) handleSaveLink();
						if (e.key === "Escape") handleCancelEditLink();
					},
					className: "border-input text-foreground focus:ring-primary bg-background/60 min-w-0 flex-1 rounded-md border px-2 py-1 text-sm font-medium outline-none focus:ring-1",
					autoFocus: true
				})] }) : /* @__PURE__ */ jsx("span", {
					className: "min-w-0 flex-1 truncate text-sm",
					children: displayUrl || t("not_configured")
				}), /* @__PURE__ */ jsx(Button, {
					variant: "ghost",
					size: "icon",
					onClick: handleCopyLink,
					disabled: !mysiteUrl,
					children: /* @__PURE__ */ jsx(Copy, { className: "size-4" })
				})]
			}), /* @__PURE__ */ jsx("div", {
				className: "grid transition-all duration-300 ease-in-out",
				style: {
					gridTemplateRows: isEditingLink ? "1fr" : "0fr",
					opacity: isEditingLink ? 1 : 0,
					marginTop: isEditingLink ? 12 : 0
				},
				children: /* @__PURE__ */ jsx("div", {
					className: "overflow-hidden",
					children: /* @__PURE__ */ jsxs("div", {
						className: "flex justify-end gap-2",
						children: [/* @__PURE__ */ jsx(Button, {
							variant: "secondary",
							size: "sm",
							onClick: handleCancelEditLink,
							children: t("cancel")
						}), /* @__PURE__ */ jsx(Button, {
							size: "sm",
							onClick: handleSaveLink,
							disabled: isSaving,
							children: isSaving ? t("saving") : t("save")
						})]
					})
				})
			})]
		})]
	});
}
//#endregion
//#region ../../mysite/ui/src/portal/components/PhonePreview.tsx
function MySitePhonePreview({ mysiteUrl, themeName, previewKey, isUpdating, onPreview }) {
	const { t } = useMysiteTranslation();
	const iframeRef = useRef(null);
	const previewSrc = `${mysiteUrl}?preview=true`;
	const isInitialLoadRef = useRef(true);
	useEffect(() => {
		isInitialLoadRef.current = true;
	}, [previewKey]);
	const handleIframeLoad = () => {
		if (isInitialLoadRef.current) {
			isInitialLoadRef.current = false;
			return;
		}
		const iframe = iframeRef.current;
		if (!iframe) return;
		isInitialLoadRef.current = true;
		iframe.src = previewSrc;
	};
	return /* @__PURE__ */ jsxs(Card, {
		className: "items-center gap-4 py-5",
		children: [/* @__PURE__ */ jsxs(CardHeader, {
			className: "w-full items-center px-5",
			children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground text-xs",
				children: t("current_theme")
			}), /* @__PURE__ */ jsx("p", {
				className: "text-foreground text-sm font-semibold",
				children: themeName
			})] }), /* @__PURE__ */ jsx(Button, {
				className: "col-start-2 row-span-2 row-start-1 cursor-pointer self-center justify-self-end",
				variant: "secondary",
				size: "sm",
				onClick: onPreview,
				disabled: !mysiteUrl,
				children: t("preview")
			})]
		}), /* @__PURE__ */ jsxs(CardContent, {
			className: "relative mx-auto my-auto w-[260px] px-0 sm:w-[320px]",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "overflow-hidden rounded-[32px] border-[6px] border-[#1e2939] bg-[#1e2939] shadow-xl sm:rounded-[40px] sm:border-[8px]",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex items-center justify-between bg-[#101828] px-5 py-1 sm:px-6 sm:py-1.5",
					children: [/* @__PURE__ */ jsx("span", {
						className: "text-[10px] font-medium text-[#ffffff] sm:text-[11px]",
						children: "9:41"
					}), /* @__PURE__ */ jsxs("div", {
						className: "flex items-center gap-1",
						children: [/* @__PURE__ */ jsx("div", { className: "h-2 w-2 rounded-full bg-[#ffffff60] sm:h-2.5 sm:w-2.5" }), /* @__PURE__ */ jsx("div", { className: "h-2 w-3.5 rounded-sm bg-[#ffffff60] sm:h-2.5 sm:w-4" })]
					})]
				}), /* @__PURE__ */ jsx("div", {
					className: "relative h-[490px] overflow-y-auto bg-[#ffffff] sm:h-[600px]",
					style: { scrollbarWidth: "none" },
					"aria-busy": isUpdating,
					children: mysiteUrl ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("iframe", {
						ref: iframeRef,
						className: "h-full w-full origin-top-left bg-[#ffffff]",
						src: previewSrc,
						title: t("mysite_preview"),
						tabIndex: -1,
						sandbox: "allow-scripts allow-same-origin",
						onLoad: handleIframeLoad
					}, previewKey), isUpdating && /* @__PURE__ */ jsx("div", {
						className: "absolute inset-0 flex items-center justify-center bg-white/60",
						children: /* @__PURE__ */ jsx(LoaderCircle, { className: "text-muted-foreground size-6 animate-spin" })
					})] }) : /* @__PURE__ */ jsx("div", {
						className: "flex h-full items-center justify-center",
						children: /* @__PURE__ */ jsx("p", {
							className: "text-muted-foreground text-sm",
							children: t("no_site_configured")
						})
					})
				})]
			}), /* @__PURE__ */ jsx("div", { className: "absolute bottom-1.5 left-1/2 h-1 w-24 -translate-x-1/2 rounded-full bg-white sm:bottom-2 sm:w-28" })]
		})]
	});
}
//#endregion
//#region ../../mysite/ui/src/portal/components/ThemeEditor.tsx
function MySiteThemeEditor({ themes, selectedThemeId, onSelectTheme, isPending, onBack }) {
	const { t } = useMysiteTranslation();
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
		className: "flex items-center gap-3",
		children: [/* @__PURE__ */ jsx(Button, {
			variant: "ghost",
			size: "icon",
			onClick: onBack,
			children: /* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" })
		}), /* @__PURE__ */ jsx("h1", {
			className: "text-foreground text-xl font-bold",
			children: t("choose_a_theme")
		})]
	}), themes.length === 0 ? /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, {
		className: "py-8 text-center",
		children: /* @__PURE__ */ jsx("p", {
			className: "text-muted-foreground",
			children: t("no_themes_available")
		})
	}) }) : /* @__PURE__ */ jsx("div", {
		className: "grid grid-cols-2 gap-4 sm:grid-cols-3",
		children: themes.map((theme) => {
			const isSelected = theme.id === selectedThemeId;
			const imageUrl = theme.preview_url ?? theme.image_url;
			return /* @__PURE__ */ jsxs("button", {
				type: "button",
				onClick: () => onSelectTheme(theme),
				className: cn("group focus:ring-primary relative overflow-hidden rounded-lg border-2 transition-all focus:ring-2 focus:ring-offset-2 focus:outline-none", isSelected ? "border-primary ring-primary ring-2" : "border-border hover:border-muted-foreground/50"),
				"aria-pressed": isSelected,
				disabled: isPending,
				children: [/* @__PURE__ */ jsxs("div", {
					className: "bg-muted relative aspect-[4/3] w-full",
					children: [
						imageUrl ? /* @__PURE__ */ jsx("img", {
							src: imageUrl,
							alt: theme.name,
							loading: "lazy",
							className: "absolute inset-0 h-full w-full object-cover"
						}) : /* @__PURE__ */ jsx("div", {
							className: "text-muted-foreground/50 flex h-full w-full items-center justify-center",
							children: /* @__PURE__ */ jsx(Palette, { className: "size-8" })
						}),
						isSelected && /* @__PURE__ */ jsx("div", {
							className: "bg-primary/20 absolute inset-0 flex items-center justify-center",
							children: /* @__PURE__ */ jsx("div", {
								className: "bg-primary text-primary-foreground flex size-8 items-center justify-center rounded-full",
								children: /* @__PURE__ */ jsx(Check, { className: "size-5" })
							})
						}),
						!isSelected && /* @__PURE__ */ jsx("div", { className: "group-hover:bg-foreground/10 absolute inset-0 transition-colors" })
					]
				}), /* @__PURE__ */ jsx("div", {
					className: "bg-card p-2",
					children: /* @__PURE__ */ jsx("p", {
						className: cn("truncate text-sm font-medium", isSelected ? "text-primary" : "text-foreground"),
						children: theme.name
					})
				})]
			}, theme.id);
		})
	})] });
}
//#endregion
//#region ../../mysite/ui/src/shared/schemas/mysite.schema.ts
const linkSchema = z.object({
	id: z.number(),
	url: z.string(),
	text: z.string(),
	order: z.number(),
	clicks: z.number().optional().default(0)
});
z.array(linkSchema);
const favoriteableSchema = z.object({
	id: z.number(),
	title: z.string().nullable().optional(),
	name: z.string().nullable().optional(),
	image_url: z.string().nullable().optional(),
	type: z.string().optional()
}).passthrough();
const favoriteSchema = z.object({
	id: z.number(),
	favoriteable_id: z.number().optional(),
	favoriteable_type: z.string(),
	order: z.number(),
	user_company_id: z.number().optional(),
	created_at: z.string().optional(),
	favoriteable: favoriteableSchema.nullable()
}).passthrough();
z.array(favoriteSchema);
z.object({ id: z.number() }).passthrough();
z.object({
	id: z.number(),
	bio: z.string().nullable(),
	facebook: z.string().nullable(),
	twitter: z.string().nullable(),
	instagram: z.string().nullable(),
	youtube: z.string().nullable(),
	pinterest: z.string().nullable(),
	tiktok: z.string().nullable(),
	linkedin: z.string().nullable(),
	whatsapp: z.string().nullable(),
	wechat: z.string().nullable(),
	image_url: z.string().nullable()
});
//#endregion
//#region ../../mysite/ui/src/shared/schemas/mysite-theme.schema.ts
const themeSchema = z.object({
	id: z.number(),
	name: z.string(),
	description: z.string().nullable(),
	public: z.boolean(),
	company_id: z.number().nullable(),
	created_at: z.string().datetime(),
	updated_at: z.string().datetime(),
	image_url: z.string().nullable(),
	application_theme_template_id: z.number().nullable(),
	default: z.boolean().nullable().optional()
});
z.array(themeSchema);
const legacyThemeTemplateSchema = z.object({
	id: z.number(),
	name: z.string(),
	content: z.string().nullable(),
	stylesheet: z.string().nullable(),
	head: z.string().nullable(),
	status: z.string()
});
z.object({ data: z.object({ legacy_theme: z.object({
	id: z.number(),
	name: z.string(),
	description: z.string().nullable(),
	image_url: z.string().nullable(),
	public: z.boolean(),
	company_id: z.number().nullable(),
	template: legacyThemeTemplateSchema
}) }) });
//#endregion
//#region ../../mysite/ui/src/shared/utils.ts
/**
* Strip the server-injected `public_id` query param from a URL so the rep
* sees their clean original URL when editing or previewing. The BFF appends
* `public_id=<rep uuid>` to outbound MySite link URLs for attribution; that
* value should not be persisted back when the rep saves an edit, and it
* should not clutter list previews.
*/
function stripRepPublicIdFromUrl(url) {
	if (!url) return url;
	try {
		const parsed = new URL(url);
		if (!parsed.searchParams.has("public_id")) return url;
		parsed.searchParams.delete("public_id");
		return parsed.toString();
	} catch {
		return url;
	}
}
function normalizeUrl(value) {
	const trimmed = value.trim();
	if (!trimmed) return "";
	if (/^https?:\/\//i.test(trimmed)) return trimmed;
	return `https://${trimmed}`;
}
//#endregion
//#region ../../mysite/ui/src/portal/components/PortalButtonsEditor.tsx
function createButtonSchema(t) {
	return z.object({
		title: z.string().min(1, t("validation_button_text_required")),
		url: z.string().transform(normalizeUrl).pipe(z.string().url(t("validation_url_invalid")))
	});
}
function SortableButtonCard({ link, onEdit, onDelete }) {
	const { t } = useMysiteTranslation();
	const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: link.id });
	const style = {
		transform: CSS.Transform.toString(transform),
		transition
	};
	const displayUrl = stripRepPublicIdFromUrl(link.url);
	const truncatedUrl = displayUrl.length > 40 ? `${displayUrl.substring(0, 40)}...` : displayUrl;
	return /* @__PURE__ */ jsxs("div", {
		ref: setNodeRef,
		style,
		className: `border-border bg-card flex items-center gap-3 rounded-lg border p-3 sm:p-4 ${isDragging ? "opacity-50 shadow-lg" : ""}`,
		children: [
			/* @__PURE__ */ jsx("button", {
				type: "button",
				className: "text-muted-foreground hover:text-foreground cursor-grab touch-none",
				"aria-label": t("drag_to_reorder"),
				...attributes,
				...listeners,
				children: /* @__PURE__ */ jsx(GripVertical, { className: "size-5" })
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "min-w-0 flex-1",
				children: [/* @__PURE__ */ jsx("p", {
					className: "text-foreground truncate font-medium",
					children: link.title
				}), /* @__PURE__ */ jsx("p", {
					className: "text-muted-foreground truncate text-sm",
					children: truncatedUrl
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex shrink-0 items-center gap-1",
				children: [/* @__PURE__ */ jsx(Button, {
					variant: "ghost",
					size: "sm",
					className: "text-muted-foreground hover:text-foreground",
					onClick: () => onEdit(link),
					"aria-label": t("edit_button_aria"),
					children: /* @__PURE__ */ jsx(Pencil, { className: "size-4" })
				}), /* @__PURE__ */ jsx(Button, {
					variant: "ghost",
					size: "sm",
					className: "text-muted-foreground hover:text-destructive",
					onClick: () => onDelete(link),
					"aria-label": t("delete_button_aria"),
					children: /* @__PURE__ */ jsx(Trash2, { className: "size-4" })
				})]
			})
		]
	});
}
/**
* Portal-specific buttons editor that uses MySiteApi context.
* No client/userId props needed — data comes from context.
*/
function PortalButtonsEditor({ onBack, onRefreshPreview, onToast }) {
	"use no memo";
	const { t } = useMysiteTranslation();
	const schema = useMemo(() => createButtonSchema(t), [t]);
	const { data: links = [], isLoading } = usePortalLinks();
	const createLinkMutation = usePortalCreateLink();
	const updateLinkMutation = usePortalUpdateLink();
	const deleteLinkMutation = usePortalDeleteLink();
	const reorderLinksMutation = usePortalReorderLinks();
	const [isAddEditDialogOpen, setIsAddEditDialogOpen] = useState(false);
	const [editingLink, setEditingLink] = useState(null);
	const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
	const [deletingLink, setDeletingLink] = useState(null);
	const { register, handleSubmit: handleButtonSubmit, reset: resetButtonForm, formState: { errors: buttonErrors, isSubmitting: isButtonSubmitting } } = useZodForm(schema, { defaultValues: {
		title: "",
		url: ""
	} });
	const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
	const handleOpenAddDialog = useCallback(() => {
		setEditingLink(null);
		resetButtonForm({
			title: "",
			url: ""
		});
		setIsAddEditDialogOpen(true);
	}, [resetButtonForm]);
	const handleOpenEditDialog = useCallback((link) => {
		setEditingLink(link);
		resetButtonForm({
			title: link.title,
			url: stripRepPublicIdFromUrl(link.url)
		});
		setIsAddEditDialogOpen(true);
	}, [resetButtonForm]);
	const handleCloseAddEditDialog = useCallback(() => {
		setIsAddEditDialogOpen(false);
		setEditingLink(null);
		resetButtonForm({
			title: "",
			url: ""
		});
	}, [resetButtonForm]);
	const onButtonSubmit = useCallback((data) => {
		if (editingLink) updateLinkMutation.mutate({
			linkId: editingLink.id,
			body: {
				title: data.title,
				url: data.url
			}
		}, {
			onSuccess: () => {
				onToast?.(t("button_updated"), "success");
				handleCloseAddEditDialog();
				onRefreshPreview?.();
			},
			onError: () => {
				onToast?.(t("button_update_failed"), "error");
			}
		});
		else createLinkMutation.mutate({
			title: data.title,
			url: data.url
		}, {
			onSuccess: () => {
				onToast?.(t("button_created"), "success");
				handleCloseAddEditDialog();
				onRefreshPreview?.();
			},
			onError: () => {
				onToast?.(t("button_create_failed"), "error");
			}
		});
	}, [
		editingLink,
		createLinkMutation,
		updateLinkMutation,
		handleCloseAddEditDialog,
		onRefreshPreview,
		onToast,
		t
	]);
	const handleOpenDeleteDialog = useCallback((link) => {
		setDeletingLink(link);
		setIsDeleteDialogOpen(true);
	}, []);
	const handleCloseDeleteDialog = useCallback(() => {
		setIsDeleteDialogOpen(false);
		setDeletingLink(null);
	}, []);
	const handleConfirmDelete = useCallback(() => {
		if (deletingLink) deleteLinkMutation.mutate(deletingLink.id, {
			onSuccess: () => {
				onToast?.(t("button_deleted"), "success");
				handleCloseDeleteDialog();
				onRefreshPreview?.();
			},
			onError: () => {
				onToast?.(t("button_delete_failed"), "error");
			}
		});
	}, [
		deletingLink,
		deleteLinkMutation,
		handleCloseDeleteDialog,
		onRefreshPreview,
		onToast,
		t
	]);
	const handleDragEnd = useCallback((event) => {
		const { active, over } = event;
		if (over && active.id !== over.id) {
			const reordered = arrayMove(links, links.findIndex((l) => l.id === active.id), links.findIndex((l) => l.id === over.id));
			const orderedIds = reordered.map((link) => link.id);
			reorderLinksMutation.mutate({
				orderedIds,
				optimisticItems: reordered
			}, {
				onSuccess: () => {
					onRefreshPreview?.();
				},
				onError: () => {
					onToast?.(t("reorder_buttons_failed"), "error");
				}
			});
		}
	}, [
		links,
		reorderLinksMutation,
		onRefreshPreview,
		onToast,
		t
	]);
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [
		/* @__PURE__ */ jsxs("div", {
			className: "flex items-center justify-between",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "flex items-center gap-3",
				children: [/* @__PURE__ */ jsx(Button, {
					variant: "ghost",
					size: "icon",
					onClick: onBack,
					children: /* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" })
				}), /* @__PURE__ */ jsx("h1", {
					className: "text-foreground text-xl font-bold",
					children: t("buttons_heading")
				})]
			}), /* @__PURE__ */ jsxs(Button, {
				size: "sm",
				onClick: handleOpenAddDialog,
				children: [/* @__PURE__ */ jsx(Plus, { className: "mr-1 size-4" }), t("add_button")]
			})]
		}),
		isLoading ? /* @__PURE__ */ jsx("div", {
			className: "space-y-2",
			children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxs("div", {
				className: "border-border bg-card flex items-center gap-3 rounded-lg border p-3 sm:p-4",
				children: [
					/* @__PURE__ */ jsx(Skeleton, { className: "size-5" }),
					/* @__PURE__ */ jsxs("div", {
						className: "min-w-0 flex-1 space-y-2",
						children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-48" })]
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "flex gap-1",
						children: [/* @__PURE__ */ jsx(Skeleton, { className: "size-8" }), /* @__PURE__ */ jsx(Skeleton, { className: "size-8" })]
					})
				]
			}, i))
		}) : links.length === 0 ? /* @__PURE__ */ jsxs(Card, {
			className: "p-6 text-center sm:p-8",
			children: [/* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground mb-4",
				children: t("no_buttons_empty")
			}), /* @__PURE__ */ jsxs(Button, {
				size: "sm",
				onClick: handleOpenAddDialog,
				children: [/* @__PURE__ */ jsx(Plus, { className: "mr-1 size-4" }), t("add_button")]
			})]
		}) : /* @__PURE__ */ jsx(DndContext, {
			sensors,
			collisionDetection: closestCenter,
			onDragEnd: handleDragEnd,
			children: /* @__PURE__ */ jsx(SortableContext, {
				items: links.map((l) => l.id),
				strategy: verticalListSortingStrategy,
				children: /* @__PURE__ */ jsx("div", {
					className: "space-y-2",
					children: links.map((link) => /* @__PURE__ */ jsx(SortableButtonCard, {
						link,
						onEdit: handleOpenEditDialog,
						onDelete: handleOpenDeleteDialog
					}, link.id))
				})
			})
		}),
		/* @__PURE__ */ jsx(Dialog, {
			open: isAddEditDialogOpen,
			onOpenChange: setIsAddEditDialogOpen,
			children: /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: editingLink ? t("edit_button_dialog") : t("add_button_dialog") }) }), /* @__PURE__ */ jsxs("form", {
				onSubmit: handleButtonSubmit(onButtonSubmit),
				className: "space-y-4",
				children: [
					/* @__PURE__ */ jsxs("div", {
						className: "space-y-2",
						children: [
							/* @__PURE__ */ jsx(Label, {
								htmlFor: "title",
								children: t("button_text_label")
							}),
							/* @__PURE__ */ jsx(Input, {
								id: "title",
								placeholder: t("button_text_placeholder"),
								...register("title"),
								className: buttonErrors.title ? "border-destructive" : ""
							}),
							buttonErrors.title && /* @__PURE__ */ jsx("p", {
								className: "text-destructive text-sm",
								children: buttonErrors.title.message
							})
						]
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "space-y-2",
						children: [
							/* @__PURE__ */ jsx(Label, {
								htmlFor: "url",
								children: t("url_label")
							}),
							/* @__PURE__ */ jsx(Input, {
								id: "url",
								placeholder: t("url_placeholder"),
								...register("url"),
								className: buttonErrors.url ? "border-destructive" : ""
							}),
							buttonErrors.url && /* @__PURE__ */ jsx("p", {
								className: "text-destructive text-sm",
								children: buttonErrors.url.message
							})
						]
					}),
					/* @__PURE__ */ jsxs(DialogFooter, {
						className: "flex justify-between",
						children: [editingLink ? /* @__PURE__ */ jsxs(Button, {
							type: "button",
							variant: "destructive",
							onClick: () => {
								handleCloseAddEditDialog();
								handleOpenDeleteDialog(editingLink);
							},
							children: [/* @__PURE__ */ jsx(Trash2, { className: "mr-1 size-4" }), t("delete")]
						}) : /* @__PURE__ */ jsx("div", {}), /* @__PURE__ */ jsxs("div", {
							className: "flex gap-2",
							children: [/* @__PURE__ */ jsx(Button, {
								type: "button",
								variant: "outline",
								onClick: handleCloseAddEditDialog,
								children: t("cancel")
							}), /* @__PURE__ */ jsx(Button, {
								type: "submit",
								disabled: isButtonSubmitting || createLinkMutation.isPending || updateLinkMutation.isPending,
								children: isButtonSubmitting || createLinkMutation.isPending || updateLinkMutation.isPending ? t("saving") : t("save")
							})]
						})]
					})
				]
			})] })
		}),
		/* @__PURE__ */ jsx(Dialog, {
			open: isDeleteDialogOpen,
			onOpenChange: setIsDeleteDialogOpen,
			children: /* @__PURE__ */ jsxs(DialogContent, { children: [
				/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("delete_button_dialog") }) }),
				/* @__PURE__ */ jsx("p", {
					className: "text-muted-foreground",
					children: t("delete_button_confirm", { name: deletingLink?.title ?? "" })
				}),
				/* @__PURE__ */ jsxs(DialogFooter, { children: [/* @__PURE__ */ jsx(Button, {
					type: "button",
					variant: "outline",
					onClick: handleCloseDeleteDialog,
					children: t("cancel")
				}), /* @__PURE__ */ jsx(Button, {
					type: "button",
					variant: "destructive",
					onClick: handleConfirmDelete,
					disabled: deleteLinkMutation.isPending,
					children: deleteLinkMutation.isPending ? t("deleting") : t("delete")
				})] })
			] })
		})
	] });
}
//#endregion
//#region ../../mysite/ui/src/portal/components/PortalFavoritesEditor.tsx
const TYPE_LABEL_KEYS = {
	Medium: "type_media",
	Library: "type_playlist",
	EnrollmentPack: "type_enrollment_pack",
	Page: "type_page"
};
function SortableFavoriteCard({ favorite, onDelete }) {
	const { t } = useMysiteTranslation();
	const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: favorite.id });
	const style = {
		transform: CSS.Transform.toString(transform),
		transition
	};
	const title = favorite.name ?? t("untitled");
	const imageUrl = favorite.image_url;
	const typeLabelKey = TYPE_LABEL_KEYS[favorite.favoriteable_type];
	const typeLabel = favorite.favoriteable_type !== "Product" ? typeLabelKey ? t(typeLabelKey) : favorite.favoriteable_type : null;
	return /* @__PURE__ */ jsxs("div", {
		ref: setNodeRef,
		style,
		className: `border-border bg-card flex items-center gap-3 rounded-lg border p-3 sm:p-4 ${isDragging ? "opacity-50 shadow-lg" : ""}`,
		children: [
			/* @__PURE__ */ jsx("button", {
				type: "button",
				className: "text-muted-foreground hover:text-foreground cursor-grab touch-none",
				"aria-label": t("drag_to_reorder"),
				...attributes,
				...listeners,
				children: /* @__PURE__ */ jsx(GripVertical, { className: "size-5" })
			}),
			/* @__PURE__ */ jsx("div", {
				className: "bg-muted size-10 shrink-0 overflow-hidden rounded-md",
				children: imageUrl ? /* @__PURE__ */ jsx("img", {
					src: imageUrl,
					alt: title,
					loading: "lazy",
					width: 40,
					height: 40,
					className: "h-full w-full object-cover"
				}) : /* @__PURE__ */ jsx("div", {
					className: "text-muted-foreground flex h-full w-full items-center justify-center text-xs",
					children: t("no_image")
				})
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "min-w-0 flex-1",
				children: [/* @__PURE__ */ jsx("p", {
					className: "text-foreground truncate font-medium",
					children: title
				}), typeLabel ? /* @__PURE__ */ jsx("span", {
					className: "text-muted-foreground text-xs",
					children: typeLabel
				}) : null]
			}),
			/* @__PURE__ */ jsx("div", {
				className: "flex shrink-0 items-center gap-1",
				children: /* @__PURE__ */ jsx(Button, {
					variant: "ghost",
					size: "sm",
					className: "text-muted-foreground hover:text-destructive",
					onClick: () => onDelete(favorite),
					"aria-label": t("remove_favorite_aria"),
					children: /* @__PURE__ */ jsx(Trash2, { className: "size-4" })
				})
			})
		]
	});
}
/**
* Portal-specific favorites editor that uses MySiteApi context.
* No client/affiliateId props needed — data comes from context.
*/
function PortalFavoritesEditor({ onBack, onRefreshPreview, onToast }) {
	const { t } = useMysiteTranslation();
	const { data: favorites = [], isLoading } = usePortalFavorites();
	const deleteFavoriteMutation = usePortalDeleteFavorite();
	const reorderFavoritesMutation = usePortalReorderFavorites();
	const [isDeleteFavoriteDialogOpen, setIsDeleteFavoriteDialogOpen] = useState(false);
	const [deletingFavorite, setDeletingFavorite] = useState(null);
	const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
	const handleOpenDeleteFavoriteDialog = useCallback((favorite) => {
		setDeletingFavorite(favorite);
		setIsDeleteFavoriteDialogOpen(true);
	}, []);
	const handleCloseDeleteFavoriteDialog = useCallback(() => {
		setIsDeleteFavoriteDialogOpen(false);
		setDeletingFavorite(null);
	}, []);
	const handleConfirmDeleteFavorite = useCallback(() => {
		if (deletingFavorite) deleteFavoriteMutation.mutate(deletingFavorite.id, {
			onSuccess: () => {
				onToast?.(t("content_removed"), "success");
				handleCloseDeleteFavoriteDialog();
				onRefreshPreview?.();
			},
			onError: () => {
				onToast?.(t("content_remove_failed"), "error");
			}
		});
	}, [
		deletingFavorite,
		deleteFavoriteMutation,
		handleCloseDeleteFavoriteDialog,
		onRefreshPreview,
		onToast,
		t
	]);
	const handleFavoriteDragEnd = useCallback((event) => {
		const { active, over } = event;
		if (over && active.id !== over.id) {
			const reordered = arrayMove(favorites, favorites.findIndex((f) => f.id === active.id), favorites.findIndex((f) => f.id === over.id));
			const orderedIds = reordered.map((fav) => fav.id);
			reorderFavoritesMutation.mutate({
				orderedIds,
				optimisticItems: reordered
			}, {
				onSuccess: () => {
					onRefreshPreview?.();
				},
				onError: () => {
					onToast?.(t("reorder_content_failed"), "error");
				}
			});
		}
	}, [
		favorites,
		reorderFavoritesMutation,
		onRefreshPreview,
		onToast,
		t
	]);
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [
		/* @__PURE__ */ jsxs("div", {
			className: "flex items-center gap-3",
			children: [/* @__PURE__ */ jsx(Button, {
				variant: "ghost",
				size: "icon",
				onClick: onBack,
				children: /* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" })
			}), /* @__PURE__ */ jsx("h1", {
				className: "text-foreground text-xl font-bold",
				children: t("content_heading")
			})]
		}),
		isLoading ? /* @__PURE__ */ jsx("div", {
			className: "space-y-2",
			children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxs("div", {
				className: "border-border bg-card flex items-center gap-3 rounded-lg border p-3 sm:p-4",
				children: [
					/* @__PURE__ */ jsx(Skeleton, { className: "size-5" }),
					/* @__PURE__ */ jsx(Skeleton, { className: "size-10 rounded-md" }),
					/* @__PURE__ */ jsxs("div", {
						className: "min-w-0 flex-1 space-y-2",
						children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-20" })]
					}),
					/* @__PURE__ */ jsx(Skeleton, { className: "size-8" })
				]
			}, i))
		}) : favorites.length === 0 ? /* @__PURE__ */ jsx(Card, {
			className: "p-6 text-center sm:p-8",
			children: /* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground",
				children: t("no_content_empty")
			})
		}) : /* @__PURE__ */ jsx(DndContext, {
			sensors,
			collisionDetection: closestCenter,
			onDragEnd: handleFavoriteDragEnd,
			children: /* @__PURE__ */ jsx(SortableContext, {
				items: favorites.map((f) => f.id),
				strategy: verticalListSortingStrategy,
				children: /* @__PURE__ */ jsx("div", {
					className: "space-y-2",
					children: favorites.map((fav) => /* @__PURE__ */ jsx(SortableFavoriteCard, {
						favorite: fav,
						onDelete: handleOpenDeleteFavoriteDialog
					}, fav.id))
				})
			})
		}),
		/* @__PURE__ */ jsx(Dialog, {
			open: isDeleteFavoriteDialogOpen,
			onOpenChange: setIsDeleteFavoriteDialogOpen,
			children: /* @__PURE__ */ jsxs(DialogContent, { children: [
				/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("remove_content_dialog") }) }),
				/* @__PURE__ */ jsx("p", {
					className: "text-muted-foreground",
					children: t("remove_content_confirm", { name: deletingFavorite?.name ?? t("untitled") })
				}),
				/* @__PURE__ */ jsxs(DialogFooter, { children: [/* @__PURE__ */ jsx(Button, {
					type: "button",
					variant: "outline",
					onClick: handleCloseDeleteFavoriteDialog,
					children: t("cancel")
				}), /* @__PURE__ */ jsx(Button, {
					type: "button",
					variant: "destructive",
					onClick: handleConfirmDeleteFavorite,
					disabled: deleteFavoriteMutation.isPending,
					children: deleteFavoriteMutation.isPending ? t("removing") : t("remove")
				})] })
			] })
		})
	] });
}
//#endregion
//#region src/screens/MySiteScreen/MySiteMainView.tsx
const navigationItems = [
	{
		labelKey: "nav_profile",
		slug: "profile",
		icon: User
	},
	{
		labelKey: "nav_theme",
		key: "theme",
		icon: Palette
	},
	{
		labelKey: "nav_content",
		key: "content",
		icon: LayoutGrid
	},
	{
		labelKey: "nav_buttons",
		key: "buttons",
		icon: Link2
	}
];
function defaultToast(message, type) {
	fluidToast({
		title: message,
		type
	});
}
function MySiteMainView({ editingSection, animPhase, showEditContent, onEditSection, onBackClick }) {
	const { t } = useMysiteTranslation();
	const { navigate } = useAppNavigation();
	const { data: profile, isLoading: isProfileLoading } = usePortalMySiteProfile();
	const { data: themes = [] } = usePortalMySiteThemes();
	const updateSettingsMutation = usePortalUpdateSettings();
	const [previewKey, setPreviewKey] = useState(0);
	const refreshPreview = useCallback(() => setPreviewKey((k) => k + 1), []);
	const [selectedThemeId, setSelectedThemeId] = useState(null);
	const resolvedThemeId = selectedThemeId ?? profile?.theme_id ?? themes.find((t) => t.name === "Default")?.id ?? themes[0]?.id ?? null;
	const themeName = themes.find((t) => t.id === resolvedThemeId)?.name ?? "Default";
	const mysiteUrl = profile?.mysite_url ?? "";
	const displayUrl = mysiteUrl ? mysiteUrl.replace(/^https?:\/\//, "") : "";
	const views = profile?.mysite_views ?? 0;
	const leads = profile?.mysite_leads ?? 0;
	const handleSelectTheme = useCallback((theme) => {
		if (theme.id === resolvedThemeId) return;
		const previousThemeId = selectedThemeId;
		setSelectedThemeId(theme.id);
		updateSettingsMutation.mutate({ theme_id: theme.id }, {
			onSuccess: () => {
				defaultToast(t("theme_changed", { name: theme.name }), "success");
				refreshPreview();
			},
			onError: () => {
				setSelectedThemeId(previousThemeId);
				defaultToast(t("theme_update_failed"), "error");
			}
		});
	}, [
		resolvedThemeId,
		selectedThemeId,
		updateSettingsMutation,
		refreshPreview,
		t
	]);
	const handleUpdateSlug = useCallback(async (slug) => {
		await new Promise((resolve, reject) => {
			updateSettingsMutation.mutate({ slug }, {
				onSuccess: () => resolve(),
				onError: () => reject(/* @__PURE__ */ new Error("Failed"))
			});
		});
	}, [updateSettingsMutation]);
	const handlePreview = useCallback(() => {
		if (mysiteUrl) window.open(`${mysiteUrl}?preview=true`, "_blank");
	}, [mysiteUrl]);
	const sectionLabel = useMemo(() => {
		if (editingSection === "theme") return t("nav_theme");
		if (editingSection === "buttons") return t("nav_buttons");
		if (editingSection === "content") return t("nav_content");
		return "";
	}, [editingSection, t]);
	if (isProfileLoading) return /* @__PURE__ */ jsxs("div", {
		className: "flex h-full flex-col overflow-y-auto px-2 py-6 2xl:flex-row 2xl:overflow-hidden",
		children: [/* @__PURE__ */ jsx("div", {
			className: "w-full px-4 2xl:w-2/3 2xl:shrink-0",
			children: /* @__PURE__ */ jsxs("div", {
				className: "flex flex-col gap-5",
				children: [
					/* @__PURE__ */ jsx("div", { className: "bg-muted h-7 w-32 animate-pulse rounded-md" }),
					/* @__PURE__ */ jsx("div", { className: "bg-muted h-20 w-full animate-pulse rounded-lg" }),
					/* @__PURE__ */ jsx("div", { className: "bg-muted h-16 w-full animate-pulse rounded-lg" }),
					/* @__PURE__ */ jsx("div", { className: "bg-muted h-40 w-full animate-pulse rounded-lg" })
				]
			})
		}), /* @__PURE__ */ jsx("div", {
			className: "w-full shrink-0 overflow-y-hidden px-4 pt-5 2xl:h-full 2xl:w-1/3 2xl:overflow-y-auto 2xl:pt-0",
			children: /* @__PURE__ */ jsxs("div", {
				className: "bg-muted flex h-full flex-col items-center gap-4 rounded-xl p-5",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex w-full items-center justify-between",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "space-y-1",
						children: [/* @__PURE__ */ jsx("div", { className: "bg-background/50 h-3 w-24 animate-pulse rounded" }), /* @__PURE__ */ jsx("div", { className: "bg-background/50 h-4 w-28 animate-pulse rounded" })]
					}), /* @__PURE__ */ jsx("div", { className: "bg-background/50 h-8 w-20 animate-pulse rounded-md" })]
				}), /* @__PURE__ */ jsx("div", { className: "bg-background/50 h-[490px] w-[260px] animate-pulse rounded-[36px] sm:h-[600px] sm:w-[320px]" })]
			})
		})]
	});
	const contentAnimClassName = getContentClassName(animPhase);
	const previewAnimClassName = getPreviewClassName(animPhase);
	return /* @__PURE__ */ jsxs("div", {
		className: "flex h-full flex-col overflow-y-auto px-2 py-6 2xl:flex-row 2xl:overflow-hidden",
		children: [/* @__PURE__ */ jsx("div", {
			className: `w-full px-4 2xl:w-2/3 2xl:shrink-0 ${contentAnimClassName}`,
			children: /* @__PURE__ */ jsx("div", {
				className: "flex min-w-0 flex-col gap-5 2xl:h-full 2xl:overflow-y-auto",
				children: showEditContent && editingSection === "theme" ? /* @__PURE__ */ jsx(MySiteThemeEditor, {
					themes,
					selectedThemeId: resolvedThemeId,
					onSelectTheme: handleSelectTheme,
					isPending: updateSettingsMutation.isPending,
					onBack: onBackClick
				}) : showEditContent && editingSection === "buttons" ? /* @__PURE__ */ jsx(PortalButtonsEditor, {
					onBack: onBackClick,
					onRefreshPreview: refreshPreview,
					onToast: defaultToast
				}) : showEditContent && editingSection === "content" ? /* @__PURE__ */ jsx(PortalFavoritesEditor, {
					onBack: onBackClick,
					onRefreshPreview: refreshPreview,
					onToast: defaultToast
				}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
					/* @__PURE__ */ jsxs("div", {
						className: "flex items-center gap-2",
						children: [/* @__PURE__ */ jsx("h1", {
							className: "text-foreground text-xl font-bold",
							children: t("heading")
						}), animPhase !== "idle" && sectionLabel && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ChevronRight, { className: "text-muted-foreground size-4" }), /* @__PURE__ */ jsx("span", {
							className: "text-foreground text-xl font-bold",
							children: sectionLabel
						})] })]
					}),
					/* @__PURE__ */ jsx(MySiteVisitorDetailsCard, {
						views,
						leads
					}),
					/* @__PURE__ */ jsx(MySiteLinkCard, {
						mysiteUrl,
						displayUrl,
						onUpdateSlug: handleUpdateSlug,
						onToast: defaultToast
					}),
					/* @__PURE__ */ jsx("div", {
						className: "border-border bg-card divide-border divide-y overflow-hidden rounded-lg border",
						children: navigationItems.map((item) => {
							const Icon = item.icon;
							return /* @__PURE__ */ jsxs("button", {
								type: "button",
								onClick: "slug" in item ? () => navigate(item.slug) : () => onEditSection(item.key),
								className: "group hover:bg-muted flex w-full items-center gap-2.5 px-3 py-2.5 transition-colors text-left cursor-pointer",
								children: [
									/* @__PURE__ */ jsx("div", {
										className: "bg-muted text-foreground flex size-7 shrink-0 items-center justify-center rounded-full",
										children: /* @__PURE__ */ jsx(Icon, { className: "size-3.5" })
									}),
									/* @__PURE__ */ jsx("span", {
										className: "text-foreground flex-1 text-sm font-medium",
										children: t(item.labelKey)
									}),
									/* @__PURE__ */ jsx(ChevronRight, { className: "text-muted-foreground size-3 shrink-0 transition-transform group-hover:translate-x-0.5" })
								]
							}, item.labelKey);
						})
					})
				] })
			})
		}), /* @__PURE__ */ jsx("div", {
			className: `w-full shrink-0 overflow-y-hidden px-4 pt-5 2xl:h-full 2xl:w-1/3 2xl:overflow-y-auto 2xl:pt-0 ${previewAnimClassName}`,
			children: /* @__PURE__ */ jsx(MySitePhonePreview, {
				mysiteUrl,
				themeName,
				previewKey,
				isUpdating: updateSettingsMutation.isPending,
				onPreview: handlePreview
			})
		})]
	});
}
//#endregion
//#region src/screens/MySiteScreen/use-mysite-editing-section.ts
function useMySiteEditingSection() {
	const [animPhase, setAnimPhase] = useState("idle");
	const [editingSection, setEditingSection] = useState(null);
	const timeoutsRef = useRef([]);
	useEffect(() => {
		const ref = timeoutsRef;
		return () => ref.current.forEach(clearTimeout);
	}, []);
	const cancelScheduled = useCallback(() => {
		timeoutsRef.current.forEach(clearTimeout);
		timeoutsRef.current = [];
	}, []);
	const schedule = useCallback((phase, delay) => {
		const id = setTimeout(() => setAnimPhase(phase), delay);
		timeoutsRef.current.push(id);
	}, []);
	return {
		editingSection,
		animPhase,
		showEditContent: [
			"slide",
			"fade-in",
			"editing",
			"exit-fade-out",
			"exit-slide"
		].includes(animPhase),
		handleEditSection: useCallback((section) => {
			cancelScheduled();
			setEditingSection(section);
			setAnimPhase("fade-out");
			schedule("slide", 300);
			schedule("fade-in", 800);
			schedule("editing", 1100);
		}, [cancelScheduled, schedule]),
		handleBackClick: useCallback(() => {
			cancelScheduled();
			setAnimPhase("exit-fade-out");
			schedule("exit-slide", 300);
			schedule("exit-fade-in", 800);
			const id = setTimeout(() => {
				setAnimPhase("idle");
				setEditingSection(null);
			}, 1100);
			timeoutsRef.current.push(id);
		}, [cancelScheduled, schedule])
	};
}
//#endregion
//#region src/screens/MySiteScreen/index.tsx
var MySiteScreen_exports = /* @__PURE__ */ __exportAll({
	MySiteScreen: () => MySiteScreen,
	mySiteScreenPropertySchema: () => mySiteScreenPropertySchema
});
function MySiteScreen({ background, textColor, accentColor, padding, borderRadius, ...divProps }) {
	return /* @__PURE__ */ jsx(MysiteTranslationBridge, { children: /* @__PURE__ */ jsx(MySiteScreenContent, { ...divProps }) });
}
function MySiteScreenContent(divProps) {
	const { t } = useMysiteTranslation();
	const { editingSection, animPhase, showEditContent, handleEditSection, handleBackClick } = useMySiteEditingSection();
	const sectionLabel = useMemo(() => {
		if (editingSection === "theme") return t("nav_theme");
		if (editingSection === "buttons") return t("nav_buttons");
		if (editingSection === "content") return t("nav_content");
		return null;
	}, [editingSection, t]);
	const handleRootCrumbClick = useCallback((e) => {
		e.preventDefault();
		if (editingSection !== null) handleBackClick();
	}, [editingSection, handleBackClick]);
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ScreenHeaderBreadcrumbs, { children: /* @__PURE__ */ jsx(Breadcrumb, { children: /* @__PURE__ */ jsxs(BreadcrumbList, {
		className: "text-lg",
		children: [/* @__PURE__ */ jsx(BreadcrumbItem, { children: sectionLabel ? /* @__PURE__ */ jsx(BreadcrumbLink, {
			href: "#",
			onClick: handleRootCrumbClick,
			children: "MySite"
		}) : /* @__PURE__ */ jsx(BreadcrumbPage, {
			className: "font-semibold",
			children: "MySite"
		}) }), sectionLabel && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(BreadcrumbSeparator, {}), /* @__PURE__ */ jsx(BreadcrumbItem, { children: /* @__PURE__ */ jsx(BreadcrumbPage, {
			className: "font-semibold",
			children: sectionLabel
		}) })] })]
	}) }) }), /* @__PURE__ */ jsx("div", {
		...divProps,
		className: `h-full ${divProps.className ?? ""}`,
		children: /* @__PURE__ */ jsx(MySiteMainView, {
			editingSection,
			animPhase,
			showEditContent,
			onEditSection: handleEditSection,
			onBackClick: handleBackClick
		})
	})] });
}
const mySiteScreenPropertySchema = {
	widgetType: "MySiteScreen",
	displayName: "MySite Screen",
	tabsConfig: [{
		id: "styling",
		label: "Styling"
	}],
	fields: []
};
//#endregion
export { MySiteScreen_exports as n, mySiteScreenPropertySchema as r, MySiteScreen as t };

//# sourceMappingURL=MySiteScreen-CJ9CD896.mjs.map