import{Form as e,Spin as t,Row as o,Col as r,Space as i,Button as n,message as s}from"antd";import{useState as l,useEffect as a}from"react";import{throttle as u}from"throttle-debounce";import d from"./FormItemsRenderer.js";import{jsx as c,jsxs as m}from"react/jsx-runtime";const p=p=>{const{values:h,options:g,gutter:w=24,span:x=12,labelCol:y={span:4},useAutoGenerateRequired:b=!0,showActionButtons:f=!0,submitButtonText:B="提交",cancelButtonText:v="取消",showSubmitButton:A=!0,showCancelButton:C=!0,customActionButtons:F,extraActionButtons:T,loading:W=!1,...k}=p,[q,z]=l(window.innerWidth),E=u(50,()=>{const e=document.querySelector("#page-layout");e&&z(e.offsetWidth)});return a(()=>{const e=setTimeout(()=>{E()},0);return f&&window.addEventListener("resize",E),()=>{f&&window.removeEventListener("resize",E),clearTimeout(e)}},[f]),c(t,{spinning:W,children:m(e,{labelCol:y,scrollToFirstError:!0,wrapperCol:{span:24-y.span},initialValues:h,onFinishFailed:()=>{s.error("请补全必填项")},style:{width:`calc(100% - ${2*w}px)`,margin:"0 auto"},...k,children:[c(o,{gutter:w,children:c(d,{options:g,labelCol:y,span:x,gutter:w,useAutoGenerateRequired:b,initialValues:h})}),f&&m("div",{style:{position:"relative",zIndex:"9"},children:[c("div",{style:{height:"32px"}}),c(o,{style:{textAlign:"center",backgroundColor:"rgb(241, 241, 242)",padding:"10px 0",position:"fixed",bottom:"0",width:q,margin:"0 -44px"},children:c(r,{span:24,style:{textAlign:"center"},children:F||m(i,{children:[A&&c(n,{type:"primary",htmlType:"submit",children:B}),T,C&&c(n,{onClick:()=>{window.history.back()},children:v})]})})})]})]})})};p.displayName="FormBuilder",p.useForm=e.useForm,p.useWatch=e.useWatch;export{p as default};
