"use client"
import { useController, useFormContext } from "react-hook-form"

import ReactAriaSelect from "@/components/TempDesignSystem/Select"

import type { SelectProps } from "./select"

export default function Select({
  items,
  label,
  name,
  placeholder,
  registerOptions = {},
}: SelectProps) {
  const { control } = useFormContext()
  const { field } = useController({
    control,
    name,
    rules: registerOptions,
  })

  return (
    <ReactAriaSelect
      defaultSelectedKey={field.value}
      disabled={field.disabled}
      items={items}
      label={label}
      name={field.name}
      onBlur={field.onBlur}
      onSelect={field.onChange}
      placeholder={placeholder}
      value={field.value}
    />
  )
}
