import { n as useFluidContext } from "./FluidProvider-DTDhVSLQ.mjs";
import { a as useActiveLocale, n as createDomainTranslations, r as useDomainDict, t as createStaticDictAdapter } from "./static-dict-adapter-BxOhLaMD.mjs";
import { B as DropdownMenuContent, C as SelectContent, D as RadioGroup, E as SelectValue, G as DropdownMenuSeparator, H as DropdownMenuLabel, O as RadioGroupItem, S as Select, T as SelectTrigger, U as DropdownMenuRadioGroup, W as DropdownMenuRadioItem, Y as DropdownMenuTrigger, an as BreadcrumbLink, cn as BreadcrumbSeparator, gt as Card, h as Skeleton, in as BreadcrumbItem, on as BreadcrumbList, rn as Breadcrumb, sn as BreadcrumbPage, vn as Button, w as SelectItem, z as DropdownMenu } from "./src-Dk1FJOX0.mjs";
import { n as ScreenHeaderBreadcrumbs, t as ScreenHeaderActions } from "./ScreenHeaderContext-Dn12BZyj.mjs";
import { t as createTranslationContext } from "./translation-api-context-factory-CQiyQFCV.mjs";
import { t as useStore } from "./use-store-BVCCB9kx.mjs";
import { n as useAppNavigation } from "./AppNavigationContext-Dvc0yoZF.mjs";
import { a as usePortalProductCatalog, i as usePortalProductDetail, n as determineProductPrice, r as getProductImageUrl, s as SearchSort, t as PortalProductsApiProvider } from "./PortalProductsApiProvider-Daft5xxE.mjs";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useInfiniteQuery } from "@tanstack/react-query";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
import { ArrowUpDown, ChevronLeft, ChevronRight, CirclePlay, ShoppingCart } from "lucide-react";
import { createPortal } from "react-dom";
//#region ../../shop/core/src/translation-api-context.ts
const { Provider, useTranslation } = createTranslationContext("Shop");
const ShopTranslationProvider = Provider;
const useShopTranslation = useTranslation;
//#endregion
//#region ../../shop/ui/src/utils/media-helpers.ts
const VIDEO_EXTENSIONS = [
	".mp4",
	".webm",
	".mov",
	".avi",
	".m4v",
	".mkv",
	".ogv",
	".ogg",
	".wmv",
	".flv",
	".3gp"
];
function isVideoUrl(url) {
	if (!url) return false;
	const lowerUrl = url.toLowerCase();
	return VIDEO_EXTENSIONS.some((ext) => lowerUrl.includes(ext));
}
function getVideoThumbnailUrl(videoUrl) {
	if (videoUrl.includes("ik.imagekit.io")) return `${videoUrl}/ik-thumbnail.jpg`;
	return videoUrl;
}
//#endregion
//#region ../../shop/ui/src/components/product-card.tsx
function tagPortalProduct(product) {
	return {
		...product,
		__portalProduct: true
	};
}
function isPortalProduct(product) {
	return "__portalProduct" in product && product.__portalProduct === true;
}
function getPortalProductCoverImage(product) {
	if (product.images && product.images.length > 0) return product.images[0]?.url ?? null;
	return null;
}
function defaultRenderImage$1({ src, alt, fill, className, onError }) {
	return /* @__PURE__ */ jsx("img", {
		src,
		alt,
		className: `${fill ? "absolute inset-0 h-full w-full" : ""} ${className ?? ""}`,
		onError
	});
}
function formatPortalPrice(price, currency) {
	if (!price) return null;
	const numericPrice = Number(price);
	if (Number.isNaN(numericPrice)) return `${currency ?? ""}${price}`;
	try {
		return new Intl.NumberFormat(void 0, {
			style: "currency",
			currency: currency || "USD"
		}).format(numericPrice);
	} catch {
		return `$${price}`;
	}
}
function ProductCardContent({ product, countryIso, companyLogoUrl, renderImage = defaultRenderImage$1 }) {
	const [isHovered, setIsHovered] = useState(false);
	const { t } = useShopTranslation();
	const isPortal = isPortalProduct(product);
	const coverImage = isPortal ? getPortalProductCoverImage(product) : getProductImageUrl(product);
	const isVideo = isVideoUrl(coverImage);
	const productName = isPortal ? product.name || t("no_title") : product.title || t("no_title");
	let repPrice = null;
	let price = null;
	if (isPortal) if (product.wholesale_price) {
		repPrice = formatPortalPrice(product.wholesale_price, product.currency);
		const retailFormatted = formatPortalPrice(product.price, product.currency);
		if (retailFormatted !== repPrice) price = retailFormatted;
	} else repPrice = formatPortalPrice(product.price, product.currency);
	else if (countryIso) {
		const prices = determineProductPrice(product, countryIso);
		repPrice = prices.repPrice;
		price = prices.price;
	}
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
		className: "bg-muted relative aspect-square overflow-hidden",
		onMouseEnter: () => isVideo && setIsHovered(true),
		onMouseLeave: () => isVideo && setIsHovered(false),
		children: [isVideo && isHovered ? /* @__PURE__ */ jsx("video", {
			src: coverImage || "",
			className: "absolute inset-0 h-full w-full object-cover",
			autoPlay: true,
			muted: true,
			loop: true,
			playsInline: true
		}) : renderImage({
			src: isVideo && coverImage ? getVideoThumbnailUrl(coverImage) : coverImage || "https://assets.fluid.app/fluid-admin/images/we-commerce/we-commerce.png",
			alt: productName,
			fill: true,
			className: "object-cover transition-transform group-hover:scale-105",
			onError: (e) => {
				e.currentTarget.src = companyLogoUrl || "https://assets.fluid.app/fluid-admin/images/we-commerce/we-commerce.png";
			},
			unoptimized: true
		}), isVideo && !isHovered && /* @__PURE__ */ jsx("div", {
			className: "absolute inset-0 flex items-center justify-center",
			children: /* @__PURE__ */ jsx("div", {
				className: "flex h-16 w-16 items-center justify-center rounded-full bg-black/50 backdrop-blur-sm",
				children: /* @__PURE__ */ jsx(CirclePlay, { className: "h-12 w-12 text-white" })
			})
		})]
	}), /* @__PURE__ */ jsxs("div", {
		className: "px-3 pt-2 pb-4",
		children: [
			/* @__PURE__ */ jsx("h3", {
				className: "text-foreground line-clamp-1 text-sm font-bold",
				children: productName
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex items-center gap-2",
				children: [repPrice && /* @__PURE__ */ jsx("span", {
					className: "text-foreground text-sm font-bold",
					children: repPrice
				}), price && /* @__PURE__ */ jsx("span", {
					className: "text-muted-foreground text-sm line-through",
					children: price
				})]
			}),
			!isPortal && countryIso && /* @__PURE__ */ jsxs("div", {
				className: "text-muted-foreground text-sm",
				children: [
					"CV",
					" ",
					getVariantCountryValue(getSelectedVariant(product), countryIso, "cv") || "-",
					" ",
					"| QV",
					" ",
					getVariantCountryValue(getSelectedVariant(product), countryIso, "qv") || "-"
				]
			}),
			isPortal && product.wholesale_price != null && /* @__PURE__ */ jsxs("div", {
				className: "text-muted-foreground text-sm",
				children: [
					"CV ",
					product.cv ?? "-",
					" | QV ",
					product.qv ?? "-"
				]
			})
		]
	})] });
}
function getSelectedVariant(product) {
	if (!product.variants || product.variants.length === 0) return null;
	const masterVariant = product.variants.find((v) => {
		return "is_master" in v && v.is_master;
	});
	if (masterVariant) return masterVariant;
	return product.variants[0] || null;
}
function getVariantCountryValue(variant, countryIso, field) {
	if (!variant || !variant.variant_countries) return null;
	if (typeof variant.variant_countries === "object" && !Array.isArray(variant.variant_countries)) return variant.variant_countries[countryIso]?.[field] ?? null;
	if (Array.isArray(variant.variant_countries)) return variant.variant_countries.find((vc) => vc.country_iso === countryIso)?.[field] ?? null;
	return null;
}
function ProductCard({ product, countryIso, companyLogoUrl, showShareModal = false, setShareModalOpen, setSelectedProduct, renderLink, renderImage, onClick }) {
	const cardContent = /* @__PURE__ */ jsx(ProductCardContent, {
		product,
		countryIso,
		companyLogoUrl,
		renderImage
	});
	const cardClassName = "overflow-hidden border-0 shadow-none pt-0 gap-0";
	if (showShareModal && !isPortalProduct(product)) {
		const handleShareClick = () => {
			if (setSelectedProduct && setShareModalOpen) {
				setSelectedProduct(product);
				setShareModalOpen(true);
			}
		};
		return /* @__PURE__ */ jsx(Card, {
			className: cardClassName,
			children: /* @__PURE__ */ jsx("button", {
				onClick: handleShareClick,
				className: "group block w-full cursor-pointer text-left",
				children: cardContent
			})
		});
	}
	if (onClick) return /* @__PURE__ */ jsx(Card, {
		className: cardClassName,
		children: /* @__PURE__ */ jsx("button", {
			onClick,
			className: "group block w-full cursor-pointer text-left",
			children: cardContent
		})
	});
	const href = `/portal/shop/${product.id}`;
	if (renderLink) return /* @__PURE__ */ jsx(Card, {
		className: cardClassName,
		children: renderLink({
			href,
			children: cardContent
		})
	});
	return /* @__PURE__ */ jsx(Card, {
		className: cardClassName,
		children: /* @__PURE__ */ jsx("a", {
			href,
			className: "group block cursor-pointer",
			children: cardContent
		})
	});
}
//#endregion
//#region ../../shop/ui/src/components/image-gallery.tsx
function defaultRenderImage({ src, alt, fill, className, onError }) {
	return /* @__PURE__ */ jsx("img", {
		src,
		alt,
		className: `${fill ? "absolute inset-0 h-full w-full" : ""} ${className ?? ""}`,
		onError
	});
}
function ImageGallery({ images, fallbackImageUrl, productTitle, renderImage = defaultRenderImage }) {
	const { t } = useShopTranslation();
	const [currentImageIndex, setCurrentImageIndex] = useState(0);
	const hasMultipleImages = images && images.length > 0;
	const displayImages = useMemo(() => hasMultipleImages ? [...images].sort((a, b) => a.position - b.position) : [{
		id: 0,
		image_url: fallbackImageUrl,
		position: 0
	}], [
		images,
		hasMultipleImages,
		fallbackImageUrl
	]);
	useEffect(() => {
		setCurrentImageIndex(0);
	}, [displayImages]);
	const nextImage = () => {
		if (displayImages.length > 1) setCurrentImageIndex((prev) => (prev + 1) % displayImages.length);
	};
	const prevImage = () => {
		if (displayImages.length > 1) setCurrentImageIndex((prev) => (prev - 1 + displayImages.length) % displayImages.length);
	};
	return /* @__PURE__ */ jsx("div", {
		className: "space-y-4",
		children: /* @__PURE__ */ jsxs("div", {
			className: "group relative aspect-square overflow-hidden rounded-sm bg-gray-100",
			children: [
				isVideoUrl(displayImages[currentImageIndex]?.image_url) ? /* @__PURE__ */ jsx("video", {
					src: displayImages[currentImageIndex]?.image_url,
					className: "absolute inset-0 h-full w-full object-cover",
					controls: true,
					loop: true,
					playsInline: true
				}, displayImages[currentImageIndex]?.id) : renderImage({
					src: displayImages[currentImageIndex]?.image_url || fallbackImageUrl,
					alt: productTitle,
					fill: true,
					className: "object-cover",
					onError: (e) => {
						e.currentTarget.src = "https://assets.fluid.app/fluid-admin/images/we-commerce/we-commerce.png";
					},
					unoptimized: true
				}),
				displayImages.length > 1 && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
					type: "button",
					"aria-label": t("previous_image"),
					className: "absolute top-1/2 left-3 z-10 flex h-8 w-8 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-white/40 shadow-sm transition-colors group-hover:bg-white/80 hover:bg-white",
					onClick: prevImage,
					children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-5 w-5 text-black/40 transition-colors group-hover:text-black" })
				}), /* @__PURE__ */ jsx("button", {
					type: "button",
					"aria-label": t("next_image"),
					className: "absolute top-1/2 right-3 z-10 flex h-8 w-8 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-white/40 shadow-sm transition-colors group-hover:bg-white/80 hover:bg-white",
					onClick: nextImage,
					children: /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5 text-black/40 transition-colors group-hover:text-black" })
				})] }),
				displayImages.length > 1 && /* @__PURE__ */ jsx("div", {
					className: "absolute bottom-3 left-1/2 flex -translate-x-1/2 gap-3",
					children: displayImages.map((_, index) => /* @__PURE__ */ jsx("button", {
						type: "button",
						className: `h-1.5 w-6 cursor-pointer rounded-lg transition-colors ${index === currentImageIndex ? "bg-gray-800" : "bg-gray-400 hover:bg-gray-600"}`,
						"aria-label": t("go_to_image", { index: String(index + 1) }),
						onClick: () => setCurrentImageIndex(index)
					}, index))
				})
			]
		})
	});
}
//#endregion
//#region ../../shop/ui/src/components/quantity-selector.tsx
function QuantitySelector({ quantity, setQuantity }) {
	return /* @__PURE__ */ jsx("div", {
		className: "flex items-center gap-3",
		children: /* @__PURE__ */ jsxs("div", {
			className: "flex items-center rounded-lg",
			children: [
				/* @__PURE__ */ jsx(Button, {
					variant: "default",
					onClick: () => setQuantity(Math.max(1, quantity - 1)),
					className: "border-0 px-3 py-2 shadow-none",
					children: "−"
				}),
				/* @__PURE__ */ jsx("span", {
					className: "text-foreground min-w-8 px-4 py-2 text-center text-sm font-medium",
					children: quantity
				}),
				/* @__PURE__ */ jsx(Button, {
					variant: "default",
					onClick: () => setQuantity(quantity + 1),
					className: "border-0 px-3 py-2 shadow-none",
					children: "+"
				})
			]
		})
	});
}
//#endregion
//#region ../../shop/ui/src/components/purchase-options.tsx
function PurchaseOptions({ showBuyOnce, showSubscribe, isSubscribe, onSubscribeChange, product_subscription_plans, selectedSubscriptionPlan, onSubscriptionPlanChange, userSelectedSubscribe, wholesalePrice, wholesaleSubscriptionPrice }) {
	const { t } = useShopTranslation();
	const defaultSubscriptionPlan = useMemo(() => {
		if (!product_subscription_plans?.length) return null;
		return product_subscription_plans.find((plan) => plan.default) || product_subscription_plans[0];
	}, [product_subscription_plans]);
	const currentSubscriptionPlan = selectedSubscriptionPlan || defaultSubscriptionPlan;
	const savingsPercentage = useMemo(() => {
		if (wholesalePrice === void 0 || wholesaleSubscriptionPrice === void 0 || wholesalePrice <= 0) return null;
		const savings = wholesalePrice - wholesaleSubscriptionPrice;
		if (savings <= 0) return null;
		const pct = Math.round(savings / wholesalePrice * 100);
		return pct > 0 ? pct : null;
	}, [wholesalePrice, wholesaleSubscriptionPrice]);
	const formatSubscriptionPlan = (plan) => {
		return `${plan.subscription_plan.billing_interval} ${plan.subscription_plan.billing_interval_unit} (${plan.subscription_plan.name})`;
	};
	const subscriptionPlanOptions = useMemo(() => {
		if (!product_subscription_plans?.length) return [];
		return product_subscription_plans.map((plan) => ({
			value: plan.subscription_plan.id.toString(),
			label: formatSubscriptionPlan(plan)
		}));
	}, [product_subscription_plans]);
	if (showBuyOnce && !showSubscribe) return null;
	const handleSubscriptionPlanChange = (planId) => {
		const selectedPlan = product_subscription_plans?.find((plan) => plan.subscription_plan.id.toString() === planId);
		if (selectedPlan && onSubscriptionPlanChange) onSubscriptionPlanChange(selectedPlan);
	};
	return /* @__PURE__ */ jsx("div", {
		className: "mb-3 flex flex-col",
		children: /* @__PURE__ */ jsxs(RadioGroup, {
			value: isSubscribe ? "subscribe" : "once",
			onValueChange: (value) => onSubscribeChange(value === "subscribe"),
			className: "gap-0 space-y-0",
			children: [showSubscribe && /* @__PURE__ */ jsx("div", {
				onClick: () => onSubscribeChange(true),
				className: `cursor-pointer rounded-t-lg p-4 text-left transition-all duration-200 ${showBuyOnce ? "border border-b-0" : "rounded-b-lg"} ${userSelectedSubscribe ? "bg-muted" : "bg-background"}`,
				children: /* @__PURE__ */ jsxs("div", {
					className: "flex items-start space-x-3",
					children: [/* @__PURE__ */ jsx(RadioGroupItem, {
						value: "subscribe",
						onClick: (e) => e.stopPropagation(),
						className: `flex items-center justify-center [&_svg]:h-1.5 [&_svg]:w-1.5 [&_svg]:fill-white ${isSubscribe ? "border-contrast bg-contrast text-foreground" : "border-border bg-background text-muted-foreground"}`
					}), /* @__PURE__ */ jsxs("div", {
						className: "flex-1",
						children: [/* @__PURE__ */ jsx("div", {
							className: "text-foreground mb-1 text-sm leading-tight font-medium",
							children: savingsPercentage ? t("subscribe_and_save", { percentage: savingsPercentage }) : t("subscribe")
						}), product_subscription_plans?.length > 0 && /* @__PURE__ */ jsxs("div", {
							className: "bg-muted mt-3 rounded-lg p-2",
							onClick: (e) => e.stopPropagation(),
							children: [/* @__PURE__ */ jsx("div", {
								className: "text-foreground mb-1 text-xs font-medium",
								children: t("delivery_frequency")
							}), /* @__PURE__ */ jsxs(Select, {
								value: currentSubscriptionPlan?.subscription_plan.id.toString() || "",
								onValueChange: handleSubscriptionPlanChange,
								disabled: product_subscription_plans?.length === 1,
								children: [/* @__PURE__ */ jsx(SelectTrigger, {
									className: "bg-background text-foreground! w-full text-xs",
									children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("select_delivery_schedule") })
								}), /* @__PURE__ */ jsx(SelectContent, { children: subscriptionPlanOptions.map((option) => /* @__PURE__ */ jsx(SelectItem, {
									value: option.value,
									children: option.label
								}, option.value)) })]
							})]
						})]
					})]
				})
			}), showBuyOnce && /* @__PURE__ */ jsx("div", {
				onClick: () => onSubscribeChange(false),
				className: `cursor-pointer rounded-b-lg border p-4 text-left transition-all duration-200 ${showSubscribe ? "border-t-0" : "rounded-t-lg"} ${!userSelectedSubscribe ? "bg-muted" : "bg-background"}`,
				children: /* @__PURE__ */ jsxs("div", {
					className: "flex items-center space-x-3",
					children: [/* @__PURE__ */ jsx(RadioGroupItem, {
						value: "once",
						onClick: (e) => e.stopPropagation(),
						className: `flex items-center justify-center [&_svg]:h-1.5 [&_svg]:w-1.5 [&_svg]:fill-white ${!isSubscribe ? "border-contrast bg-contrast text-foreground" : "border-border bg-background text-muted-foreground"}`
					}), /* @__PURE__ */ jsx("div", {
						className: "text-foreground mb-1 text-sm leading-tight font-medium",
						children: t("one_time_purchase")
					})]
				})
			})]
		})
	});
}
//#endregion
//#region ../../shop/ui/src/components/shop-app.tsx
const PAGE_SIZE = 25;
function sanitizeHtml(html) {
	const doc = new DOMParser().parseFromString(html, "text/html");
	for (const el of doc.querySelectorAll("script, iframe, object, embed, form, base, meta, link, style")) el.remove();
	for (const el of doc.querySelectorAll("*")) for (const attr of [...el.attributes]) if (attr.name.toLowerCase().startsWith("on") || attr.value.toLowerCase().trim().startsWith("javascript:")) el.removeAttribute(attr.name);
	return doc.body.innerHTML;
}
const GRID_CLASS = "grid grid-cols-1 gap-8 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-4";
function SkeletonGrid({ count = 8 }) {
	return /* @__PURE__ */ jsx("div", {
		className: GRID_CLASS,
		children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsxs("div", {
			className: "space-y-2",
			children: [
				/* @__PURE__ */ jsx(Skeleton, { className: "aspect-square w-full rounded-lg" }),
				/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" }),
				/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/2" }),
				/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-1/3" })
			]
		}, i))
	});
}
function ProductListing({ companyLogoUrl, renderImage, onSelectProduct, cartButton }) {
	const observerTarget = useRef(null);
	const { t } = useShopTranslation();
	const catalog = usePortalProductCatalog({ perPage: PAGE_SIZE });
	const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage, error, isFetched } = useInfiniteQuery({
		queryKey: catalog.queryKey,
		queryFn: ({ pageParam }) => catalog.fetchProducts(pageParam),
		getNextPageParam: catalog.getNextPageParam,
		initialPageParam: void 0
	});
	const handleIntersect = useCallback((entries) => {
		if (entries[0]?.isIntersecting && hasNextPage && !isFetchingNextPage) fetchNextPage();
	}, [
		hasNextPage,
		isFetchingNextPage,
		fetchNextPage
	]);
	useEffect(() => {
		const target = observerTarget.current;
		if (!target) return;
		const observer = new IntersectionObserver(handleIntersect, {
			threshold: .1,
			rootMargin: "200px"
		});
		observer.observe(target);
		return () => observer.disconnect();
	}, [handleIntersect]);
	const allProducts = data?.pages.flatMap((page) => page.products) ?? [];
	const sortOptions = useMemo(() => [
		{
			id: "title_asc",
			label: t("sort_title_asc")
		},
		{
			id: "title_desc",
			label: t("sort_title_desc")
		},
		{
			id: "price_asc",
			label: t("sort_price_asc")
		},
		{
			id: "price_desc",
			label: t("sort_price_desc")
		},
		{
			id: "created_at_desc",
			label: t("sort_recent")
		},
		{
			id: "created_at_asc",
			label: t("sort_oldest")
		}
	], [t]);
	return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
		className: "mx-auto px-2 md:px-10",
		children: /* @__PURE__ */ jsxs("div", {
			className: "flex items-center justify-end gap-2 py-4",
			children: [
				/* @__PURE__ */ jsx("div", {
					className: "w-full max-w-sm",
					children: /* @__PURE__ */ jsx(SearchSort, {
						searchValue: catalog.searchTerm,
						onSearchChange: catalog.setSearchTerm,
						placeholder: t("search_placeholder")
					})
				}),
				/* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
					asChild: true,
					children: /* @__PURE__ */ jsx(Button, {
						variant: "outline",
						size: "icon",
						className: "border-foreground/10 shadow-input h-9 w-9 shrink-0",
						children: /* @__PURE__ */ jsx(ArrowUpDown, { className: "h-3 w-3" })
					})
				}), /* @__PURE__ */ jsxs(DropdownMenuContent, {
					align: "end",
					className: "w-60",
					children: [
						/* @__PURE__ */ jsx(DropdownMenuLabel, { children: t("sort_by") }),
						/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
						/* @__PURE__ */ jsx(DropdownMenuRadioGroup, {
							value: catalog.currentSort,
							onValueChange: catalog.setCurrentSort,
							children: sortOptions.map((opt) => /* @__PURE__ */ jsx(DropdownMenuRadioItem, {
								value: opt.id,
								children: opt.label
							}, opt.id))
						})
					]
				})] }),
				cartButton && /* @__PURE__ */ jsx("div", {
					className: "flex shrink-0 items-center gap-3",
					children: cartButton
				})
			]
		})
	}), /* @__PURE__ */ jsx("div", {
		className: "mx-auto space-y-8 px-2 md:px-10 md:py-8",
		children: isLoading ? /* @__PURE__ */ jsx(SkeletonGrid, {}) : error ? /* @__PURE__ */ jsx("p", {
			className: "mx-auto my-6 rounded-lg bg-red-100 px-3 py-2 text-red-500",
			children: t("error_generic")
		}) : isFetched && allProducts.length === 0 ? /* @__PURE__ */ jsx("div", {
			className: "flex flex-col items-center justify-center py-8 text-center",
			children: /* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground text-sm",
				children: catalog.searchTerm ? t("no_search_results", { term: catalog.searchTerm }) : t("no_products")
			})
		}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
			/* @__PURE__ */ jsx("div", {
				className: GRID_CLASS,
				children: allProducts.map((product) => /* @__PURE__ */ jsx(ProductCard, {
					product: tagPortalProduct(product),
					companyLogoUrl,
					renderImage,
					onClick: () => onSelectProduct(String(product.id))
				}, product.id))
			}),
			/* @__PURE__ */ jsx("div", { ref: observerTarget }),
			isFetchingNextPage && /* @__PURE__ */ jsx(SkeletonGrid, { count: 4 })
		] })
	})] });
}
/**
* Build the variant options map by grouping option_values across non-master variants.
* Groups by option_id, collecting unique value entries.
*/
function buildOptionGroups(variants) {
	const groupMap = /* @__PURE__ */ new Map();
	for (const variant of variants) {
		if (variant.is_master) continue;
		for (const ov of variant.option_values ?? []) {
			if (ov.option_id == null || ov.id == null) continue;
			if (!groupMap.has(ov.option_id)) groupMap.set(ov.option_id, {
				name: ov.option_name ?? `Option ${ov.option_id}`,
				values: /* @__PURE__ */ new Map()
			});
			groupMap.get(ov.option_id).values.set(ov.id, ov.name ?? String(ov.id));
		}
	}
	return [...groupMap.entries()].map(([optionId, group]) => ({
		optionId,
		name: group.name,
		values: [...group.values.entries()].map(([id, name]) => ({
			id,
			name
		}))
	}));
}
/**
* Find the variant matching a set of selected option value IDs.
* selections is a map of optionId → selected value id.
*/
function findVariantBySelections(variants, selections) {
	const entries = Object.entries(selections).map(([k, v]) => [Number(k), v]);
	if (entries.length === 0) return void 0;
	return variants.find((v) => !v.is_master && entries.every(([optionId, valueId]) => v.option_values?.some((ov) => ov.option_id === optionId && ov.id === valueId)));
}
/**
* Map BFF flat subscription plans to the legacy ProductSubscriptionPlan shape
* expected by the PurchaseOptions component.
*/
function mapToLegacySubscriptionPlans(plans) {
	return plans.map((plan, idx) => ({
		id: plan.id,
		default: idx === 0,
		products_count: null,
		subscribers_count: null,
		active: true,
		subscription_plan: {
			id: plan.id ?? 0,
			name: plan.name ?? "",
			billing_interval: plan.billing_interval ?? 1,
			billing_interval_unit: plan.billing_interval_unit ?? "month",
			billing_frequency_in_words: plan.billing_frequency ?? `${plan.billing_interval} ${plan.billing_interval_unit}`,
			active: true,
			price_adjustment_amount: null,
			price_adjustment_type: null
		}
	}));
}
function formatPrice(price, currency) {
	if (!price) return null;
	const numericPrice = Number(price);
	if (Number.isNaN(numericPrice)) return `${currency ?? ""}${price}`;
	try {
		return new Intl.NumberFormat(void 0, {
			style: "currency",
			currency: currency || "USD"
		}).format(numericPrice);
	} catch {
		return `$${price}`;
	}
}
function ProductDetail({ productId, renderImage }) {
	const [quantity, setQuantity] = useState(1);
	const [selections, setSelections] = useState({});
	const [userSelectedSubscribe, setUserSelectedSubscribe] = useState(false);
	const [selectedSubscriptionPlan, setSelectedSubscriptionPlan] = useState(void 0);
	const { t } = useShopTranslation();
	const { product, isLoading, error, images } = usePortalProductDetail({ productId });
	const variants = useMemo(() => product?.variants ?? [], [product?.variants]);
	const subscriptionPlans = useMemo(() => product?.subscription_plans ?? [], [product?.subscription_plans]);
	const masterVariant = useMemo(() => variants.find((v) => v.is_master) ?? variants[0], [variants]);
	const optionGroups = useMemo(() => buildOptionGroups(variants), [variants]);
	const showVariantChoices = optionGroups.length === 0 && variants.length > 1;
	const [selectedVariantId, setSelectedVariantId] = useState(null);
	useEffect(() => {
		if (optionGroups.length === 0) return;
		const source = variants.find((v) => !v.is_master) ?? masterVariant;
		if (!source?.option_values?.length) return;
		const defaults = {};
		for (const ov of source.option_values) if (ov.option_id != null && ov.id != null) defaults[ov.option_id] = ov.id;
		setSelections(defaults);
	}, [
		optionGroups,
		variants,
		masterVariant
	]);
	useEffect(() => {
		if (!showVariantChoices) return;
		if (selectedVariantId != null) return;
		if (masterVariant?.id == null) return;
		setSelectedVariantId(masterVariant.id);
	}, [
		showVariantChoices,
		selectedVariantId,
		masterVariant?.id
	]);
	const selectedVariant = useMemo(() => {
		if (showVariantChoices) return variants.find((v) => v.id === selectedVariantId) ?? masterVariant;
		if (optionGroups.length === 0) return masterVariant;
		return findVariantBySelections(variants, selections) ?? masterVariant;
	}, [
		variants,
		optionGroups,
		selections,
		masterVariant,
		showVariantChoices,
		selectedVariantId
	]);
	const legacySubscriptionPlans = useMemo(() => mapToLegacySubscriptionPlans(subscriptionPlans), [subscriptionPlans]);
	const isSubscribe = selectedVariant?.subscription_only === true || userSelectedSubscribe;
	const showSubscribe = legacySubscriptionPlans.length > 0;
	const showBuyOnce = selectedVariant?.subscription_only !== true;
	useEffect(() => {
		if (selectedVariant?.subscription_only && legacySubscriptionPlans.length > 0) setUserSelectedSubscribe(true);
	}, [selectedVariant, legacySubscriptionPlans]);
	const galleryImages = useMemo(() => {
		const variantImages = selectedVariant?.images;
		if (variantImages && variantImages.length > 0) return variantImages.map((img, idx) => ({
			id: idx,
			image_url: img.url ?? "",
			image_path: null,
			position: idx
		}));
		return images.map((img, idx) => ({
			id: img.id ?? idx,
			image_url: img.url,
			image_path: null,
			position: idx
		}));
	}, [selectedVariant?.images, images]);
	const coverImage = galleryImages[0]?.image_url ?? null;
	const selectedPricing = selectedVariant?.subscription_pricing?.find((sp) => sp.plan_id === (selectedSubscriptionPlan?.subscription_plan.id ?? legacySubscriptionPlans[0]?.subscription_plan.id));
	const wholesalePrice = selectedVariant?.wholesale_price ? Number(selectedVariant.wholesale_price) : void 0;
	const wholesaleSubscriptionPrice = selectedPricing?.wholesale_price ? Number(selectedPricing.wholesale_price) : void 0;
	const currency = selectedVariant?.currency ?? product?.currency;
	const displayPrice = formatPrice(selectedVariant?.price ?? product?.price, currency);
	const displayWholesalePrice = formatPrice(selectedVariant?.wholesale_price ?? selectedVariant?.price ?? product?.price, currency);
	const displayWholesaleSubscriptionPrice = formatPrice(selectedPricing?.wholesale_price ?? selectedPricing?.price ?? selectedVariant?.wholesale_price ?? void 0, currency);
	const resolvedPlanId = selectedSubscriptionPlan?.subscription_plan.id ?? legacySubscriptionPlans.find((p) => p.default)?.subscription_plan.id ?? legacySubscriptionPlans[0]?.subscription_plan.id;
	const cartVariantId = String(selectedVariant?.id ?? product?.id ?? "");
	if (isLoading) return /* @__PURE__ */ jsx("div", {
		className: "mx-auto max-w-7xl py-8 pr-4 pl-0 md:pr-6 lg:pr-8 lg:pl-0",
		children: /* @__PURE__ */ jsxs("div", {
			className: "grid grid-cols-1 gap-5 lg:grid-cols-2",
			children: [/* @__PURE__ */ jsx(Skeleton, { className: "aspect-square w-full rounded-lg" }), /* @__PURE__ */ jsxs("div", {
				className: "space-y-4 pl-2 lg:pl-20",
				children: [
					/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-3/4" }),
					/* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-1/4" }),
					/* @__PURE__ */ jsx(Skeleton, { className: "h-20 w-full" }),
					/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-1/2" }),
					/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full" })
				]
			})]
		})
	});
	if (error) return /* @__PURE__ */ jsx("div", {
		className: "flex min-h-[400px] items-center justify-center",
		children: /* @__PURE__ */ jsxs("div", {
			className: "text-center",
			children: [/* @__PURE__ */ jsx("h3", {
				className: "text-foreground mb-2 text-lg font-medium",
				children: t("error_loading")
			}), /* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground",
				children: t("error_generic")
			})]
		})
	});
	if (!product) return /* @__PURE__ */ jsx("div", {
		className: "flex min-h-[400px] items-center justify-center",
		children: /* @__PURE__ */ jsxs("div", {
			className: "text-center",
			children: [/* @__PURE__ */ jsx("h3", {
				className: "text-foreground mb-2 text-lg font-medium",
				children: t("product_not_found")
			}), /* @__PURE__ */ jsx("p", {
				className: "text-muted-foreground",
				children: t("product_not_found_description")
			})]
		})
	});
	const title = product.name || t("product_fallback_name");
	const isBundle = product.bundle === true;
	const bundleUrl = isBundle && product.canonical_url ? product.canonical_url : null;
	return /* @__PURE__ */ jsx("div", {
		className: "pb-5 md:pl-8",
		children: /* @__PURE__ */ jsx("div", {
			className: "mx-auto max-w-7xl px-4 py-8 md:pr-6 md:pl-0 lg:pr-8 lg:pl-0",
			children: /* @__PURE__ */ jsxs("div", {
				className: "grid grid-cols-1 gap-5 lg:grid-cols-2",
				children: [/* @__PURE__ */ jsx(ImageGallery, {
					images: galleryImages,
					fallbackImageUrl: coverImage ?? "https://assets.fluid.app/fluid-admin/images/we-commerce/we-commerce.png",
					productTitle: title,
					renderImage
				}), /* @__PURE__ */ jsxs("div", {
					className: "max-w-lg pl-2 lg:pl-20",
					children: [
						/* @__PURE__ */ jsx("h1", {
							className: "text-foreground text-3xl font-bold",
							children: title
						}),
						!isBundle && /* @__PURE__ */ jsxs("div", {
							className: "mb-2 flex items-center gap-2",
							children: [/* @__PURE__ */ jsx("span", {
								className: "text-foreground text-sm",
								children: isSubscribe ? displayWholesaleSubscriptionPrice : displayWholesalePrice
							}), (isSubscribe && displayWholesaleSubscriptionPrice !== displayWholesalePrice || !isSubscribe && displayWholesalePrice !== displayPrice) && /* @__PURE__ */ jsx("span", {
								className: "text-muted-foreground text-sm line-through",
								children: isSubscribe ? displayWholesalePrice : displayPrice
							})]
						}),
						/* @__PURE__ */ jsxs("div", {
							className: "pt-2",
							children: [/* @__PURE__ */ jsx("h3", {
								className: "text-foreground mb-1 text-sm font-medium",
								children: t("product_description")
							}), /* @__PURE__ */ jsx("div", {
								className: "text-foreground mb-3 text-[12px]",
								dangerouslySetInnerHTML: { __html: sanitizeHtml(product.description ?? "") }
							})]
						}),
						product.wholesale_price != null && /* @__PURE__ */ jsxs("div", {
							className: "text-muted-foreground mb-3 text-sm",
							children: [
								"CV ",
								selectedVariant?.cv ?? "-",
								" | QV",
								" ",
								selectedVariant?.qv ?? "-"
							]
						}),
						isBundle ? /* @__PURE__ */ jsxs("div", {
							className: "pt-4",
							children: [/* @__PURE__ */ jsx(Button, {
								variant: "default",
								className: "w-full gap-2 py-2 text-base font-medium",
								disabled: !bundleUrl,
								onClick: () => {
									if (bundleUrl) window.open(bundleUrl, "_blank", "noopener,noreferrer");
								},
								children: t("purchase_bundle")
							}), !bundleUrl && /* @__PURE__ */ jsx("p", {
								className: "text-muted-foreground mt-2 text-center text-xs",
								children: t("bundle_unavailable")
							})]
						}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
							/* @__PURE__ */ jsx(PurchaseOptions, {
								showBuyOnce,
								showSubscribe,
								isSubscribe,
								userSelectedSubscribe,
								onSubscribeChange: setUserSelectedSubscribe,
								wholesalePrice,
								wholesaleSubscriptionPrice,
								product_subscription_plans: legacySubscriptionPlans,
								selectedSubscriptionPlan,
								onSubscriptionPlanChange: setSelectedSubscriptionPlan
							}),
							optionGroups.length > 0 && /* @__PURE__ */ jsx("div", {
								className: "mb-4 pt-4",
								children: optionGroups.map((group) => /* @__PURE__ */ jsxs("div", {
									className: "mb-3 flex items-center",
									children: [/* @__PURE__ */ jsx("h3", {
										className: "text-md text-foreground w-24 font-bold",
										children: group.name.charAt(0).toUpperCase() + group.name.slice(1)
									}), /* @__PURE__ */ jsxs(Select, {
										value: String(selections[group.optionId] ?? ""),
										onValueChange: (value) => setSelections((prev) => ({
											...prev,
											[group.optionId]: Number(value)
										})),
										children: [/* @__PURE__ */ jsx(SelectTrigger, {
											className: "w-48 max-w-full",
											children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("select_option", { name: group.name }) })
										}), /* @__PURE__ */ jsx(SelectContent, {
											position: "popper",
											className: "max-h-60",
											children: group.values.map((v) => /* @__PURE__ */ jsx(SelectItem, {
												value: String(v.id),
												children: v.name
											}, v.id))
										})]
									})]
								}, group.optionId))
							}),
							showVariantChoices && /* @__PURE__ */ jsx("div", {
								className: "mb-4 pt-4",
								children: /* @__PURE__ */ jsxs("div", {
									className: "mb-3 flex items-center",
									children: [/* @__PURE__ */ jsx("h3", {
										className: "text-md text-foreground w-24 font-bold",
										children: t("variant_label")
									}), /* @__PURE__ */ jsxs(Select, {
										value: selectedVariantId != null ? String(selectedVariantId) : "",
										onValueChange: (value) => setSelectedVariantId(Number(value)),
										children: [/* @__PURE__ */ jsx(SelectTrigger, {
											className: "w-48 max-w-full",
											children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("select_variant") })
										}), /* @__PURE__ */ jsx(SelectContent, {
											position: "popper",
											className: "max-h-60",
											children: variants.map((v, idx) => v.id == null ? null : /* @__PURE__ */ jsx(SelectItem, {
												value: String(v.id),
												children: v.title || t("variant_fallback_name", { index: String(idx + 1) })
											}, v.id))
										})]
									})]
								})
							}),
							selectedVariant?.subscription_only && !selectedVariant?.allow_subscription && /* @__PURE__ */ jsx("div", {
								className: "text-muted-foreground text-sm",
								children: t("product_unavailable")
							}),
							/* @__PURE__ */ jsx("div", { className: "mt-4 mb-3" }),
							/* @__PURE__ */ jsxs("div", {
								className: "flex items-center gap-3 pb-3",
								children: [/* @__PURE__ */ jsx(QuantitySelector, {
									quantity,
									setQuantity
								}), /* @__PURE__ */ jsxs(Button, {
									variant: "default",
									className: "flex-1 gap-2 py-2 text-base font-medium",
									disabled: selectedVariant?.subscription_only === true && !selectedVariant?.allow_subscription,
									"data-fluid-add-to-cart": cartVariantId,
									"data-fluid-quantity": quantity,
									"data-fluid-subscribe": isSubscribe,
									"data-fluid-subscription-plan-id": isSubscribe ? String(resolvedPlanId ?? "") : "",
									"data-fluid-open-cart-after-add": "false",
									children: [/* @__PURE__ */ jsx(ShoppingCart, { className: "h-4 w-4" }), isSubscribe ? t("subscribe") : t("add_to_cart")]
								})]
							})
						] })
					]
				})]
			})
		})
	});
}
function ShopApp({ companyLogoUrl, renderImage, productId: controlledProductId, onSelectProduct: onSelectProductProp, onBack: _onBack, cartButton }) {
	const [internalProductId, setInternalProductId] = useState(null);
	const activeProductId = controlledProductId !== void 0 ? controlledProductId : internalProductId;
	const handleSelectProduct = onSelectProductProp ?? setInternalProductId;
	if (activeProductId) return /* @__PURE__ */ jsx(ProductDetail, {
		productId: activeProductId,
		renderImage
	});
	return /* @__PURE__ */ jsx(ProductListing, {
		companyLogoUrl,
		renderImage,
		onSelectProduct: handleSelectProduct,
		cartButton
	});
}
//#endregion
//#region ../../cart/ui/src/components/cart-script.tsx
const SCRIPT_ID = "fluid-cdn-script";
const LEAD_CAPTURE_ID = "fluid-lead-capture-suppress";
const DEFAULT_SCRIPT_SRC = "https://assets.fluid.app/scripts/fluid-sdk/latest/web-widgets/index.js";
function CartScript({ subdomain, authJwt, bffMode, scriptSrc, apiBaseUrl, debug }) {
	const authJwtRef = useRef(authJwt);
	authJwtRef.current = authJwt;
	useEffect(() => {
		if (!subdomain) return;
		if (document.getElementById(SCRIPT_ID)) return;
		const script = document.createElement("script");
		script.id = SCRIPT_ID;
		script.src = scriptSrc ?? DEFAULT_SCRIPT_SRC;
		script.type = "module";
		script.crossOrigin = "anonymous";
		script.dataset.fluidShop = subdomain;
		if (bffMode) script.dataset.bffMode = "true";
		else if (authJwtRef.current) script.dataset.authJwt = authJwtRef.current;
		if (apiBaseUrl) script.dataset.fluidApiBaseUrl = apiBaseUrl;
		if (debug) script.dataset.debug = "true";
		document.head.appendChild(script);
		const leadCapture = document.createElement("fluid-lead-capture-widget");
		leadCapture.id = LEAD_CAPTURE_ID;
		leadCapture.setAttribute("hide-widget", "true");
		document.body.appendChild(leadCapture);
		return () => {
			const existing = document.getElementById(SCRIPT_ID);
			if (existing) existing.remove();
			const existingLeadCapture = document.getElementById(LEAD_CAPTURE_ID);
			if (existingLeadCapture) existingLeadCapture.remove();
		};
	}, [
		subdomain,
		bffMode,
		scriptSrc,
		apiBaseUrl,
		debug
	]);
	return null;
}
//#endregion
//#region ../../cart/ui/src/components/cart-widget.tsx
function CartWidget({ theme }) {
	const [mounted, setMounted] = useState(false);
	const widgetRef = useRef(null);
	useEffect(() => {
		setMounted(true);
	}, []);
	useEffect(() => {
		if (!mounted) return;
		const el = widgetRef.current;
		if (!el) return;
		if (theme) el.setAttribute("theme", JSON.stringify(theme));
		else el.removeAttribute("theme");
	}, [theme, mounted]);
	const widget = React.createElement("fluid-cart-widget", {
		ref: (el) => {
			widgetRef.current = el;
		},
		"data-fluid-widget": "true",
		"hide-widget": "true",
		"is-primary": "true"
	});
	if (mounted) return createPortal(widget, document.body);
	return null;
}
//#endregion
//#region ../../cart/ui/src/components/cart-button.tsx
const MAX_SDK_POLL_ATTEMPTS = 50;
function CartButton({ onCheckout }) {
	const { t } = useShopTranslation();
	const [initialCount, setInitialCount] = useState(0);
	const navigateToCheckout = useCallback(() => {
		if (!window.FluidCommerceSDK) {
			console.error("FluidCommerceSDK not available");
			return;
		}
		try {
			const checkoutUrl = window.FluidCommerceSDK.getCheckoutUrl();
			if (!checkoutUrl) {
				console.error("No checkout URL available");
				return;
			}
			onCheckout?.(checkoutUrl);
		} catch (error) {
			console.error("Error getting checkout URL:", error);
		}
	}, [onCheckout]);
	useEffect(() => {
		let timeoutId = null;
		let attempts = 0;
		let cancelled = false;
		const setupSDK = () => {
			if (cancelled) return;
			if (window.FluidCommerceSDK) {
				if (onCheckout) window.FluidCommerceSDK.setOnCheckout(navigateToCheckout);
				const count = window.FairShareSDK?.getCartItemCount?.();
				if (count != null) setInitialCount(count);
			} else if (attempts < MAX_SDK_POLL_ATTEMPTS) {
				attempts++;
				timeoutId = setTimeout(setupSDK, 100);
			}
		};
		setupSDK();
		return () => {
			cancelled = true;
			if (timeoutId) clearTimeout(timeoutId);
		};
	}, [navigateToCheckout, onCheckout]);
	return /* @__PURE__ */ jsxs(Button, {
		className: "bg-primary text-primary-foreground hover:bg-primary/70 relative flex h-8 items-center gap-2 rounded-sm px-3 py-1 text-xs",
		onClick: () => {
			window.fluidCart?.open();
		},
		children: [/* @__PURE__ */ jsxs("div", {
			className: "relative",
			children: [/* @__PURE__ */ jsx(ShoppingCart, { className: "size-4" }), /* @__PURE__ */ jsx("span", {
				id: "fluid-cart-count",
				className: "bg-primary-foreground text-primary absolute -top-1 -right-2 flex h-3.5 w-3.5 items-center justify-center rounded-full text-[8px] font-bold",
				children: initialCount
			})]
		}), /* @__PURE__ */ jsx("span", { children: t("cart") })]
	});
}
//#endregion
//#region ../../cart/ui/src/components/shop-container.tsx
function ShopContainer({ children, className = "", cartScript, cartWidget }) {
	const containerRef = useRef(null);
	const [portalContainer, setPortalContainer] = useState(null);
	useEffect(() => {
		const currentContainer = containerRef.current;
		if (!currentContainer) return;
		const reactContentWrapper = document.createElement("div");
		reactContentWrapper.id = "react-content-wrapper";
		reactContentWrapper.style.cssText = `
      position: relative;
    `;
		reactContentWrapper.className = "min-h-full";
		currentContainer.appendChild(reactContentWrapper);
		setPortalContainer(reactContentWrapper);
		return () => {
			if (currentContainer && reactContentWrapper) try {
				currentContainer.removeChild(reactContentWrapper);
			} catch (e) {
				console.warn("Failed to cleanup isolated container:", e);
			}
			setPortalContainer(null);
		};
	}, []);
	return /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("div", {
		ref: containerRef,
		className: `isolated-shop-wrapper ${className} h-full`,
		children: portalContainer && createPortal(/* @__PURE__ */ jsxs(Fragment$1, { children: [
			cartScript,
			cartWidget,
			children
		] }), portalContainer)
	}) });
}
//#endregion
//#region ../../shop/core/src/translation-adapter.ts
const shopDomain = createDomainTranslations({
	fallback: {
		breadcrumb: "Shop",
		product_fallback_name: "Product",
		search_placeholder: "Search products...",
		sort_by: "Sort By",
		sort_title_asc: "Title (A-Z)",
		sort_title_desc: "Title (Z-A)",
		sort_price_asc: "Price (Low to High)",
		sort_price_desc: "Price (High to Low)",
		sort_recent: "Recently Updated",
		sort_oldest: "Oldest Updated",
		no_products: "There are no products available at the moment.",
		no_search_results: "No products match \"{{term}}\". Try a different search term.",
		error_loading: "Unable to load product",
		error_generic: "Something went wrong. Please try again later.",
		product_not_found: "Product not found",
		product_not_found_description: "The product you're looking for doesn't exist.",
		product_description: "Product Description",
		no_title: "No title available",
		add_to_cart: "Add to Cart",
		subscribe: "Subscribe",
		subscribe_and_save: "Subscribe & Save {{percentage}}%",
		one_time_purchase: "One-Time Purchase",
		delivery_frequency: "Delivery Frequency:",
		select_delivery_schedule: "Select delivery schedule",
		purchase_bundle: "Purchase Bundle",
		bundle_unavailable: "Bundle configuration is unavailable. Please contact support.",
		product_unavailable: "This product is unavailable for purchase.",
		ratings_and_reviews: "Ratings and reviews",
		ratings_count: "{{count}} ratings",
		select_option: "Select {{name}}",
		variant_label: "Variant",
		select_variant: "Select variant",
		variant_fallback_name: "Variant {{index}}",
		previous_image: "Previous image",
		next_image: "Next image",
		go_to_image: "Go to image {{index}}",
		cart: "Cart"
	},
	loaders: {
		de: () => import("./de-C-iisOSn.mjs").then((m) => m.default),
		el: () => import("./el-2oK8DdRM.mjs").then((m) => m.default),
		es: () => import("./es-NM7DkE43.mjs").then((m) => m.default),
		fr: () => import("./fr-CicaAFb4.mjs").then((m) => m.default),
		he: () => import("./he-q50EBZeQ.mjs").then((m) => m.default),
		hu: () => import("./hu-kI9ZoFC_.mjs").then((m) => m.default),
		id: () => import("./id-CLGnq4-C.mjs").then((m) => m.default),
		it: () => import("./it-Bq69E8lm.mjs").then((m) => m.default),
		ja: () => import("./ja-C4ZsdEZL.mjs").then((m) => m.default),
		ko: () => import("./ko-pWAg9POm.mjs").then((m) => m.default),
		nl: () => import("./nl-B-k9NK4o.mjs").then((m) => m.default),
		pl: () => import("./pl-CUvGUVP7.mjs").then((m) => m.default),
		pt: () => import("./pt-DIijtQJR.mjs").then((m) => m.default),
		ro: () => import("./ro-D7Vl_vDt.mjs").then((m) => m.default),
		ru: () => import("./ru-BJjc8xd2.mjs").then((m) => m.default),
		th: () => import("./th-BpzmPZDR.mjs").then((m) => m.default),
		tl: () => import("./tl-SRdv7-WT.mjs").then((m) => m.default),
		tr: () => import("./tr-w7EX3DsH.mjs").then((m) => m.default),
		zh_CN: () => import("./zh_CN-Dh9MBKZK.mjs").then((m) => m.default),
		zh_TW: () => import("./zh_TW-AJ0XWFCB.mjs").then((m) => m.default)
	}
});
function createShopTranslationAdapter(locale, dict) {
	return createStaticDictAdapter(locale, dict);
}
//#endregion
//#region src/providers/ShopTranslationBridge.tsx
function ShopTranslationBridge({ children }) {
	const { locale } = useActiveLocale();
	const dict = useDomainDict(shopDomain, locale);
	return /* @__PURE__ */ jsx(ShopTranslationProvider, {
		value: useMemo(() => createShopTranslationAdapter(locale, dict), [locale, dict]),
		children
	});
}
//#endregion
//#region src/screens/ShopScreen.tsx
function ShopScreen(props) {
	return /* @__PURE__ */ jsx(ShopTranslationBridge, { children: /* @__PURE__ */ jsx(ShopScreenContent, { ...props }) });
}
function ShopScreenContent({ background, textColor, accentColor, padding, borderRadius, ...divProps }) {
	const { config } = useFluidContext();
	const { t } = useShopTranslation();
	const { data: store } = useStore();
	const { currentSlug, navigate } = useAppNavigation();
	const countryCode = config.countryIso ?? "US";
	const subdomain = store?.subdomain;
	const productId = currentSlug.split("/")[1] ?? null;
	useEffect(() => {
		if (!countryCode) return;
		const sdk = () => window.FairShareSDK;
		let done = false;
		let inFlight = false;
		const tryUpdate = async () => {
			const fairShareSdk = sdk();
			if (done || inFlight || !fairShareSdk) return;
			inFlight = true;
			try {
				await fairShareSdk.updateLocaleSettings({ country: countryCode });
				done = true;
				clearInterval(id);
			} catch {} finally {
				inFlight = false;
			}
		};
		let attempts = 0;
		const id = setInterval(() => {
			if (attempts >= 50) {
				console.warn("[FairShare] updateLocaleSettings: gave up after 50 attempts — session never became ready", { country: countryCode });
				clearInterval(id);
				return;
			}
			attempts++;
			tryUpdate();
		}, 100);
		return () => {
			done = true;
			clearInterval(id);
		};
	}, [countryCode]);
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [
		!productId && /* @__PURE__ */ jsx(ScreenHeaderBreadcrumbs, { children: /* @__PURE__ */ jsx(Breadcrumb, { children: /* @__PURE__ */ jsx(BreadcrumbList, {
			className: "text-lg",
			children: /* @__PURE__ */ jsx(BreadcrumbItem, { children: /* @__PURE__ */ jsx(BreadcrumbPage, {
				className: "font-semibold",
				children: t("breadcrumb")
			}) })
		}) }) }),
		/* @__PURE__ */ jsx(ScreenHeaderActions, { children: /* @__PURE__ */ jsx("div", {
			className: "flex items-center gap-4",
			children: /* @__PURE__ */ jsx(CartButton, {})
		}) }),
		/* @__PURE__ */ jsx("div", {
			...divProps,
			className: divProps.className ?? "",
			children: /* @__PURE__ */ jsx(ShopContainer, {
				cartScript: subdomain ? /* @__PURE__ */ jsx(CartScript, {
					subdomain,
					bffMode: true,
					scriptSrc: import.meta.env.DEV ? String(import.meta.env.VITE_FAIRSHARE_SDK_URL || "http://localhost:4444/index.js") : void 0,
					apiBaseUrl: import.meta.env.DEV ? String(import.meta.env.VITE_FAIRSHARE_API_BASE_URL || "http://api.fluid.localhost:3000") : void 0,
					debug: import.meta.env.DEV
				}) : null,
				cartWidget: /* @__PURE__ */ jsx(CartWidget, {}),
				children: /* @__PURE__ */ jsxs(PortalProductsApiProvider, { children: [productId && /* @__PURE__ */ jsx(ProductBreadcrumb, { productId }), /* @__PURE__ */ jsx(ShopApp, {
					companyLogoUrl: store?.logo_url ?? void 0,
					productId,
					onSelectProduct: (id) => navigate(`shop/${id}`),
					onBack: () => navigate("shop")
				})] })
			})
		})
	] });
}
const shopScreenPropertySchema = {
	widgetType: "ShopScreen",
	displayName: "Shop Screen",
	tabsConfig: [{
		id: "styling",
		label: "Styling"
	}],
	fields: []
};
/**
* Renders inside PortalProductsCoreProvider to set breadcrumbs with the
* product name: "Shop > {product name}". Overrides the parent's "Shop"
* breadcrumb once product data loads.
*/
function ProductBreadcrumb({ productId }) {
	const { navigate } = useAppNavigation();
	const { t } = useShopTranslation();
	const { product } = usePortalProductDetail({ productId });
	const productName = product?.name ?? t("product_fallback_name");
	return /* @__PURE__ */ jsx(ScreenHeaderBreadcrumbs, { children: /* @__PURE__ */ jsx(Breadcrumb, { children: /* @__PURE__ */ jsxs(BreadcrumbList, {
		className: "text-lg",
		children: [
			/* @__PURE__ */ jsx(BreadcrumbItem, { children: /* @__PURE__ */ jsx(BreadcrumbLink, {
				onClick: () => navigate("shop"),
				className: "cursor-pointer font-semibold",
				children: t("breadcrumb")
			}) }),
			/* @__PURE__ */ jsx(BreadcrumbSeparator, {}),
			/* @__PURE__ */ jsx(BreadcrumbItem, { children: /* @__PURE__ */ jsx(BreadcrumbPage, {
				className: "font-semibold",
				children: productName
			}) })
		]
	}) }) });
}
//#endregion
export { shopScreenPropertySchema as n, ShopScreen as t };

//# sourceMappingURL=ShopScreen-BmP7vkuc.mjs.map