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

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

export default function SearchForm({
  searchForm,
  handleSearch,
  setSearchForm,
}: {
  searchForm: SearchFormProps
  setSearchForm: (form: SearchFormProps) => void
  handleSearch: (e: FormEvent) => void
}) {
  return (
    <form className="mt-10" onSubmit={handleSearch}>
      <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 w-full gap-4 max-w-6xl">
        {/* Merchant Name */}
        <div className="w-full max-w-96">
          <div className="mb-2 block">
            <Label theme={labelTheme} htmlFor="name">
              Name
            </Label>
          </div>
          <TextInput
            theme={formTheme.textInput}
            id="invoice_number"
            type="text"
            placeholder="Name"
            value={searchForm.params?.name || ''}
            onChange={(e) =>
              setSearchForm({
                ...searchForm,
                params: {
                  ...searchForm.params,
                  name: e.target.value,
                },
              })
            }
          />
        </div>
      </div>

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