"use client"

import { useRouter } from "next/navigation"
import { buildSearchUrl, type SearchParams } from "@/lib/mail-search/search-params"
import { useAdvancedSearchForm } from "@/lib/mail-search/use-advanced-search-form"
import { AdvancedSearchPanelDesktop } from "@/components/gmail/mail-search/advanced-search-fields"

export function AdvancedSearchPanel({
  onClose,
  initialQuery,
  currentParams,
}: {
  onClose: () => void
  initialQuery: string
  currentParams: SearchParams | null
}) {
  const router = useRouter()
  const form = useAdvancedSearchForm(initialQuery, currentParams)

  const handleSubmit = () => {
    router.push(buildSearchUrl(form.buildParams()))
    onClose()
  }

  return (
    <AdvancedSearchPanelDesktop form={form} onSubmit={handleSubmit} onClose={onClose} />
  )
}
