| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 07:47:03 +02:00
										 |  |  | import React, { useEffect, useState } from 'react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import Link from 'next/link' | 
					
						
							| 
									
										
										
										
											2025-02-23 07:47:03 +02:00
										 |  |  | import { usePathname, useSearchParams, useSelectedLayoutSegment } from 'next/navigation' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import type { INavSelectorProps } from './nav-selector' | 
					
						
							|  |  |  | import NavSelector from './nav-selector' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import classNames from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  | import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { useStore as useAppStore } from '@/app/components/app/store' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type INavProps = { | 
					
						
							|  |  |  |   icon: React.ReactNode | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  |   activeIcon?: React.ReactNode | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   text: string | 
					
						
							|  |  |  |   activeSegment: string | string[] | 
					
						
							|  |  |  |   link: string | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   isApp: boolean | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } & INavSelectorProps | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Nav = ({ | 
					
						
							|  |  |  |   icon, | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  |   activeIcon, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   text, | 
					
						
							|  |  |  |   activeSegment, | 
					
						
							|  |  |  |   link, | 
					
						
							|  |  |  |   curNav, | 
					
						
							|  |  |  |   navs, | 
					
						
							|  |  |  |   createText, | 
					
						
							|  |  |  |   onCreate, | 
					
						
							| 
									
										
										
										
											2023-06-06 10:42:32 +08:00
										 |  |  |   onLoadmore, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   isApp, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | }: INavProps) => { | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |   const setAppDetail = useAppStore(state => state.setAppDetail) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const [hovered, setHovered] = useState(false) | 
					
						
							|  |  |  |   const segment = useSelectedLayoutSegment() | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |   const isActivated = Array.isArray(activeSegment) ? activeSegment.includes(segment!) : segment === activeSegment | 
					
						
							| 
									
										
										
										
											2025-02-23 07:47:03 +02:00
										 |  |  |   const pathname = usePathname() | 
					
						
							|  |  |  |   const searchParams = useSearchParams() | 
					
						
							|  |  |  |   const [linkLastSearchParams, setLinkLastSearchParams] = useState('') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (pathname === link) | 
					
						
							|  |  |  |       setLinkLastSearchParams(searchParams.toString()) | 
					
						
							|  |  |  |   }, [pathname, searchParams]) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={`
 | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       mr-0 flex h-8 shrink-0 items-center rounded-xl px-0.5 text-sm font-medium sm:mr-3 | 
					
						
							|  |  |  |       ${isActivated && 'bg-components-main-nav-nav-button-bg-active font-semibold shadow-md'} | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |       ${!curNav && !isActivated && 'hover:bg-components-main-nav-nav-button-bg-hover'} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     `}>
 | 
					
						
							| 
									
										
										
										
											2025-02-23 07:47:03 +02:00
										 |  |  |       <Link href={link + (linkLastSearchParams && `?${linkLastSearchParams}`)}> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         <div | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           onClick={() => setAppDetail()} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           className={classNames(`
 | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  |             flex items-center h-7 px-2.5 cursor-pointer rounded-[10px] | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |             ${isActivated ? 'text-components-main-nav-nav-button-text-active' : 'text-components-main-nav-nav-button-text'} | 
					
						
							|  |  |  |             ${curNav && isActivated && 'hover:bg-components-main-nav-nav-button-bg-active-hover'} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           `)}
 | 
					
						
							|  |  |  |           onMouseEnter={() => setHovered(true)} | 
					
						
							|  |  |  |           onMouseLeave={() => setHovered(false)} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  |           <div className='mr-2'> | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               (hovered && curNav) | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 ? <ArrowNarrowLeft className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |                 : isActivated | 
					
						
							| 
									
										
										
										
											2023-06-27 18:02:01 +08:00
										 |  |  |                   ? activeIcon | 
					
						
							|  |  |  |                   : icon | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           {text} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </Link> | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |         curNav && isActivated && ( | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           <> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |             <div className='font-light text-divider-deep'>/</div> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             <NavSelector | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |               isApp={isApp} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |               curNav={curNav} | 
					
						
							|  |  |  |               navs={navs} | 
					
						
							|  |  |  |               createText={createText} | 
					
						
							|  |  |  |               onCreate={onCreate} | 
					
						
							| 
									
										
										
										
											2023-06-06 10:42:32 +08:00
										 |  |  |               onLoadmore={onLoadmore} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             /> | 
					
						
							|  |  |  |           </> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Nav |