import React from "react";
import useFormField from "../../../Hooks/useFormField";
import { Checkbox, Form } from "antd";
import { getNestedValue } from "../utils/getNestedValue";
const CheckboxField = ({
  name,
  label,
  isDisabled,
  onChange,
  Group,
  className,
  props,
}: any) => {
  const { t, formik, isError, errorMsg } = useFormField(name, props);
  const CheckboxhandleChange = (value: any) => {
    formik.setFieldValue(name, value?.target?.checked ? 1 : 0);
  };

  return (
    <div className={Group ? "d-inline mt-3 Checkboxs" : ``}>
      <Form.Item
        hasFeedback
        validateStatus={isError ? "error" : ""}
        help={isError ? errorMsg : ""}
      >
        <Checkbox
          onChange={onChange || CheckboxhandleChange}
          disabled={isDisabled}
          checked={formik.values?.[name] === 1}
          className={className}
        >
          {t(`input.${label ? label : name}`)}
        </Checkbox>
      </Form.Item>
    </div>
  );
};

export default CheckboxField;
