import{b as I,r as P,j as e,y as A,bR as w,bt as L,t as B,K as R,R as U,a8 as $,T as y,af as D,V as S,a3 as H}from"./index-Csef3-wA.js";import{s as l,f as c,U as O,a as W}from"./styles-XiU4mAxA.js";import{c as N}from"./contact-nG1w4h1u.js";import{u as _}from"./index-LOMZblid.js";import{I as v}from"./Icon-o1TUwOIX.js";function Y({accept:d="*",onChange:g=()=>{},onMultiFileChange:t=()=>{},onUploadEnd:o=()=>{},onDelete:h=()=>{},files:i,disabled:x=!1,maxFiles:b=5,helperText:F=""}){const M=I(),m=P.useRef(null),n=i.length>=b,s={accept:d,disabled:x||n,maxFiles:b,maxSize:3072,minSize:0,onDrop:async(p,a)=>{if(!(x||n)){if(a.length===1){const[f]=a;g(f==null?void 0:f.file,i.length);return}if(a.length>1){const f=a.map(z=>z==null?void 0:z.file).filter(Boolean);t(f)}}}},{getRootProps:r,getInputProps:j,isDragActive:E}=_(s),T=j(),u=()=>{m!=null&&m.current&&m.current.click()},C=(p,a)=>{p.stopPropagation(),h(a)},k=p=>{const{files:a=[]}=p.target||{};if((a==null?void 0:a.length)>1){t(a);return}if(a!=null&&a.length){const f=a[0];g(f,i.length)}};return e.jsxs("div",{children:[e.jsxs(l.FileContainer,{className:A([{dragActive:E}]),...r(),children:[e.jsx(l.FileInput,{type:"file",id:"file",ref:m,multiple:!0,onLoad:o,disabled:x||n,...T,onChange:k}),e.jsx(l.FilePlaceholder,{children:M.formatMessage({id:"userContact.uploadFileText"})}),e.jsx(l.UploadButton,{size:"small",variant:"outlined",onClick:u,disabled:x||n,children:M.formatMessage({id:"common.uploadFile"})})]}),!!(i!=null&&i.length)&&e.jsx(l.FilesList,{children:i.map((p,a)=>e.jsxs(l.FileItemWrapper,{children:[e.jsxs(l.TextWrapper,{children:[e.jsx(v,{name:"file",size:20}),e.jsxs(l.FileInfo,{children:[e.jsx(l.FileName,{children:p.name}),e.jsx(l.FileSize,{children:w(p.size)})]})]}),e.jsx(l.IconButton,{name:"delete",variant:"text",onClick:f=>C(f,a)})]},`FileList-${p.name}-${a}`))}),F&&e.jsx(L,{error:!0,children:F})]})}function Z({disabled:d,field:{onBlur:g,...t},form:{isSubmitting:o,touched:h,errors:i},onBlur:x,helperText:b,simpleErrors:F=!1,withSuccess:M=!1,...m}){const n=B(h,t.name),s=B(i,t.name),r=(F||B(h,t.name))&&!!s;return{variant:m.variant,error:r,helperText:r?s:b,disabled:d??o,onBlur:x??function(E){g(E??t.name)},success:M&&(n||!!t.value)&&!s,...t,...m}}function G(d){return e.jsx(Y,{...Z(d)})}const q=["image/png","image/jpeg","image/webp","application/pdf"];function J({onSuccess:d=()=>{},onCancel:g=()=>{}}){const t=I(),o=R(),[h,i]=P.useState(!1),[x,b]=P.useState(!1),F=[{label:t.formatMessage({id:"userContact.subjectType1"}),value:"Facturación y Pago"},{label:t.formatMessage({id:"userContact.subjectType2"}),value:"Comentarios o sugerencias"},{label:t.formatMessage({id:"userContact.subjectType3"}),value:"Error o problemas técnicos"},{label:t.formatMessage({id:"userContact.subjectType4"}),value:"PolÃtica de reembolso"},{label:t.formatMessage({id:"userContact.subjectType5"}),value:"Otros"}],M=o.object().shape({subject:o.string().max(100).required(),reason:o.string().max(100).required(),message:o.string().max(500).required(),files:o.array().of(o.mixed().nullable().fileSize(3,t.formatMessage({id:"common.validations.fileSize"},{size:3})).test("fileFormat",t.formatMessage({id:"common.validations.fileFormat"}),n=>n&&q.includes(n.type))),ccEmails:o.string().test("isValidEmails",t.formatMessage({id:"common.validations.string.email"}),n=>{if(!n)return!0;const s=n.split(",").map(j=>j.trim()).filter(Boolean),r=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;return s.every(j=>r.test(j))})});async function m(n){try{i(!0);const s=new FormData;Object.keys(n).forEach(r=>{r!=="files"&&n[r]!==void 0&&s.append(r,n[r])});for(let r=0;r<n.files.length;r++)s.append("files",n.files[r]);await N.userContact(s),d()}catch{return b(!0)}finally{i(!1)}}return e.jsx(c.Container,{children:e.jsx(U,{initialValues:{subject:"",reason:"",message:"",files:[],ccEmails:""},enableReinitialize:!0,validationSchema:M,validateOnBlur:!0,onSubmit:m,children:({isSubmitting:n,values:s,setFieldValue:r})=>{const j=(u,C)=>{r(`files.${C}`,u)},E=u=>{r("files",[...(s==null?void 0:s.files)||[],...u])},T=u=>{const C=((s==null?void 0:s.files)||[]).filter((k,p)=>p!==u);r("files",C)};return e.jsxs(c.Form,{children:[e.jsx($,{style:{width:"100%"},autoHeight:!0,autoHeightMax:"calc(100vh - 300px)",autoHide:!0,hideTracksWhenNotNeeded:!0,children:e.jsxs(c.FormContainer,{children:[e.jsxs(c.InputsWrapper,{children:[e.jsxs(y,{id:"userContact-reason",name:"reason",InputProps:{required:!1},inputProps:{maxLength:100},required:!0,component:c.TextField,label:t.formatMessage({id:"userContact.reason"}),select:!0,SelectProps:{displayEmpty:!0},children:[e.jsx(D,{value:"",disabled:!0,children:e.jsx(S,{id:"common.select"})}),F.map((u,C)=>e.jsx(D,{value:u.value,children:u.label},`UserContact-Form-reasonOptions--${C.toString()}`))]}),e.jsx(y,{id:"contact-subject",name:"subject",required:!0,InputProps:{required:!1},inputProps:{maxLength:100},component:c.TextField,label:t.formatMessage({id:"userContact.subject"}),placeholder:t.formatMessage({id:"userContact.placeholders.subject"})})]}),e.jsx(y,{id:"userContact-message",name:"message",required:!0,InputProps:{required:!1},inputProps:{maxLength:500},component:c.TextField,label:t.formatMessage({id:"userContact.message"}),multiline:!0,placeholder:t.formatMessage({id:"userContact.placeholders.message"})}),e.jsx(y,{id:"userContact-files",name:"files",component:G,onChange:j,onMultiFileChange:E,onDelete:T,files:s==null?void 0:s.files,accept:q.join(", "),maxFiles:5}),e.jsx(y,{id:"contact-ccEmails",name:"ccEmails",multiply:!0,component:c.TextField,label:t.formatMessage({id:"userContact.ccEmails"}),placeholder:t.formatMessage({id:"userContact.placeholders.ccEmails"})}),x&&e.jsx(c.ErrorMessage,{children:e.jsx(S,{id:"common.errors.generic"})})]})}),e.jsxs(c.ActionsWrapper,{children:[e.jsx(c.Button,{variant:"outlined",onClick:g,children:e.jsx(S,{id:"common.cancel"})}),e.jsx(c.Button,{loading:n||h,type:"submit",children:e.jsx(S,{id:"common.send"})})]})]})}})})}function te(){const d=I(),g=H(),{open:t,closeContact:o}=P.useContext(O),h=()=>{o(),g.showSuccess(d.formatMessage({id:"userContact.successMessage"}))};return e.jsx(W.Dialog,{open:t,hasPadding:!0,avoidBackdropClose:!0,onClose:o,title:d.formatMessage({id:"userContact.title"}),children:e.jsx(J,{onCancel:o,onSuccess:h})})}export{te as U};