import { useRouter } from 'next/router'
import cx from 'classnames'
import { useState, useEffect, SyntheticEvent } from 'react'
import { ChevronDownIcon } from '@primer/octicons-react'
import { ActionList } from '@primer/react'
import { Link } from 'components/Link'
import { ProductTreeNode, useMainContext } from 'components/context/MainContext'
import { AllProductsLink } from 'components/sidebar/AllProductsLink'
import { EventType, sendEvent } from 'components/lib/events'
import styles from './SidebarProduct.module.scss'
export const SidebarProduct = () => {
const router = useRouter()
const { currentProductTree } = useMainContext()
useEffect(() => {
const activeArticle = document.querySelector('[data-is-current-page=true]')
// Setting to the top doesn't give enough context of surrounding categories
activeArticle?.scrollIntoView({ block: 'center' })
// scrollIntoView affects some articles that are very low in the sidebar
// The content scrolls down a bit. This sets the article content back up
// top unless the route contains a link heading.
if (!router.asPath.includes('#')) window?.scrollTo(0, 0)
}, [])
if (!currentProductTree) {
return null
}
const productTitle = currentProductTree.renderedShortTitle || currentProductTree.renderedFullTitle
// remove query string and hash
const routePath = `/${router.locale}${router.asPath.split('?')[0].split('#')[0]}`
const hasExactCategory = !!currentProductTree.childPages.find(({ href }) =>
routePath.includes(href)
)
return (