import "../Form.css";
import { jsx } from "react/jsx-runtime";
import { Form as Form$1 } from "antd";
import { useTheme } from "./Theme/UI.js";
import "./Theme/themeUtils.js";
import "./Theme/themes.js";
const formItem = "Form_formItem_00ce1";
const css = {
  formItem
};
const FormItem = ({
  children,
  label,
  labelCol = { span: 24 },
  max,
  maxMessage,
  required,
  requiredMessage,
  rules = [],
  validateMessage,
  ...props
}) => {
  const {
    themeSettings: { className: themeClass }
  } = useTheme();
  const classes = [css.formItem, themeClass];
  if (required)
    rules.push({ message: requiredMessage || `${label} required`, required: true });
  if (max)
    rules.push({ max, message: maxMessage || `${label} cannot exceed ${max} characters` });
  return /* @__PURE__ */ jsx(
    Form$1.Item,
    {
      className: classes.join(" "),
      help: validateMessage,
      label,
      labelCol,
      required,
      rules,
      ...props,
      children
    }
  );
};
const Form = ({ noValidate = true, ...props }) => {
  const {
    themeSettings: { className: themeClass }
  } = useTheme();
  const classes = (props == null ? void 0 : props.className) ? themeClass.concat(" ", props.className) : themeClass;
  return /* @__PURE__ */ jsx(Form$1, { noValidate, ...props, className: classes });
};
const ErrorList = ({ ...props }) => {
  const {
    themeSettings: { className }
  } = useTheme();
  const classes = (props == null ? void 0 : props.className) ? className.concat(" ", props.className) : className;
  return /* @__PURE__ */ jsx(Form$1.ErrorList, { ...props, className: classes });
};
Form.Item = FormItem;
Form.List = Form$1.List;
Form.ErrorList = ErrorList;
Form.useForm = Form$1.useForm;
Form.useWatch = Form$1.useWatch;
const hasErrors = (form) => {
  return form.getFieldsError().some(({ errors }) => errors.length);
};
export {
  Form as default,
  hasErrors
};
