import{j as e}from"./vendor-mui-69397583.js";import{c as m,i as y,a as f,F as g,b as v,d as n,E as S}from"./index.esm-70ab539c.js";import{W as q,I as k,B as u}from"./index-c62ac197.js";import{U as I}from"./Upload-fb34ce03.js";import"./Alert-7dfbd254.js";import"./index-6b6d0f06.js";import"./index-c2088808.js";import"./Drawer-949c18c6.js";import"./FormContainer-91c2b0e4.js";import"./vendor-react-ece1c85f.js";import"./Switcher-c8648037.js";import"./index-36228db5.js";import{u as A}from"./index-dc103f22.js";import{S as E}from"./StickyFooter-5b934274.js";const x=1,U=m({files:y().min(1,"Please upload at least one file").required("File upload is required"),fileName:f().required("File Name is required")}),C=m({files:y().min(1,"Please upload at least one file").required("File upload is required"),fileName:f().required("File Name is required"),opportunityId:m().required("Opportunity is required")}),Y=({initialData:h={files:[]},footerWidth:d,onSubmit:j,onCancel:N,accountId:c=null})=>{const b=A(t=>{var a,o,i;return(i=(o=(a=t==null?void 0:t.opportunity)==null?void 0:a.data)==null?void 0:o.opportunityList)==null?void 0:i.map(s=>({value:s.id,label:s.opportunityName}))}),F=(t,r)=>{let a=!0;const o=5242880;if(r.length>=x)return`You can only upload ${x} file(s)`;if(t)for(const i of t)i.size>=o&&(a="Upload file cannot more then 5 MB!");return a};return e.jsx(g,{initialValues:h,footerWidth:d,validationSchema:c?C:U,onSubmit:(t,{setSubmitting:r})=>{j(t,r)},children:({values:t,touched:r,errors:a,isSubmitting:o})=>e.jsx(v,{children:e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsxs("div",{children:[c&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Opportunity"}),e.jsx(n,{name:"opportunityId",children:({field:i,form:s})=>e.jsx(q,{field:i,form:s,options:b,name:"opportunityId",placeholder:"Select Opportunity",onChange:l=>{s.setFieldValue(i.name,l)}})}),a.opportunityId&&r.opportunityId&&e.jsx("div",{className:"text-red-500 text-sm mt-1",children:a.opportunityId})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Upload File"}),e.jsx(n,{name:"files",children:({field:i,form:s})=>e.jsx(I,{draggable:!0,beforeUpload:F,fileList:t.files||[],cropNeeded:!1,onChange:l=>{var p;s.setFieldValue(i.name,l),s.setFieldValue("fileName",(p=l==null?void 0:l[0])==null?void 0:p.name)},onFileRemove:l=>s.setFieldValue(i.name,l)})}),a.files&&r.files&&e.jsx("div",{className:"text-red-500 text-sm mt-1",children:a.files})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"File Name"}),e.jsx(n,{name:"fileName",children:({field:i})=>e.jsx(k,{...i,placeholder:"File Name"})}),e.jsx(S,{name:"fileName",component:"div",className:"text-red-600"})]})]}),e.jsx(E,{className:`px-8 flex items-center justify-between py-4 ${d}`,stickyClass:"bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"md:flex items-center justify-between w-full",children:[e.jsx(u,{type:"button",size:"sm",className:"mr-2",onClick:N,children:"Cancel"}),e.jsx(u,{size:"sm",variant:"solid",type:"submit",loading:o,children:"Save"})]})})]})})})};export{Y as A};
