"use strict";
const React = require("react");
const Field = require("./Field.js");
const UiForm = require("./UiForm.js");
const emotionReactJsxRuntime_browser_esm = require("../../node_modules/.pnpm/@emotion_react@11.10.4_q4mq7tnhdumujvomvw24zx33y4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const Button = require("../../components/Button.js");
require("../../components/Tabs.js");
const toast = require("react-hot-toast");
const index = require("../../node_modules/.pnpm/@arco-design_web-react@2.40.1_biqbaboplfbrettd7655fr4n2y/node_modules/@arco-design/web-react/es/Form/index.js");
const index$1 = require("../../node_modules/.pnpm/@arco-design_web-react@2.40.1_biqbaboplfbrettd7655fr4n2y/node_modules/@arco-design/web-react/es/Skeleton/index.js");
const index$2 = require("../../node_modules/.pnpm/@arco-design_web-react@2.40.1_biqbaboplfbrettd7655fr4n2y/node_modules/@arco-design/web-react/es/Button/index.js");
const FormItem = index.Item;
function FormContent({
  loading = false,
  autoComplete = "off",
  layout = "vertical",
  size = "default",
  data = [],
  type,
  cols,
  gap,
  onChange,
  compressed,
  buttons,
  pageHeader,
  formClassName,
  defaultValues = {},
  values = {},
  formId,
  onCloseModal,
  className = "",
  ...props
}) {
  const [form] = index.useForm();
  let customCols = "";
  if (cols) {
    customCols = layout !== "inline" ? `grid grid-cols-${cols} gap-x-${gap || 6} ` : "";
  }
  if (loading) {
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: "relative w-full m-auto",
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: customCols + className,
        children: data == null ? void 0 : data.map((field, index2) => /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {
          animation: true
        }, field.name))
      })
    });
  }
  const items = data == null ? void 0 : data.map((prop, index2) => {
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Field.Field, {
      ...prop
    }, `fild-${index2}`);
  });
  const onSubmit = (formData) => {
    console.log("Form onSubmit-->", formData);
    const clearData = Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).reduce((acc, key) => ({
      ...acc,
      [key]: formData[key]
    }), {});
    if (type === "create") {
      props.onSubmit && props.onSubmit(clearData);
      return;
    }
    const diffData = JSON.stringify(defaultValues) !== "{}" ? Object.keys(formData).filter((key) => defaultValues[key] !== formData[key]).reduce((ret, key) => ({
      ...ret,
      [key]: formData[key]
    }), {}) : formData;
    if (JSON.stringify(diffData) === "{}") {
      toast.toast.error("\u8BF7\u586B\u5199\u6216\u4FEE\u6539\u5185\u5BB9");
      return;
    }
    props.onSubmit && props.onSubmit(diffData);
  };
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(React.Fragment, {
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(UiForm.UiForm, {
      id: formId,
      form,
      Form: index,
      layout,
      size,
      onSubmit,
      onValuesChange: onChange,
      initialValues: defaultValues || values,
      className: formClassName,
      contentClassName: customCols + className,
      autoComplete,
      header: pageHeader,
      scrollToFirstError: true,
      validateMessages: {
        required: (_, {
          label
        }) => `\u5FC5\u987B\u586B\u5199 ${label}`,
        string: {
          length: `\u5B57\u7B26\u6570\u5FC5\u987B\u662F #{length}`,
          match: `\u4E0D\u5339\u914D\u6B63\u5219 #{pattern}`
        },
        number: {
          min: `\u6700\u5C0F\u503C\u4E3A #{min}`,
          max: `\u6700\u5927\u503C\u4E3A #{max}`
        }
      },
      children: [items, buttons ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: cols ? `col-span-${cols}` : "",
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Button.Buttons, {
          data: buttons,
          onCloseModal,
          contentClassName: layout === "horizontal" ? "ml28" : ""
        })
      }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: cols ? `col-span-${cols}` : "",
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(FormItem, {
          className: "mt-8 gap-x-6 ",
          wrapperCol: layout === "horizontal" ? {
            offset: 5
          } : {},
          children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {
            type: "primary",
            htmlType: "submit",
            size: "large",
            children: "\u786E\u8BA4\u63D0\u4EA4"
          })
        })
      })]
    })
  });
}
module.exports = FormContent;
//# sourceMappingURL=Form.js.map
