"use client";

import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { useState } from "react";

export default function Search({ link }: { link: string }) {
  const [searchTerm, setSearchTerm] = useState("");

  return (
    <div className="mt-6 w-full lg:w-1/2 flex justify-between h-12 rounded-md mx-auto overflow-hidden">
      <input
        type="text"
        className="w-full bg-transparent rounded-l-md outline-none pl-4 border-2 border-gray-200 focus:border-primary border-r-0 transition-all duration-300"
        placeholder="Search..."
        value={searchTerm}
        onChange={(e) => setSearchTerm(e.target.value)}
      />
      <Link href={`${link}?search=${searchTerm}`}>
        <button
          type="button"
          disabled={searchTerm === ""}
          className={`w-20 bg-primary h-full flex items-center justify-center ${
            searchTerm === ""
              ? "opacity-50 cursor-not-allowed"
              : "cursor-pointer"
          }`}
        >
          <SearchIcon size={20} strokeWidth={4} color="#fff" />
        </button>
      </Link>
    </div>
  );
}
