"use client"

import * as React from "react"
import { useRouter } from "next/navigation"
import { type Project } from "@/lib/rfqs/service"
import { ProjectSelector } from "./project-select"

interface ProjectSelectorWrapperProps {
  selectedProjectId?: number | null
}

export function ProjectSelectorWrapper({ selectedProjectId }: ProjectSelectorWrapperProps) {
  const router = useRouter()
  
  const handleProjectSelect = (project: Project | null) => {
    if (project && project.id) {
      router.push(`/evcp/pq-criteria/${project.id}`)
    } else {
      // 프로젝트가 null인 경우 (선택 해제)
      router.push(`/evcp/pq-criteria`)
    }
  }
  
  return (
    <div className="w-[400px]">
      <ProjectSelector 
        selectedProjectId={selectedProjectId}
        onProjectSelect={handleProjectSelect}
        placeholder="프로젝트를 선택하세요"
        showClearOption={true}
        clearOptionText="일반 PQ 보기"
      />
    </div>
  )
}