import { Select } from "@/components/FormElements/select";
import { AdminStatus } from "@/constants/enums";
import { FormErrorMessages } from "@/constants/Texts";
import { TChangeAdminStatusCredentials } from "@/lib/api";
import { capitalize } from "@/utils/shared";
import { Dispatch, FC, SetStateAction } from "react";
import { useForm } from "react-hook-form";
interface IProps {
  status: AdminStatus;
  setStatus: Dispatch<SetStateAction<string>>;
}
const ChangeStatusModalContent: FC<IProps> = ({ status, setStatus }) => {
  const { register } = useForm<TChangeAdminStatusCredentials>({
    mode: "onChange",
    defaultValues: { status },
  });
  const adminStatusEntries = Object.entries(AdminStatus).map(
    ([key, value]) => ({
      label: capitalize(key),
      value,
    }),
  );

  return (
    <form>
      <Select
        {...register("status", {
          required: { value: true, message: FormErrorMessages.required },
          onChange(event) {
            setStatus(event.target.value);
          },
        })}
        items={adminStatusEntries}
        label="Status"
        name="status"
        defaultValue={status}
        placeholder="Please select new Status"
      />
    </form>
  );
};

export default ChangeStatusModalContent;
