import { __, _x } from '@wordpress/i18n' import classnames from 'classnames' import React, { useMemo, useState } from 'react' import { isLicensed, shouldShowUpsell } from '../../utils/screen' import { buildUrl, fetchConstQueryParam } from '../../utils/urls' import { SUBPAGES, SUBPAGE_ENTRIES, type SubpageName } from '../ManageMenu/subpages' import { hasSeenDemo } from './demo/useDemoSeen' import { AiAgentIcon } from './icons/AiAgentIcon' import { BlueprintIcon } from './icons/BlueprintIcon' import { CommunityIcon } from './icons/CommunityIcon' import { LibraryIcon } from './icons/LibraryIcon' import { SettingsIcon } from './icons/SettingsIcon' import { SnippetsIcon } from './icons/SnippetsIcon' import { UpsellDialog } from './UpsellDialog' import type { SVGProps } from 'react' const searchParams = new URLSearchParams(window.location.search) const managePageSlug = window.CODE_SNIPPETS?.urls.manage ? new URL(window.CODE_SNIPPETS.urls.manage).searchParams.get('page') : null // The manage screen resolves an absent or unrecognised `subpage` to the first subpage, so // mirror that fallback here — comparing against the raw param would leave every lower-nav // tab inactive on the default Snippets view, which is where the page opens. const activeSubpage = searchParams.get('page') === managePageSlug ? fetchConstQueryParam('subpage', SUBPAGES) ?? SUBPAGES[0] : null interface UpperNavItemProps { name: string url: string label: string } const UpperNavItem = ({ name, url, label }: UpperNavItemProps) => { const pageSlug = useMemo(() => new URL(url).searchParams.get('page'), [url]) const isActive = !searchParams.get('subpage') && searchParams.get('page') === pageSlug return (