dccxx-s3-explorer 1.0.11-vib → 1.0.12-vib

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -214,6 +214,6 @@ Valid keys: `+JSON.stringify(Object.keys(U),null," "));var we=nt(Oe,Me,Te,Ne,Se
214
214
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function e$(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function t$(t){if(Array.isArray(t))return Am(t)}function CE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function bE(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?CE(Object(n),!0).forEach(function(r){xE(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):CE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function xE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function bc(t,e){return o$(t)||r$(t,e)||_E(t,e)||n$()}function n$(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
215
215
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _E(t,e){if(t){if(typeof t=="string")return Am(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Am(t,e)}}function Am(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r$(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(f){a=!0,l=f}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function o$(t){if(Array.isArray(t))return t}var i$=typeof Sm=="function"?Sm:Sm.default,a$="file-invalid-type",s$="file-too-large",c$="file-too-small",l$="too-many-files",d$=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=e.split(","),r=n.length>1?"one of ".concat(n.join(", ")):n[0];return{code:a$,message:"File type must be ".concat(r)}},TE=function(e){return{code:s$,message:"File is larger than ".concat(e," ").concat(e===1?"byte":"bytes")}},EE=function(e){return{code:c$,message:"File is smaller than ".concat(e," ").concat(e===1?"byte":"bytes")}},u$={code:l$,message:"Too many files"};function SE(t,e){var n=t.type==="application/x-moz-file"||i$(t,e);return[n,n?null:d$(e)]}function AE(t,e,n){if(ji(t.size))if(ji(e)&&ji(n)){if(t.size>n)return[!1,TE(n)];if(t.size<e)return[!1,EE(e)]}else{if(ji(e)&&t.size<e)return[!1,EE(e)];if(ji(n)&&t.size>n)return[!1,TE(n)]}return[!0,null]}function ji(t){return t!=null}function f$(t){var e=t.files,n=t.accept,r=t.minSize,o=t.maxSize,a=t.multiple,c=t.maxFiles,l=t.validator;return!a&&e.length>1||a&&c>=1&&e.length>c?!1:e.every(function(f){var h=SE(f,n),p=bc(h,1),g=p[0],w=AE(f,r,o),v=bc(w,1),C=v[0],y=l?l(f):null;return g&&C&&!y})}function Ru(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function Du(t){return t.dataTransfer?Array.prototype.some.call(t.dataTransfer.types,function(e){return e==="Files"||e==="application/x-moz-file"}):!!t.target&&!!t.target.files}function IE(t){t.preventDefault()}function h$(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function p$(t){return t.indexOf("Edge/")!==-1}function g$(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return h$(t)||p$(t)}function fo(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return function(r){for(var o=arguments.length,a=new Array(o>1?o-1:0),c=1;c<o;c++)a[c-1]=arguments[c];return e.some(function(l){return!Ru(r)&&l&&l.apply(void 0,[r].concat(a)),Ru(r)})}}function m$(){return"showOpenFilePicker"in window}function v$(t){if(ji(t)){var e=Object.entries(t).filter(function(n){var r=bc(n,2),o=r[0],a=r[1],c=!0;return kE(o)||(console.warn('Skipped "'.concat(o,'" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.')),c=!1),(!Array.isArray(a)||!a.every(NE))&&(console.warn('Skipped "'.concat(o,'" because an invalid file extension was provided.')),c=!1),c}).reduce(function(n,r){var o=bc(r,2),a=o[0],c=o[1];return bE(bE({},n),{},xE({},a,c))},{});return[{description:"Files",accept:e}]}return t}function y$(t){if(ji(t))return Object.entries(t).reduce(function(e,n){var r=bc(n,2),o=r[0],a=r[1];return[].concat(wE(e),[o],wE(a))},[]).filter(function(e){return kE(e)||NE(e)}).join(",")}function w$(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function C$(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function kE(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function NE(t){return/^.*\.[\w]+$/.test(t)}var b$=["children"],x$=["open"],_$=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],T$=["refKey","onChange","onClick"];function E$(t){return I$(t)||A$(t)||PE(t)||S$()}function S$(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
216
216
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function A$(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function I$(t){if(Array.isArray(t))return km(t)}function Im(t,e){return P$(t)||N$(t,e)||PE(t,e)||k$()}function k$(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
217
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function PE(t,e){if(t){if(typeof t=="string")return km(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return km(t,e)}}function km(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function N$(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(f){a=!0,l=f}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function P$(t){if(Array.isArray(t))return t}function OE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Ut(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?OE(Object(n),!0).forEach(function(r){Nm(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):OE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Nm(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Fu(t,e){if(t==null)return{};var n=O$(t,e),r,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(o=0;o<a.length;o++)r=a[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function O$(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,a;for(a=0;a<r.length;a++)o=r[a],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var Pm=O.forwardRef(function(t,e){var n=t.children,r=Fu(t,b$),o=RE(r),a=o.open,c=Fu(o,x$);return O.useImperativeHandle(e,function(){return{open:a}},[a]),O.createElement(O.Fragment,null,n(Ut(Ut({},c),{},{open:a})))});Pm.displayName="Dropzone";var ME={disabled:!1,getFilesFromEvent:VU,maxSize:1/0,minSize:0,multiple:!0,maxFiles:0,preventDropOnDocument:!0,noClick:!1,noKeyboard:!1,noDrag:!1,noDragEventsBubbling:!1,validator:null,useFsAccessApi:!1,autoFocus:!1};Pm.defaultProps=ME,Pm.propTypes={children:It.func,accept:It.objectOf(It.arrayOf(It.string)),multiple:It.bool,preventDropOnDocument:It.bool,noClick:It.bool,noKeyboard:It.bool,noDrag:It.bool,noDragEventsBubbling:It.bool,minSize:It.number,maxSize:It.number,maxFiles:It.number,disabled:It.bool,getFilesFromEvent:It.func,onFileDialogCancel:It.func,onFileDialogOpen:It.func,useFsAccessApi:It.bool,autoFocus:It.bool,onDragEnter:It.func,onDragLeave:It.func,onDragOver:It.func,onDrop:It.func,onDropAccepted:It.func,onDropRejected:It.func,onError:It.func,validator:It.func};var Om={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function RE(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Ut(Ut({},ME),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,a=e.maxSize,c=e.minSize,l=e.multiple,f=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,g=e.onDragOver,w=e.onDrop,v=e.onDropAccepted,C=e.onDropRejected,y=e.onFileDialogCancel,_=e.onFileDialogOpen,I=e.useFsAccessApi,k=e.autoFocus,R=e.preventDropOnDocument,M=e.noClick,S=e.noKeyboard,z=e.noDrag,V=e.noDragEventsBubbling,j=e.onError,te=e.validator,W=O.useMemo(function(){return y$(n)},[n]),me=O.useMemo(function(){return v$(n)},[n]),ce=O.useMemo(function(){return typeof _=="function"?_:DE},[_]),xe=O.useMemo(function(){return typeof y=="function"?y:DE},[y]),K=O.useRef(null),Z=O.useRef(null),q=O.useReducer(M$,Om),oe=Im(q,2),Q=oe[0],J=oe[1],U=Q.isFocused,ne=Q.isFileDialogActive,_e=O.useRef(typeof window<"u"&&window.isSecureContext&&I&&m$()),Ee=function(){!_e.current&&ne&&setTimeout(function(){if(Z.current){var ge=Z.current.files;ge.length||(J({type:"closeDialog"}),xe())}},300)};O.useEffect(function(){return window.addEventListener("focus",Ee,!1),function(){window.removeEventListener("focus",Ee,!1)}},[Z,ne,xe,_e]);var Te=O.useRef([]),Ne=function(ge){K.current&&K.current.contains(ge.target)||(ge.preventDefault(),Te.current=[])};O.useEffect(function(){return R&&(document.addEventListener("dragover",IE,!1),document.addEventListener("drop",Ne,!1)),function(){R&&(document.removeEventListener("dragover",IE),document.removeEventListener("drop",Ne))}},[K,R]),O.useEffect(function(){return!r&&k&&K.current&&K.current.focus(),function(){}},[K,k,r]);var Se=O.useCallback(function(re){j?j(re):console.error(re)},[j]),Oe=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re),Te.current=[].concat(E$(Te.current),[re.target]),Du(re)&&Promise.resolve(o(re)).then(function(ge){if(!(Ru(re)&&!V)){var Be=ge.length,Qe=Be>0&&f$({files:ge,accept:W,minSize:c,maxSize:a,multiple:l,maxFiles:f,validator:te}),pt=Be>0&&!Qe;J({isDragAccept:Qe,isDragReject:pt,isDragActive:!0,type:"setDraggedFiles"}),h&&h(re)}}).catch(function(ge){return Se(ge)})},[o,h,Se,V,W,c,a,l,f,te]),De=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re);var ge=Du(re);if(ge&&re.dataTransfer)try{re.dataTransfer.dropEffect="copy"}catch{}return ge&&g&&g(re),!1},[g,V]),Ue=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re);var ge=Te.current.filter(function(Qe){return K.current&&K.current.contains(Qe)}),Be=ge.indexOf(re.target);Be!==-1&&ge.splice(Be,1),Te.current=ge,!(ge.length>0)&&(J({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Du(re)&&p&&p(re))},[K,p,V]),Me=O.useCallback(function(re,ge){var Be=[],Qe=[];re.forEach(function(pt){var hn=SE(pt,W),kn=Im(hn,2),Wt=kn[0],Hn=kn[1],vr=AE(pt,c,a),zt=Im(vr,2),Bn=zt[0],mo=zt[1],Br=te?te(pt):null;if(Wt&&Bn&&!Br)Be.push(pt);else{var ze=[Hn,mo];Br&&(ze=ze.concat(Br)),Qe.push({file:pt,errors:ze.filter(function(vo){return vo})})}}),(!l&&Be.length>1||l&&f>=1&&Be.length>f)&&(Be.forEach(function(pt){Qe.push({file:pt,errors:[u$]})}),Be.splice(0)),J({acceptedFiles:Be,fileRejections:Qe,isDragReject:Qe.length>0,type:"setFiles"}),w&&w(Be,Qe,ge),Qe.length>0&&C&&C(Qe,ge),Be.length>0&&v&&v(Be,ge)},[J,l,W,c,a,f,w,v,C,te]),nt=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re),Te.current=[],Du(re)&&Promise.resolve(o(re)).then(function(ge){Ru(re)&&!V||Me(ge,re)}).catch(function(ge){return Se(ge)}),J({type:"reset"})},[o,Me,Se,V]),we=O.useCallback(function(){if(_e.current){J({type:"openDialog"}),ce();var re={multiple:l,types:me};window.showOpenFilePicker(re).then(function(ge){return o(ge)}).then(function(ge){Me(ge,null),J({type:"closeDialog"})}).catch(function(ge){w$(ge)?(xe(ge),J({type:"closeDialog"})):C$(ge)?(_e.current=!1,Z.current?(Z.current.value=null,Z.current.click()):Se(new Error("Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided."))):Se(ge)});return}Z.current&&(J({type:"openDialog"}),ce(),Z.current.value=null,Z.current.click())},[J,ce,xe,I,Me,Se,me,l]),lt=O.useCallback(function(re){!K.current||!K.current.isEqualNode(re.target)||(re.key===" "||re.key==="Enter"||re.keyCode===32||re.keyCode===13)&&(re.preventDefault(),we())},[K,we]),Ct=O.useCallback(function(){J({type:"focus"})},[]),fn=O.useCallback(function(){J({type:"blur"})},[]),In=O.useCallback(function(){M||(g$()?setTimeout(we,0):we())},[M,we]),Lt=function(ge){return r?null:ge},D=function(ge){return S?null:Lt(ge)},G=function(ge){return z?null:Lt(ge)},X=function(ge){V&&ge.stopPropagation()},be=O.useMemo(function(){return function(){var re=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ge=re.refKey,Be=ge===void 0?"ref":ge,Qe=re.role,pt=re.onKeyDown,hn=re.onFocus,kn=re.onBlur,Wt=re.onClick,Hn=re.onDragEnter,vr=re.onDragOver,zt=re.onDragLeave,Bn=re.onDrop,mo=Fu(re,_$);return Ut(Ut(Nm({onKeyDown:D(fo(pt,lt)),onFocus:D(fo(hn,Ct)),onBlur:D(fo(kn,fn)),onClick:Lt(fo(Wt,In)),onDragEnter:G(fo(Hn,Oe)),onDragOver:G(fo(vr,De)),onDragLeave:G(fo(zt,Ue)),onDrop:G(fo(Bn,nt)),role:typeof Qe=="string"&&Qe!==""?Qe:"presentation"},Be,K),!r&&!S?{tabIndex:0}:{}),mo)}},[K,lt,Ct,fn,In,Oe,De,Ue,nt,S,z,r]),ye=O.useCallback(function(re){re.stopPropagation()},[]),pe=O.useMemo(function(){return function(){var re=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ge=re.refKey,Be=ge===void 0?"ref":ge,Qe=re.onChange,pt=re.onClick,hn=Fu(re,T$),kn=Nm({accept:W,multiple:l,type:"file",style:{border:0,clip:"rect(0, 0, 0, 0)",clipPath:"inset(50%)",height:"1px",margin:"0 -1px -1px 0",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"},onChange:Lt(fo(Qe,nt)),onClick:Lt(fo(pt,ye)),tabIndex:-1},Be,Z);return Ut(Ut({},kn),hn)}},[Z,n,l,nt,r]);return Ut(Ut({},Q),{},{isFocused:U&&!r,getRootProps:be,getInputProps:pe,rootRef:K,inputRef:Z,open:Lt(we)})}function M$(t,e){switch(e.type){case"focus":return Ut(Ut({},t),{},{isFocused:!0});case"blur":return Ut(Ut({},t),{},{isFocused:!1});case"openDialog":return Ut(Ut({},Om),{},{isFileDialogActive:!0});case"closeDialog":return Ut(Ut({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ut(Ut({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Ut(Ut({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Ut({},Om);default:return t}}function DE(){}const R$=({onFilesSelected:t,children:e})=>{const[n,r]=O.useState(!1),{getRootProps:o,getInputProps:a}=RE({noClick:!0,onDrop:c=>{if(c&&c.length>0)if(c[0].path.split("/").length>2){const f=c.map(h=>{const g=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),h});t(f,"folder")}else t(c,"files");r(!1)},onDragOver:c=>{c.preventDefault(),n||r(!0)},multiple:!0});return O.useEffect(()=>{const c=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",c),()=>{document.removeEventListener("dragleave",c)}},[]),u.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?u.jsx("div",{className:"flex flex-col items-center justify-center p-4 border-2 border-dashed border-gray-300 rounded-lg bg-gray-50 h-screen"}):e,u.jsx("input",{...a()})]})},D$=({isOpen:t,onClose:e,files:n})=>{const[r,o]=O.useState(null),a=l=>{o(f=>!f||f.key!==l?{key:l,direction:"asc"}:{key:l,direction:f.direction==="asc"?"desc":"asc"})},c=O.useMemo(()=>r?[...n].sort((l,f)=>{var g,w;const h=((g=l[r.key])==null?void 0:g.toString().toLowerCase())||"",p=((w=f[r.key])==null?void 0:w.toString().toLowerCase())||"";return h<p?r.direction==="asc"?-1:1:h>p?r.direction==="asc"?1:-1:0}):n,[n,r]);return console.log("sortedParsingFiles",c),u.jsx(gr,{open:t,onOpenChange:e,children:u.jsxs(er,{className:"sm:max-w-[825px]",children:[u.jsxs(tr,{children:[u.jsx(nr,{children:"Tài liệu đang xử lý"}),u.jsx(Ro,{children:"Đây là danh sách các tài liệu đang trong hàng đợi xử lý."})]}),u.jsx("div",{className:"max-h-96 overflow-y-auto",children:u.jsxs(lc,{children:[u.jsx(dc,{children:u.jsxs(rr,{children:[u.jsxs(or,{colSpan:2,className:"text-left cursor-pointer hover:underline",onClick:()=>a("type"),children:["Loại ",(r==null?void 0:r.key)==="type"&&(r.direction==="asc"?"↑":"↓")]}),u.jsxs(or,{colSpan:3,className:"text-left cursor-pointer hover:underline",onClick:()=>a("name"),children:["Tên tệp"," ",(r==null?void 0:r.key)==="name"&&(r.direction==="asc"?"↑":"↓")]}),u.jsx(or,{className:"text-left",children:"Ghi chú"})]})}),u.jsx(uc,{children:c.length>0&&c.map(l=>u.jsxs(rr,{children:[u.jsx(un,{colSpan:2,children:l.type}),u.jsx(un,{colSpan:3,className:"font-medium text-left truncate max-w-[200px]",title:l.name,children:l.name}),u.jsx(un,{children:!!l.unSupported&&!l.isFolder&&`Không hỗ trợ file ${l.name.split(".").pop()}`})]}))})]})})]})})},F$=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:a,ignoreCache:c,autoSyncAfterFileOperation:l})=>{var R;const[f,h]=O.useState({}),[p,g]=O.useState(!1),[w,v]=O.useState(!1),[C,y]=O.useState(""),{toast:_}=yu();O.useEffect(()=>{t&&I(C)},[C,t]);const I=async M=>{try{v(!0);const S=await Le.get(`${n}/api/list-s3-folders?prefix=${M}`,{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});h(S==null?void 0:S.data)}catch{_({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{v(!1)}},k=async()=>{g(!0);try{const M=o.key,S=M.endsWith("/")?M:`${M}/`,z=C.endsWith("/")?C:`${C}/`;if(S===z||M===C){_({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),g(!1);return}await Le.post(`${n}/api/move`,{oldPath:M,newPath:C},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),c.current=!0,await a(),_({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${C}"`}),e(!1),r(null),y(""),l&&await l("move")}catch(M){console.error("Error renaming item:",M),_({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{g(!1)}};return u.jsx(gr,{open:t,onOpenChange:M=>{M||(e(!1),r(null),y(""))},children:u.jsxs(er,{className:"max-h-[700px] pb-3 px-1 s3-explr-input-group max-w-5xl w-[90%] p-6 bg-white rounded-lg shadow-lg",children:[u.jsxs(tr,{className:"mb-4 w-full h-full",children:[u.jsx("nav",{className:"mb-4",children:u.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[u.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(""),children:"Root"}),C.split("/").map((M,S,z)=>u.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(M==="Root"?"":z.slice(0,S+1).join("/")+"/"),children:M},S))]})}),u.jsxs(nr,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",u.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",C===""?"Root":C," )"]})]}),u.jsx(Ro,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:w?u.jsx("div",{className:"flex justify-center items-center py-4",children:u.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):u.jsx("ul",{className:"space-y-2",children:(R=Object.keys(f))==null?void 0:R.map(M=>u.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>y(M),children:M},M))})})]}),u.jsxs(Mo,{className:"flex justify-end space-x-2",children:[u.jsx($e,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),u.jsx($e,{onClick:k,disabled:p,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},L$="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",U$="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",$$="https://www.googleapis.com/auth/drive";Po(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Po.isRetryableError(t)&&t.config.method==="get"});const Un={current:!1},FE="crawl:jobs",es="crawl:current_job",H$=t=>{const[e,n]=O.useState(null),[r,o]=O.useState(0);return O.useEffect(()=>{const a=localStorage.getItem(es);if(a){const c=JSON.parse(a);n(c),c!=null&&c.startTime&&o(Math.floor((Date.now()-c.startTime)/1e3))}},[]),O.useEffect(()=>{if(!(e!=null&&e.startTime))return;const a=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(a)},[e==null?void 0:e.startTime]),O.useEffect(()=>{if(!(e!=null&&e.id))return;const a=async()=>{try{const f=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:f};return localStorage.setItem(es,JSON.stringify(p)),(f.status==="completed"||f.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(es)},100),p})}catch(l){console.error("Error polling job status:",l)}},c=setInterval(a,3e3);return a(),()=>clearInterval(c)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:a=>{a&&!a.startTime&&(a.startTime=Date.now()),n(a),a?localStorage.setItem(es,JSON.stringify(a)):localStorage.removeItem(es)}}},Lu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(c=>{n.push(c.key),c.isFolder&&r(c.key)})};return r(e),n},B$=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Lu(t,o.key))}),n},z$=(t,e,n=[],r,o,a,c,l,f,h)=>{const[p,g]=O.useState({}),[w,v]=O.useState(!1),[C,y]=O.useState(null),[_,I]=O.useState(0),k=O.useRef(e);O.useEffect(()=>{k.current=e},[e]);const R=async()=>{v(!0);try{const S=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:k.current,excludePrivateFiles:c?"false":"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5}),z=[];Qd.forEach(S.data,(V,j)=>{l!=null&&l.has(j)&&Qd.forEach(V,te=>{(f==null?void 0:f.current[te.key])!==!1&&z.push(te.key)})}),z.length&&(h==null||h(V=>{const j=new Set(V);return z.forEach(te=>j.add(te)),j})),g(S.data),y(null)}catch(S){y(S instanceof Error?S:new Error("Failed to fetch files"))}finally{v(!1),I(0),a("")}},M=async S=>{var z,V;try{if(!S)return;v(!0);const j=await Le.get(`${t}/api/search-db?query=${S}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5,headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});return g({[e]:((z=j==null?void 0:j.data)==null?void 0:z.result)||[]}),I(((V=j==null?void 0:j.data)==null?void 0:V.estimatedTotalHits)||0),j}catch(j){y(j instanceof Error?j:new Error("Failed to fetch files"))}finally{v(!1)}};return O.useEffect(()=>{!r&&!w&&R(),r&&!w&&M(r)},[r,o]),{data:p,isLoading:w,error:C,estimatedTotalHits:_,refetch:R}},xc=t=>{var r,o,a;const e=((a=(o=(r=t==null?void 0:t.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:a.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(e||"")},G$={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:"http://localhost:5173/"}},V$=new Cp(G$),K$=O.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3000",rootPrefix:n="",rootUrlHostApi:r,asSelector:o=!1,onSelected:a=h=>console.log("Đã chọn:",h),displayPrefixes:c,preSelectedFiles:l,idCreator:f})=>{var pf;const[h,p]=O.useState([]),[g,w]=O.useState(""),[v,C]=O.useState(new Set(l)),[y,_]=O.useState(n),[I,k]=O.useState(""),[R,M]=O.useState(!1),[S,z]=O.useState(""),[V,j]=O.useState(!1),[te,W]=O.useState(null),[me,ce]=O.useState(null),[xe,K]=O.useState(!1),[Z,q]=O.useState(!1),[,oe]=O.useState(null),Q=O.useRef(null),{toast:J}=yu(),[U,ne]=O.useState(null),[_e,Ee]=O.useState(null),[Te,Ne]=O.useState(""),[Se,Oe]=O.useState(!1),[De,Ue]=O.useState(!1),[Me,nt]=O.useState(new Set),[we,lt]=O.useState(""),[Ct,fn]=O.useState(!1),[In,Lt]=O.useState(!1),[D,G]=O.useState("rename"),[X,be]=O.useState(!1),[ye,pe]=O.useState(""),[re,ge]=O.useState("1"),[Be,Qe]=O.useState(!1),[pt,hn]=O.useState(!1),[kn,Wt]=O.useState(!1),[Hn,vr]=O.useState(!1),[zt,Bn]=O.useState(1),[mo,Br]=O.useState(!1),{currentJob:ze,elapsedTime:vo,setCurrentJob:Vu}=H$(e),[zr,wi]=O.useState(null),[qi,ns]=O.useState(""),[Bm,Yi]=O.useState(!1),[Ji,Ku]=O.useState(""),[zm,ju]=O.useState(!1),[Ac,Wu]=O.useState(!1),[Ci,qu]=O.useState([]),[Qi,Yu]=O.useState(!1),[rs,Gm]=O.useState(""),[Ju,Vm]=O.useState({faqUploadSize:[],hdsdUploadSize:[],normalUploadSize:[],faqParsedSize:[],hdsdParsedSize:[],normalParsedSize:[]}),[Km,Ic]=O.useState(!1),Ho=O.useRef({}),jm=async T=>{Wu(!0);try{const N=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${T}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});N.status===200&&qu(N.data.knowledgeBase.chatflows.map($=>({...$,KnowledgeBaseId:N.data.knowledgeBase.knowledge_base_id})))}catch{}finally{Wu(!1)}};O.useEffect(()=>{Ji&&r&&jm(Ji)},[Ji]),O.useEffect(()=>{console.log("pre selected files",l)},[l]);const[kt,kc]=O.useState(null),[rS,Wm]=O.useState(!1),[Nc,Pc]=O.useState(!1),[Xi,os]=O.useState(!1),[Qu,Xu]=O.useState([]),[Oc,Mc]=O.useState([]),[Zi,Rc]=O.useState([{id:"root",name:"OneDrive"}]),[qm,is]=O.useState(!1),[as,Dc]=O.useState([]),[Zu,Bo]=O.useState(!1),[ss,Fc]=O.useState([]),[Lc,cs]=O.useState([]),[ls,ef]=O.useState([]),[Uc,ea]=O.useState([{id:"root",name:"SharePoint"}]),[yo,ta]=O.useState(!1),[$c,Hc]=O.useState([]),[gt,Gr]=O.useState(null),[tf,na]=O.useState(!1),[Ym,ra]=O.useState(!1),nf=new URL(window.location.href).searchParams.get("prefix")||""||I||n,[oS,Xm]=O.useState(null),{data:wo,isLoading:bi,error:Zm,estimatedTotalHits:oa,refetch:on}=z$(e,nf,c,g,zt,w,f,v,Ho,C),[Bc,yr]=O.useState(!1),zc=O.useRef(null);O.useEffect(()=>{if(!Bc)return;function T(N){zc.current&&!zc.current.contains(N.target)&&yr(!1)}return document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[Bc]);const ev=async()=>{try{const T=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:N}=T.data,$=window.open(N,"SharePoint Login","width=600,height=600");if(!$)throw new Error("Không thể mở cửa sổ pop-up");$.focus();const ie=setInterval(()=>{try{if($.closed){clearInterval(ie);return}const fe=$.location.href;if(fe.includes("code=")){const Ce=new URL(fe).searchParams.get("code");Ce&&(rf(Ce),$.close(),clearInterval(ie))}}catch(fe){fe instanceof Error&&!fe.message.includes("cross-origin")&&console.error("SharePoint login error:",fe)}},1e3)}catch(T){at.error("Lỗi khi đăng nhập SharePoint: "+(T instanceof Error?T.message:"Unknown error"))}},tv=async()=>{try{Fc([]),ea([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),J({title:"Success",description:"Logged out from SharePoint"})}catch(T){console.error("Error logging out from SharePoint:",T),J({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},rf=async T=>{try{const N=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:T,userId:"1"}),{accessToken:$}=N.data;localStorage.setItem("sharepoint_access_token",$),Pc(!0),ta(!0)}catch(N){console.error("❌ Error fetching SharePoint access token:",N),J({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},nv=async()=>{try{Bo(!0);const N=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map($=>{const ie=new URL($.webUrl);return{id:$.id,name:$.name,description:$.description,hostname:$.hostname||ie.hostname,sitePath:$.sitePath||ie.pathname.replace(/^\/+/,"")}});Hc(N),Bo(!1)}catch(T){console.error("❌ Error fetching SharePoint sites:",T),J({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),Bo(!1)}},Nt=async T=>{Gr(T),await mt("root",T.name,T.hostname||"",T.sitePath||"")},mt=async(T,N,$,ie)=>{try{Bo(!0);const Ce=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:T,userId:"1",hostname:$,sitePath:ie})).data.files.map(Ae=>({id:Ae.id,name:Ae.name,size:Ae.size??0,lastModified:Ae.lastModifiedDateTime?new Date(Ae.lastModifiedDateTime):new Date,contentType:Ae.mimeType??void 0,isFolder:Ae.type==="folder",parentId:Ae.parentId??""}));cs(Ce.filter(Ae=>Ae.isFolder)),Fc(Ce.filter(Ae=>!Ae.isFolder)),ta(!0),ea(Ae=>Ae.some(Et=>Et.id===T)?Ae:[...Ae,{id:T,name:N==="root"?"SharePoint":N}]),Bo(!1)}catch(fe){console.error("❌ Error fetching SharePoint files:",fe),J({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),Bo(!1)}},rv=T=>{ef(N=>N.some(ie=>ie.id===T.id)?N.filter(ie=>ie.id!==T.id):[...N,{id:T.id,name:T.name,size:T.size,lastModified:T.lastModified,contentType:T.contentType,isFolder:T.isFolder,parentId:T.parentId}])},ov=T=>{var $;ea(ie=>ie.slice(0,T+1));const N=($=Uc[T])==null?void 0:$.id;N&&mt(N,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},iv=async(T,N)=>{const $=localStorage.getItem("sharepoint_access_token");if(!$){at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const ie=at.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};T.forEach(Ae=>{Ae.isFolder?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-sharepoint-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),ta(!1)}catch(fe){console.error("Lỗi khi đồng bộ file từ SharePoint:",fe),at.update(ie,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},of=()=>{ta(!1),Fc([]),ef([]),ea([{id:"root",name:"SharePoint"}])};O.useEffect(()=>{if(yo){const N=new URLSearchParams(window.location.search).get("code");N&&(rf(N),window.history.replaceState({},document.title,window.location.pathname))}},[yo]),O.useEffect(()=>{V$.initialize().then(()=>{Wm(!0)}).catch(T=>console.error("❌ Lỗi khởi tạo MSAL:",T))},[]),O.useEffect(()=>{av()},[]);async function av(){localStorage.getItem("onedrive_access_token")&&Pc(!0)}const af=T=>{Dc(N=>N.some(ie=>ie.id===T.id)?N.filter(ie=>ie.id!==T.id):[...N,{id:T.id,name:T.name,size:T.size,lastModified:T.lastModified,contentType:T.contentType,isFolder:T.isFolder,parentId:T.parentId}])};function ds(T){if(T===0)return"0 B";const N=1024,$=["B","KB","MB","GB","TB"],ie=Math.floor(Math.log(T)/Math.log(N));return parseFloat((T/Math.pow(N,ie)).toFixed(1))+" "+$[ie]}function sv(T){const N=new Date(T);return N.toLocaleDateString()+" "+N.toLocaleTimeString()}const tn=async()=>{try{const T=await Le.get(`${e}/api/login-one-drive`),{loginUrl:N}=T.data,$=window.open(N,"OneDrive Login","width=600,height=600");if(!$)throw new Error("Không thể mở cửa sổ pop-up");$.focus();const ie=setInterval(()=>{try{if($.closed){clearInterval(ie);return}const fe=$.location.href;if(fe.includes("code=")){const Ce=new URL(fe).searchParams.get("code");Ce&&(zo(Ce),$.close(),clearInterval(ie))}}catch(fe){fe instanceof Error&&!fe.message.includes("cross-origin")&&console.error("OneDrive login error:",fe)}},1e3)}catch(T){at.error("Lỗi khi đăng nhập OneDrive: "+(T instanceof Error?T.message:"Unknown error"))}},Gc=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),at.success("Đã đăng xuất khỏi OneDrive"),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin)}catch(T){at.error("Lỗi khi đăng xuất OneDrive: "+(T instanceof Error?T.message:"Unknown error"))}},zo=async T=>{try{const $=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:T,userId:"1"}),{accessToken:ie}=$.data;localStorage.setItem("onedrive_access_token",ie),Pc(!0),os(!0),await ia("root","One Drive")}catch(N){console.error("❌ Lỗi khi lấy Access Token:",N)}},ia=async(T,N)=>{try{is(!0);const fe=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:T,userId:"1"})).data.map(Ce=>({id:Ce.id,name:Ce.name,size:Ce.size??0,lastModified:Ce.lastModifiedDateTime?new Date(Ce.lastModifiedDateTime):new Date,contentType:Ce.mimeType??void 0,isFolder:Ce.type==="folder",parentId:Ce.parentId??""}));Xu(fe.filter(Ce=>Ce.isFolder)),Mc(fe.filter(Ce=>!Ce.isFolder)),os(!0),Rc(Ce=>Ce.some(Ae=>Ae.id===T)?Ce:[...Ce,{id:T,name:N==="root"?"OneDrive":N}]),is(!1)}catch($){console.error("Lỗi lấy danh sách file:",$),is(!1)}},Vc=T=>{if(T===Zi.length-1)return;const N=Zi[T];N&&(Rc(Zi.slice(0,T+1)),ia(N.id,N.name))},zn=async(T,N)=>{const $=localStorage.getItem("onedrive_access_token");if(!$){at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const ie=at.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[]};T.forEach(Ae=>{Ae.isFolder?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-one-drive-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(fe){console.error("Lỗi khi đồng bộ file từ OneDrive:",fe),at.update(ie,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},Kc=()=>{os(!1),Rc([{id:"root",name:"OneDrive"}]),Xu([]),Mc([]),Dc([]),is(!1)},sf=DO({onSuccess:T=>{Xm(T.access_token),localStorage.setItem("google_access_token",T.access_token),cf(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:$$}),cf=T=>{const N=document.createElement("script");N.src="https://apis.google.com/js/api.js",N.onload=()=>{window.gapi.load("picker",()=>lf(T))},document.body.appendChild(N)},lf=T=>{const N=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),$=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(L$).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(N).addView($).setCallback(async fe=>{if(fe.action===window.google.picker.Action.PICKED){const Ce=fe.docs.map(Ae=>({id:Ae.id,name:Ae.name,mimeType:Ae.mimeType}));await df(Ce,y)}}).build().setVisible(!0)},df=async(T,N="")=>{const $=localStorage.getItem("google_access_token");if(!$){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const ie=at.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[]};T.forEach(Ae=>{Ae.mimeType==="application/vnd.google-apps.folder"?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-drive-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});Un.current=!0,on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(fe){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",fe),at.update(ie,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};O.useEffect(()=>{const T=N=>{if(N.data.action==="logout"){const $=document.createElement("iframe");$.style.display="none",$.src="https://accounts.google.com/Logout",document.body.appendChild($),setTimeout(()=>document.body.removeChild($),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),O.useEffect(()=>{const T=new Set(l);C(T)},[]),O.useEffect(()=>{ze!=null&&ze.status&&(ze.status.status==="completed"?(J({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${ze.url} với ${ze.status.completed} trang`}),Un.current=!0,on()):ze.status.status==="failed"&&J({title:"Thu thập website thất bại",description:`Không thể thu thập ${ze.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(pf=ze==null?void 0:ze.status)==null?void 0:pf.status]);const us=O.useMemo(()=>wo[y]||[],[wo,y]),Gt=O.useMemo(()=>us,[us,y,wo]);O.useEffect(()=>{const T=async $=>{var ie;try{return(ie=(await Le.get(`${e}/api/files`,{params:{prefix:$,cache:!1,displayPrefixes:JSON.stringify([]),excludePrivateFiles:"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5})).data)==null?void 0:ie[$]}catch(fe){return console.error("Error: ",fe),[]}};(async()=>{let $=n||"vib-sample/";$.endsWith("/")||($+="/");const ie=`${n}Pilot/FAQ/Uploads/`,fe=`${n}Pilot/HDSD/Uploads/`,Ce=`${n}Pilot/Normal_Files/Uploads/`,Ae=`${n}Pilot/FAQ/FAQs/`,Et=`${n}Pilot/HDSD/general/`,pn=`${n}Pilot/Normal_Files/processed/`,[Nn,Ei,cr,wr,Pn,Gn]=await Promise.all([T(ie),T(fe),T(Ce),T(Ae),T(Et),T(pn)]);Vm({faqUploadSize:Nn,hdsdUploadSize:Ei,normalUploadSize:cr,faqParsedSize:wr,hdsdParsedSize:Pn,normalParsedSize:Gn})})()},[JSON.stringify(us)]);const aa=O.useMemo(()=>{const T=Nn=>Nn.key&&!(`${Nn.key}`.endsWith(".docx")||`${Nn.key}`.endsWith(".xlsx")),{faqUploadSize:N,hdsdUploadSize:$,normalUploadSize:ie,faqParsedSize:fe,hdsdParsedSize:Ce,normalParsedSize:Ae}=Ju,Et=[],pn=(Nn,Ei,cr,wr)=>{(Nn||[]).forEach(Pn=>{var Gn;if(T(Pn))Et.push({...Pn,type:wr,unSupported:!0});else{let lr=(Gn=(Pn==null?void 0:Pn.key)||"")==null?void 0:Gn.replace(".docx","").replace(".xlsx","").replace(".txt","").replace("/Uploads/",`/${cr}/`);lr.endsWith("/")||(lr+="/"),(Ei||[]).find(Xt=>{let St=((Xt==null?void 0:Xt.key)||"").replace(".txt","");return St.endsWith("/")||(St+="/"),St===lr})||Et.push({...Pn,type:wr})}})};return pn(N,fe,"FAQs","FAQ"),pn($,Ce,"general","Hướng dẫn sử dụng"),pn(ie,Ae,"processed","Normal"),Et},[JSON.stringify(Ju)]),an=O.useMemo(()=>{const T={};return Gt.forEach((N,$)=>{v.has(N.key)&&(T[$]=!0)}),T},[v,Gt]),cv=T=>{const N=Lu(wo,T);if(N.length===0)return v.has(T)?"all":"none";const $=N.filter(ie=>v.has(ie)).length;return $===0?"none":$===N.length?"all":"partial"},Go=(T,N=!0)=>{if(y!==T){if(f&&!y)Br(!0),k(T+f),_(T+f);else if(Br(!0),k(T),_(T),N&&!o){const $=window.location.pathname==="/"?"":window.location.pathname,ie=T?`${window.location.origin}${$}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${$}`;window.history.pushState({path:ie},"",ie)}}};O.useEffect(()=>{mo&&(Un.current=!0,on().finally(()=>Br(!1)))},[mo]);const Co=async(T,N)=>{var $,ie;j(!0);try{if(Gt.some(Et=>Et.isFolder&&Et.name.toLowerCase()===T.toLowerCase())){J({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),j(!1);return}const Ce=`${N}${T}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ce},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}})).status!==200){J({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Un.current=!0,await on(),J({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),z(""),M(!1)}catch(fe){console.error("Error creating folder:",fe);const Ce=((ie=($=fe==null?void 0:fe.response)==null?void 0:$.data)==null?void 0:ie.error)||"Không thể tạo thư mục";J({title:"Lỗi",description:Ce,variant:"destructive"})}finally{j(!1)}},xi=async(T,N,$)=>{var ie,fe,Ce,Ae,Et,pn,Nn,Ei,cr;oe($),Wt(!0);try{if(Array.from(T).reduce((gn,sa)=>gn+sa.size,0)>=100*1024*1024){J({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),oe(null),Wt(!1);return}const Pn=Array.from(T).filter(gn=>gn.size===0);if(Pn.length>0){const gn=Pn.map(sa=>sa.name).join(", ");J({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${gn}`,variant:"destructive"}),Wt(!1),oe(null);return}let Gn=localStorage.getItem("dataLogin"),lr;try{Gn&&(Gn=JSON.parse(Gn),lr=Gn.user)}catch{Gn=null}const Xt=new FormData;if(lr!=null&&lr.id&&Xt.append("metadata",JSON.stringify({creator:lr.username,creatorId:lr.id,DataSource:"Tệp tải lên"})),$==="folder"&&T[0]){const gn=T[0].webkitRelativePath.split("/")[0];gn&&Xt.append("folderName",gn)}Xt.append("prefix",N),Array.from(T).forEach(gn=>$==="folder"?Xt.append("files",gn,gn.webkitRelativePath):Xt.append("files",gn)),Un.current=!0;const St=await Le.post(`${e}/api/check-files-existed`,Xt,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});if(((ie=St==null?void 0:St.data)==null?void 0:ie.status)===200)await Le.post(`${e}/api/upload`,Xt,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),w(""),k(N),setTimeout(async()=>{oe(null),await on(),Wt(!1),await bo("upload")},500);else{if(((Ce=(fe=St==null?void 0:St.data)==null?void 0:fe.names)==null?void 0:Ce.length)>0&&!((Ae=St==null?void 0:St.data)!=null&&Ae.isFolder)){const gn=Array.from(T).filter(sa=>St.data.names.includes(sa.name));wi(gn),Yi(!0)}(Et=St==null?void 0:St.data)!=null&&Et.isFolder&&((pn=St==null?void 0:St.data)!=null&&pn.name)&&(ns((Nn=St==null?void 0:St.data)==null?void 0:Nn.name),wi(T),Yi(!0))}}catch(wr){console.error("Lỗi tải lên:",wr);const Pn=((cr=(Ei=wr==null?void 0:wr.response)==null?void 0:Ei.data)==null?void 0:cr.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:Pn,variant:"destructive"}),oe(null),Wt(!1)}},jc=async()=>{var T,N;try{Wt(!0);const $=new FormData;if(zr){oe(qi?"folder":"files"),Yi(!1);let ie=localStorage.getItem("dataLogin"),fe;try{ie&&(ie=JSON.parse(ie),fe=ie.user)}catch{ie=null}if(fe!=null&&fe.id&&$.append("metadata",JSON.stringify({creator:fe.username,creatorId:fe.id,DataSource:"Tệp tải lên"})),qi&&zr[0]){const Ce=zr[0].webkitRelativePath.split("/")[0];Ce&&$.append("folderName",Ce)}$.append("prefix",y),Array.from(zr).forEach(Ce=>qi&&zr[0]?$.append("files",Ce,Ce.webkitRelativePath):$.append("files",Ce)),fe!=null&&fe.id&&$.append("metadata",JSON.stringify({creator:fe.username,creatorId:fe.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,$,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),w(""),k(y),Un.current=!0}}catch($){console.error("Lỗi tải lên:",$);const ie=((N=(T=$==null?void 0:$.response)==null?void 0:T.data)==null?void 0:N.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:ie,variant:"destructive"})}finally{setTimeout(async()=>{oe(null),await on(),Wt(!1),ns(""),wi(null),await bo("overwrite")},500)}},Pt=async T=>{var N;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[T.key]},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v.has(T.key)){const ie=new Set(v);ie.delete(T.key),C(ie)}const $=((N=T.key)==null?void 0:N.replace(/^(.*?)(\/.*)?$/,(ie,fe,Ce)=>!Ce||Ce==="/"?"":fe+"/"))||"";k($),Un.current=!0,J({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),W(null),await bo("delete")}catch($){console.error("Error deleting file:",$),J({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{vr(!1),await on()}},sr=T=>{const N=new Set(v),$=typeof T=="function"?T(an):T;new Set(Object.keys(an).map(Number)).forEach(fe=>{const Ce=Gt[fe];Ce&&($[fe]||(N.delete(Ce.key),Ce.isFolder&&Lu(wo,Ce.key).forEach(Ae=>N.delete(Ae))))}),Object.entries($).forEach(([fe,Ce])=>{const Ae=parseInt(fe),Et=Gt[Ae];Et&&Ce&&(N.add(Et.key),Et.isFolder&&Lu(wo,Et.key).forEach(pn=>N.add(pn)))}),C(N)},Wc=async()=>{var T;K(!0);try{const N=Array.from(v),$=N.map(fe=>Object.values(wo).flat().find(Ce=>Ce.key===fe)).filter(fe=>fe!==void 0);if($.length===0){J({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:N},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});const ie=((T=$[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(fe,Ce,Ae)=>!Ae||Ae==="/"?"":Ce+"/"))||"";k(ie),Un.current=!0,on(),J({title:"Đã xóa tập tin",description:`Đã xóa thành công ${$.length} mục`}),q(!1),C(new Set),await bo("bulk-delete")}catch(N){console.error("Error deleting files:",N),J({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{K(!1)}},lv=async(T,N)=>{if(!y.trim()){J({title:"Lỗi",description:"Không thể đổi tên tập tin hoặc thư mục ở thư mục gốc. Chỉ có thể xóa.",variant:"destructive"});return}Ue(!0);try{const $=T.key;let ie;T.isFolder?ie=$.split("/").slice(0,-2).join("/")+"/":ie=$.substring(0,$.lastIndexOf("/")+1);const fe=ie+N+(T.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:$,newPath:fe},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),Un.current=!0,await on(),J({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${N}"`}),ne(null),Ne(""),Ee(null),await bo("rename")}catch($){console.error("Error renaming item:",$),J({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Ue(!1)}},fs=async T=>{nt(N=>new Set([...N,...T]));try{const N=await Le.post(`${e}/api/download`,{paths:T},{responseType:"blob",headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),$=window.URL.createObjectURL(N.data),ie=document.createElement("a");ie.href=$;const fe=N.headers["Content-Disposition"]||N.headers["content-disposition"],Ce=fe==null?void 0:fe.match(/filename="(.+)"/),Ae=Ce?decodeURIComponent(Ce[1]):"download.zip";ie.setAttribute("download",Ae),document.body.appendChild(ie),ie.click(),document.body.removeChild(ie),window.URL.revokeObjectURL($),J({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(N){console.error("Error downloading files:",N),J({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{nt(N=>{const $=new Set(N);return T.forEach(ie=>$.delete(ie)),$})}},uf=y?y.replace(n,"").split("/").filter(Boolean):[],dv=()=>{let T=Array.from(v).map($=>({key:$}));T.length>1&&(T=T.filter($=>$.key!==n));const N=$=>Qd.findIndex(T,ie=>!ie.key.endsWith("/")&&ie.key.startsWith($))!==-1;return T=T.filter($=>$.key.endsWith("/")?!N($.key):!0),T},ff=O.useMemo(()=>{const T=[{id:"select",header:()=>{const N=B$(wo,y),$=N.length>0&&N.every(fe=>v.has(fe)),ie=N.some(fe=>v.has(fe));return u.jsx(Pg,{checked:$?!0:ie?"indeterminate":!1,onCheckedChange:fe=>{if(fe){const Ce=Gt.reduce((Ae,Et,pn)=>(Ae[pn]=!0,Ae),{});sr(Ce)}else{for(const Ce of Array.from(v))Ce.startsWith(y)&&(v.delete(Ce),Ho.current[Ce]=!1);Qd.forEach(Ho.current,(Ce,Ae)=>{Ae.startsWith(y)&&(Ho.current[Ae]=!1)}),sr({})}},"aria-label":"Chọn tất cả"})},cell:({row:N})=>{const $=N.original;let fe=$.isFolder?cv($.key):v.has($.key)?"all":"none";if(fe==="none"&&$.key.endsWith("/")){for(const Ce of Array.from(v))if(Ce.startsWith($.key)){fe="all";break}}return u.jsx("div",{className:"flex items-center",children:u.jsx(Pg,{checked:fe==="partial"?"indeterminate":fe==="all",onCheckedChange:Ce=>{var Et,pn;const Ae={...an};if(Ce?Ae[N.index]=!0:delete Ae[N.index],Ho.current[((Et=N.original)==null?void 0:Et.key)||"_"]=!!Ce,(pn=N.original)!=null&&pn.key.endsWith("/"))for(const Nn of Array.from(v))Nn.startsWith(N.original.key)&&(Ho.current[N.original.key]=!1,v.delete(Nn));sr(Ae)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"stt",header:()=>"STT",size:20,cell:({row:N})=>u.jsx("div",{className:"flex flex-col group",children:u.jsx("div",{className:"flex items-center",children:N.index+1})})},{id:"fileName",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),children:["Tên tập tin",u.jsx(wg,{})]}),accessorKey:"name",cell:({row:N})=>{const $=N.original,ie=$.key.substring(0,$.key.lastIndexOf("/"))||"/",fe=g.trim()!==""&&ie!==y,Ce=ie.split("/").filter(Boolean);return u.jsxs("div",{className:"flex flex-col group",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsxs("div",{className:`flex items-center gap-2 ${$.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{$.isFolder&&Go($.key)},children:[$.isFolder?u.jsx(qs,{className:"h-5 w-5 text-blue-500"}):null,$.name]}),u.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),navigator.clipboard.writeText($.key),J({title:"Copied to clipboard",description:`Path: ${$.key}`,duration:2e3})},title:"Copy path to clipboard",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),u.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),fe&&u.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[u.jsx(qs,{className:"h-4 w-4 text-gray-500 my-auto"}),u.jsxs("span",{className:"flex items-center ml-1",children:[u.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Go("")},children:"/"}),Ce.map((Ae,Et)=>u.jsxs("span",{className:"flex items-center",children:[u.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Go(Ce.slice(0,Et+1).join("/")+"/")},children:Ae}),Et<Ce.length-1&&u.jsx("span",{children:"/"})]},Et))]})]})]})}}];return o||T.push({id:"size",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),children:["Kích thước",u.jsx(wg,{})]}),accessorKey:"size",cell:({getValue:N,row:$})=>{const ie=N();return u.jsx("span",{children:$.original.isFolder?"-":ds(ie)})}},{id:"lastModified",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",u.jsx(wg,{})]}),accessorKey:"lastModified",cell:({row:N})=>{const $=N.original.lastModified;return u.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:u.jsx("span",{children:$&&bx($).isValid()?bx($).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>u.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:N})=>u.jsxs("div",{className:"flex items-center gap-2",children:[y===""&&r&&u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Ku(N.original.key),ju(!0)},className:"h-8 w-8 p-0",children:Me.has(N.original.key)?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):u.jsx(GN,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Những Flow sử dụng Folder này làm Data"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>fs([N.original.key]),className:"h-8 w-8 p-0",disabled:Me.has(N.original.key),children:Me.has(N.original.key)?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):u.jsx(wC,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Tải xuống"})]})}),y.trim()!==""&&u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{ne(N.original),Ne(N.original.name)},className:"h-8 w-8 p-0",children:u.jsx(JN,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Đổi tên"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Oe(!0),ce(N.original)},className:"h-8 w-8 p-0",children:u.jsx(dR,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Di chuyển"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>W(N.original),className:"h-8 w-8 p-0",children:u.jsx(CC,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Xóa"})]})})]})}),T},[v,Gt,an,Me,o]),hs=Nb({data:Gt,columns:ff,state:{rowSelection:an,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:sr,getCoreRowModel:kb(),getSortedRowModel:p1()}),ps=async T=>{var N,$;fn(!0);try{if(xc(T)){const ie=await Le.get(`${e}/api/read-text`,{params:{path:T.key},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});lt(ie.data.content)}try{const ie=await Le.get(`${e}/api/read-json`,{params:{path:T.key+".metadata.json"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),fe=(($=(N=ie==null?void 0:ie.data)==null?void 0:N.content)==null?void 0:$.metadataAttributes)||null;return Ee({fullPath:U==null?void 0:U.key,...fe})}catch{return Ee("Lỗi phân tích siêu dữ liệu")}}catch(ie){console.error("Error loading file content:",ie),J({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{fn(!1)}},_i=async(T,N)=>{Lt(!0);try{await Le.post(`${e}/api/modify-text`,{path:T.key,content:N},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Un.current=!0,await on(),ne(null),lt(""),G("rename"),await bo("edit-content")}catch($){console.error("Error saving file content:",$),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Lt(!1)}},uv=async T=>{Lt(!0);try{await Le.post(`${e}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:_e}},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Un.current=!0,await on(),ne(null),lt(""),G("rename")}catch(N){console.error("Error saving file content:",N),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Lt(!1)}};O.useEffect(()=>{U&&(U.isFolder||ps(U),G("rename"))},[U]);const qc=async(T,N)=>{var $;if(ze){J({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}Qe(!0);try{const{data:ie}=await Le.post(`${e}/api/crawl`,{url:T,limit:N,prefix:y});if(ie.id){Vu({id:ie.id,url:T,limit:N,prefix:y,taskId:(($=ie.task)==null?void 0:$.id)||""});const fe=localStorage.getItem(FE),Ce=fe?JSON.parse(fe):[];Ce.some(Ae=>Ae.id===ie.id)||(Ce.unshift({url:T,id:ie.id,limit:N,prefix:y,timestamp:Date.now()}),Ce.length>20&&(Ce.length=20),localStorage.setItem(FE,JSON.stringify(Ce))),J({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${N}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),be(!1),pe(""),ge("1")}}catch(ie){console.error("Error crawling website:",ie),J({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{Qe(!1)}},hf=async()=>{try{if(!(ze!=null&&ze.id))return;Vu(null),localStorage.removeItem(es),J({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${ze.url}`})}catch(T){console.error("Error stopping job:",T),J({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};O.useEffect(()=>{if(o)return;const T=(N=!0)=>{const ie=new URL(window.location.href).searchParams.get("prefix")||"";ie?Go(ie,!1):(N&&!l&&C(new Set),k(n),_(n),Un.current=!0,setTimeout(()=>{on()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const gs=async()=>{Yu(!0);try{await Le.post(`${e}/api/prediction-report`),J({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(T){console.error("Error exporting report:",T),J({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Yu(!1)}},Yc=async()=>{try{const T=lD();T&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:y,user_id:T.id,userName:T.username},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}})).status===200&&await Ti()}catch(T){hn(!1),console.log(T)}},bo=async T=>{try{rs&&y.includes(rs)&&(console.log(`Auto syncing knowledge base after ${T} operation`),await Ti())}catch(N){console.log(`Error auto syncing after ${T}:`,N)}},xo=O.useRef(),Ti=async()=>{try{hn(!0);const T=await Le.post(`${e}/api/get-ingestion-job-status`,{prefix:y},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),{status:N}=T==null?void 0:T.data;N==="FAILED"||N==="COMPLETE"||N==="STOPPED"||N==="STOPPING"||!N?(hn(!1),xo.current&&(clearInterval(xo.current),xo.current=null),kc(T==null?void 0:T.data)):(xo.current||(xo.current=setInterval(()=>Ti(),5e3)),kc(T==null?void 0:T.data))}catch(T){console.log(T)}},Jc=()=>{const T=Array.from(v);let N;return y?N=T.filter($=>$.startsWith(y)&&$!==y).length:N=new Set(T.filter($=>$.split("/").shift())).size,`Đang chọn: ${N}`};return O.useEffect(()=>{const T=y==null?void 0:y.split("/")[0];return T!==rs&&(hn(!1),xo.current&&(clearInterval(xo.current),xo.current=null),Gm(T||""),kc(null),T&&Ti()),()=>{}},[rs,y]),O.useEffect(()=>{yo&&$c.length===0&&(nv(),Gr(null))},[yo]),O.useEffect(()=>{if(l)for(const T of Array.from(l))Ho.current[T]=!0},[]),u.jsxs("div",{className:"space-y-4 s3-explr-container",children:[u.jsx(Y_,{}),u.jsx(gr,{open:Bm,onOpenChange:T=>{Yi(T),T||(ns(""),wi(null),Wt(!1),oe(null))},children:u.jsxs(er,{children:[u.jsxs(tr,{children:[u.jsx(nr,{children:"Cảnh báo trùng lặp"}),u.jsxs(Ro,{children:[qi&&u.jsxs(u.Fragment,{children:["Folder $",qi," đã có."]}),zr&&zr.length>0&&u.jsxs(u.Fragment,{children:["Những tệp sau bị lặp:",u.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(zr).map((T,N)=>u.jsx("li",{children:T.name},N))})]})]})]}),u.jsxs(Mo,{children:[u.jsx($e,{variant:"outline",onClick:()=>{Yi(!1),ns(""),wi(null),Wt(!1),oe(null)},children:"Bỏ qua"}),u.jsx($e,{variant:"destructive",onClick:()=>jc(),children:"Ghi đè"})]})]})}),u.jsx(eu,{className:"s3-explr-breadcrumb",children:u.jsxs(tu,{className:"s3-explr-breadcrumb-list",children:[u.jsx(ac,{className:"s3-explr-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Go(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!f&&uf.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[u.jsx(nu,{className:"s3-explr-breadcrumb-separator"},`sep-${N}`),u.jsx(ac,{className:"s3-explr-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Go(n+uf.slice(0,N+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},N))]})}),u.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[u.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:u.jsx(NU,{ref:Q,onChange:T=>w(T)})}),u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{k(y),Un.current=!0,on()},disabled:bi,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${bi?"animate-spin":""}`}),"Làm mới"]}),y&&y!=="/"&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{bi||pt||(hn(!0),Yc())},"aria-disabled":bi||pt,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${pt?"animate-spin":""}`}),"Đồng bộ KB"]})}),kt&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[u.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),u.jsx("div",{className:"space-y-1",children:u.jsxs("p",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"font-medium",children:"Trạng thái:"}),u.jsxs("span",{className:`flex items-center gap-1 font-semibold ${kt.status==="COMPLETE"?"text-green-600":kt.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[kt.status==="COMPLETE"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),kt.status==="FAILED"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),kt.status!=="COMPLETE"&&kt.status!=="FAILED"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),kt.status]})]})}),kt.statistics&&u.jsxs("div",{className:"space-y-1 border-t pt-2",children:[u.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),u.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu quét:"}),u.jsx("span",{className:"font-medium",children:kt.statistics.numberOfDocumentsScanned})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Metadata quét:"}),u.jsx("span",{className:"font-medium",children:kt.statistics.numberOfMetadataDocumentsScanned})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu mới:"}),u.jsx("span",{className:"font-medium text-green-600",children:kt.statistics.numberOfNewDocumentsIndexed})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu sửa:"}),u.jsx("span",{className:"font-medium text-blue-600",children:kt.statistics.numberOfModifiedDocumentsIndexed})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Metadata sửa:"}),u.jsx("span",{className:"font-medium text-blue-600",children:kt.statistics.numberOfMetadataDocumentsModified})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu xóa:"}),u.jsx("span",{className:"font-medium text-orange-600",children:kt.statistics.numberOfDocumentsDeleted})]}),u.jsxs("div",{className:"flex justify-between col-span-2",children:[u.jsx("span",{children:"Tài liệu lỗi:"}),u.jsx("span",{className:"font-medium text-red-600",children:kt.statistics.numberOfDocumentsFailed})]})]})]}),u.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[u.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",kt.dataSourceId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",kt.ingestionJobId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",kt.knowledgeBaseId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",kt.is_still_in_stock?"Còn":"Không"]})]}),kt.errorMessage&&u.jsxs("div",{className:"border-t pt-2",children:[u.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),u.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:kt.errorMessage})]}),kt.failureReasons&&kt.failureReasons.length>0&&u.jsx(PU,{failureReasons:kt.failureReasons})]})})]})}),!!(aa!=null&&aa.length)&&u.jsxs(u.Fragment,{children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",onClick:()=>Ic(!0),children:[u.jsx(Ws,{className:"h-4 w-4 s3-explr-refresh-icon animate-spin"}),"Tài liệu đang xử lý: ",aa.length]}),u.jsx(D$,{isOpen:Km,onClose:()=>Ic(!1),files:aa})]}),u.jsxs("div",{className:"relative",ref:zc,children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",onClick:()=>yr(T=>!T),children:[u.jsx(XN,{className:"w-4 h-4"}),"Add file"]}),Bc&&u.jsxs("div",{className:"absolute z-50 mt-2 right-0 w-56 bg-white border rounded-lg shadow-lg py-2 flex flex-col",children:[u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{yr(!1);const T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=N=>{const $=N.target.files;$&&xi($,y,"files")},T.click()},children:[u.jsx(bp,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{yr(!1);const T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=N=>{const $=N.target.files;$&&xi($,y,"folder")},T.click()},children:[u.jsx(qs,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!c&&!y,onClick:()=>M(!0),children:[u.jsx(KN,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),be(!0)},children:[u.jsx(qN,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),sf()},children:[u.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[u.jsx("path",{d:"m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8h-27.5c0 1.55.4 3.1 1.2 4.5z",fill:"#0066da"}),u.jsx("path",{d:"m43.65 25-13.75-23.8c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0 -1.2 4.5h27.5z",fill:"#00ac47"}),u.jsx("path",{d:"m73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5h-27.502l5.852 11.5z",fill:"#ea4335"}),u.jsx("path",{d:"m43.65 25 13.75-23.8c-1.35-.8-2.9-1.2-4.5-1.2h-18.5c-1.6 0-3.15.45-4.5 1.2z",fill:"#00832d"}),u.jsx("path",{d:"m59.8 53h-32.3l-13.75 23.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z",fill:"#2684fc"}),u.jsx("path",{d:"m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3l-13.75 23.8 16.15 28h27.45c0-1.55-.4-3.1-1.2-4.5z",fill:"#ffba00"})]})," ","Đồng bộ Google Drive"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),tn()},children:[u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[u.jsx("path",{fill:"#094ab2",d:"M47.3 28.2C45.3 18.6 37.1 12 28 12c-8.5 0-15.9 5.6-18.4 13.5C4.2 27.2 0 32.2 0 38c0 6.6 5.4 12 12 12h36c8.3 0 16-6.6 16-15.5 0-6.8-4.9-12.4-11.7-13.3z"}),u.jsx("path",{fill:"#0067c5",d:"M44.9 30.1c-.2 0-.4-.1-.6-.1H26c-3.3 0-6 2.7-6 6 0 .9.2 1.8.6 2.6-1.7-.7-3.5-1.1-5.5-1.1C7.6 37.5 4 41.5 4 46s3.6 8.5 8.1 8.5h34.3c6.8 0 12.6-5.4 12.6-12s-5.5-11.6-11.1-12.4z"})]})," ","Đồng bộ OneDrive"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),ev()},children:[u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[u.jsx("path",{fill:"#036C70",d:"M19 14.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#17828F",d:"M16 17.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#4DB6AC",d:"M13 20.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),!o&&u.jsxs(u.Fragment,{children:[v.size>0&&u.jsxs(u.Fragment,{children:[u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>fs(Array.from(v)),disabled:Array.from(v).some(T=>Me.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(v).some(T=>Me.has(T))?u.jsx(Ht,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):u.jsx(wC,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",v.size,")"]}),u.jsxs(gr,{open:Z,onOpenChange:q,children:[u.jsx(cc,{asChild:!0,children:u.jsxs($e,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[u.jsx(CC,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",v.size,")"]})}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),u.jsxs(Ro,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",v.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>q(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:Wc,disabled:xe,className:"s3-explr-confirm-delete-btn",children:xe?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),!f&&u.jsxs(gr,{open:R,onOpenChange:M,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsx(tr,{className:"s3-explr-dialog-header",children:u.jsx(nr,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),u.jsx(oo,{disabled:V,id:"name",value:S,onChange:T=>z(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),u.jsxs($e,{onClick:()=>{S.trim()&&Co(S,y)},disabled:V,className:"s3-explr-create-btn",children:[V&&u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),V?"Đang tạo...":"Tạo"]})]})]})]}),f&&!y?u.jsx(u.Fragment,{}):u.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[ze?u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[u.jsx(Ht,{className:"h-4 w-4 animate-spin s3-explr-loader"}),ze.status?u.jsxs(u.Fragment,{children:[ze.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",ze.status.completed,"/",ze.status.total,") -"," ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}):"Đang thu thập..."]}),u.jsxs($e,{variant:"destructive",size:"sm",onClick:()=>void hf(),className:"flex items-center gap-2",children:[u.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),u.jsx(eP,{className:"h-4 w-4"})]})]})}),ze.status&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-1 p-2",children:[u.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",ze==null?void 0:ze.url]}),u.jsxs("p",{children:["Tiến độ: ",ze==null?void 0:ze.status.completed,"/",ze==null?void 0:ze.status.total," ","trang"]}),u.jsxs("p",{children:["Thời gian: ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}),u.jsxs("p",{children:["Trạng thái:"," ",(ze==null?void 0:ze.status.status)==="scraping"?"Đang thu thập":(ze==null?void 0:ze.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!f&&u.jsxs(gr,{open:X,onOpenChange:be,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Thêm website"}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),u.jsx(oo,{id:"websiteUrl",value:ye,onChange:T=>pe(T.target.value),placeholder:"https://example.com",type:"url",disabled:Be,className:"s3-explr-input"})]}),u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),u.jsx(oo,{id:"crawlLimit",value:re,onChange:T=>{const N=T.target.value;/^\d*$/.test(N)&&ge(N)},placeholder:"1",type:"text",disabled:Be,className:"s3-explr-input"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Số lượng liên kết cần thu thập (mặc định: 1)"})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{be(!1),pe(""),ge("1")},disabled:Be,className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{onClick:()=>{ye.trim()&&qc(ye.trim(),parseInt(re)||1)},disabled:Be||!ye.trim(),className:"s3-explr-crawl-btn",children:Be?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),y.startsWith("BKTTW/")&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!y,onClick:gs,children:[Qi&&u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${Qi?"animate-spin":""}`}),"Xuất báo cáo"]})}),(ze==null?void 0:ze.status)&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-1 p-2",children:[u.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",ze.url]}),u.jsxs("p",{children:["Tiến độ: ",ze.status.completed,"/",ze.status.total," ","trang"]}),u.jsxs("p",{children:["Thời gian: ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}),u.jsxs("p",{children:["Trạng thái:"," ",ze.status.status==="scraping"?"Đang thu thập":ze.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),u.jsxs(gr,{open:X,onOpenChange:be,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Thêm website"}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),u.jsx(oo,{id:"websiteUrl",value:ye,onChange:T=>pe(T.target.value),placeholder:"https://example.com",type:"url",disabled:Be,className:"s3-explr-input"})]}),u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),u.jsx(oo,{id:"crawlLimit",value:re,onChange:T=>{const N=T.target.value;/^\d*$/.test(N)&&ge(N)},placeholder:"1",type:"text",disabled:Be,className:"s3-explr-input"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Số lượng liên kết cần thu thập (mặc định: 1)"})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{be(!1),pe(""),ge("1")},disabled:Be,className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{onClick:()=>{ye.trim()&&qc(ye.trim(),parseInt(re)||1)},disabled:Be||!ye.trim(),className:"s3-explr-crawl-btn",children:Be?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),y.startsWith("BKTTW/")&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!y,onClick:gs,children:[Qi&&u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${Qi?"animate-spin":""}`}),"Xuất báo cáo"]})}),Qi&&u.jsx($r,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),u.jsxs("div",{className:"flex items-center gap-4",children:[Xi&&u.jsxs(Ys,{open:Xi,onOpenChange:os,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[u.jsxs("div",{className:"relative",children:[u.jsx($p,{asChild:!0,children:u.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:Kc,children:"✖"})}),u.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),u.jsx(eu,{className:"onedrive-breadcrumb",children:u.jsx(tu,{className:"onedrive-breadcrumb-list",children:Zi.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[N>0&&u.jsx(nu,{className:"onedrive-breadcrumb-separator"}),u.jsx(ac,{className:"onedrive-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Vc(N),className:"cursor-pointer onedrive-breadcrumb-link",children:T.name})})]},N))})})]}),u.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:qm?u.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):u.jsx(u.Fragment,{children:[...Qu,...Oc].length>0?[...Qu,...Oc].map(T=>u.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${as.some(N=>N.id===T.id)?"bg-blue-100":""}`,children:[u.jsx("input",{type:"checkbox",checked:as.some(N=>N.id===T.id),onChange:N=>{N.stopPropagation(),af(T)},className:"cursor-pointer"}),T.isFolder?u.jsx(qs,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ia(T.id,T.name)}):u.jsx(bp,{className:"text-gray-500 w-5 h-5"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:`font-medium ${T.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{T.isFolder?ia(T.id,T.name):af(T)},children:T.name}),!T.isFolder&&u.jsxs("div",{className:"text-xs text-gray-500",children:[ds(T.size)," •"," ",sv(T.lastModified.toISOString())]})]})]},T.id)):u.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),u.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:u.jsx($e,{onClick:()=>{zn(as,y),Kc()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:as.length===0,children:"Đồng bộ"})}),u.jsx("button",{onClick:()=>ra(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),u.jsx("polyline",{points:"16 17 21 12 16 7"}),u.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),u.jsxs(Ys,{open:Ym,onOpenChange:ra,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),u.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx($e,{variant:"outline",onClick:()=>ra(!1),children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>{Gc(),ra(!1)},children:"Đăng xuất"})]})]})]}),yo&&u.jsxs(Ys,{open:yo,onOpenChange:ta,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[u.jsxs("div",{className:"relative",children:[u.jsx($p,{asChild:!0,children:u.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:of,children:"✖"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[gt&&u.jsx("button",{onClick:()=>Gr(null),className:"text-gray-600 hover:text-gray-800",children:u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:u.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),u.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&u.jsx(eu,{className:"sharepoint-breadcrumb",children:u.jsx(tu,{className:"sharepoint-breadcrumb-list",children:Uc.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[N>0&&u.jsx(nu,{className:"sharepoint-breadcrumb-separator"}),u.jsx(ac,{className:"sharepoint-breadcrumb-item",children:u.jsx(sc,{onClick:()=>ov(N),className:"cursor-pointer sharepoint-breadcrumb-link",children:T.name})})]},N))})})]}),u.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Zu?u.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...Lc,...ss].length===0?u.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...Lc,...ss].map(T=>{const N=ls.some($=>$.id===T.id);return u.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${N?"bg-blue-100":""}`,children:[u.jsx("input",{type:"checkbox",checked:N,onChange:$=>{$.stopPropagation(),rv(T)},className:"cursor-pointer"}),T.isFolder?u.jsx(qs,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>mt(T.id,T.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):u.jsx(bp,{className:"text-gray-500 w-5 h-5"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:`font-medium ${T.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{T.isFolder&&mt(T.id,T.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:T.name}),!T.isFolder&&u.jsxs("div",{className:"text-xs text-gray-500",children:[ds(T.size)," •"," ",T.lastModified.toLocaleString()]})]})]},T.id)}):u.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:$c.map(T=>u.jsxs("div",{className:"cursor-pointer bg-white shadow-md rounded-xl p-5 flex flex-col justify-center items-start transition-shadow duration-200 hover:shadow-lg border border-gray-100 min-h-[120px]",style:{overflow:"hidden",wordBreak:"break-word",textOverflow:"ellipsis",whiteSpace:"normal"},onClick:()=>Nt(T),children:[u.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:T.name,children:T.name}),u.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:T.description,children:T.description})]},T.id))})}),u.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&u.jsxs(u.Fragment,{children:[u.jsx($e,{onClick:()=>{iv(ls,y),of()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:ls.length===0,children:"Đồng bộ"}),u.jsx($e,{onClick:()=>Gr(null),children:"Quay lại"})]})}),u.jsx("button",{onClick:()=>na(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),u.jsx("polyline",{points:"16 17 21 12 16 7"}),u.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),u.jsxs(Ys,{open:tf,onOpenChange:na,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),u.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx($e,{variant:"outline",onClick:()=>na(!1),children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>{tv(),na(!1)},children:"Đăng xuất"})]})]})]})]}),u.jsx(gr,{open:!!zm,onOpenChange:T=>{T||(ju(!1),qu([]),Ku(""))},children:u.jsxs(er,{className:"max-h-[700px] pb-3 px-1 s3-explr-input-group max-w-5xl w-[90%] p-6 bg-white rounded-lg shadow-lg",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:u.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",u.jsx("span",{className:"font-bold",children:Ji}),"):"," "]})}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:Ac?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ht,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):u.jsx("div",{children:Ci&&Array.isArray(Ci)&&Ci.length>0?u.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:u.jsxs("table",{className:"w-full border-collapse",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"bg-gray-100",children:[u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),u.jsx("tbody",{children:Ci.map((T,N)=>u.jsxs("tr",{className:N%2===0?"bg-white":"bg-gray-50",children:[u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.name}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.KnowledgeBaseId}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.createdDate?new Date(T.createdDate).toLocaleString("vi-VN"):"N/A"})]},N))})]})}):u.jsx("div",{className:"text-gray-500 italic py-2",children:"Không có flow nào sử dụng dữ liệu từ folder này"})})})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>Pt(te),disabled:Hn,className:"s3-explr-confirm-delete-btn",children:Hn?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),u.jsx(gr,{open:!!te,onOpenChange:T=>!T&&W(null),children:u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),u.jsxs(Ro,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",te==null?void 0:te.name,"? Hành động này không thể hoàn tác."]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>Pt(te),disabled:Hn,className:"s3-explr-confirm-delete-btn",children:Hn?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),u.jsx(gr,{open:!!U,onOpenChange:T=>{T||(ne(null),Ee(null),Ne(""),lt(""),G("rename"))},children:u.jsxs(er,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[u.jsx(tr,{className:"s3-explr-dialog-header",children:u.jsx(nr,{className:"s3-explr-dialog-title",children:U!=null&&U.isFolder?"Đổi tên thư mục":xc(U)?"Quản lý tập tin":"Đổi tên tập tin"})}),U&&u.jsxs(WD,{value:D,onValueChange:T=>G(T),children:[u.jsxs(x_,{"aria-checked":!xc(U),"aria-disabled":U.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[u.jsx(uu,{value:"rename",children:"Đổi tên"}),!U.isFolder&&u.jsxs(u.Fragment,{children:[xc(U)&&u.jsx(uu,{value:"edit",children:"Sửa nội dung"}),u.jsx(uu,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),u.jsx(fu,{value:"rename",children:u.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:u.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),u.jsx(oo,{id:"newName",value:Te,onChange:T=>Ne(T.target.value),placeholder:"Nhập tên mới",disabled:De,className:"s3-explr-input"})]})})}),!U.isFolder&&u.jsxs(u.Fragment,{children:[xc(U)&&u.jsx(fu,{value:"edit",children:u.jsx("div",{className:"space-y-4 py-4",children:Ct?u.jsx("div",{className:"flex items-center justify-center py-4",children:u.jsx(Ht,{className:"h-6 w-6 animate-spin"})}):u.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[u.jsx(Do,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),u.jsx(fc,{id:"content",value:we,onChange:T=>lt(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:In})]})})}),u.jsx(fu,{value:"edit-metadata",children:u.jsx("div",{className:"space-y-4 py-4",children:Ct?u.jsx("div",{className:"flex items-center justify-center py-4",children:u.jsx(Ht,{className:"h-6 w-6 animate-spin"})}):u.jsx("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:_e&&typeof _e=="object"&&Object.entries(_e).map(([T,N],$)=>u.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[u.jsxs(Do,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[SR[T]||T,Tg(T)&&u.jsx(uR,{className:"h-[12px] w-[12px] text-red-500"})]}),AR(T)?u.jsx(fc,{id:T,value:typeof N=="string"?N:JSON.stringify(N),onChange:ie=>{const fe={..._e,[T]:ie.target.value};Ee(fe)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:In||Tg(T)}):u.jsx(oo,{id:T,value:typeof N=="string"?N:JSON.stringify(N),onChange:ie=>{const fe={..._e,[T]:ie.target.value};Ee(fe)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:In||Tg(T)})]},$))})})})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{ne(null),Ee(null),Ne(""),lt("")},className:"s3-explr-cancel-btn",children:"Hủy"}),D==="edit"?u.jsx($e,{onClick:()=>U&&_i(U,we),disabled:In||Ct,className:"s3-explr-save-btn",children:In?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):D==="edit-metadata"?u.jsx($e,{onClick:()=>_e&&typeof _e=="object"&&U&&uv(U),disabled:In||Ct,className:"s3-explr-save-btn",children:In?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):u.jsx($e,{onClick:()=>{Te.trim()&&U&&lv(U,Te.trim())},disabled:De||!Te.trim()||Te.trim()===(U==null?void 0:U.name),className:"s3-explr-rename-btn",children:De?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),me&&Se&&u.jsx(F$,{openDialogRename:Se,setOpenDialogRename:Oe,apiBaseUrl:e,setFileToMove:ce,fileToMove:me,refreshFiles:on,ignoreCache:Un,autoSyncAfterFileOperation:bo})]})]}),Zm&&u.jsx("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative s3-explr-error",children:"Đã xảy ra lỗi khi tải danh sách tập tin"}),u.jsx(R$,{onFilesSelected:(T,N)=>xi(T,y,N),children:u.jsx("div",{className:"rounded-md border s3-explr-table-container",children:u.jsxs(lc,{className:"s3-explr-table",children:[u.jsx(dc,{className:"s3-explr-table-header",children:hs.getHeaderGroups().map(T=>u.jsx(rr,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(N=>u.jsx(or,{className:"s3-explr-header-cell",children:N.isPlaceholder?null:Ld(N.column.columnDef.header,N.getContext())},N.id))},T.id))}),u.jsx(uc,{className:"s3-explr-table-body",children:hs.getRowModel().rows.length===0?u.jsx(rr,{className:"s3-explr-empty-row",children:u.jsx(un,{colSpan:ff.length,className:"h-24 text-center s3-explr-empty-cell",children:g?u.jsxs("div",{className:"text-gray-500 s3-explr-no-results",children:['Không tìm thấy tập tin hoặc thư mục nào khớp với "',g,'"']}):u.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:bi?"Đang tải nội dung thư mục... Vui lòng đợi":"Thư mục này không chứa tập tin hoặc thư mục con nào"})})}):hs.getRowModel().rows.map(T=>u.jsx(rr,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(N=>u.jsx(un,{className:"align-middle s3-explr-cell",children:Ld(N.column.columnDef.cell,N.getContext())},N.id))},T.id))})]})})}),g&&oa!==0&&u.jsx(u.Fragment,{children:u.jsx(ru,{children:u.jsxs(ou,{children:[u.jsx(iu,{onClick:()=>Bn(T=>Math.max(T-1,1)),"aria-disabled":zt===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(oa/20)},(T,N)=>{const $=N+1,ie=Math.ceil(oa/20);return ie>7&&!($===1||$===ie||$>=zt-1&&$<=zt+1)?$===zt-2&&zt>4||$===zt+2&&zt<ie-3?u.jsx(su,{className:"pointer-events-none",children:"..."},N):null:u.jsx(Fr,{className:"cursor-pointer",children:u.jsx(ja,{isActive:zt===$,onClick:()=>Bn($),className:`${zt===$?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:$})},N)}),u.jsx(Fr,{children:u.jsx(au,{onClick:()=>Bn(T=>Math.min(T+1,Math.ceil(oa/20))),"aria-disabled":zt===Math.ceil(oa/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),o&&a&&u.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[u.jsx("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:Jc()}),u.jsx($e,{variant:"default",onClick:()=>a(dv()),disabled:v.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),j$=t=>u.jsx(MO,{clientId:U$,children:u.jsx(K$,{...t})});var _c=t=>t.type==="checkbox",Wi=t=>t instanceof Date,An=t=>t==null;const LE=t=>typeof t=="object";var jt=t=>!An(t)&&!Array.isArray(t)&&LE(t)&&!Wi(t),W$=t=>jt(t)&&t.target?_c(t.target)?t.target.checked:t.target.value:t,q$=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,Y$=(t,e)=>t.has(q$(e)),J$=t=>{const e=t.constructor&&t.constructor.prototype;return jt(e)&&e.hasOwnProperty("isPrototypeOf")},Mm=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mr(t){let e;const n=Array.isArray(t),r=typeof FileList<"u"?t instanceof FileList:!1;if(t instanceof Date)e=new Date(t);else if(t instanceof Set)e=new Set(t);else if(!(Mm&&(t instanceof Blob||r))&&(n||jt(t)))if(e=n?[]:{},!n&&!J$(t))e=t;else for(const o in t)t.hasOwnProperty(o)&&(e[o]=mr(t[o]));else return t;return e}var Uu=t=>Array.isArray(t)?t.filter(Boolean):[],Bt=t=>t===void 0,Re=(t,e,n)=>{if(!e||!jt(t))return n;const r=Uu(e.split(/[,[\].]+?/)).reduce((o,a)=>An(o)?o:o[a],t);return Bt(r)||r===t?Bt(t[e])?n:t[e]:r},ho=t=>typeof t=="boolean",Rm=t=>/^\w*$/.test(t),UE=t=>Uu(t.replace(/["|']|\]/g,"").split(/\.|\[/)),Dt=(t,e,n)=>{let r=-1;const o=Rm(e)?[e]:UE(e),a=o.length,c=a-1;for(;++r<a;){const l=o[r];let f=n;if(r!==c){const h=t[l];f=jt(h)||Array.isArray(h)?h:isNaN(+o[r+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;t[l]=f,t=t[l]}return t};const $E={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Hr={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},$o={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};O.createContext(null);var Q$=(t,e,n,r=!0)=>{const o={defaultValues:e._defaultValues};for(const a in t)Object.defineProperty(o,a,{get:()=>{const c=a;return e._proxyFormState[c]!==Hr.all&&(e._proxyFormState[c]=!r||Hr.all),t[c]}});return o},$n=t=>jt(t)&&!Object.keys(t).length,X$=(t,e,n,r)=>{n(t);const{name:o,...a}=t;return $n(a)||Object.keys(a).length>=Object.keys(e).length||Object.keys(a).find(c=>e[c]===Hr.all)},$u=t=>Array.isArray(t)?t:[t];function Z$(t){const e=O.useRef(t);e.current=t,O.useEffect(()=>{const n=!t.disabled&&e.current.subject&&e.current.subject.subscribe({next:e.current.next});return()=>{n&&n.unsubscribe()}},[t.disabled])}var po=t=>typeof t=="string",eH=(t,e,n,r,o)=>po(t)?(r&&e.watch.add(t),Re(n,t,o)):Array.isArray(t)?t.map(a=>(r&&e.watch.add(a),Re(n,a))):(r&&(e.watchAll=!0),n),tH=(t,e,n,r,o)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[r]:o||!0}}:{},HE=t=>({isOnSubmit:!t||t===Hr.onSubmit,isOnBlur:t===Hr.onBlur,isOnChange:t===Hr.onChange,isOnAll:t===Hr.all,isOnTouch:t===Hr.onTouched}),BE=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(r=>t.startsWith(r)&&/^\.\w+/.test(t.slice(r.length))));const Tc=(t,e,n,r)=>{for(const o of n||Object.keys(t)){const a=Re(t,o);if(a){const{_f:c,...l}=a;if(c){if(c.refs&&c.refs[0]&&e(c.refs[0],o)&&!r)return!0;if(c.ref&&e(c.ref,c.name)&&!r)return!0;if(Tc(l,e))break}else if(jt(l)&&Tc(l,e))break}}};var nH=(t,e,n)=>{const r=$u(Re(t,n));return Dt(r,"root",e[n]),Dt(t,n,r),t},Dm=t=>t.type==="file",go=t=>typeof t=="function",Hu=t=>{if(!Mm)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},Bu=t=>po(t),Fm=t=>t.type==="radio",zu=t=>t instanceof RegExp;const zE={value:!1,isValid:!1},GE={value:!0,isValid:!0};var VE=t=>{if(Array.isArray(t)){if(t.length>1){const e=t.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:e,isValid:!!e.length}}return t[0].checked&&!t[0].disabled?t[0].attributes&&!Bt(t[0].attributes.value)?Bt(t[0].value)||t[0].value===""?GE:{value:t[0].value,isValid:!0}:GE:zE}return zE};const KE={isValid:!1,value:null};var jE=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,KE):KE;function WE(t,e,n="validate"){if(Bu(t)||Array.isArray(t)&&t.every(Bu)||ho(t)&&!t)return{type:n,message:Bu(t)?t:"",ref:e}}var ts=t=>jt(t)&&!zu(t)?t:{value:t,message:""},qE=async(t,e,n,r,o)=>{const{ref:a,refs:c,required:l,maxLength:f,minLength:h,min:p,max:g,pattern:w,validate:v,name:C,valueAsNumber:y,mount:_,disabled:I}=t._f,k=Re(e,C);if(!_||I)return{};const R=c?c[0]:a,M=ce=>{r&&R.reportValidity&&(R.setCustomValidity(ho(ce)?"":ce||""),R.reportValidity())},S={},z=Fm(a),V=_c(a),j=z||V,te=(y||Dm(a))&&Bt(a.value)&&Bt(k)||Hu(a)&&a.value===""||k===""||Array.isArray(k)&&!k.length,W=tH.bind(null,C,n,S),me=(ce,xe,K,Z=$o.maxLength,q=$o.minLength)=>{const oe=ce?xe:K;S[C]={type:ce?Z:q,message:oe,ref:a,...W(ce?Z:q,oe)}};if(o?!Array.isArray(k)||!k.length:l&&(!j&&(te||An(k))||ho(k)&&!k||V&&!VE(c).isValid||z&&!jE(c).isValid)){const{value:ce,message:xe}=Bu(l)?{value:!!l,message:l}:ts(l);if(ce&&(S[C]={type:$o.required,message:xe,ref:R,...W($o.required,xe)},!n))return M(xe),S}if(!te&&(!An(p)||!An(g))){let ce,xe;const K=ts(g),Z=ts(p);if(!An(k)&&!isNaN(k)){const q=a.valueAsNumber||k&&+k;An(K.value)||(ce=q>K.value),An(Z.value)||(xe=q<Z.value)}else{const q=a.valueAsDate||new Date(k),oe=U=>new Date(new Date().toDateString()+" "+U),Q=a.type=="time",J=a.type=="week";po(K.value)&&k&&(ce=Q?oe(k)>oe(K.value):J?k>K.value:q>new Date(K.value)),po(Z.value)&&k&&(xe=Q?oe(k)<oe(Z.value):J?k<Z.value:q<new Date(Z.value))}if((ce||xe)&&(me(!!ce,K.message,Z.message,$o.max,$o.min),!n))return M(S[C].message),S}if((f||h)&&!te&&(po(k)||o&&Array.isArray(k))){const ce=ts(f),xe=ts(h),K=!An(ce.value)&&k.length>+ce.value,Z=!An(xe.value)&&k.length<+xe.value;if((K||Z)&&(me(K,ce.message,xe.message),!n))return M(S[C].message),S}if(w&&!te&&po(k)){const{value:ce,message:xe}=ts(w);if(zu(ce)&&!k.match(ce)&&(S[C]={type:$o.pattern,message:xe,ref:a,...W($o.pattern,xe)},!n))return M(xe),S}if(v){if(go(v)){const ce=await v(k,e),xe=WE(ce,R);if(xe&&(S[C]={...xe,...W($o.validate,xe.message)},!n))return M(xe.message),S}else if(jt(v)){let ce={};for(const xe in v){if(!$n(ce)&&!n)break;const K=WE(await v[xe](k,e),R,xe);K&&(ce={...K,...W(xe,K.message)},M(K.message),n&&(S[C]=ce))}if(!$n(ce)&&(S[C]={ref:R,...ce},!n))return S}}return M(!0),S};function rH(t,e){const n=e.slice(0,-1).length;let r=0;for(;r<n;)t=Bt(t)?r++:t[e[r++]];return t}function oH(t){for(const e in t)if(t.hasOwnProperty(e)&&!Bt(t[e]))return!1;return!0}function en(t,e){const n=Array.isArray(e)?e:Rm(e)?[e]:UE(e),r=n.length===1?t:rH(t,n),o=n.length-1,a=n[o];return r&&delete r[a],o!==0&&(jt(r)&&$n(r)||Array.isArray(r)&&oH(r))&&en(t,n.slice(0,-1)),t}var Lm=()=>{let t=[];return{get observers(){return t},next:o=>{for(const a of t)a.next&&a.next(o)},subscribe:o=>(t.push(o),{unsubscribe:()=>{t=t.filter(a=>a!==o)}}),unsubscribe:()=>{t=[]}}},Um=t=>An(t)||!LE(t);function yi(t,e){if(Um(t)||Um(e))return t===e;if(Wi(t)&&Wi(e))return t.getTime()===e.getTime();const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const o of n){const a=t[o];if(!r.includes(o))return!1;if(o!=="ref"){const c=e[o];if(Wi(a)&&Wi(c)||jt(a)&&jt(c)||Array.isArray(a)&&Array.isArray(c)?!yi(a,c):a!==c)return!1}}return!0}var YE=t=>t.type==="select-multiple",iH=t=>Fm(t)||_c(t),$m=t=>Hu(t)&&t.isConnected,JE=t=>{for(const e in t)if(go(t[e]))return!0;return!1};function Gu(t,e={}){const n=Array.isArray(t);if(jt(t)||n)for(const r in t)Array.isArray(t[r])||jt(t[r])&&!JE(t[r])?(e[r]=Array.isArray(t[r])?[]:{},Gu(t[r],e[r])):An(t[r])||(e[r]=!0);return e}function QE(t,e,n){const r=Array.isArray(t);if(jt(t)||r)for(const o in t)Array.isArray(t[o])||jt(t[o])&&!JE(t[o])?Bt(e)||Um(n[o])?n[o]=Array.isArray(t[o])?Gu(t[o],[]):{...Gu(t[o])}:QE(t[o],An(e)?{}:e[o],n[o]):n[o]=!yi(t[o],e[o]);return n}var Ec=(t,e)=>QE(t,e,Gu(e)),XE=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:r})=>Bt(t)?t:e?t===""?NaN:t&&+t:n&&po(t)?new Date(t):r?r(t):t;function Hm(t){const e=t.ref;if(!(t.refs?t.refs.every(n=>n.disabled):e.disabled))return Dm(e)?e.files:Fm(e)?jE(t.refs).value:YE(e)?[...e.selectedOptions].map(({value:n})=>n):_c(e)?VE(t.refs).value:XE(Bt(e.value)?t.ref.value:e.value,t)}var aH=(t,e,n,r)=>{const o={};for(const a of t){const c=Re(e,a);c&&Dt(o,a,c._f)}return{criteriaMode:n,names:[...t],fields:o,shouldUseNativeValidation:r}},Sc=t=>Bt(t)?t:zu(t)?t.source:jt(t)?zu(t.value)?t.value.source:t.value:t;const ZE="AsyncFunction";var sH=t=>!!t&&!!t.validate&&!!(go(t.validate)&&t.validate.constructor.name===ZE||jt(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===ZE)),cH=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate);function eS(t,e,n){const r=Re(t,n);if(r||Rm(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const a=o.join("."),c=Re(e,a),l=Re(t,a);if(c&&!Array.isArray(c)&&n!==a)return{name:n};if(l&&l.type)return{name:a,error:l};o.pop()}return{name:n}}var lH=(t,e,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(e||t):(n?r.isOnBlur:o.isOnBlur)?!t:(n?r.isOnChange:o.isOnChange)?t:!0,dH=(t,e)=>!Uu(Re(t,e)).length&&en(t,e);const uH={mode:Hr.onSubmit,reValidateMode:Hr.onChange,shouldFocusError:!0};function fH(t={}){let e={...uH,...t},n={submitCount:0,isDirty:!1,isLoading:go(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1},r={},o=jt(e.defaultValues)||jt(e.values)?mr(e.defaultValues||e.values)||{}:{},a=e.shouldUnregister?{}:mr(o),c={action:!1,mount:!1,watch:!1},l={mount:new Set,unMount:new Set,array:new Set,watch:new Set},f,h=0;const p={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},g={values:Lm(),array:Lm(),state:Lm()},w=HE(e.mode),v=HE(e.reValidateMode),C=e.criteriaMode===Hr.all,y=D=>G=>{clearTimeout(h),h=setTimeout(D,G)},_=async D=>{if(!e.disabled&&(p.isValid||D)){const G=e.resolver?$n((await j()).errors):await W(r,!0);G!==n.isValid&&g.state.next({isValid:G})}},I=(D,G)=>{!e.disabled&&(p.isValidating||p.validatingFields)&&((D||Array.from(l.mount)).forEach(X=>{X&&(G?Dt(n.validatingFields,X,G):en(n.validatingFields,X))}),g.state.next({validatingFields:n.validatingFields,isValidating:!$n(n.validatingFields)}))},k=(D,G=[],X,be,ye=!0,pe=!0)=>{if(be&&X&&!e.disabled){if(c.action=!0,pe&&Array.isArray(Re(r,D))){const re=X(Re(r,D),be.argA,be.argB);ye&&Dt(r,D,re)}if(pe&&Array.isArray(Re(n.errors,D))){const re=X(Re(n.errors,D),be.argA,be.argB);ye&&Dt(n.errors,D,re),dH(n.errors,D)}if(p.touchedFields&&pe&&Array.isArray(Re(n.touchedFields,D))){const re=X(Re(n.touchedFields,D),be.argA,be.argB);ye&&Dt(n.touchedFields,D,re)}p.dirtyFields&&(n.dirtyFields=Ec(o,a)),g.state.next({name:D,isDirty:ce(D,G),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Dt(a,D,G)},R=(D,G)=>{Dt(n.errors,D,G),g.state.next({errors:n.errors})},M=D=>{n.errors=D,g.state.next({errors:n.errors,isValid:!1})},S=(D,G,X,be)=>{const ye=Re(r,D);if(ye){const pe=Re(a,D,Bt(X)?Re(o,D):X);Bt(pe)||be&&be.defaultChecked||G?Dt(a,D,G?pe:Hm(ye._f)):Z(D,pe),c.mount&&_()}},z=(D,G,X,be,ye)=>{let pe=!1,re=!1;const ge={name:D};if(!e.disabled){const Be=!!(Re(r,D)&&Re(r,D)._f&&Re(r,D)._f.disabled);if(!X||be){p.isDirty&&(re=n.isDirty,n.isDirty=ge.isDirty=ce(),pe=re!==ge.isDirty);const Qe=Be||yi(Re(o,D),G);re=!!(!Be&&Re(n.dirtyFields,D)),Qe||Be?en(n.dirtyFields,D):Dt(n.dirtyFields,D,!0),ge.dirtyFields=n.dirtyFields,pe=pe||p.dirtyFields&&re!==!Qe}if(X){const Qe=Re(n.touchedFields,D);Qe||(Dt(n.touchedFields,D,X),ge.touchedFields=n.touchedFields,pe=pe||p.touchedFields&&Qe!==X)}pe&&ye&&g.state.next(ge)}return pe?ge:{}},V=(D,G,X,be)=>{const ye=Re(n.errors,D),pe=p.isValid&&ho(G)&&n.isValid!==G;if(e.delayError&&X?(f=y(()=>R(D,X)),f(e.delayError)):(clearTimeout(h),f=null,X?Dt(n.errors,D,X):en(n.errors,D)),(X?!yi(ye,X):ye)||!$n(be)||pe){const re={...be,...pe&&ho(G)?{isValid:G}:{},errors:n.errors,name:D};n={...n,...re},g.state.next(re)}},j=async D=>{I(D,!0);const G=await e.resolver(a,e.context,aH(D||l.mount,r,e.criteriaMode,e.shouldUseNativeValidation));return I(D),G},te=async D=>{const{errors:G}=await j(D);if(D)for(const X of D){const be=Re(G,X);be?Dt(n.errors,X,be):en(n.errors,X)}else n.errors=G;return G},W=async(D,G,X={valid:!0})=>{for(const be in D){const ye=D[be];if(ye){const{_f:pe,...re}=ye;if(pe){const ge=l.array.has(pe.name),Be=ye._f&&sH(ye._f);Be&&p.validatingFields&&I([be],!0);const Qe=await qE(ye,a,C,e.shouldUseNativeValidation&&!G,ge);if(Be&&p.validatingFields&&I([be]),Qe[pe.name]&&(X.valid=!1,G))break;!G&&(Re(Qe,pe.name)?ge?nH(n.errors,Qe,pe.name):Dt(n.errors,pe.name,Qe[pe.name]):en(n.errors,pe.name))}!$n(re)&&await W(re,G,X)}}return X.valid},me=()=>{for(const D of l.unMount){const G=Re(r,D);G&&(G._f.refs?G._f.refs.every(X=>!$m(X)):!$m(G._f.ref))&&Se(D)}l.unMount=new Set},ce=(D,G)=>!e.disabled&&(D&&G&&Dt(a,D,G),!yi(ne(),o)),xe=(D,G,X)=>eH(D,l,{...c.mount?a:Bt(G)?o:po(D)?{[D]:G}:G},X,G),K=D=>Uu(Re(c.mount?a:o,D,e.shouldUnregister?Re(o,D,[]):[])),Z=(D,G,X={})=>{const be=Re(r,D);let ye=G;if(be){const pe=be._f;pe&&(!pe.disabled&&Dt(a,D,XE(G,pe)),ye=Hu(pe.ref)&&An(G)?"":G,YE(pe.ref)?[...pe.ref.options].forEach(re=>re.selected=ye.includes(re.value)):pe.refs?_c(pe.ref)?pe.refs.length>1?pe.refs.forEach(re=>(!re.defaultChecked||!re.disabled)&&(re.checked=Array.isArray(ye)?!!ye.find(ge=>ge===re.value):ye===re.value)):pe.refs[0]&&(pe.refs[0].checked=!!ye):pe.refs.forEach(re=>re.checked=re.value===ye):Dm(pe.ref)?pe.ref.value="":(pe.ref.value=ye,pe.ref.type||g.values.next({name:D,values:{...a}})))}(X.shouldDirty||X.shouldTouch)&&z(D,ye,X.shouldTouch,X.shouldDirty,!0),X.shouldValidate&&U(D)},q=(D,G,X)=>{for(const be in G){const ye=G[be],pe=`${D}.${be}`,re=Re(r,pe);(l.array.has(D)||jt(ye)||re&&!re._f)&&!Wi(ye)?q(pe,ye,X):Z(pe,ye,X)}},oe=(D,G,X={})=>{const be=Re(r,D),ye=l.array.has(D),pe=mr(G);Dt(a,D,pe),ye?(g.array.next({name:D,values:{...a}}),(p.isDirty||p.dirtyFields)&&X.shouldDirty&&g.state.next({name:D,dirtyFields:Ec(o,a),isDirty:ce(D,pe)})):be&&!be._f&&!An(pe)?q(D,pe,X):Z(D,pe,X),BE(D,l)&&g.state.next({...n}),g.values.next({name:c.mount?D:void 0,values:{...a}})},Q=async D=>{c.mount=!0;const G=D.target;let X=G.name,be=!0;const ye=Re(r,X),pe=()=>G.type?Hm(ye._f):W$(D),re=ge=>{be=Number.isNaN(ge)||Wi(ge)&&isNaN(ge.getTime())||yi(ge,Re(a,X,ge))};if(ye){let ge,Be;const Qe=pe(),pt=D.type===$E.BLUR||D.type===$E.FOCUS_OUT,hn=!cH(ye._f)&&!e.resolver&&!Re(n.errors,X)&&!ye._f.deps||lH(pt,Re(n.touchedFields,X),n.isSubmitted,v,w),kn=BE(X,l,pt);Dt(a,X,Qe),pt?(ye._f.onBlur&&ye._f.onBlur(D),f&&f(0)):ye._f.onChange&&ye._f.onChange(D);const Wt=z(X,Qe,pt,!1),Hn=!$n(Wt)||kn;if(!pt&&g.values.next({name:X,type:D.type,values:{...a}}),hn)return p.isValid&&(e.mode==="onBlur"?pt&&_():_()),Hn&&g.state.next({name:X,...kn?{}:Wt});if(!pt&&kn&&g.state.next({...n}),e.resolver){const{errors:vr}=await j([X]);if(re(Qe),be){const zt=eS(n.errors,r,X),Bn=eS(vr,r,zt.name||X);ge=Bn.error,X=Bn.name,Be=$n(vr)}}else I([X],!0),ge=(await qE(ye,a,C,e.shouldUseNativeValidation))[X],I([X]),re(Qe),be&&(ge?Be=!1:p.isValid&&(Be=await W(r,!0)));be&&(ye._f.deps&&U(ye._f.deps),V(X,Be,ge,Wt))}},J=(D,G)=>{if(Re(n.errors,G)&&D.focus)return D.focus(),1},U=async(D,G={})=>{let X,be;const ye=$u(D);if(e.resolver){const pe=await te(Bt(D)?D:ye);X=$n(pe),be=D?!ye.some(re=>Re(pe,re)):X}else D?(be=(await Promise.all(ye.map(async pe=>{const re=Re(r,pe);return await W(re&&re._f?{[pe]:re}:re)}))).every(Boolean),!(!be&&!n.isValid)&&_()):be=X=await W(r);return g.state.next({...!po(D)||p.isValid&&X!==n.isValid?{}:{name:D},...e.resolver||!D?{isValid:X}:{},errors:n.errors}),G.shouldFocus&&!be&&Tc(r,J,D?ye:l.mount),be},ne=D=>{const G={...c.mount?a:o};return Bt(D)?G:po(D)?Re(G,D):D.map(X=>Re(G,X))},_e=(D,G)=>({invalid:!!Re((G||n).errors,D),isDirty:!!Re((G||n).dirtyFields,D),error:Re((G||n).errors,D),isValidating:!!Re(n.validatingFields,D),isTouched:!!Re((G||n).touchedFields,D)}),Ee=D=>{D&&$u(D).forEach(G=>en(n.errors,G)),g.state.next({errors:D?n.errors:{}})},Te=(D,G,X)=>{const be=(Re(r,D,{_f:{}})._f||{}).ref,ye=Re(n.errors,D)||{},{ref:pe,message:re,type:ge,...Be}=ye;Dt(n.errors,D,{...Be,...G,ref:be}),g.state.next({name:D,errors:n.errors,isValid:!1}),X&&X.shouldFocus&&be&&be.focus&&be.focus()},Ne=(D,G)=>go(D)?g.values.subscribe({next:X=>D(xe(void 0,G),X)}):xe(D,G,!0),Se=(D,G={})=>{for(const X of D?$u(D):l.mount)l.mount.delete(X),l.array.delete(X),G.keepValue||(en(r,X),en(a,X)),!G.keepError&&en(n.errors,X),!G.keepDirty&&en(n.dirtyFields,X),!G.keepTouched&&en(n.touchedFields,X),!G.keepIsValidating&&en(n.validatingFields,X),!e.shouldUnregister&&!G.keepDefaultValue&&en(o,X);g.values.next({values:{...a}}),g.state.next({...n,...G.keepDirty?{isDirty:ce()}:{}}),!G.keepIsValid&&_()},Oe=({disabled:D,name:G,field:X,fields:be,value:ye})=>{if(ho(D)&&c.mount||D){const pe=D?void 0:Bt(ye)?Hm(X?X._f:Re(be,G)._f):ye;(D||!D&&!Bt(pe))&&Dt(a,G,pe),z(G,pe,!1,!1,!0)}},De=(D,G={})=>{let X=Re(r,D);const be=ho(G.disabled)||ho(e.disabled);return Dt(r,D,{...X||{},_f:{...X&&X._f?X._f:{ref:{name:D}},name:D,mount:!0,...G}}),l.mount.add(D),X?Oe({field:X,disabled:ho(G.disabled)?G.disabled:e.disabled,name:D,value:G.value}):S(D,!0,G.value),{...be?{disabled:G.disabled||e.disabled}:{},...e.progressive?{required:!!G.required,min:Sc(G.min),max:Sc(G.max),minLength:Sc(G.minLength),maxLength:Sc(G.maxLength),pattern:Sc(G.pattern)}:{},name:D,onChange:Q,onBlur:Q,ref:ye=>{if(ye){De(D,G),X=Re(r,D);const pe=Bt(ye.value)&&ye.querySelectorAll&&ye.querySelectorAll("input,select,textarea")[0]||ye,re=iH(pe),ge=X._f.refs||[];if(re?ge.find(Be=>Be===pe):pe===X._f.ref)return;Dt(r,D,{_f:{...X._f,...re?{refs:[...ge.filter($m),pe,...Array.isArray(Re(o,D))?[{}]:[]],ref:{type:pe.type,name:D}}:{ref:pe}}}),S(D,!1,void 0,pe)}else X=Re(r,D,{}),X._f&&(X._f.mount=!1),(e.shouldUnregister||G.shouldUnregister)&&!(Y$(l.array,D)&&c.action)&&l.unMount.add(D)}}},Ue=()=>e.shouldFocusError&&Tc(r,J,l.mount),Me=D=>{ho(D)&&(g.state.next({disabled:D}),Tc(r,(G,X)=>{const be=Re(r,X);be&&(G.disabled=be._f.disabled||D,Array.isArray(be._f.refs)&&be._f.refs.forEach(ye=>{ye.disabled=be._f.disabled||D}))},0,!1))},nt=(D,G)=>async X=>{let be;if(X&&(X.preventDefault&&X.preventDefault(),X.persist&&X.persist()),e.disabled){G&&await G({...n.errors},X);return}let ye=mr(a);if(g.state.next({isSubmitting:!0}),e.resolver){const{errors:pe,values:re}=await j();n.errors=pe,ye=re}else await W(r);if(en(n.errors,"root"),$n(n.errors)){g.state.next({errors:{}});try{await D(ye,X)}catch(pe){be=pe}}else G&&await G({...n.errors},X),Ue(),setTimeout(Ue);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:$n(n.errors)&&!be,submitCount:n.submitCount+1,errors:n.errors}),be)throw be},we=(D,G={})=>{Re(r,D)&&(Bt(G.defaultValue)?oe(D,mr(Re(o,D))):(oe(D,G.defaultValue),Dt(o,D,mr(G.defaultValue))),G.keepTouched||en(n.touchedFields,D),G.keepDirty||(en(n.dirtyFields,D),n.isDirty=G.defaultValue?ce(D,mr(Re(o,D))):ce()),G.keepError||(en(n.errors,D),p.isValid&&_()),g.state.next({...n}))},lt=(D,G={})=>{const X=D?mr(D):o,be=mr(X),ye=$n(D),pe=ye?o:be;if(G.keepDefaultValues||(o=X),!G.keepValues){if(G.keepDirtyValues){const re=new Set([...l.mount,...Object.keys(Ec(o,a))]);for(const ge of Array.from(re))Re(n.dirtyFields,ge)?Dt(pe,ge,Re(a,ge)):oe(ge,Re(pe,ge))}else{if(Mm&&Bt(D))for(const re of l.mount){const ge=Re(r,re);if(ge&&ge._f){const Be=Array.isArray(ge._f.refs)?ge._f.refs[0]:ge._f.ref;if(Hu(Be)){const Qe=Be.closest("form");if(Qe){Qe.reset();break}}}}r={}}a=e.shouldUnregister?G.keepDefaultValues?mr(o):{}:mr(pe),g.array.next({values:{...pe}}),g.values.next({values:{...pe}})}l={mount:G.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},c.mount=!p.isValid||!!G.keepIsValid||!!G.keepDirtyValues,c.watch=!!e.shouldUnregister,g.state.next({submitCount:G.keepSubmitCount?n.submitCount:0,isDirty:ye?!1:G.keepDirty?n.isDirty:!!(G.keepDefaultValues&&!yi(D,o)),isSubmitted:G.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ye?{}:G.keepDirtyValues?G.keepDefaultValues&&a?Ec(o,a):n.dirtyFields:G.keepDefaultValues&&D?Ec(o,D):G.keepDirty?n.dirtyFields:{},touchedFields:G.keepTouched?n.touchedFields:{},errors:G.keepErrors?n.errors:{},isSubmitSuccessful:G.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Ct=(D,G)=>lt(go(D)?D(a):D,G);return{control:{register:De,unregister:Se,getFieldState:_e,handleSubmit:nt,setError:Te,_executeSchema:j,_getWatch:xe,_getDirty:ce,_updateValid:_,_removeUnmounted:me,_updateFieldArray:k,_updateDisabledField:Oe,_getFieldArray:K,_reset:lt,_resetDefaultValues:()=>go(e.defaultValues)&&e.defaultValues().then(D=>{Ct(D,e.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:D=>{n={...n,...D}},_disableForm:Me,_subjects:g,_proxyFormState:p,_setErrors:M,get _fields(){return r},get _formValues(){return a},get _state(){return c},set _state(D){c=D},get _defaultValues(){return o},get _names(){return l},set _names(D){l=D},get _formState(){return n},set _formState(D){n=D},get _options(){return e},set _options(D){e={...e,...D}}},trigger:U,register:De,handleSubmit:nt,watch:Ne,setValue:oe,getValues:ne,reset:Ct,resetField:we,clearErrors:Ee,unregister:Se,setError:Te,setFocus:(D,G={})=>{const X=Re(r,D),be=X&&X._f;if(be){const ye=be.refs?be.refs[0]:be.ref;ye.focus&&(ye.focus(),G.shouldSelect&&go(ye.select)&&ye.select())}},getFieldState:_e}}function hH(t={}){const e=O.useRef(),n=O.useRef(),[r,o]=O.useState({isDirty:!1,isValidating:!1,isLoading:go(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1,defaultValues:go(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...fH(t),formState:r});const a=e.current.control;return a._options=t,Z$({subject:a._subjects.state,next:c=>{X$(c,a._proxyFormState,a._updateFormState)&&o({...a._formState})}}),O.useEffect(()=>a._disableForm(t.disabled),[a,t.disabled]),O.useEffect(()=>{if(a._proxyFormState.isDirty){const c=a._getDirty();c!==r.isDirty&&a._subjects.state.next({isDirty:c})}},[a,r.isDirty]),O.useEffect(()=>{t.values&&!yi(t.values,n.current)?(a._reset(t.values,a._options.resetOptions),n.current=t.values,o(c=>({...c}))):a._resetDefaultValues()},[t.values,a]),O.useEffect(()=>{t.errors&&a._setErrors(t.errors)},[t.errors,a]),O.useEffect(()=>{a._state.mount||(a._updateValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),O.useEffect(()=>{t.shouldUnregister&&a._subjects.values.next({values:a._getWatch()})},[t.shouldUnregister,a]),O.useMemo(()=>({...e.current,formState:Q$(r,a)}),[r,a])}const tS=({className:t,children:e,content:n,side:r})=>{const[o,a]=O.useState(!1);return u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{open:o,children:[u.jsx(uo,{asChild:!0,children:u.jsx("button",{type:"button",className:Je("cursor-pointer",t),onClick:()=>a(!o),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onTouchStart:()=>a(!o),onKeyDown:c=>{c.preventDefault(),c.key==="Enter"&&a(!o)},children:e})}),u.jsx($r,{side:r,className:n?"":"hidden",children:u.jsx("span",{className:"inline-block",children:n})})]})})},pH=(t,e)=>{const[n,r]=O.useState(t);return O.useEffect(()=>{const o=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(o)}},[t,e]),n},gH=({apiBaseUrl:t="http://localhost:3000"})=>{var z,V;const[e,n]=O.useState([]),[r,o]=O.useState(!1),[a,c]=O.useState([]),[l,f]=O.useState(1),[h,p]=O.useState(1),[g,w]=O.useState(null),[v,C]=O.useState(""),y=pH(v,500),_=j=>{const te=j.match(/\d{6}/);if(!te)return{month:"",year:""};const W=te[0],me=W.substring(0,2),ce=W.substring(2);return{month:me,year:ce}},I=j=>j.map(W=>{let me=(W==null?void 0:W.month)||"",ce=(W==null?void 0:W.year)||"";if((!me||!ce)&&(W!=null&&W.file_name)){const xe=_(W.file_name);me=me||xe.month,ce=ce||xe.year}return{id:W==null?void 0:W.id,prefix:(W==null?void 0:W.prefix)||"",model:(W==null?void 0:W.model)||"",fileName:(W==null?void 0:W.file_name)||"",code:(W==null?void 0:W.stock_id)||"",month:me,year:ce,content:(W==null?void 0:W.text_summary)||"",status:(W==null?void 0:W.status)||"",note:(W==null?void 0:W.note)||"",lastUpdate:W==null?void 0:W.updated_at,stock_id:W==null?void 0:W.stock_id}}),k=j=>{if(!(j!=null&&j.data))return[];const te=I(j==null?void 0:j.data);n(te),p(j.pagination.totalPages)},R=async(j=1,te=15)=>{w(j),o(!0);try{const W=await Le.get(`${t}/api/latest-summaries`,{params:{page:j,limit:te,search:v}});(W==null?void 0:W.status)===200?k(W.data):console.error(W)}catch(W){console.error("Error fetching data:",W)}finally{w(null),o(!1)}};O.useEffect(()=>{y&&f(1),R(l)},[l,y]);const M=O.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:te})=>u.jsx("span",{className:"flex flex-col",children:te.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:te})=>{const W=te.original.month,me=te.original.year;return u.jsx("span",{className:"flex flex-col",children:`${W.toString().padStart(2,"0")}/${me}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:te})=>{const W=te.getValue("content");return u.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:W})}},{id:"status",header:"Trạng thái",accessorKey:"status",cell:({row:te})=>{const me=te.original.status!=="unpublish";return u.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${me?"bg-green-50 text-green-700 ring-1 ring-inset ring-green-600/20":"bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/20"}`,children:me?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:te})=>u.jsx(tS,{content:u.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:te.original.note}),children:u.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:te.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:te})=>{const W=new Date(te.original.lastUpdate),me=W.getDate(),ce=W.getMonth()+1,xe=`ngày ${me} tháng ${ce}`;return u.jsx("span",{className:"flex flex-col",children:xe})}},{accessorKey:"actions",header:()=>u.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:te})=>{const[W,me]=O.useState(!1),[ce,xe]=O.useState(!1),[K,Z]=O.useState(!1),{handleSubmit:q,register:oe,reset:Q}=hH(),J=te.original.id,U=te.getValue("status"),ne=te.getValue("content"),[_e,Ee]=O.useState(!1),Te=async()=>{try{Ee(!0);const Se=U==="unpublish"?"published":"unpublish",Oe=await Le.patch(`${t}/api/toggle-publish/${J}`,{id:J,typeAction:"update",status:U,idInput:J,stock_id:te.original.stock_id,prefix:te.original.prefix,model:te.original.model,summary_result:te.original.content,note:te.original.note});Oe.status===200?n(De=>De.map(Ue=>Ue.id===J?{...Ue,status:Se}:Ue)):console.error("Failed to toggle publish status:",Oe)}catch(Se){console.error("Error toggling publish status:",Se)}finally{Ee(!1)}},Ne=async Se=>{me(!0);try{const Oe=await Le.patch(`${t}/api/update-summary`,{note:Se.note,text_summary:Se.content,id:J});Oe.status===200?(await R(l),xe(!1)):console.error("Failed to update summary:",Oe)}catch(Oe){console.error("Error updating summary:",Oe)}return me(!1)};return u.jsxs("div",{className:"flex items-center justify-end gap-2",children:[u.jsx($e,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:u.jsx(lR,{className:"h-4 w-4"})}),u.jsx(gr,{open:K,onOpenChange:Z,children:u.jsxs(er,{className:"max-w-3xl max-h-[80vh]",children:[u.jsx(tr,{children:u.jsx(nr,{children:"Nội dung chi tiết"})}),u.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:u.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:ne})})]})}),u.jsxs(gr,{open:ce,onOpenChange:Se=>{xe(Se),Se?Q({content:te.original.content,note:te.original.note}):Q()},children:[u.jsx(cc,{asChild:!0,children:u.jsx($e,{variant:"outline",size:"sm",onClick:()=>xe(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),u.jsx(er,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:u.jsxs(tr,{className:"flex flex-col gap-3",children:[u.jsx(nr,{className:"max-sm:hidden text-center",children:"Sửa summary"}),u.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:q(Ne),children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex flex-col items-start",children:[u.jsx("span",{children:"Nội dung:"}),u.jsx(fc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:te.original.answer||"",rows:10,...oe("content")})]}),u.jsxs("div",{className:"flex flex-col items-start",children:[u.jsx("span",{children:"Ghi chú:"}),u.jsx(fc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:te.original.note||"",rows:1,...oe("note")})]})]}),u.jsx("div",{className:"flex justify-end",children:u.jsx($e,{disabled:W,type:"submit",variant:"default",children:W?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),u.jsx($e,{variant:"outline",size:"sm",onClick:Te,disabled:_e,className:"w-[70px] px-2 py-0.5 h-7",children:_e?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):U==="unpublish"?"Publish":"Unpublish"})]})}}],[]),S=Nb({data:e,columns:M,state:{columnFilters:a},enableRowSelection:!0,onColumnFiltersChange:c,getFilteredRowModel:h1(),getCoreRowModel:kb()});return u.jsxs("div",{className:"space-y-4 s3-explr-container",children:[u.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:u.jsxs("div",{className:"relative max-w-sm",children:[u.jsx(oo,{placeholder:"Tìm kiếm theo mã...",value:v,onChange:j=>C(j.target.value),className:"pr-8"}),v&&u.jsx($e,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>C(""),children:u.jsx(bg,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"rounded-md border s3-explr-table-container",children:u.jsxs(lc,{className:"s3-explr-table",children:[u.jsx(dc,{className:"s3-explr-table-header",children:S.getHeaderGroups().map(j=>u.jsx(rr,{className:"hover:bg-transparent s3-explr-header-row",children:j.headers.map(te=>u.jsx(or,{className:"s3-explr-header-cell",children:te.isPlaceholder?null:Ld(te.column.columnDef.header,te.getContext())},te.id))},j.id))}),u.jsx(uc,{className:"s3-explr-table-body",children:r?u.jsx(rr,{children:u.jsx(un,{colSpan:M.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(z=S.getRowModel().rows)!=null&&z.length?(V=S.getRowModel().rows)==null?void 0:V.map(j=>u.jsx(rr,{className:"h-12 s3-explr-row",children:j.getVisibleCells().map(te=>u.jsx(un,{className:"align-middle s3-explr-cell",children:Ld(te.column.columnDef.cell,te.getContext())},te.id))},j.id)):u.jsx(rr,{children:u.jsx(un,{colSpan:M.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),u.jsx("div",{className:"mt-4",children:u.jsx(ru,{children:u.jsxs(ou,{children:[u.jsx(Fr,{children:u.jsx(iu,{onClick:()=>f(j=>Math.max(1,j-1)),className:l===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:h},(j,te)=>te+1).filter(j=>j===1||j===h||Math.abs(j-l)<=1).map((j,te,W)=>u.jsxs(u.Fragment,{children:[te>0&&W[te-1]!==j-1&&u.jsx(Fr,{children:u.jsx(su,{})},j+"..."),u.jsx(Fr,{children:u.jsx(ja,{onClick:()=>f(j),isActive:l===j,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===j?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):j})},j)]})),u.jsx(Fr,{children:u.jsx(au,{onClick:()=>f(j=>Math.min(h,j+1)),className:l===h||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},nS=10,mH=O.memo(({apiBaseUrl:t="http://localhost:3000"})=>{const[e,n]=O.useState(1),[r,o]=O.useState([]),[a,c]=O.useState({total:0,page:1,limit:nS,totalPages:1}),[l,f]=O.useState(!0),[h,p]=O.useState(null),[g,w]=O.useState(new Set),{toast:v}=yu(),[C,y]=O.useState(!1),_=async S=>{try{p(S);const z=await Le.get(`${t}/api/jobs`,{params:{page:S.toString(),limit:nS.toString()}});o(z.data.data),c(z.data.pagination)}catch{v({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{p(null),f(!1)}};O.useEffect(()=>{_(e)},[e,t]);const I=async S=>{w(z=>new Set(z).add(S.toString()));try{await Le.post(`${t}/api/retry-job`,{jobId:S},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v({title:"Job Restarted",description:`Job ${S} has been successfully restarted.`}),_(e)}catch{v({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${S}. Please try again.`})}finally{w(z=>{const V=new Set(z);return V.delete(S.toString()),V})}},k=async()=>{y(!0),n(1),await _(1),y(!1)},R=S=>new Date(S).toLocaleString(),M=S=>{if(S=parseFloat(S),S<60)return`${S.toFixed(2)}s`;const z=Math.floor(S/60),V=(S%60).toFixed(0);return`${z}m ${V}s`};return u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[u.jsx(iR,{className:"w-8 h-8 text-primary"}),u.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),u.jsx($e,{variant:"outline",size:"icon",onClick:k,disabled:C||l,className:"ml-2",children:u.jsx(fR,{className:`h-4 w-4 ${C?"animate-spin":""}`})})]}),u.jsx("div",{className:"rounded-md border",children:u.jsxs(lc,{children:[u.jsx(dc,{children:u.jsxs(rr,{children:[u.jsx(or,{children:"ID"}),u.jsx(or,{children:"Tên Công Việc"}),u.jsx(or,{children:"Thời Gian Bắt Đầu"}),u.jsx(or,{children:"Thời Gian Cập Nhật"}),u.jsx(or,{children:"Thời Gian Thực Thi"}),u.jsx(or,{children:"Trạng Thái"}),u.jsx(or,{children:"Thao Tác"})]})}),u.jsx(uc,{children:l&&r.length===0?u.jsx(rr,{children:u.jsx(un,{colSpan:7,className:"text-center py-4",children:u.jsx(Ht,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(S=>{var z,V;return u.jsxs(rr,{children:[u.jsx(un,{className:"!w-[100px]",children:S.id}),u.jsx(un,{className:"font-medium",children:(z=S.job_name)==null?void 0:z.replace("Upload file","Summary")}),u.jsx(un,{className:"!w-[200px]",children:R(S.created_at)}),u.jsx(un,{className:"!w-[200px]",children:R(S.updated_at)}),u.jsx(un,{className:"!w-[150px]",children:M(S.execution_time_seconds)}),u.jsx(un,{className:"!w-[200px]",children:u.jsx(tS,{content:S.status==="fail"&&S.error?u.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:S.error}):null,children:u.jsx("div",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]
217
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function PE(t,e){if(t){if(typeof t=="string")return km(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return km(t,e)}}function km(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function N$(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(f){a=!0,l=f}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function P$(t){if(Array.isArray(t))return t}function OE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Ut(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?OE(Object(n),!0).forEach(function(r){Nm(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):OE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Nm(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Fu(t,e){if(t==null)return{};var n=O$(t,e),r,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(o=0;o<a.length;o++)r=a[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function O$(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,a;for(a=0;a<r.length;a++)o=r[a],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var Pm=O.forwardRef(function(t,e){var n=t.children,r=Fu(t,b$),o=RE(r),a=o.open,c=Fu(o,x$);return O.useImperativeHandle(e,function(){return{open:a}},[a]),O.createElement(O.Fragment,null,n(Ut(Ut({},c),{},{open:a})))});Pm.displayName="Dropzone";var ME={disabled:!1,getFilesFromEvent:VU,maxSize:1/0,minSize:0,multiple:!0,maxFiles:0,preventDropOnDocument:!0,noClick:!1,noKeyboard:!1,noDrag:!1,noDragEventsBubbling:!1,validator:null,useFsAccessApi:!1,autoFocus:!1};Pm.defaultProps=ME,Pm.propTypes={children:It.func,accept:It.objectOf(It.arrayOf(It.string)),multiple:It.bool,preventDropOnDocument:It.bool,noClick:It.bool,noKeyboard:It.bool,noDrag:It.bool,noDragEventsBubbling:It.bool,minSize:It.number,maxSize:It.number,maxFiles:It.number,disabled:It.bool,getFilesFromEvent:It.func,onFileDialogCancel:It.func,onFileDialogOpen:It.func,useFsAccessApi:It.bool,autoFocus:It.bool,onDragEnter:It.func,onDragLeave:It.func,onDragOver:It.func,onDrop:It.func,onDropAccepted:It.func,onDropRejected:It.func,onError:It.func,validator:It.func};var Om={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function RE(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Ut(Ut({},ME),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,a=e.maxSize,c=e.minSize,l=e.multiple,f=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,g=e.onDragOver,w=e.onDrop,v=e.onDropAccepted,C=e.onDropRejected,y=e.onFileDialogCancel,_=e.onFileDialogOpen,I=e.useFsAccessApi,k=e.autoFocus,R=e.preventDropOnDocument,M=e.noClick,S=e.noKeyboard,z=e.noDrag,V=e.noDragEventsBubbling,j=e.onError,te=e.validator,W=O.useMemo(function(){return y$(n)},[n]),me=O.useMemo(function(){return v$(n)},[n]),ce=O.useMemo(function(){return typeof _=="function"?_:DE},[_]),xe=O.useMemo(function(){return typeof y=="function"?y:DE},[y]),K=O.useRef(null),Z=O.useRef(null),q=O.useReducer(M$,Om),oe=Im(q,2),Q=oe[0],J=oe[1],U=Q.isFocused,ne=Q.isFileDialogActive,_e=O.useRef(typeof window<"u"&&window.isSecureContext&&I&&m$()),Ee=function(){!_e.current&&ne&&setTimeout(function(){if(Z.current){var ge=Z.current.files;ge.length||(J({type:"closeDialog"}),xe())}},300)};O.useEffect(function(){return window.addEventListener("focus",Ee,!1),function(){window.removeEventListener("focus",Ee,!1)}},[Z,ne,xe,_e]);var Te=O.useRef([]),Ne=function(ge){K.current&&K.current.contains(ge.target)||(ge.preventDefault(),Te.current=[])};O.useEffect(function(){return R&&(document.addEventListener("dragover",IE,!1),document.addEventListener("drop",Ne,!1)),function(){R&&(document.removeEventListener("dragover",IE),document.removeEventListener("drop",Ne))}},[K,R]),O.useEffect(function(){return!r&&k&&K.current&&K.current.focus(),function(){}},[K,k,r]);var Se=O.useCallback(function(re){j?j(re):console.error(re)},[j]),Oe=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re),Te.current=[].concat(E$(Te.current),[re.target]),Du(re)&&Promise.resolve(o(re)).then(function(ge){if(!(Ru(re)&&!V)){var Be=ge.length,Qe=Be>0&&f$({files:ge,accept:W,minSize:c,maxSize:a,multiple:l,maxFiles:f,validator:te}),pt=Be>0&&!Qe;J({isDragAccept:Qe,isDragReject:pt,isDragActive:!0,type:"setDraggedFiles"}),h&&h(re)}}).catch(function(ge){return Se(ge)})},[o,h,Se,V,W,c,a,l,f,te]),De=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re);var ge=Du(re);if(ge&&re.dataTransfer)try{re.dataTransfer.dropEffect="copy"}catch{}return ge&&g&&g(re),!1},[g,V]),Ue=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re);var ge=Te.current.filter(function(Qe){return K.current&&K.current.contains(Qe)}),Be=ge.indexOf(re.target);Be!==-1&&ge.splice(Be,1),Te.current=ge,!(ge.length>0)&&(J({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Du(re)&&p&&p(re))},[K,p,V]),Me=O.useCallback(function(re,ge){var Be=[],Qe=[];re.forEach(function(pt){var hn=SE(pt,W),kn=Im(hn,2),Wt=kn[0],Hn=kn[1],vr=AE(pt,c,a),zt=Im(vr,2),Bn=zt[0],mo=zt[1],Br=te?te(pt):null;if(Wt&&Bn&&!Br)Be.push(pt);else{var ze=[Hn,mo];Br&&(ze=ze.concat(Br)),Qe.push({file:pt,errors:ze.filter(function(vo){return vo})})}}),(!l&&Be.length>1||l&&f>=1&&Be.length>f)&&(Be.forEach(function(pt){Qe.push({file:pt,errors:[u$]})}),Be.splice(0)),J({acceptedFiles:Be,fileRejections:Qe,isDragReject:Qe.length>0,type:"setFiles"}),w&&w(Be,Qe,ge),Qe.length>0&&C&&C(Qe,ge),Be.length>0&&v&&v(Be,ge)},[J,l,W,c,a,f,w,v,C,te]),nt=O.useCallback(function(re){re.preventDefault(),re.persist(),X(re),Te.current=[],Du(re)&&Promise.resolve(o(re)).then(function(ge){Ru(re)&&!V||Me(ge,re)}).catch(function(ge){return Se(ge)}),J({type:"reset"})},[o,Me,Se,V]),we=O.useCallback(function(){if(_e.current){J({type:"openDialog"}),ce();var re={multiple:l,types:me};window.showOpenFilePicker(re).then(function(ge){return o(ge)}).then(function(ge){Me(ge,null),J({type:"closeDialog"})}).catch(function(ge){w$(ge)?(xe(ge),J({type:"closeDialog"})):C$(ge)?(_e.current=!1,Z.current?(Z.current.value=null,Z.current.click()):Se(new Error("Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided."))):Se(ge)});return}Z.current&&(J({type:"openDialog"}),ce(),Z.current.value=null,Z.current.click())},[J,ce,xe,I,Me,Se,me,l]),lt=O.useCallback(function(re){!K.current||!K.current.isEqualNode(re.target)||(re.key===" "||re.key==="Enter"||re.keyCode===32||re.keyCode===13)&&(re.preventDefault(),we())},[K,we]),Ct=O.useCallback(function(){J({type:"focus"})},[]),fn=O.useCallback(function(){J({type:"blur"})},[]),In=O.useCallback(function(){M||(g$()?setTimeout(we,0):we())},[M,we]),Lt=function(ge){return r?null:ge},D=function(ge){return S?null:Lt(ge)},G=function(ge){return z?null:Lt(ge)},X=function(ge){V&&ge.stopPropagation()},be=O.useMemo(function(){return function(){var re=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ge=re.refKey,Be=ge===void 0?"ref":ge,Qe=re.role,pt=re.onKeyDown,hn=re.onFocus,kn=re.onBlur,Wt=re.onClick,Hn=re.onDragEnter,vr=re.onDragOver,zt=re.onDragLeave,Bn=re.onDrop,mo=Fu(re,_$);return Ut(Ut(Nm({onKeyDown:D(fo(pt,lt)),onFocus:D(fo(hn,Ct)),onBlur:D(fo(kn,fn)),onClick:Lt(fo(Wt,In)),onDragEnter:G(fo(Hn,Oe)),onDragOver:G(fo(vr,De)),onDragLeave:G(fo(zt,Ue)),onDrop:G(fo(Bn,nt)),role:typeof Qe=="string"&&Qe!==""?Qe:"presentation"},Be,K),!r&&!S?{tabIndex:0}:{}),mo)}},[K,lt,Ct,fn,In,Oe,De,Ue,nt,S,z,r]),ye=O.useCallback(function(re){re.stopPropagation()},[]),pe=O.useMemo(function(){return function(){var re=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ge=re.refKey,Be=ge===void 0?"ref":ge,Qe=re.onChange,pt=re.onClick,hn=Fu(re,T$),kn=Nm({accept:W,multiple:l,type:"file",style:{border:0,clip:"rect(0, 0, 0, 0)",clipPath:"inset(50%)",height:"1px",margin:"0 -1px -1px 0",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"},onChange:Lt(fo(Qe,nt)),onClick:Lt(fo(pt,ye)),tabIndex:-1},Be,Z);return Ut(Ut({},kn),hn)}},[Z,n,l,nt,r]);return Ut(Ut({},Q),{},{isFocused:U&&!r,getRootProps:be,getInputProps:pe,rootRef:K,inputRef:Z,open:Lt(we)})}function M$(t,e){switch(e.type){case"focus":return Ut(Ut({},t),{},{isFocused:!0});case"blur":return Ut(Ut({},t),{},{isFocused:!1});case"openDialog":return Ut(Ut({},Om),{},{isFileDialogActive:!0});case"closeDialog":return Ut(Ut({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ut(Ut({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Ut(Ut({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Ut({},Om);default:return t}}function DE(){}const R$=({onFilesSelected:t,children:e})=>{const[n,r]=O.useState(!1),{getRootProps:o,getInputProps:a}=RE({noClick:!0,onDrop:c=>{if(c&&c.length>0)if(c[0].path.split("/").length>2){const f=c.map(h=>{const g=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),h});t(f,"folder")}else t(c,"files");r(!1)},onDragOver:c=>{c.preventDefault(),n||r(!0)},multiple:!0});return O.useEffect(()=>{const c=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",c),()=>{document.removeEventListener("dragleave",c)}},[]),u.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?u.jsx("div",{className:"flex flex-col items-center justify-center p-4 border-2 border-dashed border-gray-300 rounded-lg bg-gray-50 h-screen"}):e,u.jsx("input",{...a()})]})},D$=({isOpen:t,onClose:e,files:n})=>{const[r,o]=O.useState(null),a=l=>{o(f=>!f||f.key!==l?{key:l,direction:"asc"}:{key:l,direction:f.direction==="asc"?"desc":"asc"})},c=O.useMemo(()=>r?[...n].sort((l,f)=>{var g,w;const h=((g=l[r.key])==null?void 0:g.toString().toLowerCase())||"",p=((w=f[r.key])==null?void 0:w.toString().toLowerCase())||"";return h<p?r.direction==="asc"?-1:1:h>p?r.direction==="asc"?1:-1:0}):n,[n,r]);return console.log("sortedParsingFiles",c),u.jsx(gr,{open:t,onOpenChange:e,children:u.jsxs(er,{className:"sm:max-w-[825px]",children:[u.jsxs(tr,{children:[u.jsx(nr,{children:"Tài liệu đang xử lý"}),u.jsx(Ro,{children:"Đây là danh sách các tài liệu đang trong hàng đợi xử lý."})]}),u.jsx("div",{className:"max-h-96 overflow-y-auto",children:u.jsxs(lc,{children:[u.jsx(dc,{children:u.jsxs(rr,{children:[u.jsxs(or,{colSpan:2,className:"text-left cursor-pointer hover:underline",onClick:()=>a("type"),children:["Loại ",(r==null?void 0:r.key)==="type"&&(r.direction==="asc"?"↑":"↓")]}),u.jsxs(or,{colSpan:3,className:"text-left cursor-pointer hover:underline",onClick:()=>a("name"),children:["Tên tệp"," ",(r==null?void 0:r.key)==="name"&&(r.direction==="asc"?"↑":"↓")]}),u.jsx(or,{className:"text-left",children:"Ghi chú"})]})}),u.jsx(uc,{children:c.length>0&&c.map(l=>u.jsxs(rr,{children:[u.jsx(un,{colSpan:2,children:l.type}),u.jsx(un,{colSpan:3,className:"font-medium text-left truncate max-w-[200px]",title:l.name,children:l.name}),u.jsx(un,{children:!!l.unSupported&&!l.isFolder&&`Không hỗ trợ file ${l.name.split(".").pop()}`})]}))})]})})]})})},F$=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:a,ignoreCache:c,autoSyncAfterFileOperation:l})=>{var R;const[f,h]=O.useState({}),[p,g]=O.useState(!1),[w,v]=O.useState(!1),[C,y]=O.useState(""),{toast:_}=yu();O.useEffect(()=>{t&&I(C)},[C,t]);const I=async M=>{try{v(!0);const S=await Le.get(`${n}/api/list-s3-folders?prefix=${M}`,{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});h(S==null?void 0:S.data)}catch{_({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{v(!1)}},k=async()=>{g(!0);try{const M=o.key,S=M.endsWith("/")?M:`${M}/`,z=C.endsWith("/")?C:`${C}/`;if(S===z||M===C){_({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),g(!1);return}await Le.post(`${n}/api/move`,{oldPath:M,newPath:C},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),c.current=!0,await a(),_({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${C}"`}),e(!1),r(null),y(""),l&&await l("move")}catch(M){console.error("Error renaming item:",M),_({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{g(!1)}};return u.jsx(gr,{open:t,onOpenChange:M=>{M||(e(!1),r(null),y(""))},children:u.jsxs(er,{className:"max-h-[700px] pb-3 px-1 s3-explr-input-group max-w-5xl w-[90%] p-6 bg-white rounded-lg shadow-lg",children:[u.jsxs(tr,{className:"mb-4 w-full h-full",children:[u.jsx("nav",{className:"mb-4",children:u.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[u.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(""),children:"Root"}),C.split("/").map((M,S,z)=>u.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(M==="Root"?"":z.slice(0,S+1).join("/")+"/"),children:M},S))]})}),u.jsxs(nr,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",u.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",C===""?"Root":C," )"]})]}),u.jsx(Ro,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:w?u.jsx("div",{className:"flex justify-center items-center py-4",children:u.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):u.jsx("ul",{className:"space-y-2",children:(R=Object.keys(f))==null?void 0:R.map(M=>u.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>y(M),children:M},M))})})]}),u.jsxs(Mo,{className:"flex justify-end space-x-2",children:[u.jsx($e,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),u.jsx($e,{onClick:k,disabled:p,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},L$="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",U$="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",$$="https://www.googleapis.com/auth/drive";Po(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Po.isRetryableError(t)&&t.config.method==="get"});const Un={current:!1},FE="crawl:jobs",es="crawl:current_job",H$=t=>{const[e,n]=O.useState(null),[r,o]=O.useState(0);return O.useEffect(()=>{const a=localStorage.getItem(es);if(a){const c=JSON.parse(a);n(c),c!=null&&c.startTime&&o(Math.floor((Date.now()-c.startTime)/1e3))}},[]),O.useEffect(()=>{if(!(e!=null&&e.startTime))return;const a=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(a)},[e==null?void 0:e.startTime]),O.useEffect(()=>{if(!(e!=null&&e.id))return;const a=async()=>{try{const f=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:f};return localStorage.setItem(es,JSON.stringify(p)),(f.status==="completed"||f.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(es)},100),p})}catch(l){console.error("Error polling job status:",l)}},c=setInterval(a,3e3);return a(),()=>clearInterval(c)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:a=>{a&&!a.startTime&&(a.startTime=Date.now()),n(a),a?localStorage.setItem(es,JSON.stringify(a)):localStorage.removeItem(es)}}},Lu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(c=>{n.push(c.key),c.isFolder&&r(c.key)})};return r(e),n},B$=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Lu(t,o.key))}),n},z$=(t,e,n=[],r,o,a,c,l,f,h)=>{const[p,g]=O.useState({}),[w,v]=O.useState(!1),[C,y]=O.useState(null),[_,I]=O.useState(0),k=O.useRef(e);O.useEffect(()=>{k.current=e},[e]);const R=async()=>{v(!0);try{const S=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:k.current,excludePrivateFiles:c?"false":"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5}),z=[];Qd.forEach(S.data,(V,j)=>{l!=null&&l.has(j)&&Qd.forEach(V,te=>{(f==null?void 0:f.current[te.key])!==!1&&z.push(te.key)})}),z.length&&(h==null||h(V=>{const j=new Set(V);return z.forEach(te=>j.add(te)),j})),g(S.data),y(null)}catch(S){y(S instanceof Error?S:new Error("Failed to fetch files"))}finally{v(!1),I(0),a("")}},M=async S=>{var z,V;try{if(!S)return;v(!0);const j=await Le.get(`${t}/api/search-db?query=${S}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5,headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});return g({[e]:((z=j==null?void 0:j.data)==null?void 0:z.result)||[]}),I(((V=j==null?void 0:j.data)==null?void 0:V.estimatedTotalHits)||0),j}catch(j){y(j instanceof Error?j:new Error("Failed to fetch files"))}finally{v(!1)}};return O.useEffect(()=>{!r&&!w&&R(),r&&!w&&M(r)},[r,o]),{data:p,isLoading:w,error:C,estimatedTotalHits:_,refetch:R}},xc=t=>{var r,o,a;const e=((a=(o=(r=t==null?void 0:t.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:a.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(e||"")},G$={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:"http://localhost:5173/"}},V$=new Cp(G$),K$=O.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3000",rootPrefix:n="",rootUrlHostApi:r,asSelector:o=!1,onSelected:a=h=>console.log("Đã chọn:",h),displayPrefixes:c,preSelectedFiles:l,idCreator:f})=>{var pf;const[h,p]=O.useState([]),[g,w]=O.useState(""),[v,C]=O.useState(new Set(l)),[y,_]=O.useState(n),[I,k]=O.useState(""),[R,M]=O.useState(!1),[S,z]=O.useState(""),[V,j]=O.useState(!1),[te,W]=O.useState(null),[me,ce]=O.useState(null),[xe,K]=O.useState(!1),[Z,q]=O.useState(!1),[,oe]=O.useState(null),Q=O.useRef(null),{toast:J}=yu(),[U,ne]=O.useState(null),[_e,Ee]=O.useState(null),[Te,Ne]=O.useState(""),[Se,Oe]=O.useState(!1),[De,Ue]=O.useState(!1),[Me,nt]=O.useState(new Set),[we,lt]=O.useState(""),[Ct,fn]=O.useState(!1),[In,Lt]=O.useState(!1),[D,G]=O.useState("rename"),[X,be]=O.useState(!1),[ye,pe]=O.useState(""),[re,ge]=O.useState("1"),[Be,Qe]=O.useState(!1),[pt,hn]=O.useState(!1),[kn,Wt]=O.useState(!1),[Hn,vr]=O.useState(!1),[zt,Bn]=O.useState(1),[mo,Br]=O.useState(!1),{currentJob:ze,elapsedTime:vo,setCurrentJob:Vu}=H$(e),[zr,wi]=O.useState(null),[qi,ns]=O.useState(""),[Bm,Yi]=O.useState(!1),[Ji,Ku]=O.useState(""),[zm,ju]=O.useState(!1),[Ac,Wu]=O.useState(!1),[Ci,qu]=O.useState([]),[Qi,Yu]=O.useState(!1),[rs,Gm]=O.useState(""),[Ju,Vm]=O.useState({faqUploadSize:[],hdsdUploadSize:[],normalUploadSize:[],faqParsedSize:[],hdsdParsedSize:[],normalParsedSize:[]}),[Km,Ic]=O.useState(!1),Ho=O.useRef({}),jm=async T=>{Wu(!0);try{const N=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${T}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});N.status===200&&qu(N.data.knowledgeBase.chatflows.map($=>({...$,KnowledgeBaseId:N.data.knowledgeBase.knowledge_base_id})))}catch{}finally{Wu(!1)}};O.useEffect(()=>{Ji&&r&&jm(Ji)},[Ji]),O.useEffect(()=>{console.log("pre selected files",l)},[l]);const[kt,kc]=O.useState(null),[rS,Wm]=O.useState(!1),[Nc,Pc]=O.useState(!1),[Xi,os]=O.useState(!1),[Qu,Xu]=O.useState([]),[Oc,Mc]=O.useState([]),[Zi,Rc]=O.useState([{id:"root",name:"OneDrive"}]),[qm,is]=O.useState(!1),[as,Dc]=O.useState([]),[Zu,Bo]=O.useState(!1),[ss,Fc]=O.useState([]),[Lc,cs]=O.useState([]),[ls,ef]=O.useState([]),[Uc,ea]=O.useState([{id:"root",name:"SharePoint"}]),[yo,ta]=O.useState(!1),[$c,Hc]=O.useState([]),[gt,Gr]=O.useState(null),[tf,na]=O.useState(!1),[Ym,ra]=O.useState(!1),nf=new URL(window.location.href).searchParams.get("prefix")||""||I||n,[oS,Xm]=O.useState(null),{data:wo,isLoading:bi,error:Zm,estimatedTotalHits:oa,refetch:on}=z$(e,nf,c,g,zt,w,f,v,Ho,C),[Bc,yr]=O.useState(!1),zc=O.useRef(null);O.useEffect(()=>{if(!Bc)return;function T(N){zc.current&&!zc.current.contains(N.target)&&yr(!1)}return document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[Bc]);const ev=async()=>{try{const T=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:N}=T.data,$=window.open(N,"SharePoint Login","width=600,height=600");if(!$)throw new Error("Không thể mở cửa sổ pop-up");$.focus();const ie=setInterval(()=>{try{if($.closed){clearInterval(ie);return}const fe=$.location.href;if(fe.includes("code=")){const Ce=new URL(fe).searchParams.get("code");Ce&&(rf(Ce),$.close(),clearInterval(ie))}}catch(fe){fe instanceof Error&&!fe.message.includes("cross-origin")&&console.error("SharePoint login error:",fe)}},1e3)}catch(T){at.error("Lỗi khi đăng nhập SharePoint: "+(T instanceof Error?T.message:"Unknown error"))}},tv=async()=>{try{Fc([]),ea([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),J({title:"Success",description:"Logged out from SharePoint"})}catch(T){console.error("Error logging out from SharePoint:",T),J({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},rf=async T=>{try{const N=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:T,userId:"1"}),{accessToken:$}=N.data;localStorage.setItem("sharepoint_access_token",$),Pc(!0),ta(!0)}catch(N){console.error("❌ Error fetching SharePoint access token:",N),J({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},nv=async()=>{try{Bo(!0);const N=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map($=>{const ie=new URL($.webUrl);return{id:$.id,name:$.name,description:$.description,hostname:$.hostname||ie.hostname,sitePath:$.sitePath||ie.pathname.replace(/^\/+/,"")}});Hc(N),Bo(!1)}catch(T){console.error("❌ Error fetching SharePoint sites:",T),J({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),Bo(!1)}},Nt=async T=>{Gr(T),await mt("root",T.name,T.hostname||"",T.sitePath||"")},mt=async(T,N,$,ie)=>{try{Bo(!0);const Ce=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:T,userId:"1",hostname:$,sitePath:ie})).data.files.map(Ae=>({id:Ae.id,name:Ae.name,size:Ae.size??0,lastModified:Ae.lastModifiedDateTime?new Date(Ae.lastModifiedDateTime):new Date,contentType:Ae.mimeType??void 0,isFolder:Ae.type==="folder",parentId:Ae.parentId??""}));cs(Ce.filter(Ae=>Ae.isFolder)),Fc(Ce.filter(Ae=>!Ae.isFolder)),ta(!0),ea(Ae=>Ae.some(Et=>Et.id===T)?Ae:[...Ae,{id:T,name:N==="root"?"SharePoint":N}]),Bo(!1)}catch(fe){console.error("❌ Error fetching SharePoint files:",fe),J({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),Bo(!1)}},rv=T=>{ef(N=>N.some(ie=>ie.id===T.id)?N.filter(ie=>ie.id!==T.id):[...N,{id:T.id,name:T.name,size:T.size,lastModified:T.lastModified,contentType:T.contentType,isFolder:T.isFolder,parentId:T.parentId}])},ov=T=>{var $;ea(ie=>ie.slice(0,T+1));const N=($=Uc[T])==null?void 0:$.id;N&&mt(N,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},iv=async(T,N)=>{const $=localStorage.getItem("sharepoint_access_token");if(!$){at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const ie=at.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};T.forEach(Ae=>{Ae.isFolder?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-sharepoint-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),ta(!1)}catch(fe){console.error("Lỗi khi đồng bộ file từ SharePoint:",fe),at.update(ie,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},of=()=>{ta(!1),Fc([]),ef([]),ea([{id:"root",name:"SharePoint"}])};O.useEffect(()=>{if(yo){const N=new URLSearchParams(window.location.search).get("code");N&&(rf(N),window.history.replaceState({},document.title,window.location.pathname))}},[yo]),O.useEffect(()=>{V$.initialize().then(()=>{Wm(!0)}).catch(T=>console.error("❌ Lỗi khởi tạo MSAL:",T))},[]),O.useEffect(()=>{av()},[]);async function av(){localStorage.getItem("onedrive_access_token")&&Pc(!0)}const af=T=>{Dc(N=>N.some(ie=>ie.id===T.id)?N.filter(ie=>ie.id!==T.id):[...N,{id:T.id,name:T.name,size:T.size,lastModified:T.lastModified,contentType:T.contentType,isFolder:T.isFolder,parentId:T.parentId}])};function ds(T){if(T===0)return"0 B";const N=1024,$=["B","KB","MB","GB","TB"],ie=Math.floor(Math.log(T)/Math.log(N));return parseFloat((T/Math.pow(N,ie)).toFixed(1))+" "+$[ie]}function sv(T){const N=new Date(T);return N.toLocaleDateString()+" "+N.toLocaleTimeString()}const tn=async()=>{try{const T=await Le.get(`${e}/api/login-one-drive`),{loginUrl:N}=T.data,$=window.open(N,"OneDrive Login","width=600,height=600");if(!$)throw new Error("Không thể mở cửa sổ pop-up");$.focus();const ie=setInterval(()=>{try{if($.closed){clearInterval(ie);return}const fe=$.location.href;if(fe.includes("code=")){const Ce=new URL(fe).searchParams.get("code");Ce&&(zo(Ce),$.close(),clearInterval(ie))}}catch(fe){fe instanceof Error&&!fe.message.includes("cross-origin")&&console.error("OneDrive login error:",fe)}},1e3)}catch(T){at.error("Lỗi khi đăng nhập OneDrive: "+(T instanceof Error?T.message:"Unknown error"))}},Gc=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),at.success("Đã đăng xuất khỏi OneDrive"),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin)}catch(T){at.error("Lỗi khi đăng xuất OneDrive: "+(T instanceof Error?T.message:"Unknown error"))}},zo=async T=>{try{const $=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:T,userId:"1"}),{accessToken:ie}=$.data;localStorage.setItem("onedrive_access_token",ie),Pc(!0),os(!0),await ia("root","One Drive")}catch(N){console.error("❌ Lỗi khi lấy Access Token:",N)}},ia=async(T,N)=>{try{is(!0);const fe=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:T,userId:"1"})).data.map(Ce=>({id:Ce.id,name:Ce.name,size:Ce.size??0,lastModified:Ce.lastModifiedDateTime?new Date(Ce.lastModifiedDateTime):new Date,contentType:Ce.mimeType??void 0,isFolder:Ce.type==="folder",parentId:Ce.parentId??""}));Xu(fe.filter(Ce=>Ce.isFolder)),Mc(fe.filter(Ce=>!Ce.isFolder)),os(!0),Rc(Ce=>Ce.some(Ae=>Ae.id===T)?Ce:[...Ce,{id:T,name:N==="root"?"OneDrive":N}]),is(!1)}catch($){console.error("Lỗi lấy danh sách file:",$),is(!1)}},Vc=T=>{if(T===Zi.length-1)return;const N=Zi[T];N&&(Rc(Zi.slice(0,T+1)),ia(N.id,N.name))},zn=async(T,N)=>{const $=localStorage.getItem("onedrive_access_token");if(!$){at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const ie=at.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[]};T.forEach(Ae=>{Ae.isFolder?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-one-drive-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(fe){console.error("Lỗi khi đồng bộ file từ OneDrive:",fe),at.update(ie,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},Kc=()=>{os(!1),Rc([{id:"root",name:"OneDrive"}]),Xu([]),Mc([]),Dc([]),is(!1)},sf=DO({onSuccess:T=>{Xm(T.access_token),localStorage.setItem("google_access_token",T.access_token),cf(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:$$}),cf=T=>{const N=document.createElement("script");N.src="https://apis.google.com/js/api.js",N.onload=()=>{window.gapi.load("picker",()=>lf(T))},document.body.appendChild(N)},lf=T=>{const N=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),$=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(L$).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(N).addView($).setCallback(async fe=>{if(fe.action===window.google.picker.Action.PICKED){const Ce=fe.docs.map(Ae=>({id:Ae.id,name:Ae.name,mimeType:Ae.mimeType}));await df(Ce,y)}}).build().setVisible(!0)},df=async(T,N="")=>{const $=localStorage.getItem("google_access_token");if(!$){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),at.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const ie=at.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const fe={prefix:N,folders:[],files:[]};T.forEach(Ae=>{Ae.mimeType==="application/vnd.google-apps.folder"?fe.folders.push({id:Ae.id,name:Ae.name}):fe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-drive-to-s3`,fe,{headers:{Authorization:`Bearer ${$}`}});Un.current=!0,on(),at.update(ie,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(fe){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",fe),at.update(ie,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};O.useEffect(()=>{const T=N=>{if(N.data.action==="logout"){const $=document.createElement("iframe");$.style.display="none",$.src="https://accounts.google.com/Logout",document.body.appendChild($),setTimeout(()=>document.body.removeChild($),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),O.useEffect(()=>{const T=new Set(l);C(T)},[]),O.useEffect(()=>{ze!=null&&ze.status&&(ze.status.status==="completed"?(J({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${ze.url} với ${ze.status.completed} trang`}),Un.current=!0,on()):ze.status.status==="failed"&&J({title:"Thu thập website thất bại",description:`Không thể thu thập ${ze.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(pf=ze==null?void 0:ze.status)==null?void 0:pf.status]);const us=O.useMemo(()=>wo[y]||[],[wo,y]),Gt=O.useMemo(()=>us,[us,y,wo]);O.useEffect(()=>{const T=async $=>{var ie;try{return(ie=(await Le.get(`${e}/api/files`,{params:{prefix:$,cache:!1,displayPrefixes:JSON.stringify([]),excludePrivateFiles:"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5})).data)==null?void 0:ie[$]}catch(fe){return console.error("Error: ",fe),[]}};(async()=>{let $=n||"vib-sample/";$.endsWith("/")||($+="/");const ie=`${n}Pilot/FAQ/Uploads/`,fe=`${n}Pilot/HDSD/Uploads/`,Ce=`${n}Pilot/Normal_Files/Uploads/`,Ae=`${n}Pilot/FAQ/FAQs/`,Et=`${n}Pilot/HDSD/general/`,pn=`${n}Pilot/Normal_Files/processed/`,[Nn,Ei,cr,wr,Pn,Gn]=await Promise.all([T(ie),T(fe),T(Ce),T(Ae),T(Et),T(pn)]);Vm({faqUploadSize:Nn,hdsdUploadSize:Ei,normalUploadSize:cr,faqParsedSize:wr,hdsdParsedSize:Pn,normalParsedSize:Gn})})()},[JSON.stringify(us)]);const aa=O.useMemo(()=>{const T=Nn=>Nn.key&&!(`${Nn.key}`.endsWith(".docx")||`${Nn.key}`.endsWith(".xlsx")),{faqUploadSize:N,hdsdUploadSize:$,normalUploadSize:ie,faqParsedSize:fe,hdsdParsedSize:Ce,normalParsedSize:Ae}=Ju,Et=[],pn=(Nn,Ei,cr,wr)=>{(Nn||[]).forEach(Pn=>{var Gn;if(T(Pn))Et.push({...Pn,type:wr,unSupported:!0});else{let lr=(Gn=(Pn==null?void 0:Pn.key)||"")==null?void 0:Gn.replace(".docx","").replace(".xlsx","").replace(".txt","").replace("/Uploads/",`/${cr}/`);lr.endsWith("/")||(lr+="/"),(Ei||[]).find(Xt=>{let St=((Xt==null?void 0:Xt.key)||"").replace(".txt","");return St.endsWith("/")||(St+="/"),St===lr})||Et.push({...Pn,type:wr})}})};return pn(N,fe,"FAQs","FAQ"),pn($,Ce,"general","Hướng dẫn sử dụng"),pn(ie,Ae,"processed","Normal"),Et},[JSON.stringify(Ju)]),an=O.useMemo(()=>{const T={};return Gt.forEach((N,$)=>{v.has(N.key)&&(T[$]=!0)}),T},[v,Gt]),cv=T=>{const N=Lu(wo,T);if(N.length===0)return v.has(T)?"all":"none";const $=N.filter(ie=>v.has(ie)).length;return $===0?"none":$===N.length?"all":"partial"},Go=(T,N=!0)=>{if(y!==T){if(f&&!y)Br(!0),k(T+f),_(T+f);else if(Br(!0),k(T),_(T),N&&!o){const $=window.location.pathname==="/"?"":window.location.pathname,ie=T?`${window.location.origin}${$}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${$}`;window.history.pushState({path:ie},"",ie)}}};O.useEffect(()=>{mo&&(Un.current=!0,on().finally(()=>Br(!1)))},[mo]);const Co=async(T,N)=>{var $,ie;j(!0);try{if(Gt.some(Et=>Et.isFolder&&Et.name.toLowerCase()===T.toLowerCase())){J({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),j(!1);return}const Ce=`${N}${T}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ce},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}})).status!==200){J({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Un.current=!0,await on(),J({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),z(""),M(!1)}catch(fe){console.error("Error creating folder:",fe);const Ce=((ie=($=fe==null?void 0:fe.response)==null?void 0:$.data)==null?void 0:ie.error)||"Không thể tạo thư mục";J({title:"Lỗi",description:Ce,variant:"destructive"})}finally{j(!1)}},xi=async(T,N,$)=>{var ie,fe,Ce,Ae,Et,pn,Nn,Ei,cr;oe($),Wt(!0);try{if(Array.from(T).reduce((gn,sa)=>gn+sa.size,0)>=100*1024*1024){J({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),oe(null),Wt(!1);return}const Pn=Array.from(T).filter(gn=>gn.size===0);if(Pn.length>0){const gn=Pn.map(sa=>sa.name).join(", ");J({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${gn}`,variant:"destructive"}),Wt(!1),oe(null);return}let Gn=localStorage.getItem("dataLogin"),lr;try{Gn&&(Gn=JSON.parse(Gn),lr=Gn.user)}catch{Gn=null}const Xt=new FormData;if(lr!=null&&lr.id&&Xt.append("metadata",JSON.stringify({creator:lr.username,creatorId:lr.id,DataSource:"Tệp tải lên"})),$==="folder"&&T[0]){const gn=T[0].webkitRelativePath.split("/")[0];gn&&Xt.append("folderName",gn)}Xt.append("prefix",N),Array.from(T).forEach(gn=>$==="folder"?Xt.append("files",gn,gn.webkitRelativePath):Xt.append("files",gn)),Un.current=!0;const St=await Le.post(`${e}/api/check-files-existed`,Xt,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});if(((ie=St==null?void 0:St.data)==null?void 0:ie.status)===200)await Le.post(`${e}/api/upload`,Xt,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),w(""),k(N),setTimeout(async()=>{oe(null),await on(),Wt(!1),await bo("upload")},500);else{if(((Ce=(fe=St==null?void 0:St.data)==null?void 0:fe.names)==null?void 0:Ce.length)>0&&!((Ae=St==null?void 0:St.data)!=null&&Ae.isFolder)){const gn=Array.from(T).filter(sa=>St.data.names.includes(sa.name));wi(gn),Yi(!0)}(Et=St==null?void 0:St.data)!=null&&Et.isFolder&&((pn=St==null?void 0:St.data)!=null&&pn.name)&&(ns((Nn=St==null?void 0:St.data)==null?void 0:Nn.name),wi(T),Yi(!0))}}catch(wr){console.error("Lỗi tải lên:",wr);const Pn=((cr=(Ei=wr==null?void 0:wr.response)==null?void 0:Ei.data)==null?void 0:cr.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:Pn,variant:"destructive"}),oe(null),Wt(!1)}},jc=async()=>{var T,N;try{Wt(!0);const $=new FormData;if(zr){oe(qi?"folder":"files"),Yi(!1);let ie=localStorage.getItem("dataLogin"),fe;try{ie&&(ie=JSON.parse(ie),fe=ie.user)}catch{ie=null}if(fe!=null&&fe.id&&$.append("metadata",JSON.stringify({creator:fe.username,creatorId:fe.id,DataSource:"Tệp tải lên"})),qi&&zr[0]){const Ce=zr[0].webkitRelativePath.split("/")[0];Ce&&$.append("folderName",Ce)}$.append("prefix",y),Array.from(zr).forEach(Ce=>qi&&zr[0]?$.append("files",Ce,Ce.webkitRelativePath):$.append("files",Ce)),fe!=null&&fe.id&&$.append("metadata",JSON.stringify({creator:fe.username,creatorId:fe.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,$,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),w(""),k(y),Un.current=!0}}catch($){console.error("Lỗi tải lên:",$);const ie=((N=(T=$==null?void 0:$.response)==null?void 0:T.data)==null?void 0:N.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:ie,variant:"destructive"})}finally{setTimeout(async()=>{oe(null),await on(),Wt(!1),ns(""),wi(null),await bo("overwrite")},500)}},Pt=async T=>{var N;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[T.key]},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v.has(T.key)){const ie=new Set(v);ie.delete(T.key),C(ie)}const $=((N=T.key)==null?void 0:N.replace(/^(.*?)(\/.*)?$/,(ie,fe,Ce)=>!Ce||Ce==="/"?"":fe+"/"))||"";k($),Un.current=!0,J({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),W(null),await bo("delete")}catch($){console.error("Error deleting file:",$),J({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{vr(!1),await on()}},sr=T=>{const N=new Set(v),$=typeof T=="function"?T(an):T;new Set(Object.keys(an).map(Number)).forEach(fe=>{const Ce=Gt[fe];Ce&&($[fe]||(N.delete(Ce.key),Ce.isFolder&&Lu(wo,Ce.key).forEach(Ae=>N.delete(Ae))))}),Object.entries($).forEach(([fe,Ce])=>{const Ae=parseInt(fe),Et=Gt[Ae];Et&&Ce&&(N.add(Et.key),Et.isFolder&&Lu(wo,Et.key).forEach(pn=>N.add(pn)))}),C(N)},Wc=async()=>{var T;K(!0);try{const N=Array.from(v),$=N.map(fe=>Object.values(wo).flat().find(Ce=>Ce.key===fe)).filter(fe=>fe!==void 0);if($.length===0){J({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:N},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});const ie=((T=$[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(fe,Ce,Ae)=>!Ae||Ae==="/"?"":Ce+"/"))||"";k(ie),Un.current=!0,on(),J({title:"Đã xóa tập tin",description:`Đã xóa thành công ${$.length} mục`}),q(!1),C(new Set),await bo("bulk-delete")}catch(N){console.error("Error deleting files:",N),J({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{K(!1)}},lv=async(T,N)=>{if(!y.trim()){J({title:"Lỗi",description:"Không thể đổi tên tập tin hoặc thư mục ở thư mục gốc. Chỉ có thể xóa.",variant:"destructive"});return}Ue(!0);try{const $=T.key;let ie;T.isFolder?ie=$.split("/").slice(0,-2).join("/")+"/":ie=$.substring(0,$.lastIndexOf("/")+1);const fe=ie+N+(T.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:$,newPath:fe},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),Un.current=!0,await on(),J({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${N}"`}),ne(null),Ne(""),Ee(null),await bo("rename")}catch($){console.error("Error renaming item:",$),J({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Ue(!1)}},fs=async T=>{nt(N=>new Set([...N,...T]));try{const N=await Le.post(`${e}/api/download`,{paths:T},{responseType:"blob",headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),$=window.URL.createObjectURL(N.data),ie=document.createElement("a");ie.href=$;const fe=N.headers["Content-Disposition"]||N.headers["content-disposition"],Ce=fe==null?void 0:fe.match(/filename="(.+)"/),Ae=Ce?decodeURIComponent(Ce[1]):"download.zip";ie.setAttribute("download",Ae),document.body.appendChild(ie),ie.click(),document.body.removeChild(ie),window.URL.revokeObjectURL($),J({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(N){console.error("Error downloading files:",N),J({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{nt(N=>{const $=new Set(N);return T.forEach(ie=>$.delete(ie)),$})}},uf=y?y.replace(n,"").split("/").filter(Boolean):[],dv=()=>{let T=Array.from(v).map($=>({key:$}));T.length>1&&(T=T.filter($=>$.key!==n));const N=$=>Qd.findIndex(T,ie=>!ie.key.endsWith("/")&&ie.key.startsWith($))!==-1;return T=T.filter($=>$.key.endsWith("/")?!N($.key):!0),T},ff=O.useMemo(()=>{const T=[{id:"select",header:()=>{const N=B$(wo,y),$=N.length>0&&N.every(fe=>v.has(fe)),ie=N.some(fe=>v.has(fe));return u.jsx(Pg,{checked:$?!0:ie?"indeterminate":!1,onCheckedChange:fe=>{if(fe){const Ce=Gt.reduce((Ae,Et,pn)=>(Ae[pn]=!0,Ae),{});sr(Ce)}else{for(const Ce of Array.from(v))Ce.startsWith(y)&&(v.delete(Ce),Ho.current[Ce]=!1);Qd.forEach(Ho.current,(Ce,Ae)=>{Ae.startsWith(y)&&(Ho.current[Ae]=!1)}),sr({})}},"aria-label":"Chọn tất cả"})},cell:({row:N})=>{const $=N.original;let fe=$.isFolder?cv($.key):v.has($.key)?"all":"none";if(fe==="none"&&$.key.endsWith("/")){for(const Ce of Array.from(v))if(Ce.startsWith($.key)){fe="all";break}}return u.jsx("div",{className:"flex items-center",children:u.jsx(Pg,{checked:fe==="partial"?"indeterminate":fe==="all",onCheckedChange:Ce=>{var Et,pn;const Ae={...an};if(Ce?Ae[N.index]=!0:delete Ae[N.index],Ho.current[((Et=N.original)==null?void 0:Et.key)||"_"]=!!Ce,(pn=N.original)!=null&&pn.key.endsWith("/"))for(const Nn of Array.from(v))Nn.startsWith(N.original.key)&&(Ho.current[N.original.key]=!1,v.delete(Nn));sr(Ae)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"stt",header:()=>"STT",size:20,cell:({row:N})=>u.jsx("div",{className:"flex flex-col group",children:u.jsx("div",{className:"flex items-center",children:N.index+1})})},{id:"fileName",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),children:["Tên tập tin",u.jsx(wg,{})]}),accessorKey:"name",cell:({row:N})=>{const $=N.original,ie=$.key.substring(0,$.key.lastIndexOf("/"))||"/",fe=g.trim()!==""&&ie!==y,Ce=ie.split("/").filter(Boolean);return u.jsxs("div",{className:"flex flex-col group",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsxs("div",{className:`flex items-center gap-2 ${$.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{$.isFolder&&Go($.key)},children:[$.isFolder?u.jsx(qs,{className:"h-5 w-5 text-blue-500"}):null,$.name]}),u.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),navigator.clipboard.writeText($.key),J({title:"Copied to clipboard",description:`Path: ${$.key}`,duration:2e3})},title:"Copy path to clipboard",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),u.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),fe&&u.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[u.jsx(qs,{className:"h-4 w-4 text-gray-500 my-auto"}),u.jsxs("span",{className:"flex items-center ml-1",children:[u.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Go("")},children:"/"}),Ce.map((Ae,Et)=>u.jsxs("span",{className:"flex items-center",children:[u.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Go(Ce.slice(0,Et+1).join("/")+"/")},children:Ae}),Et<Ce.length-1&&u.jsx("span",{children:"/"})]},Et))]})]})]})}}];return o||T.push({id:"size",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),children:["Kích thước",u.jsx(wg,{})]}),accessorKey:"size",cell:({getValue:N,row:$})=>{const ie=N();return u.jsx("span",{children:$.original.isFolder?"-":ds(ie)})}},{id:"lastModified",header:({column:N})=>u.jsxs($e,{variant:"ghost",onClick:()=>N.toggleSorting(N.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",u.jsx(wg,{})]}),accessorKey:"lastModified",cell:({row:N})=>{const $=N.original.lastModified;return u.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:u.jsx("span",{children:$&&bx($).isValid()?bx($).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>u.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:N})=>u.jsxs("div",{className:"flex items-center gap-2",children:[y===""&&r&&u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Ku(N.original.key),ju(!0)},className:"h-8 w-8 p-0",children:Me.has(N.original.key)?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):u.jsx(GN,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Những Flow sử dụng Folder này làm Data"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>fs([N.original.key]),className:"h-8 w-8 p-0",disabled:Me.has(N.original.key),children:Me.has(N.original.key)?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):u.jsx(wC,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Tải xuống"})]})}),y.trim()!==""&&u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{ne(N.original),Ne(N.original.name)},className:"h-8 w-8 p-0",children:u.jsx(JN,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Đổi tên"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Oe(!0),ce(N.original)},className:"h-8 w-8 p-0",children:u.jsx(dR,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Di chuyển"})]})}),u.jsx(co,{children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsx($e,{variant:"ghost",size:"icon",onClick:()=>W(N.original),className:"h-8 w-8 p-0",children:u.jsx(CC,{className:"h-4 w-4"})})}),u.jsx($r,{children:"Xóa"})]})})]})}),T},[v,Gt,an,Me,o]),hs=Nb({data:Gt,columns:ff,state:{rowSelection:an,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:sr,getCoreRowModel:kb(),getSortedRowModel:p1()}),ps=async T=>{var N,$;fn(!0);try{if(xc(T)){const ie=await Le.get(`${e}/api/read-text`,{params:{path:T.key},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});lt(ie.data.content)}try{const ie=await Le.get(`${e}/api/read-json`,{params:{path:T.key+".metadata.json"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),fe=(($=(N=ie==null?void 0:ie.data)==null?void 0:N.content)==null?void 0:$.metadataAttributes)||null;return Ee({fullPath:U==null?void 0:U.key,...fe})}catch{return Ee("Lỗi phân tích siêu dữ liệu")}}catch(ie){console.error("Error loading file content:",ie),J({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{fn(!1)}},_i=async(T,N)=>{Lt(!0);try{await Le.post(`${e}/api/modify-text`,{path:T.key,content:N},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Un.current=!0,await on(),ne(null),lt(""),G("rename"),await bo("edit-content")}catch($){console.error("Error saving file content:",$),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Lt(!1)}},uv=async T=>{Lt(!0);try{await Le.post(`${e}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:_e}},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Un.current=!0,await on(),ne(null),lt(""),G("rename")}catch(N){console.error("Error saving file content:",N),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Lt(!1)}};O.useEffect(()=>{U&&(U.isFolder||ps(U),G("rename"))},[U]);const qc=async(T,N)=>{var $;if(ze){J({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}Qe(!0);try{const{data:ie}=await Le.post(`${e}/api/crawl`,{url:T,limit:N,prefix:y});if(ie.id){Vu({id:ie.id,url:T,limit:N,prefix:y,taskId:(($=ie.task)==null?void 0:$.id)||""});const fe=localStorage.getItem(FE),Ce=fe?JSON.parse(fe):[];Ce.some(Ae=>Ae.id===ie.id)||(Ce.unshift({url:T,id:ie.id,limit:N,prefix:y,timestamp:Date.now()}),Ce.length>20&&(Ce.length=20),localStorage.setItem(FE,JSON.stringify(Ce))),J({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${N}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),be(!1),pe(""),ge("1")}}catch(ie){console.error("Error crawling website:",ie),J({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{Qe(!1)}},hf=async()=>{try{if(!(ze!=null&&ze.id))return;Vu(null),localStorage.removeItem(es),J({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${ze.url}`})}catch(T){console.error("Error stopping job:",T),J({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};O.useEffect(()=>{if(o)return;const T=(N=!0)=>{const ie=new URL(window.location.href).searchParams.get("prefix")||"";ie?Go(ie,!1):(N&&!l&&C(new Set),k(n),_(n),Un.current=!0,setTimeout(()=>{on()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const gs=async()=>{Yu(!0);try{await Le.post(`${e}/api/prediction-report`),J({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(T){console.error("Error exporting report:",T),J({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Yu(!1)}},Yc=async()=>{try{const T=lD();T&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:y,user_id:T.id,userName:T.username},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}})).status===200&&await Ti()}catch(T){hn(!1),console.log(T)}},bo=async T=>{try{rs&&y.includes(rs)&&(console.log(`Auto syncing knowledge base after ${T} operation`),await Ti())}catch(N){console.log(`Error auto syncing after ${T}:`,N)}},xo=O.useRef(),Ti=async()=>{try{hn(!0);const T=await Le.post(`${e}/api/ingestion-job-status`,{prefix:y},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),{status:N}=T==null?void 0:T.data;N==="FAILED"||N==="COMPLETE"||N==="STOPPED"||N==="STOPPING"||!N?(hn(!1),xo.current&&(clearInterval(xo.current),xo.current=null),kc(T==null?void 0:T.data)):(xo.current||(xo.current=setInterval(()=>Ti(),5e3)),kc(T==null?void 0:T.data))}catch(T){console.log(T)}},Jc=()=>{const T=Array.from(v);let N;return y?N=T.filter($=>$.startsWith(y)&&$!==y).length:N=new Set(T.filter($=>$.split("/").shift())).size,`Đang chọn: ${N}`};return O.useEffect(()=>{const T=y==null?void 0:y.split("/")[0];return T!==rs&&(hn(!1),xo.current&&(clearInterval(xo.current),xo.current=null),Gm(T||""),kc(null),T&&Ti()),()=>{}},[rs,y]),O.useEffect(()=>{yo&&$c.length===0&&(nv(),Gr(null))},[yo]),O.useEffect(()=>{if(l)for(const T of Array.from(l))Ho.current[T]=!0},[]),u.jsxs("div",{className:"space-y-4 s3-explr-container",children:[u.jsx(Y_,{}),u.jsx(gr,{open:Bm,onOpenChange:T=>{Yi(T),T||(ns(""),wi(null),Wt(!1),oe(null))},children:u.jsxs(er,{children:[u.jsxs(tr,{children:[u.jsx(nr,{children:"Cảnh báo trùng lặp"}),u.jsxs(Ro,{children:[qi&&u.jsxs(u.Fragment,{children:["Folder $",qi," đã có."]}),zr&&zr.length>0&&u.jsxs(u.Fragment,{children:["Những tệp sau bị lặp:",u.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(zr).map((T,N)=>u.jsx("li",{children:T.name},N))})]})]})]}),u.jsxs(Mo,{children:[u.jsx($e,{variant:"outline",onClick:()=>{Yi(!1),ns(""),wi(null),Wt(!1),oe(null)},children:"Bỏ qua"}),u.jsx($e,{variant:"destructive",onClick:()=>jc(),children:"Ghi đè"})]})]})}),u.jsx(eu,{className:"s3-explr-breadcrumb",children:u.jsxs(tu,{className:"s3-explr-breadcrumb-list",children:[u.jsx(ac,{className:"s3-explr-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Go(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!f&&uf.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[u.jsx(nu,{className:"s3-explr-breadcrumb-separator"},`sep-${N}`),u.jsx(ac,{className:"s3-explr-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Go(n+uf.slice(0,N+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},N))]})}),u.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[u.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:u.jsx(NU,{ref:Q,onChange:T=>w(T)})}),u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{k(y),Un.current=!0,on()},disabled:bi,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${bi?"animate-spin":""}`}),"Làm mới"]}),y&&y!=="/"&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{bi||pt||(hn(!0),Yc())},"aria-disabled":bi||pt,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${pt?"animate-spin":""}`}),"Đồng bộ KB"]})}),kt&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[u.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),u.jsx("div",{className:"space-y-1",children:u.jsxs("p",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"font-medium",children:"Trạng thái:"}),u.jsxs("span",{className:`flex items-center gap-1 font-semibold ${kt.status==="COMPLETE"?"text-green-600":kt.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[kt.status==="COMPLETE"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),kt.status==="FAILED"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),kt.status!=="COMPLETE"&&kt.status!=="FAILED"&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),kt.status]})]})}),kt.statistics&&u.jsxs("div",{className:"space-y-1 border-t pt-2",children:[u.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),u.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu quét:"}),u.jsx("span",{className:"font-medium",children:kt.statistics.numberOfDocumentsScanned})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Metadata quét:"}),u.jsx("span",{className:"font-medium",children:kt.statistics.numberOfMetadataDocumentsScanned})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu mới:"}),u.jsx("span",{className:"font-medium text-green-600",children:kt.statistics.numberOfNewDocumentsIndexed})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu sửa:"}),u.jsx("span",{className:"font-medium text-blue-600",children:kt.statistics.numberOfModifiedDocumentsIndexed})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Metadata sửa:"}),u.jsx("span",{className:"font-medium text-blue-600",children:kt.statistics.numberOfMetadataDocumentsModified})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{children:"Tài liệu xóa:"}),u.jsx("span",{className:"font-medium text-orange-600",children:kt.statistics.numberOfDocumentsDeleted})]}),u.jsxs("div",{className:"flex justify-between col-span-2",children:[u.jsx("span",{children:"Tài liệu lỗi:"}),u.jsx("span",{className:"font-medium text-red-600",children:kt.statistics.numberOfDocumentsFailed})]})]})]}),u.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[u.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",kt.dataSourceId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",kt.ingestionJobId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",kt.knowledgeBaseId]}),u.jsxs("p",{children:[u.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",kt.is_still_in_stock?"Còn":"Không"]})]}),kt.errorMessage&&u.jsxs("div",{className:"border-t pt-2",children:[u.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),u.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:kt.errorMessage})]}),kt.failureReasons&&kt.failureReasons.length>0&&u.jsx(PU,{failureReasons:kt.failureReasons})]})})]})}),!!(aa!=null&&aa.length)&&u.jsxs(u.Fragment,{children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",onClick:()=>Ic(!0),children:[u.jsx(Ws,{className:"h-4 w-4 s3-explr-refresh-icon animate-spin"}),"Tài liệu đang xử lý: ",aa.length]}),u.jsx(D$,{isOpen:Km,onClose:()=>Ic(!1),files:aa})]}),u.jsxs("div",{className:"relative",ref:zc,children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",onClick:()=>yr(T=>!T),children:[u.jsx(XN,{className:"w-4 h-4"}),"Add file"]}),Bc&&u.jsxs("div",{className:"absolute z-50 mt-2 right-0 w-56 bg-white border rounded-lg shadow-lg py-2 flex flex-col",children:[u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{yr(!1);const T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=N=>{const $=N.target.files;$&&xi($,y,"files")},T.click()},children:[u.jsx(bp,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{yr(!1);const T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=N=>{const $=N.target.files;$&&xi($,y,"folder")},T.click()},children:[u.jsx(qs,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!c&&!y,onClick:()=>M(!0),children:[u.jsx(KN,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),be(!0)},children:[u.jsx(qN,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),sf()},children:[u.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[u.jsx("path",{d:"m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8h-27.5c0 1.55.4 3.1 1.2 4.5z",fill:"#0066da"}),u.jsx("path",{d:"m43.65 25-13.75-23.8c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0 -1.2 4.5h27.5z",fill:"#00ac47"}),u.jsx("path",{d:"m73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5h-27.502l5.852 11.5z",fill:"#ea4335"}),u.jsx("path",{d:"m43.65 25 13.75-23.8c-1.35-.8-2.9-1.2-4.5-1.2h-18.5c-1.6 0-3.15.45-4.5 1.2z",fill:"#00832d"}),u.jsx("path",{d:"m59.8 53h-32.3l-13.75 23.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z",fill:"#2684fc"}),u.jsx("path",{d:"m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3l-13.75 23.8 16.15 28h27.45c0-1.55-.4-3.1-1.2-4.5z",fill:"#ffba00"})]})," ","Đồng bộ Google Drive"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),tn()},children:[u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[u.jsx("path",{fill:"#094ab2",d:"M47.3 28.2C45.3 18.6 37.1 12 28 12c-8.5 0-15.9 5.6-18.4 13.5C4.2 27.2 0 32.2 0 38c0 6.6 5.4 12 12 12h36c8.3 0 16-6.6 16-15.5 0-6.8-4.9-12.4-11.7-13.3z"}),u.jsx("path",{fill:"#0067c5",d:"M44.9 30.1c-.2 0-.4-.1-.6-.1H26c-3.3 0-6 2.7-6 6 0 .9.2 1.8.6 2.6-1.7-.7-3.5-1.1-5.5-1.1C7.6 37.5 4 41.5 4 46s3.6 8.5 8.1 8.5h34.3c6.8 0 12.6-5.4 12.6-12s-5.5-11.6-11.1-12.4z"})]})," ","Đồng bộ OneDrive"]}),u.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{yr(!1),ev()},children:[u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[u.jsx("path",{fill:"#036C70",d:"M19 14.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#17828F",d:"M16 17.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#4DB6AC",d:"M13 20.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),u.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),!o&&u.jsxs(u.Fragment,{children:[v.size>0&&u.jsxs(u.Fragment,{children:[u.jsxs($e,{variant:"outline",size:"sm",onClick:()=>fs(Array.from(v)),disabled:Array.from(v).some(T=>Me.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(v).some(T=>Me.has(T))?u.jsx(Ht,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):u.jsx(wC,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",v.size,")"]}),u.jsxs(gr,{open:Z,onOpenChange:q,children:[u.jsx(cc,{asChild:!0,children:u.jsxs($e,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[u.jsx(CC,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",v.size,")"]})}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),u.jsxs(Ro,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",v.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>q(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:Wc,disabled:xe,className:"s3-explr-confirm-delete-btn",children:xe?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),!f&&u.jsxs(gr,{open:R,onOpenChange:M,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsx(tr,{className:"s3-explr-dialog-header",children:u.jsx(nr,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),u.jsx(oo,{disabled:V,id:"name",value:S,onChange:T=>z(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),u.jsxs($e,{onClick:()=>{S.trim()&&Co(S,y)},disabled:V,className:"s3-explr-create-btn",children:[V&&u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),V?"Đang tạo...":"Tạo"]})]})]})]}),f&&!y?u.jsx(u.Fragment,{}):u.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[ze?u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[u.jsx(Ht,{className:"h-4 w-4 animate-spin s3-explr-loader"}),ze.status?u.jsxs(u.Fragment,{children:[ze.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",ze.status.completed,"/",ze.status.total,") -"," ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}):"Đang thu thập..."]}),u.jsxs($e,{variant:"destructive",size:"sm",onClick:()=>void hf(),className:"flex items-center gap-2",children:[u.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),u.jsx(eP,{className:"h-4 w-4"})]})]})}),ze.status&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-1 p-2",children:[u.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",ze==null?void 0:ze.url]}),u.jsxs("p",{children:["Tiến độ: ",ze==null?void 0:ze.status.completed,"/",ze==null?void 0:ze.status.total," ","trang"]}),u.jsxs("p",{children:["Thời gian: ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}),u.jsxs("p",{children:["Trạng thái:"," ",(ze==null?void 0:ze.status.status)==="scraping"?"Đang thu thập":(ze==null?void 0:ze.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!f&&u.jsxs(gr,{open:X,onOpenChange:be,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Thêm website"}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),u.jsx(oo,{id:"websiteUrl",value:ye,onChange:T=>pe(T.target.value),placeholder:"https://example.com",type:"url",disabled:Be,className:"s3-explr-input"})]}),u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),u.jsx(oo,{id:"crawlLimit",value:re,onChange:T=>{const N=T.target.value;/^\d*$/.test(N)&&ge(N)},placeholder:"1",type:"text",disabled:Be,className:"s3-explr-input"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Số lượng liên kết cần thu thập (mặc định: 1)"})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{be(!1),pe(""),ge("1")},disabled:Be,className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{onClick:()=>{ye.trim()&&qc(ye.trim(),parseInt(re)||1)},disabled:Be||!ye.trim(),className:"s3-explr-crawl-btn",children:Be?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),y.startsWith("BKTTW/")&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!y,onClick:gs,children:[Qi&&u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${Qi?"animate-spin":""}`}),"Xuất báo cáo"]})}),(ze==null?void 0:ze.status)&&u.jsx($r,{side:"right",sideOffset:5,children:u.jsxs("div",{className:"space-y-1 p-2",children:[u.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",ze.url]}),u.jsxs("p",{children:["Tiến độ: ",ze.status.completed,"/",ze.status.total," ","trang"]}),u.jsxs("p",{children:["Thời gian: ",Math.floor(vo/60),":",String(vo%60).padStart(2,"0")]}),u.jsxs("p",{children:["Trạng thái:"," ",ze.status.status==="scraping"?"Đang thu thập":ze.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),u.jsxs(gr,{open:X,onOpenChange:be,children:[u.jsx(cc,{asChild:!0}),u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Thêm website"}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),u.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),u.jsx(oo,{id:"websiteUrl",value:ye,onChange:T=>pe(T.target.value),placeholder:"https://example.com",type:"url",disabled:Be,className:"s3-explr-input"})]}),u.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),u.jsx(oo,{id:"crawlLimit",value:re,onChange:T=>{const N=T.target.value;/^\d*$/.test(N)&&ge(N)},placeholder:"1",type:"text",disabled:Be,className:"s3-explr-input"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Số lượng liên kết cần thu thập (mặc định: 1)"})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{be(!1),pe(""),ge("1")},disabled:Be,className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{onClick:()=>{ye.trim()&&qc(ye.trim(),parseInt(re)||1)},disabled:Be||!ye.trim(),className:"s3-explr-crawl-btn",children:Be?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),y.startsWith("BKTTW/")&&u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{children:[u.jsx(uo,{asChild:!0,children:u.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!y,onClick:gs,children:[Qi&&u.jsx(Ws,{className:`h-4 w-4 s3-explr-refresh-icon ${Qi?"animate-spin":""}`}),"Xuất báo cáo"]})}),Qi&&u.jsx($r,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),u.jsxs("div",{className:"flex items-center gap-4",children:[Xi&&u.jsxs(Ys,{open:Xi,onOpenChange:os,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[u.jsxs("div",{className:"relative",children:[u.jsx($p,{asChild:!0,children:u.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:Kc,children:"✖"})}),u.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),u.jsx(eu,{className:"onedrive-breadcrumb",children:u.jsx(tu,{className:"onedrive-breadcrumb-list",children:Zi.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[N>0&&u.jsx(nu,{className:"onedrive-breadcrumb-separator"}),u.jsx(ac,{className:"onedrive-breadcrumb-item",children:u.jsx(sc,{onClick:()=>Vc(N),className:"cursor-pointer onedrive-breadcrumb-link",children:T.name})})]},N))})})]}),u.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:qm?u.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):u.jsx(u.Fragment,{children:[...Qu,...Oc].length>0?[...Qu,...Oc].map(T=>u.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${as.some(N=>N.id===T.id)?"bg-blue-100":""}`,children:[u.jsx("input",{type:"checkbox",checked:as.some(N=>N.id===T.id),onChange:N=>{N.stopPropagation(),af(T)},className:"cursor-pointer"}),T.isFolder?u.jsx(qs,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ia(T.id,T.name)}):u.jsx(bp,{className:"text-gray-500 w-5 h-5"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:`font-medium ${T.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{T.isFolder?ia(T.id,T.name):af(T)},children:T.name}),!T.isFolder&&u.jsxs("div",{className:"text-xs text-gray-500",children:[ds(T.size)," •"," ",sv(T.lastModified.toISOString())]})]})]},T.id)):u.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),u.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:u.jsx($e,{onClick:()=>{zn(as,y),Kc()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:as.length===0,children:"Đồng bộ"})}),u.jsx("button",{onClick:()=>ra(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),u.jsx("polyline",{points:"16 17 21 12 16 7"}),u.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),u.jsxs(Ys,{open:Ym,onOpenChange:ra,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),u.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx($e,{variant:"outline",onClick:()=>ra(!1),children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>{Gc(),ra(!1)},children:"Đăng xuất"})]})]})]}),yo&&u.jsxs(Ys,{open:yo,onOpenChange:ta,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[u.jsxs("div",{className:"relative",children:[u.jsx($p,{asChild:!0,children:u.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:of,children:"✖"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[gt&&u.jsx("button",{onClick:()=>Gr(null),className:"text-gray-600 hover:text-gray-800",children:u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:u.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),u.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&u.jsx(eu,{className:"sharepoint-breadcrumb",children:u.jsx(tu,{className:"sharepoint-breadcrumb-list",children:Uc.map((T,N)=>u.jsxs("div",{className:"flex items-center",children:[N>0&&u.jsx(nu,{className:"sharepoint-breadcrumb-separator"}),u.jsx(ac,{className:"sharepoint-breadcrumb-item",children:u.jsx(sc,{onClick:()=>ov(N),className:"cursor-pointer sharepoint-breadcrumb-link",children:T.name})})]},N))})})]}),u.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Zu?u.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...Lc,...ss].length===0?u.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...Lc,...ss].map(T=>{const N=ls.some($=>$.id===T.id);return u.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${N?"bg-blue-100":""}`,children:[u.jsx("input",{type:"checkbox",checked:N,onChange:$=>{$.stopPropagation(),rv(T)},className:"cursor-pointer"}),T.isFolder?u.jsx(qs,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>mt(T.id,T.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):u.jsx(bp,{className:"text-gray-500 w-5 h-5"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:`font-medium ${T.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{T.isFolder&&mt(T.id,T.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:T.name}),!T.isFolder&&u.jsxs("div",{className:"text-xs text-gray-500",children:[ds(T.size)," •"," ",T.lastModified.toLocaleString()]})]})]},T.id)}):u.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:$c.map(T=>u.jsxs("div",{className:"cursor-pointer bg-white shadow-md rounded-xl p-5 flex flex-col justify-center items-start transition-shadow duration-200 hover:shadow-lg border border-gray-100 min-h-[120px]",style:{overflow:"hidden",wordBreak:"break-word",textOverflow:"ellipsis",whiteSpace:"normal"},onClick:()=>Nt(T),children:[u.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:T.name,children:T.name}),u.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:T.description,children:T.description})]},T.id))})}),u.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&u.jsxs(u.Fragment,{children:[u.jsx($e,{onClick:()=>{iv(ls,y),of()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:ls.length===0,children:"Đồng bộ"}),u.jsx($e,{onClick:()=>Gr(null),children:"Quay lại"})]})}),u.jsx("button",{onClick:()=>na(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),u.jsx("polyline",{points:"16 17 21 12 16 7"}),u.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),u.jsxs(Ys,{open:tf,onOpenChange:na,children:[u.jsx(Ha,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),u.jsxs(Ba,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),u.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx($e,{variant:"outline",onClick:()=>na(!1),children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>{tv(),na(!1)},children:"Đăng xuất"})]})]})]})]}),u.jsx(gr,{open:!!zm,onOpenChange:T=>{T||(ju(!1),qu([]),Ku(""))},children:u.jsxs(er,{className:"max-h-[700px] pb-3 px-1 s3-explr-input-group max-w-5xl w-[90%] p-6 bg-white rounded-lg shadow-lg",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:u.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",u.jsx("span",{className:"font-bold",children:Ji}),"):"," "]})}),u.jsx(Ro,{className:"s3-explr-dialog-description",children:Ac?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ht,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):u.jsx("div",{children:Ci&&Array.isArray(Ci)&&Ci.length>0?u.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:u.jsxs("table",{className:"w-full border-collapse",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"bg-gray-100",children:[u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),u.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),u.jsx("tbody",{children:Ci.map((T,N)=>u.jsxs("tr",{className:N%2===0?"bg-white":"bg-gray-50",children:[u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.name}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.KnowledgeBaseId}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),u.jsx("td",{className:"border border-gray-300 px-4 py-2",children:T.createdDate?new Date(T.createdDate).toLocaleString("vi-VN"):"N/A"})]},N))})]})}):u.jsx("div",{className:"text-gray-500 italic py-2",children:"Không có flow nào sử dụng dữ liệu từ folder này"})})})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>Pt(te),disabled:Hn,className:"s3-explr-confirm-delete-btn",children:Hn?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),u.jsx(gr,{open:!!te,onOpenChange:T=>!T&&W(null),children:u.jsxs(er,{className:"s3-explr-dialog-content",children:[u.jsxs(tr,{className:"s3-explr-dialog-header",children:[u.jsx(nr,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),u.jsxs(Ro,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",te==null?void 0:te.name,"? Hành động này không thể hoàn tác."]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),u.jsx($e,{variant:"destructive",onClick:()=>Pt(te),disabled:Hn,className:"s3-explr-confirm-delete-btn",children:Hn?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),u.jsx(gr,{open:!!U,onOpenChange:T=>{T||(ne(null),Ee(null),Ne(""),lt(""),G("rename"))},children:u.jsxs(er,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[u.jsx(tr,{className:"s3-explr-dialog-header",children:u.jsx(nr,{className:"s3-explr-dialog-title",children:U!=null&&U.isFolder?"Đổi tên thư mục":xc(U)?"Quản lý tập tin":"Đổi tên tập tin"})}),U&&u.jsxs(WD,{value:D,onValueChange:T=>G(T),children:[u.jsxs(x_,{"aria-checked":!xc(U),"aria-disabled":U.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[u.jsx(uu,{value:"rename",children:"Đổi tên"}),!U.isFolder&&u.jsxs(u.Fragment,{children:[xc(U)&&u.jsx(uu,{value:"edit",children:"Sửa nội dung"}),u.jsx(uu,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),u.jsx(fu,{value:"rename",children:u.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:u.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[u.jsx(Do,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),u.jsx(oo,{id:"newName",value:Te,onChange:T=>Ne(T.target.value),placeholder:"Nhập tên mới",disabled:De,className:"s3-explr-input"})]})})}),!U.isFolder&&u.jsxs(u.Fragment,{children:[xc(U)&&u.jsx(fu,{value:"edit",children:u.jsx("div",{className:"space-y-4 py-4",children:Ct?u.jsx("div",{className:"flex items-center justify-center py-4",children:u.jsx(Ht,{className:"h-6 w-6 animate-spin"})}):u.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[u.jsx(Do,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),u.jsx(fc,{id:"content",value:we,onChange:T=>lt(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:In})]})})}),u.jsx(fu,{value:"edit-metadata",children:u.jsx("div",{className:"space-y-4 py-4",children:Ct?u.jsx("div",{className:"flex items-center justify-center py-4",children:u.jsx(Ht,{className:"h-6 w-6 animate-spin"})}):u.jsx("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:_e&&typeof _e=="object"&&Object.entries(_e).map(([T,N],$)=>u.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[u.jsxs(Do,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[SR[T]||T,Tg(T)&&u.jsx(uR,{className:"h-[12px] w-[12px] text-red-500"})]}),AR(T)?u.jsx(fc,{id:T,value:typeof N=="string"?N:JSON.stringify(N),onChange:ie=>{const fe={..._e,[T]:ie.target.value};Ee(fe)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:In||Tg(T)}):u.jsx(oo,{id:T,value:typeof N=="string"?N:JSON.stringify(N),onChange:ie=>{const fe={..._e,[T]:ie.target.value};Ee(fe)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:In||Tg(T)})]},$))})})})]})]}),u.jsxs(Mo,{className:"s3-explr-dialog-footer",children:[u.jsx($e,{variant:"outline",onClick:()=>{ne(null),Ee(null),Ne(""),lt("")},className:"s3-explr-cancel-btn",children:"Hủy"}),D==="edit"?u.jsx($e,{onClick:()=>U&&_i(U,we),disabled:In||Ct,className:"s3-explr-save-btn",children:In?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):D==="edit-metadata"?u.jsx($e,{onClick:()=>_e&&typeof _e=="object"&&U&&uv(U),disabled:In||Ct,className:"s3-explr-save-btn",children:In?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):u.jsx($e,{onClick:()=>{Te.trim()&&U&&lv(U,Te.trim())},disabled:De||!Te.trim()||Te.trim()===(U==null?void 0:U.name),className:"s3-explr-rename-btn",children:De?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),me&&Se&&u.jsx(F$,{openDialogRename:Se,setOpenDialogRename:Oe,apiBaseUrl:e,setFileToMove:ce,fileToMove:me,refreshFiles:on,ignoreCache:Un,autoSyncAfterFileOperation:bo})]})]}),Zm&&u.jsx("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative s3-explr-error",children:"Đã xảy ra lỗi khi tải danh sách tập tin"}),u.jsx(R$,{onFilesSelected:(T,N)=>xi(T,y,N),children:u.jsx("div",{className:"rounded-md border s3-explr-table-container",children:u.jsxs(lc,{className:"s3-explr-table",children:[u.jsx(dc,{className:"s3-explr-table-header",children:hs.getHeaderGroups().map(T=>u.jsx(rr,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(N=>u.jsx(or,{className:"s3-explr-header-cell",children:N.isPlaceholder?null:Ld(N.column.columnDef.header,N.getContext())},N.id))},T.id))}),u.jsx(uc,{className:"s3-explr-table-body",children:hs.getRowModel().rows.length===0?u.jsx(rr,{className:"s3-explr-empty-row",children:u.jsx(un,{colSpan:ff.length,className:"h-24 text-center s3-explr-empty-cell",children:g?u.jsxs("div",{className:"text-gray-500 s3-explr-no-results",children:['Không tìm thấy tập tin hoặc thư mục nào khớp với "',g,'"']}):u.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:bi?"Đang tải nội dung thư mục... Vui lòng đợi":"Thư mục này không chứa tập tin hoặc thư mục con nào"})})}):hs.getRowModel().rows.map(T=>u.jsx(rr,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(N=>u.jsx(un,{className:"align-middle s3-explr-cell",children:Ld(N.column.columnDef.cell,N.getContext())},N.id))},T.id))})]})})}),g&&oa!==0&&u.jsx(u.Fragment,{children:u.jsx(ru,{children:u.jsxs(ou,{children:[u.jsx(iu,{onClick:()=>Bn(T=>Math.max(T-1,1)),"aria-disabled":zt===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(oa/20)},(T,N)=>{const $=N+1,ie=Math.ceil(oa/20);return ie>7&&!($===1||$===ie||$>=zt-1&&$<=zt+1)?$===zt-2&&zt>4||$===zt+2&&zt<ie-3?u.jsx(su,{className:"pointer-events-none",children:"..."},N):null:u.jsx(Fr,{className:"cursor-pointer",children:u.jsx(ja,{isActive:zt===$,onClick:()=>Bn($),className:`${zt===$?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:$})},N)}),u.jsx(Fr,{children:u.jsx(au,{onClick:()=>Bn(T=>Math.min(T+1,Math.ceil(oa/20))),"aria-disabled":zt===Math.ceil(oa/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),o&&a&&u.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[u.jsx("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:Jc()}),u.jsx($e,{variant:"default",onClick:()=>a(dv()),disabled:v.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),j$=t=>u.jsx(MO,{clientId:U$,children:u.jsx(K$,{...t})});var _c=t=>t.type==="checkbox",Wi=t=>t instanceof Date,An=t=>t==null;const LE=t=>typeof t=="object";var jt=t=>!An(t)&&!Array.isArray(t)&&LE(t)&&!Wi(t),W$=t=>jt(t)&&t.target?_c(t.target)?t.target.checked:t.target.value:t,q$=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,Y$=(t,e)=>t.has(q$(e)),J$=t=>{const e=t.constructor&&t.constructor.prototype;return jt(e)&&e.hasOwnProperty("isPrototypeOf")},Mm=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mr(t){let e;const n=Array.isArray(t),r=typeof FileList<"u"?t instanceof FileList:!1;if(t instanceof Date)e=new Date(t);else if(t instanceof Set)e=new Set(t);else if(!(Mm&&(t instanceof Blob||r))&&(n||jt(t)))if(e=n?[]:{},!n&&!J$(t))e=t;else for(const o in t)t.hasOwnProperty(o)&&(e[o]=mr(t[o]));else return t;return e}var Uu=t=>Array.isArray(t)?t.filter(Boolean):[],Bt=t=>t===void 0,Re=(t,e,n)=>{if(!e||!jt(t))return n;const r=Uu(e.split(/[,[\].]+?/)).reduce((o,a)=>An(o)?o:o[a],t);return Bt(r)||r===t?Bt(t[e])?n:t[e]:r},ho=t=>typeof t=="boolean",Rm=t=>/^\w*$/.test(t),UE=t=>Uu(t.replace(/["|']|\]/g,"").split(/\.|\[/)),Dt=(t,e,n)=>{let r=-1;const o=Rm(e)?[e]:UE(e),a=o.length,c=a-1;for(;++r<a;){const l=o[r];let f=n;if(r!==c){const h=t[l];f=jt(h)||Array.isArray(h)?h:isNaN(+o[r+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;t[l]=f,t=t[l]}return t};const $E={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Hr={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},$o={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};O.createContext(null);var Q$=(t,e,n,r=!0)=>{const o={defaultValues:e._defaultValues};for(const a in t)Object.defineProperty(o,a,{get:()=>{const c=a;return e._proxyFormState[c]!==Hr.all&&(e._proxyFormState[c]=!r||Hr.all),t[c]}});return o},$n=t=>jt(t)&&!Object.keys(t).length,X$=(t,e,n,r)=>{n(t);const{name:o,...a}=t;return $n(a)||Object.keys(a).length>=Object.keys(e).length||Object.keys(a).find(c=>e[c]===Hr.all)},$u=t=>Array.isArray(t)?t:[t];function Z$(t){const e=O.useRef(t);e.current=t,O.useEffect(()=>{const n=!t.disabled&&e.current.subject&&e.current.subject.subscribe({next:e.current.next});return()=>{n&&n.unsubscribe()}},[t.disabled])}var po=t=>typeof t=="string",eH=(t,e,n,r,o)=>po(t)?(r&&e.watch.add(t),Re(n,t,o)):Array.isArray(t)?t.map(a=>(r&&e.watch.add(a),Re(n,a))):(r&&(e.watchAll=!0),n),tH=(t,e,n,r,o)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[r]:o||!0}}:{},HE=t=>({isOnSubmit:!t||t===Hr.onSubmit,isOnBlur:t===Hr.onBlur,isOnChange:t===Hr.onChange,isOnAll:t===Hr.all,isOnTouch:t===Hr.onTouched}),BE=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(r=>t.startsWith(r)&&/^\.\w+/.test(t.slice(r.length))));const Tc=(t,e,n,r)=>{for(const o of n||Object.keys(t)){const a=Re(t,o);if(a){const{_f:c,...l}=a;if(c){if(c.refs&&c.refs[0]&&e(c.refs[0],o)&&!r)return!0;if(c.ref&&e(c.ref,c.name)&&!r)return!0;if(Tc(l,e))break}else if(jt(l)&&Tc(l,e))break}}};var nH=(t,e,n)=>{const r=$u(Re(t,n));return Dt(r,"root",e[n]),Dt(t,n,r),t},Dm=t=>t.type==="file",go=t=>typeof t=="function",Hu=t=>{if(!Mm)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},Bu=t=>po(t),Fm=t=>t.type==="radio",zu=t=>t instanceof RegExp;const zE={value:!1,isValid:!1},GE={value:!0,isValid:!0};var VE=t=>{if(Array.isArray(t)){if(t.length>1){const e=t.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:e,isValid:!!e.length}}return t[0].checked&&!t[0].disabled?t[0].attributes&&!Bt(t[0].attributes.value)?Bt(t[0].value)||t[0].value===""?GE:{value:t[0].value,isValid:!0}:GE:zE}return zE};const KE={isValid:!1,value:null};var jE=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,KE):KE;function WE(t,e,n="validate"){if(Bu(t)||Array.isArray(t)&&t.every(Bu)||ho(t)&&!t)return{type:n,message:Bu(t)?t:"",ref:e}}var ts=t=>jt(t)&&!zu(t)?t:{value:t,message:""},qE=async(t,e,n,r,o)=>{const{ref:a,refs:c,required:l,maxLength:f,minLength:h,min:p,max:g,pattern:w,validate:v,name:C,valueAsNumber:y,mount:_,disabled:I}=t._f,k=Re(e,C);if(!_||I)return{};const R=c?c[0]:a,M=ce=>{r&&R.reportValidity&&(R.setCustomValidity(ho(ce)?"":ce||""),R.reportValidity())},S={},z=Fm(a),V=_c(a),j=z||V,te=(y||Dm(a))&&Bt(a.value)&&Bt(k)||Hu(a)&&a.value===""||k===""||Array.isArray(k)&&!k.length,W=tH.bind(null,C,n,S),me=(ce,xe,K,Z=$o.maxLength,q=$o.minLength)=>{const oe=ce?xe:K;S[C]={type:ce?Z:q,message:oe,ref:a,...W(ce?Z:q,oe)}};if(o?!Array.isArray(k)||!k.length:l&&(!j&&(te||An(k))||ho(k)&&!k||V&&!VE(c).isValid||z&&!jE(c).isValid)){const{value:ce,message:xe}=Bu(l)?{value:!!l,message:l}:ts(l);if(ce&&(S[C]={type:$o.required,message:xe,ref:R,...W($o.required,xe)},!n))return M(xe),S}if(!te&&(!An(p)||!An(g))){let ce,xe;const K=ts(g),Z=ts(p);if(!An(k)&&!isNaN(k)){const q=a.valueAsNumber||k&&+k;An(K.value)||(ce=q>K.value),An(Z.value)||(xe=q<Z.value)}else{const q=a.valueAsDate||new Date(k),oe=U=>new Date(new Date().toDateString()+" "+U),Q=a.type=="time",J=a.type=="week";po(K.value)&&k&&(ce=Q?oe(k)>oe(K.value):J?k>K.value:q>new Date(K.value)),po(Z.value)&&k&&(xe=Q?oe(k)<oe(Z.value):J?k<Z.value:q<new Date(Z.value))}if((ce||xe)&&(me(!!ce,K.message,Z.message,$o.max,$o.min),!n))return M(S[C].message),S}if((f||h)&&!te&&(po(k)||o&&Array.isArray(k))){const ce=ts(f),xe=ts(h),K=!An(ce.value)&&k.length>+ce.value,Z=!An(xe.value)&&k.length<+xe.value;if((K||Z)&&(me(K,ce.message,xe.message),!n))return M(S[C].message),S}if(w&&!te&&po(k)){const{value:ce,message:xe}=ts(w);if(zu(ce)&&!k.match(ce)&&(S[C]={type:$o.pattern,message:xe,ref:a,...W($o.pattern,xe)},!n))return M(xe),S}if(v){if(go(v)){const ce=await v(k,e),xe=WE(ce,R);if(xe&&(S[C]={...xe,...W($o.validate,xe.message)},!n))return M(xe.message),S}else if(jt(v)){let ce={};for(const xe in v){if(!$n(ce)&&!n)break;const K=WE(await v[xe](k,e),R,xe);K&&(ce={...K,...W(xe,K.message)},M(K.message),n&&(S[C]=ce))}if(!$n(ce)&&(S[C]={ref:R,...ce},!n))return S}}return M(!0),S};function rH(t,e){const n=e.slice(0,-1).length;let r=0;for(;r<n;)t=Bt(t)?r++:t[e[r++]];return t}function oH(t){for(const e in t)if(t.hasOwnProperty(e)&&!Bt(t[e]))return!1;return!0}function en(t,e){const n=Array.isArray(e)?e:Rm(e)?[e]:UE(e),r=n.length===1?t:rH(t,n),o=n.length-1,a=n[o];return r&&delete r[a],o!==0&&(jt(r)&&$n(r)||Array.isArray(r)&&oH(r))&&en(t,n.slice(0,-1)),t}var Lm=()=>{let t=[];return{get observers(){return t},next:o=>{for(const a of t)a.next&&a.next(o)},subscribe:o=>(t.push(o),{unsubscribe:()=>{t=t.filter(a=>a!==o)}}),unsubscribe:()=>{t=[]}}},Um=t=>An(t)||!LE(t);function yi(t,e){if(Um(t)||Um(e))return t===e;if(Wi(t)&&Wi(e))return t.getTime()===e.getTime();const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const o of n){const a=t[o];if(!r.includes(o))return!1;if(o!=="ref"){const c=e[o];if(Wi(a)&&Wi(c)||jt(a)&&jt(c)||Array.isArray(a)&&Array.isArray(c)?!yi(a,c):a!==c)return!1}}return!0}var YE=t=>t.type==="select-multiple",iH=t=>Fm(t)||_c(t),$m=t=>Hu(t)&&t.isConnected,JE=t=>{for(const e in t)if(go(t[e]))return!0;return!1};function Gu(t,e={}){const n=Array.isArray(t);if(jt(t)||n)for(const r in t)Array.isArray(t[r])||jt(t[r])&&!JE(t[r])?(e[r]=Array.isArray(t[r])?[]:{},Gu(t[r],e[r])):An(t[r])||(e[r]=!0);return e}function QE(t,e,n){const r=Array.isArray(t);if(jt(t)||r)for(const o in t)Array.isArray(t[o])||jt(t[o])&&!JE(t[o])?Bt(e)||Um(n[o])?n[o]=Array.isArray(t[o])?Gu(t[o],[]):{...Gu(t[o])}:QE(t[o],An(e)?{}:e[o],n[o]):n[o]=!yi(t[o],e[o]);return n}var Ec=(t,e)=>QE(t,e,Gu(e)),XE=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:r})=>Bt(t)?t:e?t===""?NaN:t&&+t:n&&po(t)?new Date(t):r?r(t):t;function Hm(t){const e=t.ref;if(!(t.refs?t.refs.every(n=>n.disabled):e.disabled))return Dm(e)?e.files:Fm(e)?jE(t.refs).value:YE(e)?[...e.selectedOptions].map(({value:n})=>n):_c(e)?VE(t.refs).value:XE(Bt(e.value)?t.ref.value:e.value,t)}var aH=(t,e,n,r)=>{const o={};for(const a of t){const c=Re(e,a);c&&Dt(o,a,c._f)}return{criteriaMode:n,names:[...t],fields:o,shouldUseNativeValidation:r}},Sc=t=>Bt(t)?t:zu(t)?t.source:jt(t)?zu(t.value)?t.value.source:t.value:t;const ZE="AsyncFunction";var sH=t=>!!t&&!!t.validate&&!!(go(t.validate)&&t.validate.constructor.name===ZE||jt(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===ZE)),cH=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate);function eS(t,e,n){const r=Re(t,n);if(r||Rm(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const a=o.join("."),c=Re(e,a),l=Re(t,a);if(c&&!Array.isArray(c)&&n!==a)return{name:n};if(l&&l.type)return{name:a,error:l};o.pop()}return{name:n}}var lH=(t,e,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(e||t):(n?r.isOnBlur:o.isOnBlur)?!t:(n?r.isOnChange:o.isOnChange)?t:!0,dH=(t,e)=>!Uu(Re(t,e)).length&&en(t,e);const uH={mode:Hr.onSubmit,reValidateMode:Hr.onChange,shouldFocusError:!0};function fH(t={}){let e={...uH,...t},n={submitCount:0,isDirty:!1,isLoading:go(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1},r={},o=jt(e.defaultValues)||jt(e.values)?mr(e.defaultValues||e.values)||{}:{},a=e.shouldUnregister?{}:mr(o),c={action:!1,mount:!1,watch:!1},l={mount:new Set,unMount:new Set,array:new Set,watch:new Set},f,h=0;const p={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},g={values:Lm(),array:Lm(),state:Lm()},w=HE(e.mode),v=HE(e.reValidateMode),C=e.criteriaMode===Hr.all,y=D=>G=>{clearTimeout(h),h=setTimeout(D,G)},_=async D=>{if(!e.disabled&&(p.isValid||D)){const G=e.resolver?$n((await j()).errors):await W(r,!0);G!==n.isValid&&g.state.next({isValid:G})}},I=(D,G)=>{!e.disabled&&(p.isValidating||p.validatingFields)&&((D||Array.from(l.mount)).forEach(X=>{X&&(G?Dt(n.validatingFields,X,G):en(n.validatingFields,X))}),g.state.next({validatingFields:n.validatingFields,isValidating:!$n(n.validatingFields)}))},k=(D,G=[],X,be,ye=!0,pe=!0)=>{if(be&&X&&!e.disabled){if(c.action=!0,pe&&Array.isArray(Re(r,D))){const re=X(Re(r,D),be.argA,be.argB);ye&&Dt(r,D,re)}if(pe&&Array.isArray(Re(n.errors,D))){const re=X(Re(n.errors,D),be.argA,be.argB);ye&&Dt(n.errors,D,re),dH(n.errors,D)}if(p.touchedFields&&pe&&Array.isArray(Re(n.touchedFields,D))){const re=X(Re(n.touchedFields,D),be.argA,be.argB);ye&&Dt(n.touchedFields,D,re)}p.dirtyFields&&(n.dirtyFields=Ec(o,a)),g.state.next({name:D,isDirty:ce(D,G),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Dt(a,D,G)},R=(D,G)=>{Dt(n.errors,D,G),g.state.next({errors:n.errors})},M=D=>{n.errors=D,g.state.next({errors:n.errors,isValid:!1})},S=(D,G,X,be)=>{const ye=Re(r,D);if(ye){const pe=Re(a,D,Bt(X)?Re(o,D):X);Bt(pe)||be&&be.defaultChecked||G?Dt(a,D,G?pe:Hm(ye._f)):Z(D,pe),c.mount&&_()}},z=(D,G,X,be,ye)=>{let pe=!1,re=!1;const ge={name:D};if(!e.disabled){const Be=!!(Re(r,D)&&Re(r,D)._f&&Re(r,D)._f.disabled);if(!X||be){p.isDirty&&(re=n.isDirty,n.isDirty=ge.isDirty=ce(),pe=re!==ge.isDirty);const Qe=Be||yi(Re(o,D),G);re=!!(!Be&&Re(n.dirtyFields,D)),Qe||Be?en(n.dirtyFields,D):Dt(n.dirtyFields,D,!0),ge.dirtyFields=n.dirtyFields,pe=pe||p.dirtyFields&&re!==!Qe}if(X){const Qe=Re(n.touchedFields,D);Qe||(Dt(n.touchedFields,D,X),ge.touchedFields=n.touchedFields,pe=pe||p.touchedFields&&Qe!==X)}pe&&ye&&g.state.next(ge)}return pe?ge:{}},V=(D,G,X,be)=>{const ye=Re(n.errors,D),pe=p.isValid&&ho(G)&&n.isValid!==G;if(e.delayError&&X?(f=y(()=>R(D,X)),f(e.delayError)):(clearTimeout(h),f=null,X?Dt(n.errors,D,X):en(n.errors,D)),(X?!yi(ye,X):ye)||!$n(be)||pe){const re={...be,...pe&&ho(G)?{isValid:G}:{},errors:n.errors,name:D};n={...n,...re},g.state.next(re)}},j=async D=>{I(D,!0);const G=await e.resolver(a,e.context,aH(D||l.mount,r,e.criteriaMode,e.shouldUseNativeValidation));return I(D),G},te=async D=>{const{errors:G}=await j(D);if(D)for(const X of D){const be=Re(G,X);be?Dt(n.errors,X,be):en(n.errors,X)}else n.errors=G;return G},W=async(D,G,X={valid:!0})=>{for(const be in D){const ye=D[be];if(ye){const{_f:pe,...re}=ye;if(pe){const ge=l.array.has(pe.name),Be=ye._f&&sH(ye._f);Be&&p.validatingFields&&I([be],!0);const Qe=await qE(ye,a,C,e.shouldUseNativeValidation&&!G,ge);if(Be&&p.validatingFields&&I([be]),Qe[pe.name]&&(X.valid=!1,G))break;!G&&(Re(Qe,pe.name)?ge?nH(n.errors,Qe,pe.name):Dt(n.errors,pe.name,Qe[pe.name]):en(n.errors,pe.name))}!$n(re)&&await W(re,G,X)}}return X.valid},me=()=>{for(const D of l.unMount){const G=Re(r,D);G&&(G._f.refs?G._f.refs.every(X=>!$m(X)):!$m(G._f.ref))&&Se(D)}l.unMount=new Set},ce=(D,G)=>!e.disabled&&(D&&G&&Dt(a,D,G),!yi(ne(),o)),xe=(D,G,X)=>eH(D,l,{...c.mount?a:Bt(G)?o:po(D)?{[D]:G}:G},X,G),K=D=>Uu(Re(c.mount?a:o,D,e.shouldUnregister?Re(o,D,[]):[])),Z=(D,G,X={})=>{const be=Re(r,D);let ye=G;if(be){const pe=be._f;pe&&(!pe.disabled&&Dt(a,D,XE(G,pe)),ye=Hu(pe.ref)&&An(G)?"":G,YE(pe.ref)?[...pe.ref.options].forEach(re=>re.selected=ye.includes(re.value)):pe.refs?_c(pe.ref)?pe.refs.length>1?pe.refs.forEach(re=>(!re.defaultChecked||!re.disabled)&&(re.checked=Array.isArray(ye)?!!ye.find(ge=>ge===re.value):ye===re.value)):pe.refs[0]&&(pe.refs[0].checked=!!ye):pe.refs.forEach(re=>re.checked=re.value===ye):Dm(pe.ref)?pe.ref.value="":(pe.ref.value=ye,pe.ref.type||g.values.next({name:D,values:{...a}})))}(X.shouldDirty||X.shouldTouch)&&z(D,ye,X.shouldTouch,X.shouldDirty,!0),X.shouldValidate&&U(D)},q=(D,G,X)=>{for(const be in G){const ye=G[be],pe=`${D}.${be}`,re=Re(r,pe);(l.array.has(D)||jt(ye)||re&&!re._f)&&!Wi(ye)?q(pe,ye,X):Z(pe,ye,X)}},oe=(D,G,X={})=>{const be=Re(r,D),ye=l.array.has(D),pe=mr(G);Dt(a,D,pe),ye?(g.array.next({name:D,values:{...a}}),(p.isDirty||p.dirtyFields)&&X.shouldDirty&&g.state.next({name:D,dirtyFields:Ec(o,a),isDirty:ce(D,pe)})):be&&!be._f&&!An(pe)?q(D,pe,X):Z(D,pe,X),BE(D,l)&&g.state.next({...n}),g.values.next({name:c.mount?D:void 0,values:{...a}})},Q=async D=>{c.mount=!0;const G=D.target;let X=G.name,be=!0;const ye=Re(r,X),pe=()=>G.type?Hm(ye._f):W$(D),re=ge=>{be=Number.isNaN(ge)||Wi(ge)&&isNaN(ge.getTime())||yi(ge,Re(a,X,ge))};if(ye){let ge,Be;const Qe=pe(),pt=D.type===$E.BLUR||D.type===$E.FOCUS_OUT,hn=!cH(ye._f)&&!e.resolver&&!Re(n.errors,X)&&!ye._f.deps||lH(pt,Re(n.touchedFields,X),n.isSubmitted,v,w),kn=BE(X,l,pt);Dt(a,X,Qe),pt?(ye._f.onBlur&&ye._f.onBlur(D),f&&f(0)):ye._f.onChange&&ye._f.onChange(D);const Wt=z(X,Qe,pt,!1),Hn=!$n(Wt)||kn;if(!pt&&g.values.next({name:X,type:D.type,values:{...a}}),hn)return p.isValid&&(e.mode==="onBlur"?pt&&_():_()),Hn&&g.state.next({name:X,...kn?{}:Wt});if(!pt&&kn&&g.state.next({...n}),e.resolver){const{errors:vr}=await j([X]);if(re(Qe),be){const zt=eS(n.errors,r,X),Bn=eS(vr,r,zt.name||X);ge=Bn.error,X=Bn.name,Be=$n(vr)}}else I([X],!0),ge=(await qE(ye,a,C,e.shouldUseNativeValidation))[X],I([X]),re(Qe),be&&(ge?Be=!1:p.isValid&&(Be=await W(r,!0)));be&&(ye._f.deps&&U(ye._f.deps),V(X,Be,ge,Wt))}},J=(D,G)=>{if(Re(n.errors,G)&&D.focus)return D.focus(),1},U=async(D,G={})=>{let X,be;const ye=$u(D);if(e.resolver){const pe=await te(Bt(D)?D:ye);X=$n(pe),be=D?!ye.some(re=>Re(pe,re)):X}else D?(be=(await Promise.all(ye.map(async pe=>{const re=Re(r,pe);return await W(re&&re._f?{[pe]:re}:re)}))).every(Boolean),!(!be&&!n.isValid)&&_()):be=X=await W(r);return g.state.next({...!po(D)||p.isValid&&X!==n.isValid?{}:{name:D},...e.resolver||!D?{isValid:X}:{},errors:n.errors}),G.shouldFocus&&!be&&Tc(r,J,D?ye:l.mount),be},ne=D=>{const G={...c.mount?a:o};return Bt(D)?G:po(D)?Re(G,D):D.map(X=>Re(G,X))},_e=(D,G)=>({invalid:!!Re((G||n).errors,D),isDirty:!!Re((G||n).dirtyFields,D),error:Re((G||n).errors,D),isValidating:!!Re(n.validatingFields,D),isTouched:!!Re((G||n).touchedFields,D)}),Ee=D=>{D&&$u(D).forEach(G=>en(n.errors,G)),g.state.next({errors:D?n.errors:{}})},Te=(D,G,X)=>{const be=(Re(r,D,{_f:{}})._f||{}).ref,ye=Re(n.errors,D)||{},{ref:pe,message:re,type:ge,...Be}=ye;Dt(n.errors,D,{...Be,...G,ref:be}),g.state.next({name:D,errors:n.errors,isValid:!1}),X&&X.shouldFocus&&be&&be.focus&&be.focus()},Ne=(D,G)=>go(D)?g.values.subscribe({next:X=>D(xe(void 0,G),X)}):xe(D,G,!0),Se=(D,G={})=>{for(const X of D?$u(D):l.mount)l.mount.delete(X),l.array.delete(X),G.keepValue||(en(r,X),en(a,X)),!G.keepError&&en(n.errors,X),!G.keepDirty&&en(n.dirtyFields,X),!G.keepTouched&&en(n.touchedFields,X),!G.keepIsValidating&&en(n.validatingFields,X),!e.shouldUnregister&&!G.keepDefaultValue&&en(o,X);g.values.next({values:{...a}}),g.state.next({...n,...G.keepDirty?{isDirty:ce()}:{}}),!G.keepIsValid&&_()},Oe=({disabled:D,name:G,field:X,fields:be,value:ye})=>{if(ho(D)&&c.mount||D){const pe=D?void 0:Bt(ye)?Hm(X?X._f:Re(be,G)._f):ye;(D||!D&&!Bt(pe))&&Dt(a,G,pe),z(G,pe,!1,!1,!0)}},De=(D,G={})=>{let X=Re(r,D);const be=ho(G.disabled)||ho(e.disabled);return Dt(r,D,{...X||{},_f:{...X&&X._f?X._f:{ref:{name:D}},name:D,mount:!0,...G}}),l.mount.add(D),X?Oe({field:X,disabled:ho(G.disabled)?G.disabled:e.disabled,name:D,value:G.value}):S(D,!0,G.value),{...be?{disabled:G.disabled||e.disabled}:{},...e.progressive?{required:!!G.required,min:Sc(G.min),max:Sc(G.max),minLength:Sc(G.minLength),maxLength:Sc(G.maxLength),pattern:Sc(G.pattern)}:{},name:D,onChange:Q,onBlur:Q,ref:ye=>{if(ye){De(D,G),X=Re(r,D);const pe=Bt(ye.value)&&ye.querySelectorAll&&ye.querySelectorAll("input,select,textarea")[0]||ye,re=iH(pe),ge=X._f.refs||[];if(re?ge.find(Be=>Be===pe):pe===X._f.ref)return;Dt(r,D,{_f:{...X._f,...re?{refs:[...ge.filter($m),pe,...Array.isArray(Re(o,D))?[{}]:[]],ref:{type:pe.type,name:D}}:{ref:pe}}}),S(D,!1,void 0,pe)}else X=Re(r,D,{}),X._f&&(X._f.mount=!1),(e.shouldUnregister||G.shouldUnregister)&&!(Y$(l.array,D)&&c.action)&&l.unMount.add(D)}}},Ue=()=>e.shouldFocusError&&Tc(r,J,l.mount),Me=D=>{ho(D)&&(g.state.next({disabled:D}),Tc(r,(G,X)=>{const be=Re(r,X);be&&(G.disabled=be._f.disabled||D,Array.isArray(be._f.refs)&&be._f.refs.forEach(ye=>{ye.disabled=be._f.disabled||D}))},0,!1))},nt=(D,G)=>async X=>{let be;if(X&&(X.preventDefault&&X.preventDefault(),X.persist&&X.persist()),e.disabled){G&&await G({...n.errors},X);return}let ye=mr(a);if(g.state.next({isSubmitting:!0}),e.resolver){const{errors:pe,values:re}=await j();n.errors=pe,ye=re}else await W(r);if(en(n.errors,"root"),$n(n.errors)){g.state.next({errors:{}});try{await D(ye,X)}catch(pe){be=pe}}else G&&await G({...n.errors},X),Ue(),setTimeout(Ue);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:$n(n.errors)&&!be,submitCount:n.submitCount+1,errors:n.errors}),be)throw be},we=(D,G={})=>{Re(r,D)&&(Bt(G.defaultValue)?oe(D,mr(Re(o,D))):(oe(D,G.defaultValue),Dt(o,D,mr(G.defaultValue))),G.keepTouched||en(n.touchedFields,D),G.keepDirty||(en(n.dirtyFields,D),n.isDirty=G.defaultValue?ce(D,mr(Re(o,D))):ce()),G.keepError||(en(n.errors,D),p.isValid&&_()),g.state.next({...n}))},lt=(D,G={})=>{const X=D?mr(D):o,be=mr(X),ye=$n(D),pe=ye?o:be;if(G.keepDefaultValues||(o=X),!G.keepValues){if(G.keepDirtyValues){const re=new Set([...l.mount,...Object.keys(Ec(o,a))]);for(const ge of Array.from(re))Re(n.dirtyFields,ge)?Dt(pe,ge,Re(a,ge)):oe(ge,Re(pe,ge))}else{if(Mm&&Bt(D))for(const re of l.mount){const ge=Re(r,re);if(ge&&ge._f){const Be=Array.isArray(ge._f.refs)?ge._f.refs[0]:ge._f.ref;if(Hu(Be)){const Qe=Be.closest("form");if(Qe){Qe.reset();break}}}}r={}}a=e.shouldUnregister?G.keepDefaultValues?mr(o):{}:mr(pe),g.array.next({values:{...pe}}),g.values.next({values:{...pe}})}l={mount:G.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},c.mount=!p.isValid||!!G.keepIsValid||!!G.keepDirtyValues,c.watch=!!e.shouldUnregister,g.state.next({submitCount:G.keepSubmitCount?n.submitCount:0,isDirty:ye?!1:G.keepDirty?n.isDirty:!!(G.keepDefaultValues&&!yi(D,o)),isSubmitted:G.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ye?{}:G.keepDirtyValues?G.keepDefaultValues&&a?Ec(o,a):n.dirtyFields:G.keepDefaultValues&&D?Ec(o,D):G.keepDirty?n.dirtyFields:{},touchedFields:G.keepTouched?n.touchedFields:{},errors:G.keepErrors?n.errors:{},isSubmitSuccessful:G.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Ct=(D,G)=>lt(go(D)?D(a):D,G);return{control:{register:De,unregister:Se,getFieldState:_e,handleSubmit:nt,setError:Te,_executeSchema:j,_getWatch:xe,_getDirty:ce,_updateValid:_,_removeUnmounted:me,_updateFieldArray:k,_updateDisabledField:Oe,_getFieldArray:K,_reset:lt,_resetDefaultValues:()=>go(e.defaultValues)&&e.defaultValues().then(D=>{Ct(D,e.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:D=>{n={...n,...D}},_disableForm:Me,_subjects:g,_proxyFormState:p,_setErrors:M,get _fields(){return r},get _formValues(){return a},get _state(){return c},set _state(D){c=D},get _defaultValues(){return o},get _names(){return l},set _names(D){l=D},get _formState(){return n},set _formState(D){n=D},get _options(){return e},set _options(D){e={...e,...D}}},trigger:U,register:De,handleSubmit:nt,watch:Ne,setValue:oe,getValues:ne,reset:Ct,resetField:we,clearErrors:Ee,unregister:Se,setError:Te,setFocus:(D,G={})=>{const X=Re(r,D),be=X&&X._f;if(be){const ye=be.refs?be.refs[0]:be.ref;ye.focus&&(ye.focus(),G.shouldSelect&&go(ye.select)&&ye.select())}},getFieldState:_e}}function hH(t={}){const e=O.useRef(),n=O.useRef(),[r,o]=O.useState({isDirty:!1,isValidating:!1,isLoading:go(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1,defaultValues:go(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...fH(t),formState:r});const a=e.current.control;return a._options=t,Z$({subject:a._subjects.state,next:c=>{X$(c,a._proxyFormState,a._updateFormState)&&o({...a._formState})}}),O.useEffect(()=>a._disableForm(t.disabled),[a,t.disabled]),O.useEffect(()=>{if(a._proxyFormState.isDirty){const c=a._getDirty();c!==r.isDirty&&a._subjects.state.next({isDirty:c})}},[a,r.isDirty]),O.useEffect(()=>{t.values&&!yi(t.values,n.current)?(a._reset(t.values,a._options.resetOptions),n.current=t.values,o(c=>({...c}))):a._resetDefaultValues()},[t.values,a]),O.useEffect(()=>{t.errors&&a._setErrors(t.errors)},[t.errors,a]),O.useEffect(()=>{a._state.mount||(a._updateValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),O.useEffect(()=>{t.shouldUnregister&&a._subjects.values.next({values:a._getWatch()})},[t.shouldUnregister,a]),O.useMemo(()=>({...e.current,formState:Q$(r,a)}),[r,a])}const tS=({className:t,children:e,content:n,side:r})=>{const[o,a]=O.useState(!1);return u.jsx(co,{delayDuration:0,children:u.jsxs(lo,{open:o,children:[u.jsx(uo,{asChild:!0,children:u.jsx("button",{type:"button",className:Je("cursor-pointer",t),onClick:()=>a(!o),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onTouchStart:()=>a(!o),onKeyDown:c=>{c.preventDefault(),c.key==="Enter"&&a(!o)},children:e})}),u.jsx($r,{side:r,className:n?"":"hidden",children:u.jsx("span",{className:"inline-block",children:n})})]})})},pH=(t,e)=>{const[n,r]=O.useState(t);return O.useEffect(()=>{const o=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(o)}},[t,e]),n},gH=({apiBaseUrl:t="http://localhost:3000"})=>{var z,V;const[e,n]=O.useState([]),[r,o]=O.useState(!1),[a,c]=O.useState([]),[l,f]=O.useState(1),[h,p]=O.useState(1),[g,w]=O.useState(null),[v,C]=O.useState(""),y=pH(v,500),_=j=>{const te=j.match(/\d{6}/);if(!te)return{month:"",year:""};const W=te[0],me=W.substring(0,2),ce=W.substring(2);return{month:me,year:ce}},I=j=>j.map(W=>{let me=(W==null?void 0:W.month)||"",ce=(W==null?void 0:W.year)||"";if((!me||!ce)&&(W!=null&&W.file_name)){const xe=_(W.file_name);me=me||xe.month,ce=ce||xe.year}return{id:W==null?void 0:W.id,prefix:(W==null?void 0:W.prefix)||"",model:(W==null?void 0:W.model)||"",fileName:(W==null?void 0:W.file_name)||"",code:(W==null?void 0:W.stock_id)||"",month:me,year:ce,content:(W==null?void 0:W.text_summary)||"",status:(W==null?void 0:W.status)||"",note:(W==null?void 0:W.note)||"",lastUpdate:W==null?void 0:W.updated_at,stock_id:W==null?void 0:W.stock_id}}),k=j=>{if(!(j!=null&&j.data))return[];const te=I(j==null?void 0:j.data);n(te),p(j.pagination.totalPages)},R=async(j=1,te=15)=>{w(j),o(!0);try{const W=await Le.get(`${t}/api/latest-summaries`,{params:{page:j,limit:te,search:v}});(W==null?void 0:W.status)===200?k(W.data):console.error(W)}catch(W){console.error("Error fetching data:",W)}finally{w(null),o(!1)}};O.useEffect(()=>{y&&f(1),R(l)},[l,y]);const M=O.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:te})=>u.jsx("span",{className:"flex flex-col",children:te.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:te})=>{const W=te.original.month,me=te.original.year;return u.jsx("span",{className:"flex flex-col",children:`${W.toString().padStart(2,"0")}/${me}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:te})=>{const W=te.getValue("content");return u.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:W})}},{id:"status",header:"Trạng thái",accessorKey:"status",cell:({row:te})=>{const me=te.original.status!=="unpublish";return u.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${me?"bg-green-50 text-green-700 ring-1 ring-inset ring-green-600/20":"bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/20"}`,children:me?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:te})=>u.jsx(tS,{content:u.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:te.original.note}),children:u.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:te.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:te})=>{const W=new Date(te.original.lastUpdate),me=W.getDate(),ce=W.getMonth()+1,xe=`ngày ${me} tháng ${ce}`;return u.jsx("span",{className:"flex flex-col",children:xe})}},{accessorKey:"actions",header:()=>u.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:te})=>{const[W,me]=O.useState(!1),[ce,xe]=O.useState(!1),[K,Z]=O.useState(!1),{handleSubmit:q,register:oe,reset:Q}=hH(),J=te.original.id,U=te.getValue("status"),ne=te.getValue("content"),[_e,Ee]=O.useState(!1),Te=async()=>{try{Ee(!0);const Se=U==="unpublish"?"published":"unpublish",Oe=await Le.patch(`${t}/api/toggle-publish/${J}`,{id:J,typeAction:"update",status:U,idInput:J,stock_id:te.original.stock_id,prefix:te.original.prefix,model:te.original.model,summary_result:te.original.content,note:te.original.note});Oe.status===200?n(De=>De.map(Ue=>Ue.id===J?{...Ue,status:Se}:Ue)):console.error("Failed to toggle publish status:",Oe)}catch(Se){console.error("Error toggling publish status:",Se)}finally{Ee(!1)}},Ne=async Se=>{me(!0);try{const Oe=await Le.patch(`${t}/api/update-summary`,{note:Se.note,text_summary:Se.content,id:J});Oe.status===200?(await R(l),xe(!1)):console.error("Failed to update summary:",Oe)}catch(Oe){console.error("Error updating summary:",Oe)}return me(!1)};return u.jsxs("div",{className:"flex items-center justify-end gap-2",children:[u.jsx($e,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:u.jsx(lR,{className:"h-4 w-4"})}),u.jsx(gr,{open:K,onOpenChange:Z,children:u.jsxs(er,{className:"max-w-3xl max-h-[80vh]",children:[u.jsx(tr,{children:u.jsx(nr,{children:"Nội dung chi tiết"})}),u.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:u.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:ne})})]})}),u.jsxs(gr,{open:ce,onOpenChange:Se=>{xe(Se),Se?Q({content:te.original.content,note:te.original.note}):Q()},children:[u.jsx(cc,{asChild:!0,children:u.jsx($e,{variant:"outline",size:"sm",onClick:()=>xe(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),u.jsx(er,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:u.jsxs(tr,{className:"flex flex-col gap-3",children:[u.jsx(nr,{className:"max-sm:hidden text-center",children:"Sửa summary"}),u.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:q(Ne),children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex flex-col items-start",children:[u.jsx("span",{children:"Nội dung:"}),u.jsx(fc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:te.original.answer||"",rows:10,...oe("content")})]}),u.jsxs("div",{className:"flex flex-col items-start",children:[u.jsx("span",{children:"Ghi chú:"}),u.jsx(fc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:te.original.note||"",rows:1,...oe("note")})]})]}),u.jsx("div",{className:"flex justify-end",children:u.jsx($e,{disabled:W,type:"submit",variant:"default",children:W?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),u.jsx($e,{variant:"outline",size:"sm",onClick:Te,disabled:_e,className:"w-[70px] px-2 py-0.5 h-7",children:_e?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):U==="unpublish"?"Publish":"Unpublish"})]})}}],[]),S=Nb({data:e,columns:M,state:{columnFilters:a},enableRowSelection:!0,onColumnFiltersChange:c,getFilteredRowModel:h1(),getCoreRowModel:kb()});return u.jsxs("div",{className:"space-y-4 s3-explr-container",children:[u.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:u.jsxs("div",{className:"relative max-w-sm",children:[u.jsx(oo,{placeholder:"Tìm kiếm theo mã...",value:v,onChange:j=>C(j.target.value),className:"pr-8"}),v&&u.jsx($e,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>C(""),children:u.jsx(bg,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"rounded-md border s3-explr-table-container",children:u.jsxs(lc,{className:"s3-explr-table",children:[u.jsx(dc,{className:"s3-explr-table-header",children:S.getHeaderGroups().map(j=>u.jsx(rr,{className:"hover:bg-transparent s3-explr-header-row",children:j.headers.map(te=>u.jsx(or,{className:"s3-explr-header-cell",children:te.isPlaceholder?null:Ld(te.column.columnDef.header,te.getContext())},te.id))},j.id))}),u.jsx(uc,{className:"s3-explr-table-body",children:r?u.jsx(rr,{children:u.jsx(un,{colSpan:M.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(z=S.getRowModel().rows)!=null&&z.length?(V=S.getRowModel().rows)==null?void 0:V.map(j=>u.jsx(rr,{className:"h-12 s3-explr-row",children:j.getVisibleCells().map(te=>u.jsx(un,{className:"align-middle s3-explr-cell",children:Ld(te.column.columnDef.cell,te.getContext())},te.id))},j.id)):u.jsx(rr,{children:u.jsx(un,{colSpan:M.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),u.jsx("div",{className:"mt-4",children:u.jsx(ru,{children:u.jsxs(ou,{children:[u.jsx(Fr,{children:u.jsx(iu,{onClick:()=>f(j=>Math.max(1,j-1)),className:l===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:h},(j,te)=>te+1).filter(j=>j===1||j===h||Math.abs(j-l)<=1).map((j,te,W)=>u.jsxs(u.Fragment,{children:[te>0&&W[te-1]!==j-1&&u.jsx(Fr,{children:u.jsx(su,{})},j+"..."),u.jsx(Fr,{children:u.jsx(ja,{onClick:()=>f(j),isActive:l===j,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===j?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):j})},j)]})),u.jsx(Fr,{children:u.jsx(au,{onClick:()=>f(j=>Math.min(h,j+1)),className:l===h||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},nS=10,mH=O.memo(({apiBaseUrl:t="http://localhost:3000"})=>{const[e,n]=O.useState(1),[r,o]=O.useState([]),[a,c]=O.useState({total:0,page:1,limit:nS,totalPages:1}),[l,f]=O.useState(!0),[h,p]=O.useState(null),[g,w]=O.useState(new Set),{toast:v}=yu(),[C,y]=O.useState(!1),_=async S=>{try{p(S);const z=await Le.get(`${t}/api/jobs`,{params:{page:S.toString(),limit:nS.toString()}});o(z.data.data),c(z.data.pagination)}catch{v({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{p(null),f(!1)}};O.useEffect(()=>{_(e)},[e,t]);const I=async S=>{w(z=>new Set(z).add(S.toString()));try{await Le.post(`${t}/api/retry-job`,{jobId:S},{headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v({title:"Job Restarted",description:`Job ${S} has been successfully restarted.`}),_(e)}catch{v({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${S}. Please try again.`})}finally{w(z=>{const V=new Set(z);return V.delete(S.toString()),V})}},k=async()=>{y(!0),n(1),await _(1),y(!1)},R=S=>new Date(S).toLocaleString(),M=S=>{if(S=parseFloat(S),S<60)return`${S.toFixed(2)}s`;const z=Math.floor(S/60),V=(S%60).toFixed(0);return`${z}m ${V}s`};return u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[u.jsx(iR,{className:"w-8 h-8 text-primary"}),u.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),u.jsx($e,{variant:"outline",size:"icon",onClick:k,disabled:C||l,className:"ml-2",children:u.jsx(fR,{className:`h-4 w-4 ${C?"animate-spin":""}`})})]}),u.jsx("div",{className:"rounded-md border",children:u.jsxs(lc,{children:[u.jsx(dc,{children:u.jsxs(rr,{children:[u.jsx(or,{children:"ID"}),u.jsx(or,{children:"Tên Công Việc"}),u.jsx(or,{children:"Thời Gian Bắt Đầu"}),u.jsx(or,{children:"Thời Gian Cập Nhật"}),u.jsx(or,{children:"Thời Gian Thực Thi"}),u.jsx(or,{children:"Trạng Thái"}),u.jsx(or,{children:"Thao Tác"})]})}),u.jsx(uc,{children:l&&r.length===0?u.jsx(rr,{children:u.jsx(un,{colSpan:7,className:"text-center py-4",children:u.jsx(Ht,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(S=>{var z,V;return u.jsxs(rr,{children:[u.jsx(un,{className:"!w-[100px]",children:S.id}),u.jsx(un,{className:"font-medium",children:(z=S.job_name)==null?void 0:z.replace("Upload file","Summary")}),u.jsx(un,{className:"!w-[200px]",children:R(S.created_at)}),u.jsx(un,{className:"!w-[200px]",children:R(S.updated_at)}),u.jsx(un,{className:"!w-[150px]",children:M(S.execution_time_seconds)}),u.jsx(un,{className:"!w-[200px]",children:u.jsx(tS,{content:S.status==="fail"&&S.error?u.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:S.error}):null,children:u.jsx("div",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]
218
218
  ${S.status==="done"?"bg-green-100 text-green-800":S.status==="fail"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:S.status==="fail"?"FAILED":(V=S.status)==null?void 0:V.toUpperCase()})})}),u.jsx(un,{className:"!w-[200px]",children:S.status==="fail"?u.jsx($e,{variant:"outline",size:"sm",onClick:()=>I(S.id),disabled:g.has(S.id.toString()),className:"h-[32px]",children:g.has(S.id.toString())?u.jsxs(u.Fragment,{children:[u.jsx(Ht,{className:"mr-2 h-4 w-4 animate-spin"}),"Đang thử lại..."]}):"Thử Lại"}):u.jsx("div",{className:"h-[32px]"})})]},S.id)})})]})}),u.jsx("div",{className:"mt-4",children:u.jsx(ru,{children:u.jsxs(ou,{children:[u.jsx(Fr,{children:u.jsx(iu,{onClick:()=>n(S=>Math.max(1,S-1)),className:e===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:a.totalPages},(S,z)=>z+1).filter(S=>S===1||S===a.totalPages||Math.abs(S-e)<=1).map((S,z,V)=>u.jsxs(u.Fragment,{children:[z>0&&V[z-1]!==S-1&&u.jsx(Fr,{children:u.jsx(su,{})},S+"..."),u.jsx(Fr,{children:u.jsx(ja,{onClick:()=>n(S),isActive:e===S,className:`cursor-pointer ${h!==null?"pointer-events-none":""}`,children:h===S?u.jsx(Ht,{className:"h-4 w-4 animate-spin"}):S})},S)]})),u.jsx(Fr,{children:u.jsx(au,{onClick:()=>n(S=>Math.min(a.totalPages,S+1)),className:e===a.totalPages||h!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),u.jsx(Y_,{})]})});Sr.Job=mH,Sr.S3Explorer=j$,Sr.Summary=gH,Object.defineProperty(Sr,Symbol.toStringTag,{value:"Module"})});
219
219
  //# sourceMappingURL=s3-explorer.umd.cjs.map