"use client";
import { useMemo } from "react";
import { usePathname } from "next/navigation";
function extractModule(pathParts) {
  const backendIndex = pathParts.indexOf("backend");
  if (backendIndex === -1 || backendIndex >= pathParts.length - 1) {
    return null;
  }
  return pathParts[backendIndex + 1] || null;
}
function extractEntityType(pathParts) {
  const backendIndex = pathParts.indexOf("backend");
  if (backendIndex === -1 || backendIndex >= pathParts.length - 2) {
    return null;
  }
  return pathParts[backendIndex + 2] || null;
}
function extractRecordId(pathParts) {
  const backendIndex = pathParts.indexOf("backend");
  if (backendIndex === -1 || backendIndex >= pathParts.length - 3) {
    return null;
  }
  const potentialId = pathParts[backendIndex + 3];
  if (potentialId && /^[a-f0-9-]{36}$/i.test(potentialId)) {
    return potentialId;
  }
  return null;
}
function usePageContext(options) {
  const pathname = usePathname();
  const { tenantId, organizationId } = options;
  const pageContext = useMemo(() => {
    const parts = pathname.split("/").filter(Boolean);
    return {
      path: pathname,
      module: extractModule(parts),
      entityType: extractEntityType(parts),
      recordId: extractRecordId(parts),
      tenantId,
      organizationId
    };
  }, [pathname, tenantId, organizationId]);
  return pageContext;
}
export {
  usePageContext
};
//# sourceMappingURL=usePageContext.js.map
