// src/components/Search/SearchBar.tsx
import { useState } from "react"
import { useNavigate } from "react-router-dom"

export default function SearchBar() {
  const [query, setQuery] = useState("")
  const navigate = useNavigate()

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault()
    if (query.trim()) navigate(`/search?query=${encodeURIComponent(query)}`)
  }

  return (
    <form
      onSubmit={handleSubmit}
      className="flex items-center bg-[#2A2A2A] rounded-md overflow-hidden w-full max-w-md"
    >
      <input
        type="text"
        placeholder="Fırsat ara..."
        value={query}
        onChange={(e) => setQuery(e.target.value)}
        className="flex-1 px-4 py-2 bg-transparent text-white placeholder-gray-400 focus:outline-none"
      />
      <button
        type="submit"
        className="bg-primary hover:bg-primary/90 text-white font-semibold px-4 py-2 transition"
      >
        Ara
      </button>
    </form>
  )
}
