require("./chunk-9hOWP6kD.cjs");
const require_AppNavigationContext = require("./AppNavigationContext-D1Xx1-jH.cjs");
let react = require("react");
//#region ../core/src/navigation/system-navigation-items.ts
const SYSTEM_NAVIGATION_SLUGS = [
	"app-download",
	"contacts",
	"account",
	"messages",
	"my-site",
	"orders",
	"profile",
	"subscriptions",
	"share/media",
	"share/pages",
	"share/playlists",
	"share/products",
	"shop"
];
/**
* Slugs hidden from the quicklinks/shortcuts menu.
* These screens still exist and are navigable, but don't appear in the grid.
*/
const QUICKLINKS_HIDDEN_SLUGS = new Set(["app-download"]);
/**
* Slugs restricted to rep (non-customer) users.
* Customers will not see these in navigation and cannot access these routes.
*/
const REP_ONLY_SLUGS = new Set(["messages", "my-site"]);
/**
* Check if a slug is restricted to rep users only.
* Handles both exact matches and prefix matches (e.g. "contacts/123").
*/
function isRepOnlySlug(slug) {
	if (!slug) return false;
	const normalized = slug.startsWith("/") ? slug.slice(1) : slug;
	if (REP_ONLY_SLUGS.has(normalized)) return true;
	for (const repSlug of REP_ONLY_SLUGS) if (normalized.startsWith(repSlug + "/")) return true;
	return false;
}
const SYSTEM_NAVIGATION_ITEMS = {
	"app-download": {
		slug: "app-download",
		label: "App Download",
		icon: "mobile",
		section: "User"
	},
	contacts: {
		slug: "contacts",
		label: "Contacts",
		icon: "circle-user",
		section: "User"
	},
	messages: {
		slug: "messages",
		label: "Messaging",
		icon: "message",
		section: "User"
	},
	"my-site": {
		slug: "my-site",
		label: "MySite",
		icon: "globe",
		section: "Shareables"
	},
	orders: {
		slug: "orders",
		label: "Orders",
		icon: "package-open",
		section: "User"
	},
	profile: {
		slug: "profile",
		label: "Profile",
		icon: "user",
		section: "User"
	},
	account: {
		slug: "profile",
		label: "Account",
		icon: "user",
		section: "User"
	},
	"share/media": {
		slug: "share/media",
		label: "Media",
		icon: "file-video",
		section: "Shareables"
	},
	"share/pages": {
		slug: "share/pages",
		label: "Pages",
		icon: "file-lines",
		section: "Shareables"
	},
	"share/playlists": {
		slug: "share/playlists",
		label: "Playlists",
		icon: "list-music",
		section: "Shareables"
	},
	"share/products": {
		slug: "share/products",
		label: "Products",
		icon: "box",
		section: "Shareables"
	},
	shop: {
		slug: "shop",
		label: "Shop",
		icon: "store",
		section: "User"
	},
	subscriptions: {
		slug: "subscriptions",
		label: "Subscriptions",
		icon: "arrows-repeat",
		section: "User"
	}
};
/**
* Check if a navigation item is a system item that doesn't require a screen_id.
* Used by RepApp to skip screen validation for these items.
*/
function isSystemNavigationItem(slug) {
	if (!slug) return false;
	return SYSTEM_NAVIGATION_SLUGS.includes(slug);
}
/**
* Get system navigation items grouped by section.
*/
function getSystemNavigationBySection() {
	const sections = {};
	const seenSlugs = /* @__PURE__ */ new Set();
	for (const item of Object.values(SYSTEM_NAVIGATION_ITEMS)) {
		if (item.slug && seenSlugs.has(item.slug)) continue;
		if (item.slug) seenSlugs.add(item.slug);
		if (item.slug && QUICKLINKS_HIDDEN_SLUGS.has(item.slug)) continue;
		const section = item.section || "Other";
		if (!sections[section]) sections[section] = [];
		sections[section].push(item);
	}
	return sections;
}
/**
* Normalize a navigation slug by stripping a leading slash.
*/
function normalizeSlug(slug) {
	if (!slug) return "";
	return slug.startsWith("/") ? slug.slice(1) : slug;
}
//#endregion
//#region ../core/src/navigation/slug-utils.ts
/**
* Extract all slugs from a navigation tree, sorted by segment count descending.
* Longest slugs first enables greedy prefix matching (e.g. "share/playlists"
* is checked before "share").
*/
function collectNavSlugs(items) {
	const slugs = [];
	for (const item of items) {
		if (item.slug) slugs.push(normalizeSlug(item.slug));
		for (const child of item.children ?? []) if (child.slug) slugs.push(normalizeSlug(child.slug));
	}
	return slugs.toSorted((a, b) => b.split("/").length - a.split("/").length);
}
/**
* Find the longest registered nav slug that is a prefix of `fullSlug`.
* Uses segment-boundary checking to prevent "shop" from matching "shopping".
*/
function matchSlugPrefix(fullSlug, navSlugs) {
	const normalized = normalizeSlug(fullSlug);
	if (!normalized) return void 0;
	for (const navSlug of navSlugs) {
		if (normalized === navSlug) return {
			matchedSlug: navSlug,
			rest: ""
		};
		if (normalized.startsWith(navSlug + "/")) return {
			matchedSlug: navSlug,
			rest: normalized.slice(navSlug.length + 1)
		};
	}
}
/**
* Extract the slug portion from a full pathname by stripping the basePath prefix.
* Returns an empty string when the pathname equals the basePath exactly.
*
* Examples:
*   extractSlugFromPathname("/contacts/123", "/")        → "contacts/123"
*   extractSlugFromPathname("/portal/contacts", "/portal") → "contacts"
*   extractSlugFromPathname("/portal", "/portal")          → ""
*   extractSlugFromPathname("/", "/")                      → ""
*/
function extractSlugFromPathname(pathname, basePath) {
	if (basePath === "/") return pathname.replace(/^\//, "");
	if (pathname.startsWith(basePath)) return pathname.slice(basePath.length).replace(/^\//, "");
	return pathname.replace(/^\//, "");
}
/**
* Generate a URL-safe slug from a human-readable name. Mirrors the admin
* builder's `generateSlugFromName` so a navigation item authored as
* `slugifyName(screen.name)` can be matched back to the screen at runtime
* even when the screen's own `slug` is opaque (e.g. `screen-{uuid}`).
*/
function slugifyName(name) {
	return name.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
}
function resolveSlugLabel(slug, items) {
	const normalized = normalizeSlug(slug);
	if (!normalized) return null;
	const target = matchSlugPrefix(normalized, collectNavSlugs(items))?.matchedSlug ?? normalized;
	for (const item of items) {
		if (normalizeSlug(item.slug) === target) return item.label;
		for (const child of item.children ?? []) if (normalizeSlug(child.slug) === target) return child.label;
	}
	return null;
}
function isSlugInSection(item, currentSlug, navSlugs) {
	const baseSlug = matchSlugPrefix(currentSlug, navSlugs)?.matchedSlug ?? normalizeSlug(currentSlug);
	if (normalizeSlug(item.slug) === baseSlug) return true;
	return item.children?.some((child) => normalizeSlug(child.slug) === baseSlug) ?? false;
}
//#endregion
//#region src/shell/use-navigation-parent.ts
/**
* Resolve the previous in-session slug into a labeled back-target. Returns
* `null` when there's no referrer or the referrer can't be matched to a
* known nav item — callers should fall back to their structural parent.
*/
function useNavigationParent() {
	const { previousSlug, navItems, navigate } = require_AppNavigationContext.useAppNavigation();
	return (0, react.useMemo)(() => {
		if (!previousSlug) return null;
		const label = resolveSlugLabel(previousSlug, navItems);
		if (!label) return null;
		return {
			slug: previousSlug,
			label,
			onClick: () => navigate(previousSlug)
		};
	}, [
		previousSlug,
		navItems,
		navigate
	]);
}
//#endregion
Object.defineProperty(exports, "SYSTEM_NAVIGATION_ITEMS", {
	enumerable: true,
	get: function() {
		return SYSTEM_NAVIGATION_ITEMS;
	}
});
Object.defineProperty(exports, "collectNavSlugs", {
	enumerable: true,
	get: function() {
		return collectNavSlugs;
	}
});
Object.defineProperty(exports, "extractSlugFromPathname", {
	enumerable: true,
	get: function() {
		return extractSlugFromPathname;
	}
});
Object.defineProperty(exports, "getSystemNavigationBySection", {
	enumerable: true,
	get: function() {
		return getSystemNavigationBySection;
	}
});
Object.defineProperty(exports, "isRepOnlySlug", {
	enumerable: true,
	get: function() {
		return isRepOnlySlug;
	}
});
Object.defineProperty(exports, "isSlugInSection", {
	enumerable: true,
	get: function() {
		return isSlugInSection;
	}
});
Object.defineProperty(exports, "isSystemNavigationItem", {
	enumerable: true,
	get: function() {
		return isSystemNavigationItem;
	}
});
Object.defineProperty(exports, "matchSlugPrefix", {
	enumerable: true,
	get: function() {
		return matchSlugPrefix;
	}
});
Object.defineProperty(exports, "normalizeSlug", {
	enumerable: true,
	get: function() {
		return normalizeSlug;
	}
});
Object.defineProperty(exports, "slugifyName", {
	enumerable: true,
	get: function() {
		return slugifyName;
	}
});
Object.defineProperty(exports, "useNavigationParent", {
	enumerable: true,
	get: function() {
		return useNavigationParent;
	}
});

//# sourceMappingURL=use-navigation-parent-BR0d5weV.cjs.map