"use client" import * as React from "react" import { useRouter, usePathname, useSearchParams } from "next/navigation" import { ChevronDown } from "lucide-react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { InformationButton } from "@/components/information/information-button" interface ItemType { id: string name: string } interface ItemTechContainerProps { itemTypes: ItemType[] children: React.ReactNode } export function ItemTechContainer({ itemTypes, children, }: ItemTechContainerProps) { const router = useRouter() const pathname = usePathname() const searchParamsObj = useSearchParams() // useSearchParams를 메모이제이션하여 안정적인 참조 생성 const searchParams = React.useMemo( () => searchParamsObj || new URLSearchParams(), [searchParamsObj] ) // URL에서 현재 선택된 아이템 타입 가져오기 const itemType = searchParams.get("type") || "ship" // 선택한 아이템 타입에 해당하는 이름 찾기 const selectedItem = itemTypes.find((item) => item.id === itemType)?.name || "조선 아이템" // 아이템 타입 변경 핸들러 const handleItemTypeChange = React.useCallback((value: string) => { const params = new URLSearchParams(searchParams.toString()) params.set("type", value) router.push(`${pathname}?${params.toString()}`) }, [router, pathname, searchParams]) return ( <> {/* 상단 영역: 제목 왼쪽 / 아이템 타입 선택기 오른쪽 */}
{/* 왼쪽: 타이틀 & 설명 */}

자재 관리

{/*

조선 및 해양 자재를 등록하고 관리할 수 있습니다.

*/}
{/* 오른쪽: 아이템 타입 드롭다운 */} {itemTypes.map((item) => ( handleItemTypeChange(item.id)} className={item.id === itemType ? "bg-muted" : ""} > {item.name} ))}
{/* 컨텐츠 영역 */}
{children}
) }