import{S as q}from"./index.22cf9654.js";import{_ as z}from"./plugin-vue_export-helper.21dcd24c.js";import{r as x,c as f,a as b,f as $,m as l,i as p,o as k,D as w,g as E,u as y,t as I,k as Z,Y as j}from"./index.965ac11d.js";const A={class:"z-form"},R={class:"space-y-8 divide-y divide-gray-200"},S={class:"z-form-body"},B={class:"z-form-title text-lg leading-6 font-medium text-gray-900"},O={class:"z-form-sub-title mt-2 max-w-3xl text-sm text-gray-500"},V={class:"z-form-footer"},C={class:"pt-5"},D={class:"flex justify-end"},N={name:"ZForm"},M=Object.assign(N,{props:{model:Object,rules:Object},setup(_,{expose:s}){const u=_;let m=x({}),d=x([]),i=f(()=>{const e={};return d.value.forEach(({prop:r,required:n,label:o})=>{if(n&&(e[r]=[{required:!0,message:`${o}\u4E0D\u80FD\u4E3A\u7A7A`}]),u.rules[r]===void 0){console.debug(`prop \u4E3A ${r} \u7684 FormItem \u6821\u9A8C\u89C4\u5219\u4E0D\u5B58\u5728, \u8DF3\u8FC7.`);return}if(!Array.isArray(u.rules[r])){console.warn(`prop \u4E3A ${r} \u7684 FormItem \u6821\u9A8C\u89C4\u5219\u4E0D\u5B58\u5728\u6216\u8005\u5176\u503C\u4E0D\u662F\u6570\u7EC4`),e[r]=[{required:!0}];return}e[r]=u.rules[r]}),e}),v=f(()=>d.value.reduce((e,{prop:r})=>{let n=r.split(".");if(n.length>1){let o=u.model;for(;n.length>=1;){let c=n.shift();o[c]!==void 0&&(o=o[c])}e[r]=o}else e[r]=u.model[r];return e},{}));const h=e=>{new q(i.value).validate(v.value,n=>{let o={};n&&n.length?n.forEach(({message:c,field:F})=>{o[F]=c}):o={},m.value=o,e(Object.keys(o).length===0)})},g=e=>{e&&(d.value=[...d.value,e])},t=e=>{e&&(d.value=d.value.filter(({prop:r})=>r!==e.prop))};let a=f(()=>u.rules);return s({validate:h,formAddField:g,formRemoveField:t,rulesArray:a,formError:m}),(e,r)=>(b(),$("form",A,[l("div",R,[l("div",S,[l("div",null,[l("h3",B,[p(e.$slots,"form-title",{},void 0,!0)]),l("p",O,[p(e.$slots,"form-sub-title",{},void 0,!0)])]),p(e.$slots,"default",{},void 0,!0)]),l("div",V,[l("div",C,[l("div",D,[p(e.$slots,"footer",{},void 0,!0)])])])])]))}});var Q=z(M,[["__scopeId","data-v-c597957c"]]);const T={class:"sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5"},U=["for"],Y={class:"mt-1 sm:mt-0 sm:col-span-2"},G={class:"empty:mt-0 mt-2 text-sm max-w-2xl text-gray-400 z-form-item-tips"},H={class:"empty:mt-0 mt-2 text-sm text-red-500"},J={__name:"ZFormItem",props:{required:Boolean,prop:String,label:String},setup(_){const s=_,{proxy:u}=j();let m=f(()=>{let t=i.value.rulesArray;return t?t[s.prop]:[]}),d=f(()=>{if(s.required)return!0;if(m.value)for(let t=0;t<m.value.length;t++){let a=m.value[t].required;if(typeof a=="boolean")return!0;if(typeof a=="function")return a()}return!1}),i=f(()=>{let t=u.$parent;for(;t.$options.name!=="ZForm";)t=t.parent;return t});f(()=>s.prop&&i.value.formError[s.prop]||"");const v=(t,a)=>{i.value[t](a)};let h=x();k(()=>{s.prop&&v("formAddField",{prop:s.prop,required:s.required,label:s.label,el:h.value})}),w(()=>{v("formRemoveField",{prop:s.prop})});const g=t=>{let a=t.target.value,e={},r={};m.value&&(e[s.prop]=m.value,r[s.prop]=a),new q(e).validate(r,o=>{o&&o.length?o.forEach(({message:c,field:F})=>{i.value.formError[s.prop]=c}):i.value.formError[s.prop]=""})};return(t,a)=>(b(),$("div",{ref_key:"zFormItem",ref:h,class:E([y(i).formError[s.prop]?"is-error":"is-success","z-form-item mt-6 sm:mt-5 space-y-6 sm:space-y-5"])},[l("div",T,[_.label?(b(),$("label",{key:0,for:s.prop,class:E([y(d)?"required":"not-required","block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2"])},I(_.label),11,U)):Z("",!0),l("div",Y,[l("div",{class:"input max-w-2xl flex rounded-md z-form-item-input",onInput:g},[p(t.$slots,"default",{},void 0,!0)],32),l("p",G,[p(t.$slots,"tips",{},void 0,!0)]),l("p",H,I(y(i).formError[s.prop]),1)])])],2))}};var W=z(J,[["__scopeId","data-v-22eef9f0"]]);export{W as Z,Q as a};
