import { jsx } from "react/jsx-runtime";
import { ErrorMessage } from "@hookform/error-message";
import { useFormContext, Controller } from "react-hook-form";
/* empty css                                                                                                                                                                                       */
/* empty css                                                                                                                                                                                        */
/* empty css                                                                                                                                                                                                */
/* empty css                                                                                                                                                                                           */
/* empty css                                                                                                                                                                                           */
import { Select } from "../../primitive/Select/index.mjs";
const FormSelect = ({ name, rules, onChange: onSelect, data, ...restProps }) => {
  const { control, formState, getFieldState } = useFormContext();
  const { error } = getFieldState(name, formState);
  return /* @__PURE__ */ jsx(
    Controller,
    {
      name,
      control,
      rules,
      render: ({ field: { onChange, value } }) => {
        return /* @__PURE__ */ jsx(
          Select,
          {
            value,
            data,
            onChange: (val, option) => {
              onChange(val);
              onSelect == null ? void 0 : onSelect(val, option);
            },
            error: error ? /* @__PURE__ */ jsx(ErrorMessage, { errors: formState.errors, name }) : void 0,
            ...restProps
          }
        );
      }
    }
  );
};
export {
  FormSelect
};
