require("./chunk-9hOWP6kD.cjs");
const require_portal_tenant = require("./portal_tenant-CNmiAf_A.cjs");
const require_PortalTenantClientProvider = require("./PortalTenantClientProvider-bZL5OGQ7.cjs");
const require_src = require("./src-BFJg9F_s.cjs");
const require_ScreenHeaderContext = require("./ScreenHeaderContext-JDIUM84f.cjs");
const require_AppNavigationContext = require("./AppNavigationContext-CDowN9gd.cjs");
const require_order_status_badge = require("./order-status-badge-CIhvEZ4G.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/adapters/orders-api-adapter.ts
/**
* Requires a BFF money field to be present. The BFF contract guarantees
* subtotal/discount/shipping/tax on every Order, so a missing value signals
* a broken contract. Mirrors the fail-loud pattern in subscriptions-api-adapter
* (see the `BFF returned a successful response but subscription data was
* missing` throw) and avoids silently rendering $0.00 in the UI, which a
* customer cannot distinguish from a legitimately free line.
*/
function requireMoneyField(value, field) {
	if (value == null) throw new Error(`BFF returned an order without required money field "${field}"`);
	return value;
}
function mapAddress(raw) {
	if (!raw) return null;
	return {
		id: raw.id ?? 0,
		name: raw.name ?? null,
		address1: raw.address1 ?? null,
		address2: raw.address2 ?? null,
		city: raw.city ?? null,
		state: raw.state ?? null,
		postal_code: raw.postal_code ?? null,
		country_code: raw.country_code ?? null
	};
}
function mapPaymentMethod(raw) {
	if (!raw) return null;
	return {
		id: raw.id ?? 0,
		source: raw.source ?? "",
		payment_type: raw.payment_type ?? "",
		card_type: raw.card_type ?? null,
		last4: raw.last4 ?? null
	};
}
function mapToPortalTenantOrder(raw) {
	const subtotal = requireMoneyField(raw.subtotal, "subtotal");
	const discount = requireMoneyField(raw.discount, "discount");
	const shipping = requireMoneyField(raw.shipping, "shipping");
	const tax = requireMoneyField(raw.tax, "tax");
	const total = requireMoneyField(raw.total, "total");
	return {
		id: raw.id ?? 0,
		token: raw.token ?? "",
		status: raw.status ?? "pending",
		subtotal,
		subtotal_in_currency: raw.subtotal_in_currency ?? subtotal,
		discount,
		discount_in_currency: raw.discount_in_currency ?? discount,
		shipping,
		shipping_in_currency: raw.shipping_in_currency ?? shipping,
		tax,
		tax_in_currency: raw.tax_in_currency ?? tax,
		total,
		total_in_currency: raw.total_in_currency ?? total,
		currency: raw.currency ?? "",
		line_items: (raw.line_items ?? []).map((li) => {
			const liPrice = li.price ?? "0";
			const liTotal = li.total ?? "0";
			return {
				id: li.id ?? 0,
				product_id: li.product_id ?? 0,
				product_name: li.product_name ?? "",
				variant_id: li.variant_id ?? null,
				variant_name: li.variant_name ?? null,
				sku: li.sku ?? null,
				image_url: li.image_url ?? null,
				quantity: li.quantity ?? 0,
				price: liPrice,
				price_in_currency: li.price_in_currency ?? liPrice,
				total: liTotal,
				total_in_currency: li.total_in_currency ?? liTotal,
				source_subscription: li.source_subscription?.subscription_token ? { subscription_token: li.source_subscription.subscription_token } : null
			};
		}),
		customer_name: raw.customer_name ?? null,
		customer_email: raw.customer_email ?? null,
		address: mapAddress(raw.address),
		payment_method: mapPaymentMethod(raw.payment_method),
		subscription_order: raw.subscription_order ?? false,
		subscription_token: raw.subscription_token ?? null,
		total_points_credited: typeof raw.total_points_credited === "number" ? raw.total_points_credited : void 0,
		customer_points_balance: typeof raw.customer_points_balance === "number" ? raw.customer_points_balance : void 0,
		created_at: raw.created_at ?? "",
		updated_at: raw.updated_at ?? ""
	};
}
function mapToListOrder(raw) {
	const firstLineItem = raw.line_items?.[0];
	return {
		id: raw.id ?? 0,
		external_id: null,
		order_number: "",
		email: raw.customer_email ?? null,
		first_name: raw.customer_name?.split(" ")[0] ?? null,
		last_name: raw.customer_name?.split(" ").slice(1).join(" ") || null,
		amount: raw.total ?? "0",
		status: raw.status ?? "pending",
		order_status: raw.status ?? "pending",
		fulfillment_status: "unfulfilled",
		financial_status: "pending",
		currency_code: raw.currency ?? "",
		note: null,
		token: raw.token ?? "",
		warehouse_id: null,
		source: "web",
		created_at: raw.created_at ?? "",
		updated_at: raw.updated_at ?? "",
		total_display_amount: raw.total_in_currency ?? raw.total ?? "0",
		total_cv: 0,
		total_qv: 0,
		currency_symbol: raw.currency ?? "",
		items_count: raw.line_items?.length ?? 0,
		quantity_count: raw.line_items?.reduce((sum, li) => sum + (li.quantity ?? 0), 0) ?? 0,
		order_on_behalf_of: false,
		sale_date: null,
		customer: null,
		first_item: firstLineItem ? {
			title: firstLineItem.product_name ?? "",
			image_url: firstLineItem.image_url ?? ""
		} : null,
		subscription: raw.subscription_order && raw.subscription_token ? {
			subscription_token: raw.subscription_token,
			status: "active"
		} : raw.subscription_order ? {
			subscription_token: "",
			status: "active"
		} : null
	};
}
function createPortalOrdersAdapter(client) {
	return {
		fetchOrderById: async (id) => {
			const response = await require_portal_tenant.orders_show(client, id);
			return {
				order: mapToPortalTenantOrder(response.order ?? {}),
				meta: {
					request_id: response.meta?.request_id ?? "",
					timestamp: response.meta?.timestamp ?? ""
				}
			};
		},
		fetchCustomerOrders: async (params) => {
			const response = await require_portal_tenant.orders_list(client, {
				"page[cursor]": params.cursor,
				"page[limit]": params.limit,
				status: params.status,
				q: params.search
			});
			return {
				orders: (response.orders ?? []).map(mapToListOrder),
				meta: {
					request_id: response.meta?.request_id ?? "",
					timestamp: response.meta?.timestamp ?? "",
					pagination: {
						cursor: response.meta?.pagination?.cursor ?? null,
						limit: response.meta?.pagination?.limit ?? 25,
						next_cursor: response.meta?.pagination?.next_cursor ?? null,
						prev_cursor: response.meta?.pagination?.prev_cursor ?? null
					}
				}
			};
		}
	};
}
//#endregion
//#region src/orders/PortalOrdersApiProvider.tsx
function PortalOrdersApiProvider({ children }) {
	const client = require_PortalTenantClientProvider.usePortalTenantClient();
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_order_status_badge.OrdersCoreProvider, {
		api: (0, react.useMemo)(() => createPortalOrdersAdapter(client), [client]),
		children
	});
}
//#endregion
//#region ../../orders/ui/src/screens/OrdersListScreen.tsx
function OrdersListScreen$1({ customerId, onOrderClick, onSubscriptionClick, t, isLoadingCustomer }) {
	require_ScreenHeaderContext.useScreenHeaderBreadcrumbs((0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Breadcrumb, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbList, {
		className: "text-lg",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbItem, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbPage, {
			className: "font-semibold",
			children: "Orders"
		}) })
	}) }), []));
	if (isLoadingCustomer) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "space-y-3",
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-10 animate-pulse rounded" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-64 animate-pulse rounded" })]
		})
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_order_status_badge.OrdersList, {
			customerId,
			onOrderClick,
			onSubscriptionClick,
			t
		})
	});
}
//#endregion
//#region src/screens/OrdersListScreen.tsx
const translations = {
	search_orders: "Search orders...",
	order_number: "Order #",
	date: "Date",
	status: "Status",
	product: "Product",
	no_orders_found: "No orders found",
	no_matching_orders: "No matching orders",
	no_image_available: "No image available",
	this_product_no_longer_exists: "This product no longer exists",
	subscription: "Subscription",
	view_subscription: "View Subscription",
	total: "Total",
	results: "results",
	previous: "Previous",
	next: "Next",
	pagination: "Pagination"
};
const BFF_SCOPED_CUSTOMER_ID = 1;
function OrdersListScreen() {
	const { navigate } = require_AppNavigationContext.useAppNavigation();
	const handleOrderClick = (order) => {
		navigate(`orders/${order.token}`);
	};
	const handleSubscriptionClick = (subscriptionToken) => {
		navigate(`subscriptions/${subscriptionToken}`);
	};
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OrdersListScreen$1, {
		customerId: BFF_SCOPED_CUSTOMER_ID,
		onOrderClick: handleOrderClick,
		onSubscriptionClick: handleSubscriptionClick,
		t: (key) => translations[key] ?? key
	});
}
//#endregion
//#region ../../orders/ui/src/components/portal-order-detail.tsx
const PAYMENT_TYPE_LABELS = {
	apple_pay: "Apple Pay",
	google_pay: "Google Pay",
	paypal: "PayPal",
	braintree_paypal: "PayPal",
	affirm: "Affirm",
	klarna: "Klarna",
	bread: "Bread",
	iap: "In-App Purchase",
	citcon: "Citcon",
	ppro: "PPRO",
	dlocal: "dLocal",
	droplet: "Droplet"
};
function DetailSkeleton() {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "flex flex-col lg:grid lg:grid-cols-8",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			className: "bg-muted flex flex-col items-center px-8 lg:col-span-4",
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
				className: "w-full max-w-lg py-6",
				children: [
					/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "mb-4 h-6 w-48" }),
					/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
						className: "space-y-4",
						children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "flex items-center space-x-4",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-24 w-24 rounded" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
								className: "flex-1 space-y-2",
								children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-3/4" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-1/2" })]
							})]
						})
					}),
					/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
						className: "mt-6 space-y-2",
						children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-full" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-5 w-full" })]
					})
				]
			})
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			className: "bg-background px-8 pt-4 lg:col-span-4",
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
				className: "mx-auto max-w-lg lg:mx-0 lg:mr-auto",
				children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "mb-4 h-10 w-full rounded" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
					className: "mt-6 space-y-4",
					children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-5 w-40" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-16 w-full rounded" })]
				})]
			})
		})]
	});
}
function SummaryRow({ label, value }) {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "flex items-center justify-between text-sm",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
			className: "text-muted-foreground",
			children: label
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
			className: "text-foreground",
			children: value
		})]
	});
}
/**
* Display a positive money string as a deduction (prefixed with "-").
* Idempotent: if the value already starts with "-" we leave it alone, so
* a future BFF that returns signed discounts can't produce "--$10.00".
*/
function asNegative(value) {
	return value.startsWith("-") ? value : `-${value}`;
}
/**
* Pick the formatted currency string when present, falling back to the raw
* decimal so the row still renders something for orders where the BFF left
* the field nil (e.g. a checkout where shipping was never set).
*/
function moneyDisplay(formatted, fallback) {
	return formatted ?? fallback;
}
function formatAddressLines(address) {
	const lines = [];
	if (address.name) lines.push(address.name);
	if (address.address1) lines.push(address.address1);
	if (address.address2) lines.push(address.address2);
	const cityLine = [
		address.city,
		address.state,
		address.postal_code
	].filter(Boolean).join(", ");
	if (cityLine) lines.push(cityLine);
	if (address.country_code) lines.push(address.country_code);
	return lines;
}
function AddressSection({ address }) {
	const lines = formatAddressLines(address);
	if (lines.length === 0) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "border-border mb-6 border-b pb-6",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
			className: "text-foreground mb-3 text-sm/6 font-semibold",
			children: "Shipping Address"
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			className: "text-foreground space-y-0.5 text-sm",
			children: lines.map((line, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: line }, index))
		})]
	});
}
function PaymentMethodSection({ paymentMethod }) {
	const { card_type, last4 } = paymentMethod;
	const brand = card_type ? card_type.toUpperCase() : PAYMENT_TYPE_LABELS[paymentMethod.payment_type] ?? paymentMethod.payment_type;
	const label = last4 ? `${brand} ending in ${last4}` : brand;
	if (!label) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "border-border mb-6 border-b pb-6",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
			className: "text-foreground mb-3 text-sm/6 font-semibold",
			children: "Payment Method"
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
			className: "text-foreground text-sm",
			children: label
		})]
	});
}
function LineItemImage({ src, alt }) {
	const [errored, setErrored] = (0, react.useState)(false);
	if (errored) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
		className: "text-xs",
		children: "No image"
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
		src,
		alt,
		className: "h-full w-full object-cover",
		onError: () => setErrored(true)
	});
}
function ItemRow({ item, onSubscriptionClick }) {
	const subscriptionToken = item.source_subscription?.subscription_token;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "flex items-center space-x-4 py-4",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "relative shrink-0",
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
				className: "bg-muted text-muted-foreground flex h-24 w-24 items-center justify-center overflow-hidden rounded",
				children: item.image_url ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LineItemImage, {
					src: item.image_url,
					alt: item.product_name
				}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
					className: "text-xs",
					children: "No image"
				})
			}), item.quantity > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
				className: "bg-foreground text-background absolute -top-2 -right-2 z-10 flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium",
				children: item.quantity
			})]
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "flex min-w-0 flex-1 flex-col space-y-0.5",
			children: [
				/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
					className: "text-foreground truncate text-sm font-medium",
					title: item.product_name,
					children: item.product_name
				}),
				item.variant_name && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
					className: "text-muted-foreground truncate text-xs",
					title: item.variant_name,
					children: item.variant_name
				}),
				/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
					className: "text-foreground text-sm font-medium",
					children: moneyDisplay(item.total_in_currency, item.total)
				}),
				item.quantity > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
					className: "text-muted-foreground text-xs",
					children: [
						moneyDisplay(item.price_in_currency, item.price),
						" x ",
						item.quantity
					]
				}),
				subscriptionToken && onSubscriptionClick && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
					type: "button",
					title: subscriptionToken,
					className: "mt-1 max-w-full cursor-pointer truncate text-left text-xs text-blue-600 transition-colors duration-200 hover:text-blue-700 hover:underline",
					onClick: () => onSubscriptionClick(subscriptionToken),
					children: ["Subscription #", subscriptionToken]
				})
			]
		})]
	});
}
function ItemsSection({ order, onSubscriptionClick }) {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
		className: "bg-muted flex w-full flex-col items-center px-8 lg:col-span-4",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "flex w-full max-w-lg flex-col",
			children: [
				/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
					className: "mt-4",
					children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h2", {
						className: "text-foreground mb-2 text-lg font-medium",
						children: [
							"Items (",
							order.line_items.length,
							")"
						]
					}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("hr", { className: "border-border" })]
				}),
				/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
					className: "divide-border divide-y",
					children: order.line_items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemRow, {
						item,
						onSubscriptionClick
					}, item.id))
				}),
				/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
					className: "border-border mb-4 space-y-1 border-t pt-4",
					children: [
						/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryRow, {
							label: "Subtotal",
							value: moneyDisplay(order.subtotal_in_currency, order.subtotal)
						}),
						parseFloat(order.discount) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryRow, {
							label: "Discount",
							value: asNegative(moneyDisplay(order.discount_in_currency, order.discount))
						}),
						/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryRow, {
							label: "Shipping",
							value: moneyDisplay(order.shipping_in_currency, order.shipping)
						}),
						/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryRow, {
							label: "Tax",
							value: moneyDisplay(order.tax_in_currency, order.tax)
						}),
						/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "mt-2 flex items-center justify-between text-base font-medium",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
								className: "text-muted-foreground text-sm font-medium",
								children: "Total"
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
								className: "text-foreground text-base font-bold",
								children: moneyDisplay(order.total_in_currency, order.total)
							})]
						})
					]
				}),
				order.total_points_credited != null && order.total_points_credited > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
					className: "border-border mb-4 border-t pt-4",
					children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
						className: "flex items-baseline justify-between",
						children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
							className: "text-foreground text-sm font-semibold",
							children: "Points Earned on This Order!"
						}), order.customer_points_balance != null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
							className: "text-muted-foreground text-xs",
							children: [order.customer_points_balance.toLocaleString(), " points total"]
						})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "text-right",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
								className: "text-foreground text-sm font-semibold",
								children: ["+", order.total_points_credited.toLocaleString()]
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
								className: "text-muted-foreground text-xs",
								children: "points"
							})]
						})]
					})
				})
			]
		})
	});
}
function DetailsSection({ order }) {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "bg-background px-8 pt-4 lg:col-span-4",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "mx-auto max-w-lg lg:mx-0 lg:mr-auto",
			children: [
				/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
					className: "border-border mb-6 border-b pb-6",
					children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
						className: "flex flex-wrap items-center gap-3",
						children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "flex items-center gap-2",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
								className: "text-muted-foreground text-sm",
								children: "Status:"
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_order_status_badge.OrderStatusBadge, { status: order.status })]
						})
					})
				}),
				/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
					className: "border-border mb-6 border-b pb-6",
					children: [
						/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
							className: "text-foreground mb-3 text-sm/6 font-semibold",
							children: "Order Info"
						}),
						/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "divide-border flex divide-x",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
								className: "flex-1 pr-4",
								children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
									className: "text-muted-foreground text-sm",
									children: "Order"
								}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
									className: "text-foreground font-medium",
									children: ["#", order.id]
								})]
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
								className: "flex-1 pl-4 text-right",
								children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
									className: "text-muted-foreground text-sm",
									children: "Date"
								}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
									className: "text-foreground font-medium",
									children: new Date(order.created_at).toLocaleDateString("en-US", {
										year: "numeric",
										month: "short",
										day: "numeric"
									})
								})]
							})]
						}),
						order.customer_email && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "mt-3",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
								className: "text-muted-foreground text-sm",
								children: "Email"
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
								className: "text-foreground text-sm font-medium",
								children: order.customer_email
							})]
						}),
						order.customer_name && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
							className: "mt-3",
							children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
								className: "text-muted-foreground text-sm",
								children: "Customer"
							}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
								className: "text-foreground text-sm font-medium",
								children: order.customer_name
							})]
						})
					]
				}),
				order.address && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AddressSection, { address: order.address }),
				order.payment_method && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PaymentMethodSection, { paymentMethod: order.payment_method })
			]
		})
	});
}
function PortalOrderDetail({ id, onNotFound, onError, onSubscriptionClick }) {
	const { data, isLoading, error } = require_order_status_badge.usePortalTenantOrder(id);
	const order = data?.order;
	(0, react.useEffect)(() => {
		if (!isLoading && error) onError?.(error);
	}, [
		isLoading,
		error,
		onError
	]);
	(0, react.useEffect)(() => {
		if (!isLoading && !error && !order) onNotFound?.();
	}, [
		isLoading,
		error,
		order,
		onNotFound
	]);
	if (isLoading) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DetailSkeleton, {});
	if (!order) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "flex flex-col lg:grid lg:grid-cols-8",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemsSection, {
			order,
			onSubscriptionClick
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DetailsSection, { order })]
	});
}
//#endregion
//#region ../../orders/ui/src/screens/PortalOrderDetailScreen.tsx
function PortalOrderDetailScreen({ id, onNavigateToList, onNotFound, onError, onSubscriptionClick }) {
	require_ScreenHeaderContext.useScreenHeaderBreadcrumbs((0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Breadcrumb, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.BreadcrumbList, {
		className: "text-lg",
		children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbItem, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbLink, {
				href: "#",
				onClick: (e) => {
					e.preventDefault();
					onNavigateToList();
				},
				children: "Orders"
			}) }),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbSeparator, {}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbItem, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.BreadcrumbPage, {
				className: "font-semibold",
				children: ["Order #", id]
			}) })
		]
	}) }), [id, onNavigateToList]));
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PortalOrderDetail, {
			id,
			onNotFound,
			onError,
			onSubscriptionClick
		})
	});
}
//#endregion
//#region src/screens/OrderDetailScreen.tsx
function OrderDetailScreen({ token, onToast }) {
	const { navigate } = require_AppNavigationContext.useAppNavigation();
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PortalOrderDetailScreen, {
		id: token,
		onNavigateToList: () => navigate("orders"),
		onNotFound: () => {
			onToast("Order not found", "warning");
			navigate("orders");
		},
		onError: (err) => {
			onToast(`Failed to load order: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
		},
		onSubscriptionClick: (subscriptionToken) => navigate(`subscriptions/${subscriptionToken}`)
	});
}
//#endregion
//#region src/screens/OrdersScreen.tsx
function defaultToast(message, type) {
	require_src.fluidToast({
		title: message,
		type
	});
}
function OrdersScreen({ onToast, background, textColor, accentColor, padding, borderRadius, ...divProps }) {
	const { currentSlug } = require_AppNavigationContext.useAppNavigation();
	const effectiveToast = onToast ?? defaultToast;
	const detailToken = currentSlug.split("/")[1];
	if (detailToken !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		...divProps,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PortalOrdersApiProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OrderDetailScreen, {
			token: detailToken,
			onToast: effectiveToast
		}) })
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		...divProps,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PortalOrdersApiProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OrdersListScreen, {}) })
	});
}
const ordersScreenPropertySchema = {
	widgetType: "OrdersScreen",
	displayName: "Orders Screen",
	tabsConfig: [{
		id: "styling",
		label: "Styling"
	}],
	fields: []
};
//#endregion
Object.defineProperty(exports, "OrdersScreen", {
	enumerable: true,
	get: function() {
		return OrdersScreen;
	}
});
Object.defineProperty(exports, "ordersScreenPropertySchema", {
	enumerable: true,
	get: function() {
		return ordersScreenPropertySchema;
	}
});

//# sourceMappingURL=OrdersScreen-B2Gk4bJQ.cjs.map