1import{u as $,r as o,j as e,L as G,d as H,a as U}from"./index-BGB5_nt1.js";const V=["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","image/png","image/jpeg","image/bmp"],x=[".pdf",".docx",".xlsx",".pptx",".png",".jpg",".jpeg",".bmp"];function K({assessmentId:v,existingDocuments:y=[]}){const{t:S}=$(),j=o.useRef(null),[F,N]=o.useState(!1),[i,c]=o.useState(),[u,w]=o.useState(!1),[k,r]=o.useState(null),[L,d]=o.useState(null),[h,f]=o.useState(y),[B,p]=o.useState(!1),[n,g]=o.useState(null),[b,D]=o.useState(!1),C=s=>{var a;const t="."+((a=s.name.split(".").pop())==null?void 0:a.toLowerCase());return x.includes(t)?V.includes(s.type)?!0:(r(`El archivo ${s.name} no es de un tipo permitido.`),!1):(r(`El archivo ${s.name} no es de un tipo permitido. Los tipos permitidos son: ${x.join(", ")}`),!1)},E=s=>new Promise((t,a)=>{const l=new FileReader;l.readAsDataURL(s),l.onload=()=>{var m;t({name:s.name,content:((m=l.result)==null?void 0:m.toString().split(",")[1])||"",size:s.size})},l.onerror=m=>a(m)}),z=async s=>{if(r(null),d(null),s.target.files&&s.target.files[0]){const t=s.target.files[0];if(C(t)){const a=await E(t);c(a)}}},A=s=>{s.preventDefault(),s.currentTarget.classList.add("bg-blue-50")},M=s=>{s.preventDefault(),s.currentTarget.classList.remove("bg-blue-50")},O=async s=>{if(s.preventDefault(),s.currentTarget.classList.remove("bg-blue-50"),r(null),d(null),s.dataTransfer.files&&s.dataTransfer.files[0]){const t=s.dataTransfer.files[0];if(C(t)){const a=await E(t);c(a)}}},T=s=>{if(s===0)return"0 Bytes";const t=1024,a=["Bytes","KB","MB","GB"],l=Math.floor(Math.log(s)/Math.log(t));return parseFloat((s/Math.pow(t,l)).toFixed(2))+" "+a[l]},W=()=>{N(!0),r(null),d(null),c(void 0),f(y)},I=()=>{u||(N(!1),c(void 0),r(null),d(null),window.location.reload())},P=s=>{g(s),p(!0)},R=async()=>{if(!(n!=null&&n.id)){console.error("No document ID found for deletion"),r("Error al eliminar el archivo: ID no encontrado");return}D(!0);try{await H(n.id),f(s=>s.filter(t=>t.id!==n.id)),d("Archivo eliminado exitosamente.")}catch(s){console.error("Error eliminando archivo: ",s),r("Error al eliminar el archivo")}finally{D(!1),p(!1),g(null)}},_=async()=>{if(!i){r("Por favor selecciona un archivo para subir");return}w(!0);try{const s={assessmentId:v,documentName:i.name,documentContent:i.content},t=await U(s);if(!t)throw new Error("No se recibió respuesta del servidor");const a={id:Number(t.id),documentName:i.name,assessmentId:v,uploadedBy:t.uploadedBy||"",uploadedByName:t.uploadedByName||""};f(l=>[...l,a]),d("Archivo subido exitosamente. Puedes subir otro archivo o cerrar esta ventana."),c(void 0),window.location.reload()}catch(s){console.error("Error subiendo archivo: ",s),r("Error al subir el archivo")}finally{w(!1)}};return e.jsxs(o.Fragment,{children:[e.jsx("button",{className:"flex items-center justify-center p-2 text-white transition-all duration-200 transform bg-blue-600 rounded-lg shadow-sm hover:bg-blue-700 active:bg-blue-800 hover:shadow-md hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-blue-600 disabled:hover:scale-100",onClick:W,children:"Subir Archivos"}),F&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center overflow-y-auto bg-black bg-opacity-50",children:e.jsx("div",{className:"w-full bg-white md:min-h-fit md:rounded-xl md:shadow-xl md:max-w-4xl md:my-8 md:mx-4",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"sticky top-0 z-10 flex-shrink-0 px-4 py-4 bg-white border-b border-gray-200",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-800",children:"Subir Archivos"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"Puedes cargar varios archivos de forma secuencial. Selecciona un archivo, súbelo y repite el proceso para agregar más."})]},"modal-header"),e.jsx("div",{className:"flex-grow p-4",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-6 text-center transition-colors duration-200 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer hover:border-blue-500",onDragOver:A,onDragLeave:M,onDrop:O,onClick:()=>{var s;return(s=j.current)==null?void 0:s.click()},children:[e.jsx("input",{type:"file",ref:j,onChange:z,accept:x.join(","),className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"w-12 h-12 mx-auto text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 14v20c0 4.418 3.582 8 8 8h16c4.418 0 8-3.582 8-8V14m-16-4v16m-8-8h16"})}),e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("span",{className:"font-medium text-blue-600 hover:text-blue-500",children:"Haz clic para seleccionar"})," ","o arrastra y suelta"]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Formatos permitidos:"," ",x.join(", ")
1]})]},"dropzone-content")]},"dropzone"),k&&e.jsx("div",{className:"p-3 text-sm text-red-600 rounded-md bg-red-50",children:k},"error-message"),L&&e.jsx("div",{className:"p-3 text-sm text-green-600 rounded-md bg-green-50",children:L},"success-message"),i&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-gray-700",children:"Archivo listo para subir"}),e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-gray-50",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-sm text-gray-600",children:i.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",T(i.size),")"]})]}),e.jsx("button",{type:"button",onClick:()=>c(void 0),className:"text-red-500 hover:text-red-700",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{d:"M6 18L18 6M6 6l12 12"})})})]})]},"selected-file"),h.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("h4",{className:"mb-2 text-sm font-medium text-gray-700",children:["Archivos subidos (",h.length,")"]}),e.jsx("div",{className:"space-y-2",children:h.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-gray-50",children:[e.jsx("span",{className:"text-sm text-gray-600",children:s.documentName}),e.jsx("button",{type:"button",onClick:()=>P(s),className:"text-red-500 hover:text-red-700",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{d:"M6 18L18 6M6 6l12 12"})})})]},`doc-${s.id||"temp-"+Math.random()}`))})]})]})},"modal-body"),e.jsxs("div",{className:"sticky bottom-0 flex justify-end px-4 py-4 space-x-3 bg-white border-t border-gray-200",children:[e.jsx("button",{type:"button",onClick:I,disabled:u,className:"px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-200 rounded-md hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50",children:S("common.close")}),e.jsx("button",{onClick:_,disabled:!i&&!n||u,className:"px-4 py-2 text-sm font-medium text-white transition-colors duration-200 bg-blue-600 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",children:i?"Subir Archivo":n?"Guardar Cambios":"Subir Archivo"})]},"modal-footer")]},"modal-content")},"modal-container")},"modal-overlay"),B&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black bg-opacity-50",children:e.jsx("div",{className:"w-full max-w-md mx-4 bg-white rounded-lg shadow-xl",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"¿Confirmar eliminación?"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["¿Estás seguro que deseas eliminar el archivo"," ",n==null?void 0:n.documentName,"? Esta acción no se puede deshacer."]})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{type:"button",onClick:()=>{p(!1),g(null)},disabled:b,className:"px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-200 bg-gray-100 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50",children:"Cancelar"}),e.jsx("button",{type:"button",onClick:R,disabled:b,className:"relative px-4 py-2 text-sm font-medium text-white transition-colors duration-200 bg-red-600 rounded-md hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50",children:b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-0",children:"Eliminar"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("svg",{className:"w-5 h-5 text-white animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})]}):"Eliminar"})]})]})})}),e.jsx(G,{loading:u})]},"addfile-fragment")}export{K as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.