'use client'

import React from 'react'
import { Label, TextInput } from 'flowbite-react'

import SearchButton from '@/lib/components/buttons/SearchButton'
import formTheme from '@/lib/themes/form'
import { SearchFormProps } from '../types'

interface Props {
  searchForm: SearchFormProps
  handleSearch: (e?: React.FormEvent) => void
  setSearchForm: React.Dispatch<React.SetStateAction<SearchFormProps>>
}

export default function SearchForm({
  searchForm,
  handleSearch,
  setSearchForm,
}: Props) {
  return (
    <form onSubmit={handleSearch} className="mt-10">
      <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 w-full max-w-6xl gap-4">
        {/* Name */}
        <div className="w-full max-w-96">
          <div className="mb-2 block">
            <Label htmlFor="name">Name</Label>
          </div>

          <TextInput
            id="name"
            theme={formTheme.textInput}
            placeholder="Search by name..."
            value={searchForm.params.search || ''}
            onChange={(e) =>
              setSearchForm({
                ...searchForm,
                params: { ...searchForm.params, search: e.target.value },
              })
            }
          />
        </div>
      </div>

      <SearchButton isProcessing={searchForm.searching} className="mt-5" />
    </form>
  )
}
