import{aA as i,j as r,G as j,az as l,ax as x,a9 as y,aT as q,k as C,l as F,o as S,E as g}from"./app-BgLa5dit.js";import{M as h}from"./DwzYo0zp.chunk.js";function k({fields:a,onSubmit:u,closePopup:o,showSpinner:c}){const p=a.reduce((n,e)=>(e.type==="boolean"?n[e.name]=!1:e.type==="number"?n[e.name]=0:e.type==="string"&&(n[e.name]=""),n),{}),b=i.object().shape(a.reduce((n,e)=>(e.type==="string"?n[e.name]=i.string().required(`${e.name} is required`):e.type==="number"?n[e.name]=i.number().required(`${e.name} is required`):e.type==="boolean"&&(n[e.name]=i.boolean().required(`${e.name} is required`)),n),{}));return r.jsx(j,{initialValues:p,validationSchema:b,onSubmit:n=>{const e=a.reduce((s,m)=>(m.type==="boolean"?s[m.name]=!!n[m.name]:s[m.name]=n[m.name],s),{});u([e])},children:({values:n,handleChange:e,handleBlur:s,handleSubmit:m})=>r.jsxs(l,{onSubmit:m,children:[r.jsx("div",{children:r.jsx("div",{className:"col",children:a.map(t=>r.jsxs("div",{className:"mb-3",children:[t.type==="string"&&r.jsx(x,{name:t.name,label:t.name,type:"text",value:n[t.name],onChange:e,onBlur:s,placeholder:`Enter ${t.name}`,required:t.name==="id"}),t.type==="number"&&r.jsx(x,{name:t.name,label:t.name,type:"number",value:n[t.name],onChange:e,onBlur:s,placeholder:`Enter ${t.name}`,required:t.name==="id"}),t.type==="boolean"&&r.jsx(x,{name:t.name,label:t.name,type:"checkbox",checked:n[t.name],onChange:e,onBlur:s,required:t.name==="id"})]},t.name))})}),r.jsxs(y,{className:"mt-2",children:[r.jsx(y.Cancel,{onClick:o}),r.jsx(y.Submit,{showSpinner:c,variant:"dark",text:"Create items",disabled:c})]})]})})}function v({catalogName:a,region:u,closePopup:o}){const[c,p]=q.useState(!1),b=C(),n=F(),e=S(h.getCatalog(a,u));if(!e.hasCompleted)return r.jsx(r.Fragment,{});const s=e.data.fields;async function m(t){p(!0),b(h.createItem(a,t,u)).then(()=>n.success(`Successfully created items for: ${a}`)).catch(()=>n.error(`Failed to create items for: ${a}. Please try again.`)).finally(o)}return r.jsx(g,{title:"Create Item",closePopup:o,backdrop:"static",children:r.jsx(k,{fields:s,closePopup:o,onSubmit:m,showSpinner:c})})}export{v as CreateItemView};
//# sourceMappingURL=C81i6a0O.chunk.js.map
