dccxx-s3-explorer 1.0.54 → 1.0.56

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.
@@ -172,6 +172,6 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var K=Ce(ae,le,ee,ce,oe+
172
172
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fS(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function pS(e){if(Array.isArray(e))return xs(e)}function Yf(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function Xf(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Yf(Object(n),!0).forEach(function(r){Jf(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Yf(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Jf(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function xr(e,t){return hS(e)||mS(e,t)||Zf(e,t)||gS()}function gS(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
173
173
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Zf(e,t){if(e){if(typeof e=="string")return xs(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return xs(e,t)}}function xs(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function mS(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,a,s;try{for(n=n.call(e);!(o=(a=n.next()).done)&&(r.push(a.value),!(t&&r.length===t));o=!0);}catch(u){i=!0,s=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw s}}return r}}function hS(e){if(Array.isArray(e))return e}var vS=typeof ys=="function"?ys:ys.default,yS="file-invalid-type",xS="file-too-large",bS="file-too-small",wS="too-many-files",CS=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=t.split(","),r=n.length>1?"one of ".concat(n.join(", ")):n[0];return{code:yS,message:"File type must be ".concat(r)}},Qf=function(t){return{code:xS,message:"File is larger than ".concat(t," ").concat(t===1?"byte":"bytes")}},ep=function(t){return{code:bS,message:"File is smaller than ".concat(t," ").concat(t===1?"byte":"bytes")}},SS={code:wS,message:"Too many files"};function tp(e,t){var n=e.type==="application/x-moz-file"||vS(e,t);return[n,n?null:CS(t)]}function np(e,t,n){if(Cn(e.size))if(Cn(t)&&Cn(n)){if(e.size>n)return[!1,Qf(n)];if(e.size<t)return[!1,ep(t)]}else{if(Cn(t)&&e.size<t)return[!1,ep(t)];if(Cn(n)&&e.size>n)return[!1,Qf(n)]}return[!0,null]}function Cn(e){return e!=null}function ES(e){var t=e.files,n=e.accept,r=e.minSize,o=e.maxSize,i=e.multiple,a=e.maxFiles,s=e.validator;return!i&&t.length>1||i&&a>=1&&t.length>a?!1:t.every(function(u){var c=tp(u,n),d=xr(c,1),g=d[0],m=np(u,r,o),f=xr(m,1),v=f[0],h=s?s(u):null;return g&&v&&!h})}function qo(e){return typeof e.isPropagationStopped=="function"?e.isPropagationStopped():typeof e.cancelBubble<"u"?e.cancelBubble:!1}function Go(e){return e.dataTransfer?Array.prototype.some.call(e.dataTransfer.types,function(t){return t==="Files"||t==="application/x-moz-file"}):!!e.target&&!!e.target.files}function rp(e){e.preventDefault()}function _S(e){return e.indexOf("MSIE")!==-1||e.indexOf("Trident/")!==-1}function TS(e){return e.indexOf("Edge/")!==-1}function AS(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return _S(e)||TS(e)}function kt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(r){for(var o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return t.some(function(s){return!qo(r)&&s&&s.apply(void 0,[r].concat(i)),qo(r)})}}function PS(){return"showOpenFilePicker"in window}function NS(e){if(Cn(e)){var t=Object.entries(e).filter(function(n){var r=xr(n,2),o=r[0],i=r[1],a=!0;return op(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.')),a=!1),(!Array.isArray(i)||!i.every(ip))&&(console.warn('Skipped "'.concat(o,'" because an invalid file extension was provided.')),a=!1),a}).reduce(function(n,r){var o=xr(r,2),i=o[0],a=o[1];return Xf(Xf({},n),{},Jf({},i,a))},{});return[{description:"Files",accept:t}]}return e}function kS(e){if(Cn(e))return Object.entries(e).reduce(function(t,n){var r=xr(n,2),o=r[0],i=r[1];return[].concat(Kf(t),[o],Kf(i))},[]).filter(function(t){return op(t)||ip(t)}).join(",")}function OS(e){return e instanceof DOMException&&(e.name==="AbortError"||e.code===e.ABORT_ERR)}function FS(e){return e instanceof DOMException&&(e.name==="SecurityError"||e.code===e.SECURITY_ERR)}function op(e){return e==="audio/*"||e==="video/*"||e==="image/*"||e==="text/*"||e==="application/*"||/\w+\/[-+.\w]+/g.test(e)}function ip(e){return/^.*\.[\w]+$/.test(e)}var DS=["children"],IS=["open"],MS=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],$S=["refKey","onChange","onClick"];function LS(e){return jS(e)||VS(e)||ap(e)||RS()}function RS(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
174
174
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function VS(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function jS(e){if(Array.isArray(e))return ws(e)}function bs(e,t){return HS(e)||BS(e,t)||ap(e,t)||zS()}function zS(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
175
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ap(e,t){if(e){if(typeof e=="string")return ws(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ws(e,t)}}function ws(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function BS(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,a,s;try{for(n=n.call(e);!(o=(a=n.next()).done)&&(r.push(a.value),!(t&&r.length===t));o=!0);}catch(u){i=!0,s=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw s}}return r}}function HS(e){if(Array.isArray(e))return e}function sp(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function De(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?sp(Object(n),!0).forEach(function(r){Cs(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):sp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Cs(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ko(e,t){if(e==null)return{};var n=US(e,t),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function US(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,i;for(i=0;i<r.length;i++)o=r[i],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}var Ss=_.forwardRef(function(e,t){var n=e.children,r=Ko(e,DS),o=cp(r),i=o.open,a=Ko(o,IS);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});Ss.displayName="Dropzone";var lp={disabled:!1,getFilesFromEvent:nS,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};Ss.defaultProps=lp,Ss.propTypes={children:Ne.func,accept:Ne.objectOf(Ne.arrayOf(Ne.string)),multiple:Ne.bool,preventDropOnDocument:Ne.bool,noClick:Ne.bool,noKeyboard:Ne.bool,noDrag:Ne.bool,noDragEventsBubbling:Ne.bool,minSize:Ne.number,maxSize:Ne.number,maxFiles:Ne.number,disabled:Ne.bool,getFilesFromEvent:Ne.func,onFileDialogCancel:Ne.func,onFileDialogOpen:Ne.func,useFsAccessApi:Ne.bool,autoFocus:Ne.bool,onDragEnter:Ne.func,onDragLeave:Ne.func,onDragOver:Ne.func,onDrop:Ne.func,onDropAccepted:Ne.func,onDropRejected:Ne.func,onError:Ne.func,validator:Ne.func};var Es={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function cp(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},lp),e),n=t.accept,r=t.disabled,o=t.getFilesFromEvent,i=t.maxSize,a=t.minSize,s=t.multiple,u=t.maxFiles,c=t.onDragEnter,d=t.onDragLeave,g=t.onDragOver,m=t.onDrop,f=t.onDropAccepted,v=t.onDropRejected,h=t.onFileDialogCancel,y=t.onFileDialogOpen,b=t.useFsAccessApi,w=t.autoFocus,C=t.preventDropOnDocument,E=t.noClick,x=t.noKeyboard,O=t.noDrag,I=t.noDragEventsBubbling,$=t.onError,H=t.validator,D=_.useMemo(function(){return kS(n)},[n]),G=_.useMemo(function(){return NS(n)},[n]),U=_.useMemo(function(){return typeof y=="function"?y:up},[y]),Z=_.useMemo(function(){return typeof h=="function"?h:up},[h]),k=_.useRef(null),M=_.useRef(null),F=_.useReducer(WS,Es),q=bs(F,2),P=q[0],j=q[1],A=P.isFocused,B=P.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&PS()),re=function(){!Q.current&&B&&setTimeout(function(){if(M.current){var Y=M.current.files;Y.length||(j({type:"closeDialog"}),Z())}},300)};_.useEffect(function(){return window.addEventListener("focus",re,!1),function(){window.removeEventListener("focus",re,!1)}},[M,B,Z,Q]);var ee=_.useRef([]),ce=function(Y){k.current&&k.current.contains(Y.target)||(Y.preventDefault(),ee.current=[])};_.useEffect(function(){return C&&(document.addEventListener("dragover",rp,!1),document.addEventListener("drop",ce,!1)),function(){C&&(document.removeEventListener("dragover",rp),document.removeEventListener("drop",ce))}},[k,C]),_.useEffect(function(){return!r&&w&&k.current&&k.current.focus(),function(){}},[k,w,r]);var oe=_.useCallback(function(z){$?$(z):console.error(z)},[$]),ae=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),ee.current=[].concat(LS(ee.current),[z.target]),Go(z)&&Promise.resolve(o(z)).then(function(Y){if(!(qo(z)&&!I)){var xe=Y.length,we=xe>0&&ES({files:Y,accept:D,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Fe=xe>0&&!we;j({isDragAccept:we,isDragReject:Fe,isDragActive:!0,type:"setDraggedFiles"}),c&&c(z)}}).catch(function(Y){return oe(Y)})},[o,c,oe,I,D,a,i,s,u,H]),de=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=Go(z);if(Y&&z.dataTransfer)try{z.dataTransfer.dropEffect="copy"}catch{}return Y&&g&&g(z),!1},[g,I]),ue=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=ee.current.filter(function(we){return k.current&&k.current.contains(we)}),xe=Y.indexOf(z.target);xe!==-1&&Y.splice(xe,1),ee.current=Y,!(Y.length>0)&&(j({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Go(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var xe=[],we=[];z.forEach(function(Fe){var sn=tp(Fe,D),Re=bs(sn,2),Mt=Re[0],En=Re[1],Be=np(Fe,a,i),$t=bs(Be,2),Wt=$t[0],Yn=$t[1],_e=H?H(Fe):null;if(Mt&&Wt&&!_e)xe.push(Fe);else{var ln=[En,Yn];_e&&(ln=ln.concat(_e)),we.push({file:Fe,errors:ln.filter(function(ni){return ni})})}}),(!s&&xe.length>1||s&&u>=1&&xe.length>u)&&(xe.forEach(function(Fe){we.push({file:Fe,errors:[SS]})}),xe.splice(0)),j({acceptedFiles:xe,fileRejections:we,isDragReject:we.length>0,type:"setFiles"}),m&&m(xe,we,Y),we.length>0&&v&&v(we,Y),xe.length>0&&f&&f(xe,Y)},[j,s,D,a,i,u,m,f,v,H]),Ce=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),ee.current=[],Go(z)&&Promise.resolve(o(z)).then(function(Y){qo(z)&&!I||le(Y,z)}).catch(function(Y){return oe(Y)}),j({type:"reset"})},[o,le,oe,I]),K=_.useCallback(function(){if(Q.current){j({type:"openDialog"}),U();var z={multiple:s,types:G};window.showOpenFilePicker(z).then(function(Y){return o(Y)}).then(function(Y){le(Y,null),j({type:"closeDialog"})}).catch(function(Y){OS(Y)?(Z(Y),j({type:"closeDialog"})):FS(Y)?(Q.current=!1,M.current?(M.current.value=null,M.current.click()):oe(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."))):oe(Y)});return}M.current&&(j({type:"openDialog"}),U(),M.current.value=null,M.current.click())},[j,U,Z,b,le,oe,G,s]),Ee=_.useCallback(function(z){!k.current||!k.current.isEqualNode(z.target)||(z.key===" "||z.key==="Enter"||z.keyCode===32||z.keyCode===13)&&(z.preventDefault(),K())},[k,K]),We=_.useCallback(function(){j({type:"focus"})},[]),qe=_.useCallback(function(){j({type:"blur"})},[]),It=_.useCallback(function(){E||(AS()?setTimeout(K,0):K())},[E,K]),st=function(Y){return r?null:Y},S=function(Y){return x?null:st(Y)},N=function(Y){return O?null:st(Y)},V=function(Y){I&&Y.stopPropagation()},ne=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,xe=Y===void 0?"ref":Y,we=z.role,Fe=z.onKeyDown,sn=z.onFocus,Re=z.onBlur,Mt=z.onClick,En=z.onDragEnter,Be=z.onDragOver,$t=z.onDragLeave,Wt=z.onDrop,Yn=Ko(z,MS);return De(De(Cs({onKeyDown:S(kt(Fe,Ee)),onFocus:S(kt(sn,We)),onBlur:S(kt(Re,qe)),onClick:st(kt(Mt,It)),onDragEnter:N(kt(En,ae)),onDragOver:N(kt(Be,de)),onDragLeave:N(kt($t,ue)),onDrop:N(kt(Wt,Ce)),role:typeof we=="string"&&we!==""?we:"presentation"},xe,k),!r&&!x?{tabIndex:0}:{}),Yn)}},[k,Ee,We,qe,It,ae,de,ue,Ce,x,O,r]),J=_.useCallback(function(z){z.stopPropagation()},[]),X=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,xe=Y===void 0?"ref":Y,we=z.onChange,Fe=z.onClick,sn=Ko(z,$S),Re=Cs({accept:D,multiple:s,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:st(kt(we,Ce)),onClick:st(kt(Fe,J)),tabIndex:-1},xe,M);return De(De({},Re),sn)}},[M,n,s,Ce,r]);return De(De({},P),{},{isFocused:A&&!r,getRootProps:ne,getInputProps:X,rootRef:k,inputRef:M,open:st(K)})}function WS(e,t){switch(t.type){case"focus":return De(De({},e),{},{isFocused:!0});case"blur":return De(De({},e),{},{isFocused:!1});case"openDialog":return De(De({},Es),{},{isFileDialogActive:!0});case"closeDialog":return De(De({},e),{},{isFileDialogActive:!1});case"setDraggedFiles":return De(De({},e),{},{isDragActive:t.isDragActive,isDragAccept:t.isDragAccept,isDragReject:t.isDragReject});case"setFiles":return De(De({},e),{},{acceptedFiles:t.acceptedFiles,fileRejections:t.fileRejections,isDragReject:t.isDragReject});case"reset":return De({},Es);default:return e}}function up(){}const qS=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=cp({noClick:!0,onDrop:a=>{if(a&&a.length>0)if(a[0].path.split("/").length>2){const u=a.map(c=>{const g=(c.path||c.relativePath||"").split("/").slice(1).join("/");return(!c.webkitRelativePath||c.webkitRelativePath==="")&&Object.defineProperty(c,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),c});e(u,"folder")}else e(a,"files");r(!1)},onDragOver:a=>{a.preventDefault(),n||r(!0)},multiple:!0});return _.useEffect(()=>{const a=s=>{s.clientX===0&&s.clientY===0&&r(!1)};return document.addEventListener("dragleave",a),()=>{document.removeEventListener("dragleave",a)}},[]),l.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?l.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"}):t,l.jsx("input",{...i()})]})},GS=({openDialogRename:e,setOpenDialogRename:t,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:i,ignoreCache:a})=>{var w;const[s,u]=_.useState({}),[c,d]=_.useState(!1),[g,m]=_.useState(!1),[f,v]=_.useState(""),{toast:h}=ko();_.useEffect(()=>{e&&y(f)},[f,e]);const y=async C=>{try{m(!0);const E=await me.get(`${n}/api/list-s3-folders?prefix=${C}`);u(E==null?void 0:E.data)}catch{h({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{m(!1)}},b=async()=>{d(!0);try{const C=o.key,E=C.endsWith("/")?C:`${C}/`,x=f.endsWith("/")?f:`${f}/`;if(E===x||C===f){h({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),d(!1);return}await me.post(`${n}/api/move`,{oldPath:C,newPath:f}),a.current=!0,await i(),h({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${f}"`}),t(!1),r(null),v("")}catch(C){console.error("Error renaming item:",C),h({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{d(!1)}};return l.jsx(jt,{open:e,onOpenChange:C=>{C||(t(!1),r(null),v(""))},children:l.jsxs(St,{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:[l.jsxs(Et,{className:"mb-4 w-full h-full",children:[l.jsx("nav",{className:"mb-4",children:l.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>v(""),children:"Root"}),f.split("/").map((C,E,x)=>l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>v(C==="Root"?"":x.slice(0,E+1).join("/")+"/"),children:C},E))]})}),l.jsxs(_t,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",l.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",f===""?"Root":f," )"]})]}),l.jsx(Rn,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:g?l.jsx("div",{className:"flex justify-center items-center py-4",children:l.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):l.jsx("ul",{className:"space-y-2",children:(w=Object.keys(s))==null?void 0:w.map(C=>l.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>v(C),children:C},C))})})]}),l.jsxs(hn,{className:"flex justify-end space-x-2",children:[l.jsx(ve,{variant:"outline",onClick:()=>t(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),l.jsx(ve,{onClick:b,disabled:c,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},KS="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",YS="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",XS="https://www.googleapis.com/auth/drive";Kt(me,{retries:3});const Qe={current:!1},dp="crawl:jobs",Gn="crawl:current_job",JS=e=>{const[t,n]=_.useState(null),[r,o]=_.useState(0);return _.useEffect(()=>{const i=localStorage.getItem(Gn);if(i){const a=JSON.parse(i);n(a),a!=null&&a.startTime&&o(Math.floor((Date.now()-a.startTime)/1e3))}},[]),_.useEffect(()=>{if(!(t!=null&&t.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-t.startTime)/1e3))},1e3);return()=>clearInterval(i)},[t==null?void 0:t.startTime]),_.useEffect(()=>{if(!(t!=null&&t.id))return;const i=async()=>{try{const u=(await me.get(`${e}/api/crawl/${t.id}?taskId=${t.taskId}`)).data;n(c=>{if(!c)return null;const d={...c,status:u};return localStorage.setItem(Gn,JSON.stringify(d)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Gn)},100),d})}catch(s){console.error("Error polling job status:",s)}},a=setInterval(i,3e3);return i(),()=>clearInterval(a)},[t==null?void 0:t.id,e]),{currentJob:t,elapsedTime:r,setCurrentJob:i=>{i&&!i.startTime&&(i.startTime=Date.now()),n(i),i?localStorage.setItem(Gn,JSON.stringify(i)):localStorage.removeItem(Gn)}}},Yo=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},ZS=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Yo(e,o.key))}),n},QS=(e,t,n=[],r,o,i)=>{const[a,s]=_.useState({}),[u,c]=_.useState(!1),[d,g]=_.useState(null),[m,f]=_.useState(0),v=_.useRef(t);_.useEffect(()=>{v.current=t},[t]);const h=async()=>{c(!0);try{const b=await me.get(`${e}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:v.current},timeout:3e5});s(b.data),g(null)}catch(b){g(b instanceof Error?b:new Error("Failed to fetch files"))}finally{c(!1),f(0),i("")}},y=async b=>{var w,C;try{if(!b)return;c(!0);const E=await me.get(`${e}/api/search-db?query=${b}&rootPrefix=${t}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return s({[t]:((w=E==null?void 0:E.data)==null?void 0:w.result)||[]}),f(((C=E==null?void 0:E.data)==null?void 0:C.estimatedTotalHits)||0),E}catch(E){g(E instanceof Error?E:new Error("Failed to fetch files"))}finally{c(!1)}};return _.useEffect(()=>{!r&&!u&&h(),r&&!u&&y(r)},[r,o]),{data:a,isLoading:u,error:d,estimatedTotalHits:m,refetch:h}},br=e=>{var r,o,i;const t=((i=(o=(r=e==null?void 0:e.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:i.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(t||"")},eE=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="https://vib-s3-explorer.cmcts1.studio.ai.vn",rootPrefix:n="",asSelector:r=!1,onSelected:o=s=>console.log("Đã chọn:",s),displayPrefixes:i,preSelectedFiles:a})=>{var Lp;const[s,u]=_.useState([]),[c,d]=_.useState(""),[g,m]=_.useState(new Set(a)),[f,v]=_.useState(n),[h,y]=_.useState(""),[b,w]=_.useState(!1),[C,E]=_.useState(""),[x,O]=_.useState(!1),[I,$]=_.useState(null),[H,D]=_.useState(null),[G,U]=_.useState(!1),[Z,k]=_.useState(!1),[M,F]=_.useState(null),q=_.useRef(null),{toast:P}=ko(),[j,A]=_.useState(null),[B,Q]=_.useState(null),[re,ee]=_.useState(""),[ce,oe]=_.useState(!1),[ae,de]=_.useState(!1),[ue,le]=_.useState(new Set),[Ce,K]=_.useState(""),[Ee,We]=_.useState(!1),[qe,It]=_.useState(!1),[st,S]=_.useState("rename"),[N,V]=_.useState(!1),[ne,J]=_.useState(""),[X,z]=_.useState("1"),[Y,xe]=_.useState(!1),[we,Fe]=_.useState(!1),[sn,Re]=_.useState(!1),[Mt,En]=_.useState(!1),[Be,$t]=_.useState(1),[Wt,Yn]=_.useState(!1),{currentJob:_e,elapsedTime:ln,setCurrentJob:ni}=JS(t),[cn,_r]=_.useState(null),[Tr,ri]=_.useState(""),[TE,Ar]=_.useState(!1),[Ds,Fp]=_.useState(!1),[AE,PE]=_.useState(""),NE=new URL(window.location.href).searchParams.get("prefix")||""||h||n,[w_,kE]=_.useState(null),{data:Lt,isLoading:Pr,error:OE,estimatedTotalHits:Nr,refetch:tt}=QS(t,NE,i,c,Be,d),FE=og({onSuccess:T=>{kE(T.access_token),localStorage.setItem("google_access_token",T.access_token),DE(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:XS}),DE=T=>{const L=document.createElement("script");L.src="https://apis.google.com/js/api.js",L.onload=()=>{window.gapi.load("picker",()=>IE(T))},document.body.appendChild(L)},IE=T=>{const L=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),W=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(KS).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(L).addView(W).setCallback(async ie=>{if(ie.action===window.google.picker.Action.PICKED){const ge=ie.docs.map(Se=>({id:Se.id,name:Se.name,mimeType:Se.mimeType}));await ME(ge,f)}}).build().setVisible(!0)},ME=async(T,L="")=>{const W=localStorage.getItem("google_access_token");if(!W){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),Pe.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const te=Pe.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:L,folders:[],files:[]};T.forEach(Se=>{Se.mimeType==="application/vnd.google-apps.folder"?ie.folders.push({id:Se.id,name:Se.name}):ie.files.push({id:Se.id,name:Se.name})});const ge=await me.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${W}`}});Qe.current=!0,tt(),Pe.update(te,{render:`Đồng bộ thành công! Đã tải lên ${ge.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(ie){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",ie),Pe.update(te,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const T=L=>{if(L.data.action==="logout"){const W=document.createElement("iframe");W.style.display="none",W.src="https://accounts.google.com/Logout",document.body.appendChild(W),setTimeout(()=>document.body.removeChild(W),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),_.useEffect(()=>{const T=new Set(a);m(T)},[]),_.useEffect(()=>{_e!=null&&_e.status&&(_e.status.status==="completed"?(P({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${_e.url} với ${_e.status.completed} trang`}),Qe.current=!0,tt()):_e.status.status==="failed"&&P({title:"Thu thập website thất bại",description:`Không thể thu thập ${_e.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(Lp=_e==null?void 0:_e.status)==null?void 0:Lp.status]);const Dp=_.useMemo(()=>Lt[f]||[],[Lt,f]),un=_.useMemo(()=>Dp,[Dp,f,Lt]),kr=_.useMemo(()=>{const T={};return un.forEach((L,W)=>{g.has(L.key)&&(T[W]=!0)}),T},[g,un]),$E=T=>{const L=Yo(Lt,T);if(L.length===0)return g.has(T)?"all":"none";const W=L.filter(te=>g.has(te)).length;return W===0?"none":W===L.length?"all":"partial"},Xn=(T,L=!0)=>{if(console.log("🚀 ~ Home.tsx:620 ~ handleFolderClick ~ currentPrefix:",{currentPrefix:f,prefix:T,forcePrefix:h}),f!==T&&(Yn(!0),y(T),v(T),a||m(new Set),L)){const W=window.location.pathname==="/"?"":window.location.pathname,te=T?`${window.location.origin}${W}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${W}`;window.history.pushState({path:te},"",te)}};_.useEffect(()=>{Wt&&(Qe.current=!0,tt().finally(()=>Yn(!1)))},[Wt]);const LE=async(T,L)=>{var W,te;O(!0);try{if(un.some(Ye=>Ye.isFolder&&Ye.name.toLowerCase()===T.toLowerCase())){P({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),O(!1);return}const ge=`${L}${T}/`;if((await me.post(`${t}/api/create-folder`,{prefix:ge})).status!==200){P({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qe.current=!0,await tt(),P({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),E(""),w(!1)}catch(ie){console.error("Error creating folder:",ie);const ge=((te=(W=ie==null?void 0:ie.response)==null?void 0:W.data)==null?void 0:te.error)||"Không thể tạo thư mục";P({title:"Lỗi",description:ge,variant:"destructive"})}finally{O(!1)}},Is=async(T,L,W)=>{var te,ie,ge,Se,Ye,Jn,Rp,Vp,jp;F(W),Re(!0);try{if(Array.from(T).reduce((Xe,Dr)=>Xe+Dr.size,0)>=100*1024*1024){P({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),F(null),Re(!1);return}const ii=Array.from(T).filter(Xe=>Xe.size===0);if(ii.length>0){const Xe=ii.map(Dr=>Dr.name).join(", ");P({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Xe}`,variant:"destructive"}),Re(!1),F(null);return}let Fr=localStorage.getItem("dataLogin"),Zn;try{Fr&&(Fr=JSON.parse(Fr),Zn=Fr.user)}catch{Fr=null}const _n=new FormData;if(Zn!=null&&Zn.id&&_n.append("metadata",JSON.stringify({creator:Zn.username,creatorId:Zn.id,DataSource:"Tệp tải lên"})),W==="folder"&&T[0]){const Xe=T[0].webkitRelativePath.split("/")[0];Xe&&_n.append("folderName",Xe)}_n.append("prefix",L),Array.from(T).forEach(Xe=>W==="folder"?_n.append("files",Xe,Xe.webkitRelativePath):_n.append("files",Xe)),Qe.current=!0;const ze=await me.post(`${t}/api/check-files-existed`,_n,{headers:{"Content-Type":"multipart/form-data"}});if(((te=ze==null?void 0:ze.data)==null?void 0:te.status)===200)await me.post(`${t}/api/upload`,_n,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(L),setTimeout(async()=>{F(null),await tt(),Re(!1)},500);else{if(((ge=(ie=ze==null?void 0:ze.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Se=ze==null?void 0:ze.data)!=null&&Se.isFolder)){const Xe=Array.from(T).filter(Dr=>ze.data.names.includes(Dr.name));_r(Xe),Ar(!0)}(Ye=ze==null?void 0:ze.data)!=null&&Ye.isFolder&&((Jn=ze==null?void 0:ze.data)!=null&&Jn.name)&&(ri((Rp=ze==null?void 0:ze.data)==null?void 0:Rp.name),_r(T),Ar(!0))}}catch(Or){console.error("Lỗi tải lên:",Or);const ii=((jp=(Vp=Or==null?void 0:Or.response)==null?void 0:Vp.data)==null?void 0:jp.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:ii,variant:"destructive"}),F(null),Re(!1)}},RE=async()=>{var T,L;try{Re(!0);const W=new FormData;if(cn){F(Tr?"folder":"files"),Ar(!1);let te=localStorage.getItem("dataLogin"),ie;try{te&&(te=JSON.parse(te),ie=te.user)}catch{te=null}if(ie!=null&&ie.id&&(console.log("🚀 ~ uploadFiles ~ user:",ie),W.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"}))),Tr&&cn[0]){const ge=cn[0].webkitRelativePath.split("/")[0];ge&&W.append("folderName",ge)}W.append("prefix",f),Array.from(cn).forEach(ge=>Tr&&cn[0]?W.append("files",ge,ge.webkitRelativePath):W.append("files",ge)),ie!=null&&ie.id&&W.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"})),await me.post(`${t}/api/upload`,W,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(f),Qe.current=!0}}catch(W){console.error("Lỗi tải lên:",W);const te=((L=(T=W==null?void 0:W.response)==null?void 0:T.data)==null?void 0:L.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:te,variant:"destructive"})}finally{setTimeout(async()=>{F(null),await tt(),Re(!1),ri(""),_r(null)},500)}},VE=async T=>{var L;try{if(await me.delete(`${t}/api/files`,{data:{paths:[T.key]}}),g.has(T.key)){const te=new Set(g);te.delete(T.key),m(te)}const W=((L=T.key)==null?void 0:L.replace(/^(.*?)(\/.*)?$/,(te,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";y(W),Qe.current=!0,P({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),$(null)}catch(W){console.error("Error deleting file:",W),P({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{En(!1),await tt()}},oi=T=>{const L=new Set(g),W=typeof T=="function"?T(kr):T;new Set(Object.keys(kr).map(Number)).forEach(ie=>{const ge=un[ie];ge&&(W[ie]||(L.delete(ge.key),ge.isFolder&&Yo(Lt,ge.key).forEach(Se=>L.delete(Se))))}),Object.entries(W).forEach(([ie,ge])=>{const Se=parseInt(ie),Ye=un[Se];Ye&&ge&&(L.add(Ye.key),Ye.isFolder&&Yo(Lt,Ye.key).forEach(Jn=>L.add(Jn)))}),m(L)},jE=async()=>{var T;U(!0);try{const L=Array.from(g),W=L.map(ie=>Object.values(Lt).flat().find(ge=>ge.key===ie)).filter(ie=>ie!==void 0);if(W.length===0){P({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await me.delete(`${t}/api/files`,{data:{paths:L}});const te=((T=W[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Se)=>!Se||Se==="/"?"":ge+"/"))||"";y(te),Qe.current=!0,tt(),P({title:"Đã xóa tập tin",description:`Đã xóa thành công ${W.length} mục`}),k(!1),m(new Set)}catch(L){console.error("Error deleting files:",L),P({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{U(!1)}},zE=async(T,L)=>{if(!f.trim()){P({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}de(!0);try{const W=T.key;let te;T.isFolder?te=W.split("/").slice(0,-2).join("/")+"/":te=W.substring(0,W.lastIndexOf("/")+1);const ie=te+L+(T.isFolder?"/":"");await me.post(`${t}/api/rename`,{oldPath:W,newPath:ie}),Qe.current=!0,await tt(),P({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${L}"`}),A(null),ee(""),Q(null)}catch(W){console.error("Error renaming item:",W),P({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{de(!1)}},Ip=async T=>{le(L=>new Set([...L,...T]));try{const L=await me.post(`${t}/api/download`,{paths:T},{responseType:"blob"}),W=window.URL.createObjectURL(L.data),te=document.createElement("a");te.href=W;const ie=L.headers["Content-Disposition"]||L.headers["content-disposition"],ge=ie==null?void 0:ie.match(/filename="(.+)"/),Se=ge?decodeURIComponent(ge[1]):"download.zip";te.setAttribute("download",Se),document.body.appendChild(te),te.click(),document.body.removeChild(te),window.URL.revokeObjectURL(W),P({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(L){console.error("Error downloading files:",L),P({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{le(L=>{const W=new Set(L);return T.forEach(te=>W.delete(te)),W})}},Mp=f?f.replace(n,"").split("/").filter(Boolean):[],BE=()=>Array.from(g).map(T=>{var L;for(const W in Lt){const te=(L=Lt[W])==null?void 0:L.find(ie=>ie.key===T);if(te)return te}return null}).filter(T=>T!==null),$p=_.useMemo(()=>{const T=[{id:"select",header:()=>{const L=ZS(Lt,f),W=L.length>0&&L.every(ie=>g.has(ie)),te=L.some(ie=>g.has(ie));return l.jsx(na,{checked:W?!0:te?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=un.reduce((Se,Ye,Jn)=>(Se[Jn]=!0,Se),{});oi(ge)}else oi({})},"aria-label":"Chọn tất cả"})},cell:({row:L})=>{const W=L.original,ie=W.isFolder?$E(W.key):g.has(W.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(na,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Se={...kr};ge?Se[L.index]=!0:delete Se[L.index],oi(Se)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Bi,{})]}),accessorKey:"name",cell:({row:L})=>{const W=L.original,te=W.key.substring(0,W.key.lastIndexOf("/"))||"/",ie=c.trim()!==""&&te!==f,ge=te.split("/").filter(Boolean);return l.jsxs("div",{className:"flex flex-col",children:[l.jsxs("div",{className:`flex items-center gap-2 ${W.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{W.isFolder&&(a||m(new Set),Xn(W.key))},children:[W.isFolder?l.jsx(li,{className:"h-5 w-5 text-blue-500"}):null,W.name]}),ie&&l.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[l.jsx(li,{className:"h-4 w-4 text-gray-500 my-auto"}),l.jsxs("span",{className:"flex items-center ml-1",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn("")},children:"/"}),ge.map((Se,Ye)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn(ge.slice(0,Ye+1).join("/")+"/")},children:Se}),Ye<ge.length-1&&l.jsx("span",{children:"/"})]},Ye))]})]})]})}}];return r||T.push({id:"size",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Bi,{})]}),accessorKey:"size",cell:({getValue:L,row:W})=>{const te=L();return l.jsx("span",{children:W.original.isFolder?"-":Fv(te)})}},{id:"lastModified",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",l.jsx(Bi,{})]}),accessorKey:"lastModified",cell:({row:L})=>{const W=L.original.lastModified;return l.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:l.jsx("span",{children:W&&Wl(W).isValid()?Wl(W).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>l.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:L})=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>Ip([L.original.key]),className:"h-8 w-8 p-0",disabled:ue.has(L.original.key),children:ue.has(L.original.key)?l.jsx($e,{className:"h-4 w-4 animate-spin"}):l.jsx(Vs,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Tải xuống"})]})}),f.trim()!==""&&l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>{A(L.original),ee(L.original.name)},className:"h-8 w-8 p-0",children:l.jsx(Jp,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Đổi tên"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>{oe(!0),D(L.original)},className:"h-8 w-8 p-0",children:l.jsx(Dh,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Di chuyển"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>$(L.original),className:"h-8 w-8 p-0",children:l.jsx(js,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Xóa"})]})})]})}),T},[g,un,kr,ue,r]),Ms=el({data:un,columns:$p,state:{rowSelection:kr,sorting:s},onSortingChange:u,enableRowSelection:!0,onRowSelectionChange:oi,getCoreRowModel:Qs(),getSortedRowModel:Lg()}),HE=async T=>{var L,W;We(!0);try{if(br(T)){const te=await me.get(`${t}/api/read-text`,{params:{path:T.key}});K(te.data.content)}try{const te=await me.get(`${t}/api/read-json`,{params:{path:T.key+".metadata.json"}}),ie=((W=(L=te==null?void 0:te.data)==null?void 0:L.content)==null?void 0:W.metadataAttributes)||null;return Q({fullPath:j==null?void 0:j.key,...ie})}catch{return Q("Lỗi phân tích siêu dữ liệu")}}catch(te){console.error("Error loading file content:",te),P({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{We(!1)}},UE=async(T,L)=>{It(!0);try{await me.post(`${t}/api/modify-text`,{path:T.key,content:L}),P({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await tt(),A(null),K(""),S("rename")}catch(W){console.error("Error saving file content:",W),P({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{It(!1)}},WE=async T=>{It(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",B),await me.post(`${t}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:B}}),P({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await tt(),A(null),K(""),S("rename")}catch(L){console.error("Error saving file content:",L),P({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{It(!1)}};_.useEffect(()=>{j&&(j.isFolder||HE(j),S("rename"))},[j]);const qE=async(T,L)=>{var W;if(_e){P({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}xe(!0);try{const{data:te}=await me.post(`${t}/api/crawl`,{url:T,limit:L,prefix:f});if(te.id){ni({id:te.id,url:T,limit:L,prefix:f,taskId:((W=te.task)==null?void 0:W.id)||""});const ie=localStorage.getItem(dp),ge=ie?JSON.parse(ie):[];ge.some(Se=>Se.id===te.id)||(ge.unshift({url:T,id:te.id,limit:L,prefix:f,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(dp,JSON.stringify(ge))),P({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${L}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),V(!1),J(""),z("1")}}catch(te){console.error("Error crawling website:",te),P({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{xe(!1)}},GE=async()=>{try{if(!(_e!=null&&_e.id))return;ni(null),localStorage.removeItem(Gn),P({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${_e.url}`})}catch(T){console.error("Error stopping job:",T),P({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const T=(L=!0)=>{const te=new URL(window.location.href).searchParams.get("prefix")||"";te?Xn(te,!1):(L&&!a&&m(new Set),y(n),v(n),Qe.current=!0,setTimeout(()=>{tt()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const KE=async()=>{Fp(!0);try{const T=await me.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",T),P({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),P({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Fp(!1)}},YE=async()=>{try{const T=await me.post(`${t}/api/start-ingestion-job`,{prefix:f});T.status===200&&(console.log("🚀 ~ Home.tsx:1744 ~ handleSyncKnowledgeBase ~ response:",T),await Ls())}catch(T){console.log(T)}},$s=_.useRef(),Ls=async()=>{try{const T=await me.post(`${t}/api/get-ingestion-job-status`,{prefix:f});T.data==="FAILED"||T.data==="COMPLETE"||T.data==="STOPPED"||T.data==="STOPPING"?(Fe(!1),$s.current&&clearInterval($s.current)):(Fe(!0),$s.current=setInterval(()=>Ls(),5e3))}catch(T){console.log(T)}};return _.useEffect(()=>{const T=f==null?void 0:f.split("/")[0];return T&&(PE(T),f&&Ls()),()=>{}},[AE,f]),l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(Sd,{}),l.jsx(jt,{open:TE,onOpenChange:T=>{Ar(T),T||(ri(""),_r(null),Re(!1),F(null))},children:l.jsxs(St,{children:[l.jsxs(Et,{children:[l.jsx(_t,{children:"Cảnh báo trùng lặp"}),l.jsxs(Rn,{children:[Tr&&l.jsxs(l.Fragment,{children:["Folder $",Tr," đã có."]}),cn&&cn.length>0&&l.jsxs(l.Fragment,{children:["Những tệp sau bị lặp:",l.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(cn).map((T,L)=>l.jsx("li",{children:T.name},L))})]})]})]}),l.jsxs(hn,{children:[l.jsx(ve,{variant:"outline",onClick:()=>{Ar(!1),ri(""),_r(null),Re(!1),F(null)},children:"Bỏ qua"}),l.jsx(ve,{variant:"destructive",onClick:()=>RE(),children:"Ghi đè"})]})]})}),l.jsx(uc,{className:"s3-explr-breadcrumb",children:l.jsxs(dc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(Ji,{className:"s3-explr-breadcrumb-item",children:l.jsx(Zi,{onClick:()=>Xn(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),Mp.map((T,L)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(fc,{className:"s3-explr-breadcrumb-separator"},`sep-${L}`),l.jsx(Ji,{className:"s3-explr-breadcrumb-item",children:l.jsx(Zi,{onClick:()=>Xn(n+Mp.slice(0,L+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},L))]})}),l.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[l.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:l.jsx(HC,{ref:q,onChange:T=>d(T)})}),l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{y(f),Qe.current=!0,tt()},disabled:Pr,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Pr?"animate-spin":""}`}),"Làm mới"]}),f&&f!=="/"&&l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{Fe(!0),YE()},disabled:Pr||we,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Pr||we?"animate-spin":""}`}),"Đồng bộ KB"]}),!r&&l.jsxs(l.Fragment,{children:[g.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>Ip(Array.from(g)),disabled:Array.from(g).some(T=>ue.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(g).some(T=>ue.has(T))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(Vs,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",g.size,")"]}),l.jsxs(jt,{open:Z,onOpenChange:k,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx(js,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",g.size,")"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),l.jsxs(Rn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",g.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>k(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{variant:"destructive",onClick:jE,disabled:G,className:"s3-explr-confirm-delete-btn",children:G?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),l.jsxs(jt,{open:b,onOpenChange:w,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!f,children:[l.jsx(qp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsx(Et,{className:"s3-explr-dialog-header",children:l.jsx(_t,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),l.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),l.jsx(en,{disabled:x,id:"name",value:C,onChange:T=>E(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ve,{onClick:()=>{C.trim()&&LE(C,f)},disabled:x,className:"s3-explr-create-btn",children:[x&&l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),x?"Đang tạo...":"Tạo"]})]})]})]}),l.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[l.jsx(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-files-btn",onClick:()=>{const T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=L=>{const W=L.target.files;W&&Is(W,f,"files")},T.click()},disabled:M!==null||!!i&&!f,children:M==="files"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang tải lên..."]}):l.jsxs(l.Fragment,{children:[l.jsx(Up,{className:"h-4 w-4 s3-explr-upload-icon"}),"Tải lên tập tin"]})}),l.jsx(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-folder-btn",onClick:()=>{const T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=L=>{const W=L.target.files;W&&Is(W,f,"folder")},T.click()},disabled:M!==null||!!i&&!f,children:M==="folder"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang tải lên..."]}):l.jsxs(l.Fragment,{children:[l.jsx(li,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),_e?l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[l.jsx($e,{className:"h-4 w-4 animate-spin s3-explr-loader"}),_e.status?l.jsxs(l.Fragment,{children:[_e.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",_e.status.completed,"/",_e.status.total,") -"," ",Math.floor(ln/60),":",String(ln%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ve,{variant:"destructive",size:"sm",onClick:()=>void GE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(Qp,{className:"h-4 w-4"})]})]})}),_e.status&&l.jsx(on,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",_e.url]}),l.jsxs("p",{children:["Tiến độ: ",_e.status.completed,"/",_e.status.total," trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(ln/60),":",String(ln%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",_e.status.status==="scraping"?"Đang thu thập":_e.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):l.jsxs(jt,{open:N,onOpenChange:V,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,children:[l.jsx(Yp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Thêm website"}),l.jsx(Rn,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),l.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),l.jsx(en,{id:"websiteUrl",value:ne,onChange:T=>J(T.target.value),placeholder:"https://example.com",type:"url",disabled:Y,className:"s3-explr-input"})]}),l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),l.jsx(en,{id:"crawlLimit",value:X,onChange:T=>{const L=T.target.value;/^\d*$/.test(L)&&z(L)},placeholder:"1",type:"text",disabled:Y,className:"s3-explr-input"}),l.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)"})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>{V(!1),J(""),z("1")},disabled:Y,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{onClick:()=>{ne.trim()&&qE(ne.trim(),parseInt(X)||1)},disabled:Y||!ne.trim(),className:"s3-explr-crawl-btn",children:Y?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),f.startsWith("BKTTW/")&&l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,onClick:KE,children:[Ds&&l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Ds?"animate-spin":""}`}),"Xuất báo cáo"]})}),Ds&&l.jsx(on,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>FE(),className:"flex items-center gap-2",children:[l.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",children:[l.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"}),l.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"}),l.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"}),l.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"}),l.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"}),l.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"]})}),l.jsx(jt,{open:!!I,onOpenChange:T=>!T&&$(null),children:l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),l.jsxs(Rn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",I==null?void 0:I.name,"? Hành động này không thể hoàn tác."]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>$(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{variant:"destructive",onClick:()=>VE(I),disabled:Mt,className:"s3-explr-confirm-delete-btn",children:Mt?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),l.jsx(jt,{open:!!j,onOpenChange:T=>{T||(A(null),Q(null),ee(""),K(""),S("rename"))},children:l.jsxs(St,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(Et,{className:"s3-explr-dialog-header",children:l.jsx(_t,{className:"s3-explr-dialog-title",children:j!=null&&j.isFolder?"Đổi tên thư mục":br(j)?"Quản lý tập tin":"Đổi tên tập tin"})}),j&&l.jsxs(ab,{value:st,onValueChange:T=>S(T),children:[l.jsxs(Xu,{"aria-checked":!br(j),"aria-disabled":j.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[l.jsx(So,{value:"rename",children:"Đổi tên"}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(So,{value:"edit",children:"Sửa nội dung"}),l.jsx(So,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Eo,{value:"rename",children:l.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:l.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),l.jsx(en,{id:"newName",value:re,onChange:T=>ee(T.target.value),placeholder:"Nhập tên mới",disabled:ae,className:"s3-explr-input"})]})})}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(Eo,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:Ee?l.jsx("div",{className:"flex items-center justify-center py-4",children:l.jsx($e,{className:"h-6 w-6 animate-spin"})}):l.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[l.jsx(vn,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),l.jsx(ur,{id:"content",value:Ce,onChange:T=>K(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:qe})]})})}),l.jsx(Eo,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:Ee?l.jsx("div",{className:"flex items-center justify-center py-4",children:l.jsx($e,{className:"h-6 w-6 animate-spin"})}):l.jsx("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:B&&typeof B=="object"&&Object.entries(B).map(([T,L],W)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(vn,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[Yh[T]||T,qi(T)&&l.jsx(Ih,{className:"h-[12px] w-[12px] text-red-500"})]}),Xh(T)?l.jsx(ur,{id:T,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[T]:te.target.value};Q(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:qe||qi(T)}):l.jsx(en,{id:T,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[T]:te.target.value};Q(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:qe||qi(T)})]},W))})})})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>{A(null),Q(null),ee(""),K("")},className:"s3-explr-cancel-btn",children:"Hủy"}),st==="edit"?l.jsx(ve,{onClick:()=>j&&UE(j,Ce),disabled:qe||Ee,className:"s3-explr-save-btn",children:qe?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):st==="edit-metadata"?l.jsx(ve,{onClick:()=>B&&typeof B=="object"&&j&&WE(j),disabled:qe||Ee,className:"s3-explr-save-btn",children:qe?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):l.jsx(ve,{onClick:()=>{re.trim()&&j&&zE(j,re.trim())},disabled:ae||!re.trim()||re.trim()===(j==null?void 0:j.name),className:"s3-explr-rename-btn",children:ae?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),H&&ce&&l.jsx(GS,{openDialogRename:ce,setOpenDialogRename:oe,apiBaseUrl:t,setFileToMove:D,fileToMove:H,refreshFiles:tt,ignoreCache:Qe})]})]}),OE&&l.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"}),l.jsx(qS,{onFilesSelected:(T,L)=>Is(T,f,L),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(vo,{className:"s3-explr-table",children:[l.jsx(yo,{className:"s3-explr-table-header",children:Ms.getHeaderGroups().map(T=>l.jsx(ht,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(L=>l.jsx(Tt,{className:"s3-explr-header-cell",children:L.isPlaceholder?null:Vr(L.column.columnDef.header,L.getContext())},L.id))},T.id))}),l.jsx(xo,{className:"s3-explr-table-body",children:Ms.getRowModel().rows.length===0?l.jsx(ht,{className:"s3-explr-empty-row",children:l.jsx(Ze,{colSpan:$p.length,className:"h-24 text-center s3-explr-empty-cell",children:c?l.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 "',c,'"']}):l.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:Pr?"Đ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"})})}):Ms.getRowModel().rows.map(T=>l.jsx(ht,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(L=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Vr(L.column.columnDef.cell,L.getContext())},L.id))},T.id))})]})})}),c&&Nr!==0&&l.jsx(l.Fragment,{children:l.jsx(fo,{children:l.jsxs(po,{children:[l.jsx(go,{onClick:()=>$t(T=>Math.max(T-1,1)),"aria-disabled":Be===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Nr/20)},(T,L)=>{const W=L+1,te=Math.ceil(Nr/20);return te>7&&!(W===1||W===te||W>=Be-1&&W<=Be+1)?W===Be-2&&Be>4||W===Be+2&&Be<te-3?l.jsx(ho,{className:"pointer-events-none",children:"..."},L):null:l.jsx(mt,{className:"cursor-pointer",children:l.jsx(Vn,{isActive:Be===W,onClick:()=>$t(W),className:`${Be===W?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:W})},L)}),l.jsx(mt,{children:l.jsx(mo,{onClick:()=>$t(T=>Math.min(T+1,Math.ceil(Nr/20))),"aria-disabled":Be===Math.ceil(Nr/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),r&&o&&l.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[l.jsxs("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:[g.size," ",(g.size===1,"tập tin")," đã chọn"]}),l.jsx(ve,{variant:"default",onClick:()=>o(BE()),disabled:g.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),tE=e=>l.jsx(ng,{clientId:YS,children:l.jsx(eE,{...e})});var wr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Ke=e=>e==null;const fp=e=>typeof e=="object";var Me=e=>!Ke(e)&&!Array.isArray(e)&&fp(e)&&!Sn(e),nE=e=>Me(e)&&e.target?wr(e.target)?e.target.checked:e.target.value:e,rE=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,oE=(e,t)=>e.has(rE(t)),iE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},_s=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ut(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(_s&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!iE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ut(e[o]));else return e;return t}var Xo=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,se=(e,t,n)=>{if(!t||!Me(e))return n;const r=Xo(t.split(/[,[\].]+?/)).reduce((o,i)=>Ke(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Ot=e=>typeof e=="boolean",Ts=e=>/^\w*$/.test(e),pp=e=>Xo(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Oe=(e,t,n)=>{let r=-1;const o=Ts(t)?[t]:pp(t),i=o.length,a=i-1;for(;++r<i;){const s=o[r];let u=n;if(r!==a){const c=e[s];u=Me(c)||Array.isArray(c)?c:isNaN(+o[r+1])?{}:[]}if(s==="__proto__"||s==="constructor"||s==="prototype")return;e[s]=u,e=e[s]}return e};const gp={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},xt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Ut={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};_.createContext(null);var aE=(e,t,n,r=!0)=>{const o={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(o,i,{get:()=>{const a=i;return t._proxyFormState[a]!==xt.all&&(t._proxyFormState[a]=!r||xt.all),e[a]}});return o},et=e=>Me(e)&&!Object.keys(e).length,sE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return et(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===xt.all)},Jo=e=>Array.isArray(e)?e:[e];function lE(e){const t=_.useRef(e);t.current=e,_.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Ft=e=>typeof e=="string",cE=(e,t,n,r,o)=>Ft(e)?(r&&t.watch.add(e),se(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),se(n,i))):(r&&(t.watchAll=!0),n),uE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},mp=e=>({isOnSubmit:!e||e===xt.onSubmit,isOnBlur:e===xt.onBlur,isOnChange:e===xt.onChange,isOnAll:e===xt.all,isOnTouch:e===xt.onTouched}),hp=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Cr=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=se(e,o);if(i){const{_f:a,...s}=i;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],o)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Cr(s,t))break}else if(Me(s)&&Cr(s,t))break}}};var dE=(e,t,n)=>{const r=Jo(se(e,n));return Oe(r,"root",t[n]),Oe(e,n,r),e},As=e=>e.type==="file",Dt=e=>typeof e=="function",Zo=e=>{if(!_s)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Qo=e=>Ft(e),Ps=e=>e.type==="radio",ei=e=>e instanceof RegExp;const vp={value:!1,isValid:!1},yp={value:!0,isValid:!0};var xp=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Ie(e[0].attributes.value)?Ie(e[0].value)||e[0].value===""?yp:{value:e[0].value,isValid:!0}:yp:vp}return vp};const bp={isValid:!1,value:null};var wp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,bp):bp;function Cp(e,t,n="validate"){if(Qo(e)||Array.isArray(e)&&e.every(Qo)||Ot(e)&&!e)return{type:n,message:Qo(e)?e:"",ref:t}}var Kn=e=>Me(e)&&!ei(e)?e:{value:e,message:""},Sp=async(e,t,n,r,o)=>{const{ref:i,refs:a,required:s,maxLength:u,minLength:c,min:d,max:g,pattern:m,validate:f,name:v,valueAsNumber:h,mount:y,disabled:b}=e._f,w=se(t,v);if(!y||b)return{};const C=a?a[0]:i,E=U=>{r&&C.reportValidity&&(C.setCustomValidity(Ot(U)?"":U||""),C.reportValidity())},x={},O=Ps(i),I=wr(i),$=O||I,H=(h||As(i))&&Ie(i.value)&&Ie(w)||Zo(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,D=uE.bind(null,v,n,x),G=(U,Z,k,M=Ut.maxLength,F=Ut.minLength)=>{const q=U?Z:k;x[v]={type:U?M:F,message:q,ref:i,...D(U?M:F,q)}};if(o?!Array.isArray(w)||!w.length:s&&(!$&&(H||Ke(w))||Ot(w)&&!w||I&&!xp(a).isValid||O&&!wp(a).isValid)){const{value:U,message:Z}=Qo(s)?{value:!!s,message:s}:Kn(s);if(U&&(x[v]={type:Ut.required,message:Z,ref:C,...D(Ut.required,Z)},!n))return E(Z),x}if(!H&&(!Ke(d)||!Ke(g))){let U,Z;const k=Kn(g),M=Kn(d);if(!Ke(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ke(k.value)||(U=F>k.value),Ke(M.value)||(Z=F<M.value)}else{const F=i.valueAsDate||new Date(w),q=A=>new Date(new Date().toDateString()+" "+A),P=i.type=="time",j=i.type=="week";Ft(k.value)&&w&&(U=P?q(w)>q(k.value):j?w>k.value:F>new Date(k.value)),Ft(M.value)&&w&&(Z=P?q(w)<q(M.value):j?w<M.value:F<new Date(M.value))}if((U||Z)&&(G(!!U,k.message,M.message,Ut.max,Ut.min),!n))return E(x[v].message),x}if((u||c)&&!H&&(Ft(w)||o&&Array.isArray(w))){const U=Kn(u),Z=Kn(c),k=!Ke(U.value)&&w.length>+U.value,M=!Ke(Z.value)&&w.length<+Z.value;if((k||M)&&(G(k,U.message,Z.message),!n))return E(x[v].message),x}if(m&&!H&&Ft(w)){const{value:U,message:Z}=Kn(m);if(ei(U)&&!w.match(U)&&(x[v]={type:Ut.pattern,message:Z,ref:i,...D(Ut.pattern,Z)},!n))return E(Z),x}if(f){if(Dt(f)){const U=await f(w,t),Z=Cp(U,C);if(Z&&(x[v]={...Z,...D(Ut.validate,Z.message)},!n))return E(Z.message),x}else if(Me(f)){let U={};for(const Z in f){if(!et(U)&&!n)break;const k=Cp(await f[Z](w,t),C,Z);k&&(U={...k,...D(Z,k.message)},E(k.message),n&&(x[v]=U))}if(!et(U)&&(x[v]={ref:C,...U},!n))return x}}return E(!0),x};function fE(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Ie(e)?r++:e[t[r++]];return e}function pE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ie(e[t]))return!1;return!0}function je(e,t){const n=Array.isArray(t)?t:Ts(t)?[t]:pp(t),r=n.length===1?e:fE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&et(r)||Array.isArray(r)&&pE(r))&&je(e,n.slice(0,-1)),e}var Ns=()=>{let e=[];return{get observers(){return e},next:o=>{for(const i of e)i.next&&i.next(o)},subscribe:o=>(e.push(o),{unsubscribe:()=>{e=e.filter(i=>i!==o)}}),unsubscribe:()=>{e=[]}}},ks=e=>Ke(e)||!fp(e);function an(e,t){if(ks(e)||ks(t))return e===t;if(Sn(e)&&Sn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){const i=e[o];if(!r.includes(o))return!1;if(o!=="ref"){const a=t[o];if(Sn(i)&&Sn(a)||Me(i)&&Me(a)||Array.isArray(i)&&Array.isArray(a)?!an(i,a):i!==a)return!1}}return!0}var Ep=e=>e.type==="select-multiple",gE=e=>Ps(e)||wr(e),Os=e=>Zo(e)&&e.isConnected,_p=e=>{for(const t in e)if(Dt(e[t]))return!0;return!1};function ti(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!_p(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ti(e[r],t[r])):Ke(e[r])||(t[r]=!0);return t}function Tp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!_p(e[o])?Ie(t)||ks(n[o])?n[o]=Array.isArray(e[o])?ti(e[o],[]):{...ti(e[o])}:Tp(e[o],Ke(t)?{}:t[o],n[o]):n[o]=!an(e[o],t[o]);return n}var Sr=(e,t)=>Tp(e,t,ti(t)),Ap=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&Ft(e)?new Date(e):r?r(e):e;function Fs(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return As(t)?t.files:Ps(t)?wp(e.refs).value:Ep(t)?[...t.selectedOptions].map(({value:n})=>n):wr(t)?xp(e.refs).value:Ap(Ie(t.value)?e.ref.value:t.value,e)}var mE=(e,t,n,r)=>{const o={};for(const i of e){const a=se(t,i);a&&Oe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Er=e=>Ie(e)?e:ei(e)?e.source:Me(e)?ei(e.value)?e.value.source:e.value:e;const Pp="AsyncFunction";var hE=e=>!!e&&!!e.validate&&!!(Dt(e.validate)&&e.validate.constructor.name===Pp||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Pp)),vE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Np(e,t,n){const r=se(e,n);if(r||Ts(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),a=se(t,i),s=se(e,i);if(a&&!Array.isArray(a)&&n!==i)return{name:n};if(s&&s.type)return{name:i,error:s};o.pop()}return{name:n}}var yE=(e,t,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(t||e):(n?r.isOnBlur:o.isOnBlur)?!e:(n?r.isOnChange:o.isOnChange)?e:!0,xE=(e,t)=>!Xo(se(e,t)).length&&je(e,t);const bE={mode:xt.onSubmit,reValidateMode:xt.onChange,shouldFocusError:!0};function wE(e={}){let t={...bE,...e},n={submitCount:0,isDirty:!1,isLoading:Dt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},o=Me(t.defaultValues)||Me(t.values)?ut(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ut(o),a={action:!1,mount:!1,watch:!1},s={mount:new Set,unMount:new Set,array:new Set,watch:new Set},u,c=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},g={values:Ns(),array:Ns(),state:Ns()},m=mp(t.mode),f=mp(t.reValidateMode),v=t.criteriaMode===xt.all,h=S=>N=>{clearTimeout(c),c=setTimeout(S,N)},y=async S=>{if(!t.disabled&&(d.isValid||S)){const N=t.resolver?et((await $()).errors):await D(r,!0);N!==n.isValid&&g.state.next({isValid:N})}},b=(S,N)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((S||Array.from(s.mount)).forEach(V=>{V&&(N?Oe(n.validatingFields,V,N):je(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!et(n.validatingFields)}))},w=(S,N=[],V,ne,J=!0,X=!0)=>{if(ne&&V&&!t.disabled){if(a.action=!0,X&&Array.isArray(se(r,S))){const z=V(se(r,S),ne.argA,ne.argB);J&&Oe(r,S,z)}if(X&&Array.isArray(se(n.errors,S))){const z=V(se(n.errors,S),ne.argA,ne.argB);J&&Oe(n.errors,S,z),xE(n.errors,S)}if(d.touchedFields&&X&&Array.isArray(se(n.touchedFields,S))){const z=V(se(n.touchedFields,S),ne.argA,ne.argB);J&&Oe(n.touchedFields,S,z)}d.dirtyFields&&(n.dirtyFields=Sr(o,i)),g.state.next({name:S,isDirty:U(S,N),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Oe(i,S,N)},C=(S,N)=>{Oe(n.errors,S,N),g.state.next({errors:n.errors})},E=S=>{n.errors=S,g.state.next({errors:n.errors,isValid:!1})},x=(S,N,V,ne)=>{const J=se(r,S);if(J){const X=se(i,S,Ie(V)?se(o,S):V);Ie(X)||ne&&ne.defaultChecked||N?Oe(i,S,N?X:Fs(J._f)):M(S,X),a.mount&&y()}},O=(S,N,V,ne,J)=>{let X=!1,z=!1;const Y={name:S};if(!t.disabled){const xe=!!(se(r,S)&&se(r,S)._f&&se(r,S)._f.disabled);if(!V||ne){d.isDirty&&(z=n.isDirty,n.isDirty=Y.isDirty=U(),X=z!==Y.isDirty);const we=xe||an(se(o,S),N);z=!!(!xe&&se(n.dirtyFields,S)),we||xe?je(n.dirtyFields,S):Oe(n.dirtyFields,S,!0),Y.dirtyFields=n.dirtyFields,X=X||d.dirtyFields&&z!==!we}if(V){const we=se(n.touchedFields,S);we||(Oe(n.touchedFields,S,V),Y.touchedFields=n.touchedFields,X=X||d.touchedFields&&we!==V)}X&&J&&g.state.next(Y)}return X?Y:{}},I=(S,N,V,ne)=>{const J=se(n.errors,S),X=d.isValid&&Ot(N)&&n.isValid!==N;if(t.delayError&&V?(u=h(()=>C(S,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Oe(n.errors,S,V):je(n.errors,S)),(V?!an(J,V):J)||!et(ne)||X){const z={...ne,...X&&Ot(N)?{isValid:N}:{},errors:n.errors,name:S};n={...n,...z},g.state.next(z)}},$=async S=>{b(S,!0);const N=await t.resolver(i,t.context,mE(S||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(S),N},H=async S=>{const{errors:N}=await $(S);if(S)for(const V of S){const ne=se(N,V);ne?Oe(n.errors,V,ne):je(n.errors,V)}else n.errors=N;return N},D=async(S,N,V={valid:!0})=>{for(const ne in S){const J=S[ne];if(J){const{_f:X,...z}=J;if(X){const Y=s.array.has(X.name),xe=J._f&&hE(J._f);xe&&d.validatingFields&&b([ne],!0);const we=await Sp(J,i,v,t.shouldUseNativeValidation&&!N,Y);if(xe&&d.validatingFields&&b([ne]),we[X.name]&&(V.valid=!1,N))break;!N&&(se(we,X.name)?Y?dE(n.errors,we,X.name):Oe(n.errors,X.name,we[X.name]):je(n.errors,X.name))}!et(z)&&await D(z,N,V)}}return V.valid},G=()=>{for(const S of s.unMount){const N=se(r,S);N&&(N._f.refs?N._f.refs.every(V=>!Os(V)):!Os(N._f.ref))&&oe(S)}s.unMount=new Set},U=(S,N)=>!t.disabled&&(S&&N&&Oe(i,S,N),!an(B(),o)),Z=(S,N,V)=>cE(S,s,{...a.mount?i:Ie(N)?o:Ft(S)?{[S]:N}:N},V,N),k=S=>Xo(se(a.mount?i:o,S,t.shouldUnregister?se(o,S,[]):[])),M=(S,N,V={})=>{const ne=se(r,S);let J=N;if(ne){const X=ne._f;X&&(!X.disabled&&Oe(i,S,Ap(N,X)),J=Zo(X.ref)&&Ke(N)?"":N,Ep(X.ref)?[...X.ref.options].forEach(z=>z.selected=J.includes(z.value)):X.refs?wr(X.ref)?X.refs.length>1?X.refs.forEach(z=>(!z.defaultChecked||!z.disabled)&&(z.checked=Array.isArray(J)?!!J.find(Y=>Y===z.value):J===z.value)):X.refs[0]&&(X.refs[0].checked=!!J):X.refs.forEach(z=>z.checked=z.value===J):As(X.ref)?X.ref.value="":(X.ref.value=J,X.ref.type||g.values.next({name:S,values:{...i}})))}(V.shouldDirty||V.shouldTouch)&&O(S,J,V.shouldTouch,V.shouldDirty,!0),V.shouldValidate&&A(S)},F=(S,N,V)=>{for(const ne in N){const J=N[ne],X=`${S}.${ne}`,z=se(r,X);(s.array.has(S)||Me(J)||z&&!z._f)&&!Sn(J)?F(X,J,V):M(X,J,V)}},q=(S,N,V={})=>{const ne=se(r,S),J=s.array.has(S),X=ut(N);Oe(i,S,X),J?(g.array.next({name:S,values:{...i}}),(d.isDirty||d.dirtyFields)&&V.shouldDirty&&g.state.next({name:S,dirtyFields:Sr(o,i),isDirty:U(S,X)})):ne&&!ne._f&&!Ke(X)?F(S,X,V):M(S,X,V),hp(S,s)&&g.state.next({...n}),g.values.next({name:a.mount?S:void 0,values:{...i}})},P=async S=>{a.mount=!0;const N=S.target;let V=N.name,ne=!0;const J=se(r,V),X=()=>N.type?Fs(J._f):nE(S),z=Y=>{ne=Number.isNaN(Y)||Sn(Y)&&isNaN(Y.getTime())||an(Y,se(i,V,Y))};if(J){let Y,xe;const we=X(),Fe=S.type===gp.BLUR||S.type===gp.FOCUS_OUT,sn=!vE(J._f)&&!t.resolver&&!se(n.errors,V)&&!J._f.deps||yE(Fe,se(n.touchedFields,V),n.isSubmitted,f,m),Re=hp(V,s,Fe);Oe(i,V,we),Fe?(J._f.onBlur&&J._f.onBlur(S),u&&u(0)):J._f.onChange&&J._f.onChange(S);const Mt=O(V,we,Fe,!1),En=!et(Mt)||Re;if(!Fe&&g.values.next({name:V,type:S.type,values:{...i}}),sn)return d.isValid&&(t.mode==="onBlur"?Fe&&y():y()),En&&g.state.next({name:V,...Re?{}:Mt});if(!Fe&&Re&&g.state.next({...n}),t.resolver){const{errors:Be}=await $([V]);if(z(we),ne){const $t=Np(n.errors,r,V),Wt=Np(Be,r,$t.name||V);Y=Wt.error,V=Wt.name,xe=et(Be)}}else b([V],!0),Y=(await Sp(J,i,v,t.shouldUseNativeValidation))[V],b([V]),z(we),ne&&(Y?xe=!1:d.isValid&&(xe=await D(r,!0)));ne&&(J._f.deps&&A(J._f.deps),I(V,xe,Y,Mt))}},j=(S,N)=>{if(se(n.errors,N)&&S.focus)return S.focus(),1},A=async(S,N={})=>{let V,ne;const J=Jo(S);if(t.resolver){const X=await H(Ie(S)?S:J);V=et(X),ne=S?!J.some(z=>se(X,z)):V}else S?(ne=(await Promise.all(J.map(async X=>{const z=se(r,X);return await D(z&&z._f?{[X]:z}:z)}))).every(Boolean),!(!ne&&!n.isValid)&&y()):ne=V=await D(r);return g.state.next({...!Ft(S)||d.isValid&&V!==n.isValid?{}:{name:S},...t.resolver||!S?{isValid:V}:{},errors:n.errors}),N.shouldFocus&&!ne&&Cr(r,j,S?J:s.mount),ne},B=S=>{const N={...a.mount?i:o};return Ie(S)?N:Ft(S)?se(N,S):S.map(V=>se(N,V))},Q=(S,N)=>({invalid:!!se((N||n).errors,S),isDirty:!!se((N||n).dirtyFields,S),error:se((N||n).errors,S),isValidating:!!se(n.validatingFields,S),isTouched:!!se((N||n).touchedFields,S)}),re=S=>{S&&Jo(S).forEach(N=>je(n.errors,N)),g.state.next({errors:S?n.errors:{}})},ee=(S,N,V)=>{const ne=(se(r,S,{_f:{}})._f||{}).ref,J=se(n.errors,S)||{},{ref:X,message:z,type:Y,...xe}=J;Oe(n.errors,S,{...xe,...N,ref:ne}),g.state.next({name:S,errors:n.errors,isValid:!1}),V&&V.shouldFocus&&ne&&ne.focus&&ne.focus()},ce=(S,N)=>Dt(S)?g.values.subscribe({next:V=>S(Z(void 0,N),V)}):Z(S,N,!0),oe=(S,N={})=>{for(const V of S?Jo(S):s.mount)s.mount.delete(V),s.array.delete(V),N.keepValue||(je(r,V),je(i,V)),!N.keepError&&je(n.errors,V),!N.keepDirty&&je(n.dirtyFields,V),!N.keepTouched&&je(n.touchedFields,V),!N.keepIsValidating&&je(n.validatingFields,V),!t.shouldUnregister&&!N.keepDefaultValue&&je(o,V);g.values.next({values:{...i}}),g.state.next({...n,...N.keepDirty?{isDirty:U()}:{}}),!N.keepIsValid&&y()},ae=({disabled:S,name:N,field:V,fields:ne,value:J})=>{if(Ot(S)&&a.mount||S){const X=S?void 0:Ie(J)?Fs(V?V._f:se(ne,N)._f):J;(S||!S&&!Ie(X))&&Oe(i,N,X),O(N,X,!1,!1,!0)}},de=(S,N={})=>{let V=se(r,S);const ne=Ot(N.disabled)||Ot(t.disabled);return Oe(r,S,{...V||{},_f:{...V&&V._f?V._f:{ref:{name:S}},name:S,mount:!0,...N}}),s.mount.add(S),V?ae({field:V,disabled:Ot(N.disabled)?N.disabled:t.disabled,name:S,value:N.value}):x(S,!0,N.value),{...ne?{disabled:N.disabled||t.disabled}:{},...t.progressive?{required:!!N.required,min:Er(N.min),max:Er(N.max),minLength:Er(N.minLength),maxLength:Er(N.maxLength),pattern:Er(N.pattern)}:{},name:S,onChange:P,onBlur:P,ref:J=>{if(J){de(S,N),V=se(r,S);const X=Ie(J.value)&&J.querySelectorAll&&J.querySelectorAll("input,select,textarea")[0]||J,z=gE(X),Y=V._f.refs||[];if(z?Y.find(xe=>xe===X):X===V._f.ref)return;Oe(r,S,{_f:{...V._f,...z?{refs:[...Y.filter(Os),X,...Array.isArray(se(o,S))?[{}]:[]],ref:{type:X.type,name:S}}:{ref:X}}}),x(S,!1,void 0,X)}else V=se(r,S,{}),V._f&&(V._f.mount=!1),(t.shouldUnregister||N.shouldUnregister)&&!(oE(s.array,S)&&a.action)&&s.unMount.add(S)}}},ue=()=>t.shouldFocusError&&Cr(r,j,s.mount),le=S=>{Ot(S)&&(g.state.next({disabled:S}),Cr(r,(N,V)=>{const ne=se(r,V);ne&&(N.disabled=ne._f.disabled||S,Array.isArray(ne._f.refs)&&ne._f.refs.forEach(J=>{J.disabled=ne._f.disabled||S}))},0,!1))},Ce=(S,N)=>async V=>{let ne;if(V&&(V.preventDefault&&V.preventDefault(),V.persist&&V.persist()),t.disabled){N&&await N({...n.errors},V);return}let J=ut(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:X,values:z}=await $();n.errors=X,J=z}else await D(r);if(je(n.errors,"root"),et(n.errors)){g.state.next({errors:{}});try{await S(J,V)}catch(X){ne=X}}else N&&await N({...n.errors},V),ue(),setTimeout(ue);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:et(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},K=(S,N={})=>{se(r,S)&&(Ie(N.defaultValue)?q(S,ut(se(o,S))):(q(S,N.defaultValue),Oe(o,S,ut(N.defaultValue))),N.keepTouched||je(n.touchedFields,S),N.keepDirty||(je(n.dirtyFields,S),n.isDirty=N.defaultValue?U(S,ut(se(o,S))):U()),N.keepError||(je(n.errors,S),d.isValid&&y()),g.state.next({...n}))},Ee=(S,N={})=>{const V=S?ut(S):o,ne=ut(V),J=et(S),X=J?o:ne;if(N.keepDefaultValues||(o=V),!N.keepValues){if(N.keepDirtyValues){const z=new Set([...s.mount,...Object.keys(Sr(o,i))]);for(const Y of Array.from(z))se(n.dirtyFields,Y)?Oe(X,Y,se(i,Y)):q(Y,se(X,Y))}else{if(_s&&Ie(S))for(const z of s.mount){const Y=se(r,z);if(Y&&Y._f){const xe=Array.isArray(Y._f.refs)?Y._f.refs[0]:Y._f.ref;if(Zo(xe)){const we=xe.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?N.keepDefaultValues?ut(o):{}:ut(X),g.array.next({values:{...X}}),g.values.next({values:{...X}})}s={mount:N.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!N.keepIsValid||!!N.keepDirtyValues,a.watch=!!t.shouldUnregister,g.state.next({submitCount:N.keepSubmitCount?n.submitCount:0,isDirty:J?!1:N.keepDirty?n.isDirty:!!(N.keepDefaultValues&&!an(S,o)),isSubmitted:N.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:J?{}:N.keepDirtyValues?N.keepDefaultValues&&i?Sr(o,i):n.dirtyFields:N.keepDefaultValues&&S?Sr(o,S):N.keepDirty?n.dirtyFields:{},touchedFields:N.keepTouched?n.touchedFields:{},errors:N.keepErrors?n.errors:{},isSubmitSuccessful:N.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},We=(S,N)=>Ee(Dt(S)?S(i):S,N);return{control:{register:de,unregister:oe,getFieldState:Q,handleSubmit:Ce,setError:ee,_executeSchema:$,_getWatch:Z,_getDirty:U,_updateValid:y,_removeUnmounted:G,_updateFieldArray:w,_updateDisabledField:ae,_getFieldArray:k,_reset:Ee,_resetDefaultValues:()=>Dt(t.defaultValues)&&t.defaultValues().then(S=>{We(S,t.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:S=>{n={...n,...S}},_disableForm:le,_subjects:g,_proxyFormState:d,_setErrors:E,get _fields(){return r},get _formValues(){return i},get _state(){return a},set _state(S){a=S},get _defaultValues(){return o},get _names(){return s},set _names(S){s=S},get _formState(){return n},set _formState(S){n=S},get _options(){return t},set _options(S){t={...t,...S}}},trigger:A,register:de,handleSubmit:Ce,watch:ce,setValue:q,getValues:B,reset:We,resetField:K,clearErrors:re,unregister:oe,setError:ee,setFocus:(S,N={})=>{const V=se(r,S),ne=V&&V._f;if(ne){const J=ne.refs?ne.refs[0]:ne.ref;J.focus&&(J.focus(),N.shouldSelect&&Dt(J.select)&&J.select())}},getFieldState:Q}}function CE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:Dt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Dt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...wE(e),formState:r});const i=t.current.control;return i._options=e,lE({subject:i._subjects.state,next:a=>{sE(a,i._proxyFormState,i._updateFormState)&&o({...i._formState})}}),_.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),_.useEffect(()=>{if(i._proxyFormState.isDirty){const a=i._getDirty();a!==r.isDirty&&i._subjects.state.next({isDirty:a})}},[i,r.isDirty]),_.useEffect(()=>{e.values&&!an(e.values,n.current)?(i._reset(e.values,i._options.resetOptions),n.current=e.values,o(a=>({...a}))):i._resetDefaultValues()},[e.values,i]),_.useEffect(()=>{e.errors&&i._setErrors(e.errors)},[e.errors,i]),_.useEffect(()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),_.useEffect(()=>{e.shouldUnregister&&i._subjects.values.next({values:i._getWatch()})},[e.shouldUnregister,i]),_.useMemo(()=>({...t.current,formState:aE(r,i)}),[r,i])}const kp=({className:e,children:t,content:n,side:r})=>{const[o,i]=_.useState(!1);return l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{open:o,children:[l.jsx(wn,{asChild:!0,children:l.jsx("button",{type:"button",className:he("cursor-pointer",e),onClick:()=>i(!o),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onTouchStart:()=>i(!o),onKeyDown:a=>{a.preventDefault(),a.key==="Enter"&&i(!o)},children:t})}),l.jsx(on,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},SE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},EE=({apiBaseUrl:e="https://vib-s3-explorer.cmcts1.studio.ai.vn"})=>{var O,I;const[t,n]=_.useState([]),[r,o]=_.useState(!1),[i,a]=_.useState([]),[s,u]=_.useState(1),[c,d]=_.useState(1),[g,m]=_.useState(null),[f,v]=_.useState(""),h=SE(f,500),y=$=>{const H=$.match(/\d{6}/);if(!H)return{month:"",year:""};const D=H[0],G=D.substring(0,2),U=D.substring(2);return{month:G,year:U}},b=$=>$.map(D=>{let G=(D==null?void 0:D.month)||"",U=(D==null?void 0:D.year)||"";if((!G||!U)&&(D!=null&&D.file_name)){const Z=y(D.file_name);G=G||Z.month,U=U||Z.year}return{id:D==null?void 0:D.id,prefix:(D==null?void 0:D.prefix)||"",model:(D==null?void 0:D.model)||"",fileName:(D==null?void 0:D.file_name)||"",code:(D==null?void 0:D.stock_id)||"",month:G,year:U,content:(D==null?void 0:D.text_summary)||"",status:(D==null?void 0:D.status)||"",note:(D==null?void 0:D.note)||"",lastUpdate:D==null?void 0:D.updated_at,stock_id:D==null?void 0:D.stock_id}}),w=$=>{if(!($!=null&&$.data))return[];const H=b($==null?void 0:$.data);n(H),d($.pagination.totalPages)},C=async($=1,H=15)=>{m($),o(!0);try{const D=await me.get(`${e}/api/latest-summaries`,{params:{page:$,limit:H,search:f}});(D==null?void 0:D.status)===200?w(D.data):console.error(D)}catch(D){console.error("Error fetching data:",D)}finally{m(null),o(!1)}};_.useEffect(()=>{h&&u(1),C(s)},[s,h]);const E=_.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:H})=>l.jsx("span",{className:"flex flex-col",children:H.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:H})=>{const D=H.original.month,G=H.original.year;return l.jsx("span",{className:"flex flex-col",children:`${D.toString().padStart(2,"0")}/${G}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:H})=>{const D=H.getValue("content");return l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:D})}},{id:"status",header:"Trạng thái",accessorKey:"status",cell:({row:H})=>{const G=H.original.status!=="unpublish";return l.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${G?"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:G?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:H})=>l.jsx(kp,{content:l.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:H.original.note}),children:l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:H.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:H})=>{const D=new Date(H.original.lastUpdate),G=D.getDate(),U=D.getMonth()+1,Z=`ngày ${G} tháng ${U}`;return l.jsx("span",{className:"flex flex-col",children:Z})}},{accessorKey:"actions",header:()=>l.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:H})=>{const[D,G]=_.useState(!1),[U,Z]=_.useState(!1),[k,M]=_.useState(!1),{handleSubmit:F,register:q,reset:P}=CE(),j=H.original.id,A=H.getValue("status"),B=H.getValue("content"),[Q,re]=_.useState(!1),ee=async()=>{try{re(!0);const oe=A==="unpublish"?"published":"unpublish",ae=await me.patch(`${e}/api/toggle-publish/${j}`,{id:j,typeAction:"update",status:A,idInput:j,stock_id:H.original.stock_id,prefix:H.original.prefix,model:H.original.model,summary_result:H.original.content,note:H.original.note});ae.status===200?n(de=>de.map(ue=>ue.id===j?{...ue,status:oe}:ue)):console.error("Failed to toggle publish status:",ae)}catch(oe){console.error("Error toggling publish status:",oe)}finally{re(!1)}},ce=async oe=>{G(!0);try{const ae=await me.patch(`${e}/api/update-summary`,{note:oe.note,text_summary:oe.content,id:j});ae.status===200?(await C(s),Z(!1)):console.error("Failed to update summary:",ae)}catch(ae){console.error("Error updating summary:",ae)}return G(!1)};return l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ve,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"px-2 py-0.5 h-7",children:l.jsx(Fh,{className:"h-4 w-4"})}),l.jsx(jt,{open:k,onOpenChange:M,children:l.jsxs(St,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(Et,{children:l.jsx(_t,{children:"Nội dung chi tiết"})}),l.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:l.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:B})})]})}),l.jsxs(jt,{open:U,onOpenChange:oe=>{Z(oe),oe?P({content:H.original.content,note:H.original.note}):P()},children:[l.jsx(uo,{asChild:!0,children:l.jsx(ve,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),l.jsx(St,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(Et,{className:"flex flex-col gap-3",children:[l.jsx(_t,{className:"max-sm:hidden text-center",children:"Sửa summary"}),l.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:F(ce),children:[l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Nội dung:"}),l.jsx(ur,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.answer||"",rows:10,...q("content")})]}),l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Ghi chú:"}),l.jsx(ur,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.note||"",rows:1,...q("note")})]})]}),l.jsx("div",{className:"flex justify-end",children:l.jsx(ve,{disabled:D,type:"submit",variant:"default",children:D?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ve,{variant:"outline",size:"sm",onClick:ee,disabled:Q,className:"w-[70px] px-2 py-0.5 h-7",children:Q?l.jsx($e,{className:"h-4 w-4 animate-spin"}):A==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=el({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:$g(),getCoreRowModel:Qs()});return l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:l.jsxs("div",{className:"relative max-w-sm",children:[l.jsx(en,{placeholder:"Tìm kiếm theo mã...",value:f,onChange:$=>v($.target.value),className:"pr-8"}),f&&l.jsx(ve,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>v(""),children:l.jsx(Hi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(vo,{className:"s3-explr-table",children:[l.jsx(yo,{className:"s3-explr-table-header",children:x.getHeaderGroups().map($=>l.jsx(ht,{className:"hover:bg-transparent s3-explr-header-row",children:$.headers.map(H=>l.jsx(Tt,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Vr(H.column.columnDef.header,H.getContext())},H.id))},$.id))}),l.jsx(xo,{className:"s3-explr-table-body",children:r?l.jsx(ht,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(O=x.getRowModel().rows)!=null&&O.length?(I=x.getRowModel().rows)==null?void 0:I.map($=>l.jsx(ht,{className:"h-12 s3-explr-row",children:$.getVisibleCells().map(H=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Vr(H.column.columnDef.cell,H.getContext())},H.id))},$.id)):l.jsx(ht,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(fo,{children:l.jsxs(po,{children:[l.jsx(mt,{children:l.jsx(go,{onClick:()=>u($=>Math.max(1,$-1)),className:s===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:c},($,H)=>H+1).filter($=>$===1||$===c||Math.abs($-s)<=1).map(($,H,D)=>l.jsxs(l.Fragment,{children:[H>0&&D[H-1]!==$-1&&l.jsx(mt,{children:l.jsx(ho,{})},$+"..."),l.jsx(mt,{children:l.jsx(Vn,{onClick:()=>u($),isActive:s===$,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===$?l.jsx($e,{className:"h-4 w-4 animate-spin"}):$})},$)]})),l.jsx(mt,{children:l.jsx(mo,{onClick:()=>u($=>Math.min(c,$+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Op=10,_E=_.memo(({apiBaseUrl:e="https://vib-s3-explorer.cmcts1.studio.ai.vn"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Op,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:f}=ko(),[v,h]=_.useState(!1),y=async x=>{try{d(x);const O=await me.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Op.toString()}});o(O.data.data),a(O.data.pagination)}catch{f({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{d(null),u(!1)}};_.useEffect(()=>{y(t)},[t,e]);const b=async x=>{m(O=>new Set(O).add(x.toString()));try{await me.post(`${e}/api/retry-job`,{jobId:x}),f({title:"Job Restarted",description:`Job ${x} has been successfully restarted.`}),y(t)}catch{f({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${x}. Please try again.`})}finally{m(O=>{const I=new Set(O);return I.delete(x.toString()),I})}},w=async()=>{h(!0),n(1),await y(1),h(!1)},C=x=>new Date(x).toLocaleString(),E=x=>{if(x=parseFloat(x),x<60)return`${x.toFixed(2)}s`;const O=Math.floor(x/60),I=(x%60).toFixed(0);return`${O}m ${I}s`};return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[l.jsx(Ph,{className:"w-8 h-8 text-primary"}),l.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),l.jsx(ve,{variant:"outline",size:"icon",onClick:w,disabled:v||s,className:"ml-2",children:l.jsx(Mh,{className:`h-4 w-4 ${v?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(vo,{children:[l.jsx(yo,{children:l.jsxs(ht,{children:[l.jsx(Tt,{children:"ID"}),l.jsx(Tt,{children:"Tên Công Việc"}),l.jsx(Tt,{children:"Thời Gian Bắt Đầu"}),l.jsx(Tt,{children:"Thời Gian Cập Nhật"}),l.jsx(Tt,{children:"Thời Gian Thực Thi"}),l.jsx(Tt,{children:"Trạng Thái"}),l.jsx(Tt,{children:"Thao Tác"})]})}),l.jsx(xo,{children:s&&r.length===0?l.jsx(ht,{children:l.jsx(Ze,{colSpan:7,className:"text-center py-4",children:l.jsx($e,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(x=>{var O,I;return l.jsxs(ht,{children:[l.jsx(Ze,{className:"!w-[100px]",children:x.id}),l.jsx(Ze,{className:"font-medium",children:(O=x.job_name)==null?void 0:O.replace("Upload file","Summary")}),l.jsx(Ze,{className:"!w-[200px]",children:C(x.created_at)}),l.jsx(Ze,{className:"!w-[200px]",children:C(x.updated_at)}),l.jsx(Ze,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Ze,{className:"!w-[200px]",children:l.jsx(kp,{content:x.status==="fail"&&x.error?l.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:x.error}):null,children:l.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]
175
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ap(e,t){if(e){if(typeof e=="string")return ws(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ws(e,t)}}function ws(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function BS(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,a,s;try{for(n=n.call(e);!(o=(a=n.next()).done)&&(r.push(a.value),!(t&&r.length===t));o=!0);}catch(u){i=!0,s=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw s}}return r}}function HS(e){if(Array.isArray(e))return e}function sp(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function De(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?sp(Object(n),!0).forEach(function(r){Cs(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):sp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Cs(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ko(e,t){if(e==null)return{};var n=US(e,t),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function US(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,i;for(i=0;i<r.length;i++)o=r[i],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}var Ss=_.forwardRef(function(e,t){var n=e.children,r=Ko(e,DS),o=cp(r),i=o.open,a=Ko(o,IS);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});Ss.displayName="Dropzone";var lp={disabled:!1,getFilesFromEvent:nS,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};Ss.defaultProps=lp,Ss.propTypes={children:Ne.func,accept:Ne.objectOf(Ne.arrayOf(Ne.string)),multiple:Ne.bool,preventDropOnDocument:Ne.bool,noClick:Ne.bool,noKeyboard:Ne.bool,noDrag:Ne.bool,noDragEventsBubbling:Ne.bool,minSize:Ne.number,maxSize:Ne.number,maxFiles:Ne.number,disabled:Ne.bool,getFilesFromEvent:Ne.func,onFileDialogCancel:Ne.func,onFileDialogOpen:Ne.func,useFsAccessApi:Ne.bool,autoFocus:Ne.bool,onDragEnter:Ne.func,onDragLeave:Ne.func,onDragOver:Ne.func,onDrop:Ne.func,onDropAccepted:Ne.func,onDropRejected:Ne.func,onError:Ne.func,validator:Ne.func};var Es={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function cp(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},lp),e),n=t.accept,r=t.disabled,o=t.getFilesFromEvent,i=t.maxSize,a=t.minSize,s=t.multiple,u=t.maxFiles,c=t.onDragEnter,d=t.onDragLeave,g=t.onDragOver,m=t.onDrop,f=t.onDropAccepted,v=t.onDropRejected,h=t.onFileDialogCancel,y=t.onFileDialogOpen,b=t.useFsAccessApi,w=t.autoFocus,C=t.preventDropOnDocument,E=t.noClick,x=t.noKeyboard,O=t.noDrag,I=t.noDragEventsBubbling,$=t.onError,H=t.validator,D=_.useMemo(function(){return kS(n)},[n]),G=_.useMemo(function(){return NS(n)},[n]),U=_.useMemo(function(){return typeof y=="function"?y:up},[y]),Z=_.useMemo(function(){return typeof h=="function"?h:up},[h]),k=_.useRef(null),M=_.useRef(null),F=_.useReducer(WS,Es),q=bs(F,2),P=q[0],j=q[1],A=P.isFocused,B=P.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&PS()),re=function(){!Q.current&&B&&setTimeout(function(){if(M.current){var Y=M.current.files;Y.length||(j({type:"closeDialog"}),Z())}},300)};_.useEffect(function(){return window.addEventListener("focus",re,!1),function(){window.removeEventListener("focus",re,!1)}},[M,B,Z,Q]);var ee=_.useRef([]),ce=function(Y){k.current&&k.current.contains(Y.target)||(Y.preventDefault(),ee.current=[])};_.useEffect(function(){return C&&(document.addEventListener("dragover",rp,!1),document.addEventListener("drop",ce,!1)),function(){C&&(document.removeEventListener("dragover",rp),document.removeEventListener("drop",ce))}},[k,C]),_.useEffect(function(){return!r&&w&&k.current&&k.current.focus(),function(){}},[k,w,r]);var oe=_.useCallback(function(z){$?$(z):console.error(z)},[$]),ae=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),ee.current=[].concat(LS(ee.current),[z.target]),Go(z)&&Promise.resolve(o(z)).then(function(Y){if(!(qo(z)&&!I)){var xe=Y.length,we=xe>0&&ES({files:Y,accept:D,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Fe=xe>0&&!we;j({isDragAccept:we,isDragReject:Fe,isDragActive:!0,type:"setDraggedFiles"}),c&&c(z)}}).catch(function(Y){return oe(Y)})},[o,c,oe,I,D,a,i,s,u,H]),de=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=Go(z);if(Y&&z.dataTransfer)try{z.dataTransfer.dropEffect="copy"}catch{}return Y&&g&&g(z),!1},[g,I]),ue=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=ee.current.filter(function(we){return k.current&&k.current.contains(we)}),xe=Y.indexOf(z.target);xe!==-1&&Y.splice(xe,1),ee.current=Y,!(Y.length>0)&&(j({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Go(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var xe=[],we=[];z.forEach(function(Fe){var sn=tp(Fe,D),Re=bs(sn,2),Mt=Re[0],En=Re[1],Be=np(Fe,a,i),$t=bs(Be,2),Wt=$t[0],Yn=$t[1],_e=H?H(Fe):null;if(Mt&&Wt&&!_e)xe.push(Fe);else{var ln=[En,Yn];_e&&(ln=ln.concat(_e)),we.push({file:Fe,errors:ln.filter(function(ni){return ni})})}}),(!s&&xe.length>1||s&&u>=1&&xe.length>u)&&(xe.forEach(function(Fe){we.push({file:Fe,errors:[SS]})}),xe.splice(0)),j({acceptedFiles:xe,fileRejections:we,isDragReject:we.length>0,type:"setFiles"}),m&&m(xe,we,Y),we.length>0&&v&&v(we,Y),xe.length>0&&f&&f(xe,Y)},[j,s,D,a,i,u,m,f,v,H]),Ce=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),ee.current=[],Go(z)&&Promise.resolve(o(z)).then(function(Y){qo(z)&&!I||le(Y,z)}).catch(function(Y){return oe(Y)}),j({type:"reset"})},[o,le,oe,I]),K=_.useCallback(function(){if(Q.current){j({type:"openDialog"}),U();var z={multiple:s,types:G};window.showOpenFilePicker(z).then(function(Y){return o(Y)}).then(function(Y){le(Y,null),j({type:"closeDialog"})}).catch(function(Y){OS(Y)?(Z(Y),j({type:"closeDialog"})):FS(Y)?(Q.current=!1,M.current?(M.current.value=null,M.current.click()):oe(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."))):oe(Y)});return}M.current&&(j({type:"openDialog"}),U(),M.current.value=null,M.current.click())},[j,U,Z,b,le,oe,G,s]),Ee=_.useCallback(function(z){!k.current||!k.current.isEqualNode(z.target)||(z.key===" "||z.key==="Enter"||z.keyCode===32||z.keyCode===13)&&(z.preventDefault(),K())},[k,K]),We=_.useCallback(function(){j({type:"focus"})},[]),qe=_.useCallback(function(){j({type:"blur"})},[]),It=_.useCallback(function(){E||(AS()?setTimeout(K,0):K())},[E,K]),st=function(Y){return r?null:Y},S=function(Y){return x?null:st(Y)},N=function(Y){return O?null:st(Y)},V=function(Y){I&&Y.stopPropagation()},ne=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,xe=Y===void 0?"ref":Y,we=z.role,Fe=z.onKeyDown,sn=z.onFocus,Re=z.onBlur,Mt=z.onClick,En=z.onDragEnter,Be=z.onDragOver,$t=z.onDragLeave,Wt=z.onDrop,Yn=Ko(z,MS);return De(De(Cs({onKeyDown:S(kt(Fe,Ee)),onFocus:S(kt(sn,We)),onBlur:S(kt(Re,qe)),onClick:st(kt(Mt,It)),onDragEnter:N(kt(En,ae)),onDragOver:N(kt(Be,de)),onDragLeave:N(kt($t,ue)),onDrop:N(kt(Wt,Ce)),role:typeof we=="string"&&we!==""?we:"presentation"},xe,k),!r&&!x?{tabIndex:0}:{}),Yn)}},[k,Ee,We,qe,It,ae,de,ue,Ce,x,O,r]),J=_.useCallback(function(z){z.stopPropagation()},[]),X=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,xe=Y===void 0?"ref":Y,we=z.onChange,Fe=z.onClick,sn=Ko(z,$S),Re=Cs({accept:D,multiple:s,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:st(kt(we,Ce)),onClick:st(kt(Fe,J)),tabIndex:-1},xe,M);return De(De({},Re),sn)}},[M,n,s,Ce,r]);return De(De({},P),{},{isFocused:A&&!r,getRootProps:ne,getInputProps:X,rootRef:k,inputRef:M,open:st(K)})}function WS(e,t){switch(t.type){case"focus":return De(De({},e),{},{isFocused:!0});case"blur":return De(De({},e),{},{isFocused:!1});case"openDialog":return De(De({},Es),{},{isFileDialogActive:!0});case"closeDialog":return De(De({},e),{},{isFileDialogActive:!1});case"setDraggedFiles":return De(De({},e),{},{isDragActive:t.isDragActive,isDragAccept:t.isDragAccept,isDragReject:t.isDragReject});case"setFiles":return De(De({},e),{},{acceptedFiles:t.acceptedFiles,fileRejections:t.fileRejections,isDragReject:t.isDragReject});case"reset":return De({},Es);default:return e}}function up(){}const qS=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=cp({noClick:!0,onDrop:a=>{if(a&&a.length>0)if(a[0].path.split("/").length>2){const u=a.map(c=>{const g=(c.path||c.relativePath||"").split("/").slice(1).join("/");return(!c.webkitRelativePath||c.webkitRelativePath==="")&&Object.defineProperty(c,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),c});e(u,"folder")}else e(a,"files");r(!1)},onDragOver:a=>{a.preventDefault(),n||r(!0)},multiple:!0});return _.useEffect(()=>{const a=s=>{s.clientX===0&&s.clientY===0&&r(!1)};return document.addEventListener("dragleave",a),()=>{document.removeEventListener("dragleave",a)}},[]),l.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?l.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"}):t,l.jsx("input",{...i()})]})},GS=({openDialogRename:e,setOpenDialogRename:t,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:i,ignoreCache:a})=>{var w;const[s,u]=_.useState({}),[c,d]=_.useState(!1),[g,m]=_.useState(!1),[f,v]=_.useState(""),{toast:h}=ko();_.useEffect(()=>{e&&y(f)},[f,e]);const y=async C=>{try{m(!0);const E=await me.get(`${n}/api/list-s3-folders?prefix=${C}`);u(E==null?void 0:E.data)}catch{h({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{m(!1)}},b=async()=>{d(!0);try{const C=o.key,E=C.endsWith("/")?C:`${C}/`,x=f.endsWith("/")?f:`${f}/`;if(E===x||C===f){h({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),d(!1);return}await me.post(`${n}/api/move`,{oldPath:C,newPath:f}),a.current=!0,await i(),h({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${f}"`}),t(!1),r(null),v("")}catch(C){console.error("Error renaming item:",C),h({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{d(!1)}};return l.jsx(jt,{open:e,onOpenChange:C=>{C||(t(!1),r(null),v(""))},children:l.jsxs(St,{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:[l.jsxs(Et,{className:"mb-4 w-full h-full",children:[l.jsx("nav",{className:"mb-4",children:l.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>v(""),children:"Root"}),f.split("/").map((C,E,x)=>l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>v(C==="Root"?"":x.slice(0,E+1).join("/")+"/"),children:C},E))]})}),l.jsxs(_t,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",l.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",f===""?"Root":f," )"]})]}),l.jsx(Rn,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:g?l.jsx("div",{className:"flex justify-center items-center py-4",children:l.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):l.jsx("ul",{className:"space-y-2",children:(w=Object.keys(s))==null?void 0:w.map(C=>l.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>v(C),children:C},C))})})]}),l.jsxs(hn,{className:"flex justify-end space-x-2",children:[l.jsx(ve,{variant:"outline",onClick:()=>t(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),l.jsx(ve,{onClick:b,disabled:c,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},KS="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",YS="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",XS="https://www.googleapis.com/auth/drive";Kt(me,{retries:3});const Qe={current:!1},dp="crawl:jobs",Gn="crawl:current_job",JS=e=>{const[t,n]=_.useState(null),[r,o]=_.useState(0);return _.useEffect(()=>{const i=localStorage.getItem(Gn);if(i){const a=JSON.parse(i);n(a),a!=null&&a.startTime&&o(Math.floor((Date.now()-a.startTime)/1e3))}},[]),_.useEffect(()=>{if(!(t!=null&&t.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-t.startTime)/1e3))},1e3);return()=>clearInterval(i)},[t==null?void 0:t.startTime]),_.useEffect(()=>{if(!(t!=null&&t.id))return;const i=async()=>{try{const u=(await me.get(`${e}/api/crawl/${t.id}?taskId=${t.taskId}`)).data;n(c=>{if(!c)return null;const d={...c,status:u};return localStorage.setItem(Gn,JSON.stringify(d)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Gn)},100),d})}catch(s){console.error("Error polling job status:",s)}},a=setInterval(i,3e3);return i(),()=>clearInterval(a)},[t==null?void 0:t.id,e]),{currentJob:t,elapsedTime:r,setCurrentJob:i=>{i&&!i.startTime&&(i.startTime=Date.now()),n(i),i?localStorage.setItem(Gn,JSON.stringify(i)):localStorage.removeItem(Gn)}}},Yo=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},ZS=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Yo(e,o.key))}),n},QS=(e,t,n=[],r,o,i)=>{const[a,s]=_.useState({}),[u,c]=_.useState(!1),[d,g]=_.useState(null),[m,f]=_.useState(0),v=_.useRef(t);_.useEffect(()=>{v.current=t},[t]);const h=async()=>{c(!0);try{const b=await me.get(`${e}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:v.current},timeout:3e5});s(b.data),g(null)}catch(b){g(b instanceof Error?b:new Error("Failed to fetch files"))}finally{c(!1),f(0),i("")}},y=async b=>{var w,C;try{if(!b)return;c(!0);const E=await me.get(`${e}/api/search-db?query=${b}&rootPrefix=${t}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return s({[t]:((w=E==null?void 0:E.data)==null?void 0:w.result)||[]}),f(((C=E==null?void 0:E.data)==null?void 0:C.estimatedTotalHits)||0),E}catch(E){g(E instanceof Error?E:new Error("Failed to fetch files"))}finally{c(!1)}};return _.useEffect(()=>{!r&&!u&&h(),r&&!u&&y(r)},[r,o]),{data:a,isLoading:u,error:d,estimatedTotalHits:m,refetch:h}},br=e=>{var r,o,i;const t=((i=(o=(r=e==null?void 0:e.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:i.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(t||"")},eE=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="https://vib-s3-explorer.cmcts1.studio.ai.vn",rootPrefix:n="",asSelector:r=!1,onSelected:o=s=>console.log("Đã chọn:",s),displayPrefixes:i,preSelectedFiles:a})=>{var Lp;const[s,u]=_.useState([]),[c,d]=_.useState(""),[g,m]=_.useState(new Set(a)),[f,v]=_.useState(n),[h,y]=_.useState(""),[b,w]=_.useState(!1),[C,E]=_.useState(""),[x,O]=_.useState(!1),[I,$]=_.useState(null),[H,D]=_.useState(null),[G,U]=_.useState(!1),[Z,k]=_.useState(!1),[M,F]=_.useState(null),q=_.useRef(null),{toast:P}=ko(),[j,A]=_.useState(null),[B,Q]=_.useState(null),[re,ee]=_.useState(""),[ce,oe]=_.useState(!1),[ae,de]=_.useState(!1),[ue,le]=_.useState(new Set),[Ce,K]=_.useState(""),[Ee,We]=_.useState(!1),[qe,It]=_.useState(!1),[st,S]=_.useState("rename"),[N,V]=_.useState(!1),[ne,J]=_.useState(""),[X,z]=_.useState("1"),[Y,xe]=_.useState(!1),[we,Fe]=_.useState(!1),[sn,Re]=_.useState(!1),[Mt,En]=_.useState(!1),[Be,$t]=_.useState(1),[Wt,Yn]=_.useState(!1),{currentJob:_e,elapsedTime:ln,setCurrentJob:ni}=JS(t),[cn,_r]=_.useState(null),[Tr,ri]=_.useState(""),[TE,Ar]=_.useState(!1),[Ds,Fp]=_.useState(!1),[AE,PE]=_.useState(""),NE=new URL(window.location.href).searchParams.get("prefix")||""||h||n,[w_,kE]=_.useState(null),{data:Lt,isLoading:Pr,error:OE,estimatedTotalHits:Nr,refetch:tt}=QS(t,NE,i,c,Be,d),FE=og({onSuccess:T=>{kE(T.access_token),localStorage.setItem("google_access_token",T.access_token),DE(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:XS}),DE=T=>{const L=document.createElement("script");L.src="https://apis.google.com/js/api.js",L.onload=()=>{window.gapi.load("picker",()=>IE(T))},document.body.appendChild(L)},IE=T=>{const L=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),W=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(KS).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(L).addView(W).setCallback(async ie=>{if(ie.action===window.google.picker.Action.PICKED){const ge=ie.docs.map(Se=>({id:Se.id,name:Se.name,mimeType:Se.mimeType}));await ME(ge,f)}}).build().setVisible(!0)},ME=async(T,L="")=>{const W=localStorage.getItem("google_access_token");if(!W){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),Pe.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const te=Pe.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:L,folders:[],files:[]};T.forEach(Se=>{Se.mimeType==="application/vnd.google-apps.folder"?ie.folders.push({id:Se.id,name:Se.name}):ie.files.push({id:Se.id,name:Se.name})});const ge=await me.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${W}`}});Qe.current=!0,tt(),Pe.update(te,{render:`Đồng bộ thành công! Đã tải lên ${ge.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(ie){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",ie),Pe.update(te,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const T=L=>{if(L.data.action==="logout"){const W=document.createElement("iframe");W.style.display="none",W.src="https://accounts.google.com/Logout",document.body.appendChild(W),setTimeout(()=>document.body.removeChild(W),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),_.useEffect(()=>{const T=new Set(a);m(T)},[]),_.useEffect(()=>{_e!=null&&_e.status&&(_e.status.status==="completed"?(P({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${_e.url} với ${_e.status.completed} trang`}),Qe.current=!0,tt()):_e.status.status==="failed"&&P({title:"Thu thập website thất bại",description:`Không thể thu thập ${_e.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(Lp=_e==null?void 0:_e.status)==null?void 0:Lp.status]);const Dp=_.useMemo(()=>Lt[f]||[],[Lt,f]),un=_.useMemo(()=>Dp,[Dp,f,Lt]),kr=_.useMemo(()=>{const T={};return un.forEach((L,W)=>{g.has(L.key)&&(T[W]=!0)}),T},[g,un]),$E=T=>{const L=Yo(Lt,T);if(L.length===0)return g.has(T)?"all":"none";const W=L.filter(te=>g.has(te)).length;return W===0?"none":W===L.length?"all":"partial"},Xn=(T,L=!0)=>{if(console.log("🚀 ~ Home.tsx:620 ~ handleFolderClick ~ currentPrefix:",{currentPrefix:f,prefix:T,forcePrefix:h}),f!==T&&(Yn(!0),y(T),v(T),a||m(new Set),L)){const W=window.location.pathname==="/"?"":window.location.pathname,te=T?`${window.location.origin}${W}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${W}`;window.history.pushState({path:te},"",te)}};_.useEffect(()=>{Wt&&(Qe.current=!0,tt().finally(()=>Yn(!1)))},[Wt]);const LE=async(T,L)=>{var W,te;O(!0);try{if(un.some(Ye=>Ye.isFolder&&Ye.name.toLowerCase()===T.toLowerCase())){P({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),O(!1);return}const ge=`${L}${T}/`;if((await me.post(`${t}/api/create-folder`,{prefix:ge})).status!==200){P({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qe.current=!0,await tt(),P({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),E(""),w(!1)}catch(ie){console.error("Error creating folder:",ie);const ge=((te=(W=ie==null?void 0:ie.response)==null?void 0:W.data)==null?void 0:te.error)||"Không thể tạo thư mục";P({title:"Lỗi",description:ge,variant:"destructive"})}finally{O(!1)}},Is=async(T,L,W)=>{var te,ie,ge,Se,Ye,Jn,Rp,Vp,jp;F(W),Re(!0);try{if(Array.from(T).reduce((Xe,Dr)=>Xe+Dr.size,0)>=100*1024*1024){P({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),F(null),Re(!1);return}const ii=Array.from(T).filter(Xe=>Xe.size===0);if(ii.length>0){const Xe=ii.map(Dr=>Dr.name).join(", ");P({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Xe}`,variant:"destructive"}),Re(!1),F(null);return}let Fr=localStorage.getItem("dataLogin"),Zn;try{Fr&&(Fr=JSON.parse(Fr),Zn=Fr.user)}catch{Fr=null}const _n=new FormData;if(Zn!=null&&Zn.id&&_n.append("metadata",JSON.stringify({creator:Zn.username,creatorId:Zn.id,DataSource:"Tệp tải lên"})),W==="folder"&&T[0]){const Xe=T[0].webkitRelativePath.split("/")[0];Xe&&_n.append("folderName",Xe)}_n.append("prefix",L),Array.from(T).forEach(Xe=>W==="folder"?_n.append("files",Xe,Xe.webkitRelativePath):_n.append("files",Xe)),Qe.current=!0;const ze=await me.post(`${t}/api/check-files-existed`,_n,{headers:{"Content-Type":"multipart/form-data"}});if(((te=ze==null?void 0:ze.data)==null?void 0:te.status)===200)await me.post(`${t}/api/upload`,_n,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(L),setTimeout(async()=>{F(null),await tt(),Re(!1)},500);else{if(((ge=(ie=ze==null?void 0:ze.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Se=ze==null?void 0:ze.data)!=null&&Se.isFolder)){const Xe=Array.from(T).filter(Dr=>ze.data.names.includes(Dr.name));_r(Xe),Ar(!0)}(Ye=ze==null?void 0:ze.data)!=null&&Ye.isFolder&&((Jn=ze==null?void 0:ze.data)!=null&&Jn.name)&&(ri((Rp=ze==null?void 0:ze.data)==null?void 0:Rp.name),_r(T),Ar(!0))}}catch(Or){console.error("Lỗi tải lên:",Or);const ii=((jp=(Vp=Or==null?void 0:Or.response)==null?void 0:Vp.data)==null?void 0:jp.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:ii,variant:"destructive"}),F(null),Re(!1)}},RE=async()=>{var T,L;try{Re(!0);const W=new FormData;if(cn){F(Tr?"folder":"files"),Ar(!1);let te=localStorage.getItem("dataLogin"),ie;try{te&&(te=JSON.parse(te),ie=te.user)}catch{te=null}if(ie!=null&&ie.id&&(console.log("🚀 ~ uploadFiles ~ user:",ie),W.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"}))),Tr&&cn[0]){const ge=cn[0].webkitRelativePath.split("/")[0];ge&&W.append("folderName",ge)}W.append("prefix",f),Array.from(cn).forEach(ge=>Tr&&cn[0]?W.append("files",ge,ge.webkitRelativePath):W.append("files",ge)),ie!=null&&ie.id&&W.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"})),await me.post(`${t}/api/upload`,W,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(f),Qe.current=!0}}catch(W){console.error("Lỗi tải lên:",W);const te=((L=(T=W==null?void 0:W.response)==null?void 0:T.data)==null?void 0:L.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:te,variant:"destructive"})}finally{setTimeout(async()=>{F(null),await tt(),Re(!1),ri(""),_r(null)},500)}},VE=async T=>{var L;try{if(await me.delete(`${t}/api/files`,{data:{paths:[T.key]}}),g.has(T.key)){const te=new Set(g);te.delete(T.key),m(te)}const W=((L=T.key)==null?void 0:L.replace(/^(.*?)(\/.*)?$/,(te,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";y(W),Qe.current=!0,P({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),$(null)}catch(W){console.error("Error deleting file:",W),P({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{En(!1),await tt()}},oi=T=>{const L=new Set(g),W=typeof T=="function"?T(kr):T;new Set(Object.keys(kr).map(Number)).forEach(ie=>{const ge=un[ie];ge&&(W[ie]||(L.delete(ge.key),ge.isFolder&&Yo(Lt,ge.key).forEach(Se=>L.delete(Se))))}),Object.entries(W).forEach(([ie,ge])=>{const Se=parseInt(ie),Ye=un[Se];Ye&&ge&&(L.add(Ye.key),Ye.isFolder&&Yo(Lt,Ye.key).forEach(Jn=>L.add(Jn)))}),m(L)},jE=async()=>{var T;U(!0);try{const L=Array.from(g),W=L.map(ie=>Object.values(Lt).flat().find(ge=>ge.key===ie)).filter(ie=>ie!==void 0);if(W.length===0){P({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await me.delete(`${t}/api/files`,{data:{paths:L}});const te=((T=W[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Se)=>!Se||Se==="/"?"":ge+"/"))||"";y(te),Qe.current=!0,tt(),P({title:"Đã xóa tập tin",description:`Đã xóa thành công ${W.length} mục`}),k(!1),m(new Set)}catch(L){console.error("Error deleting files:",L),P({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{U(!1)}},zE=async(T,L)=>{if(!f.trim()){P({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}de(!0);try{const W=T.key;let te;T.isFolder?te=W.split("/").slice(0,-2).join("/")+"/":te=W.substring(0,W.lastIndexOf("/")+1);const ie=te+L+(T.isFolder?"/":"");await me.post(`${t}/api/rename`,{oldPath:W,newPath:ie}),Qe.current=!0,await tt(),P({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${L}"`}),A(null),ee(""),Q(null)}catch(W){console.error("Error renaming item:",W),P({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{de(!1)}},Ip=async T=>{le(L=>new Set([...L,...T]));try{const L=await me.post(`${t}/api/download`,{paths:T},{responseType:"blob"}),W=window.URL.createObjectURL(L.data),te=document.createElement("a");te.href=W;const ie=L.headers["Content-Disposition"]||L.headers["content-disposition"],ge=ie==null?void 0:ie.match(/filename="(.+)"/),Se=ge?decodeURIComponent(ge[1]):"download.zip";te.setAttribute("download",Se),document.body.appendChild(te),te.click(),document.body.removeChild(te),window.URL.revokeObjectURL(W),P({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(L){console.error("Error downloading files:",L),P({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{le(L=>{const W=new Set(L);return T.forEach(te=>W.delete(te)),W})}},Mp=f?f.replace(n,"").split("/").filter(Boolean):[],BE=()=>Array.from(g).map(T=>{var L;for(const W in Lt){const te=(L=Lt[W])==null?void 0:L.find(ie=>ie.key===T);if(te)return te}return null}).filter(T=>T!==null),$p=_.useMemo(()=>{const T=[{id:"select",header:()=>{const L=ZS(Lt,f),W=L.length>0&&L.every(ie=>g.has(ie)),te=L.some(ie=>g.has(ie));return l.jsx(na,{checked:W?!0:te?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=un.reduce((Se,Ye,Jn)=>(Se[Jn]=!0,Se),{});oi(ge)}else oi({})},"aria-label":"Chọn tất cả"})},cell:({row:L})=>{const W=L.original,ie=W.isFolder?$E(W.key):g.has(W.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(na,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Se={...kr};ge?Se[L.index]=!0:delete Se[L.index],oi(Se)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Bi,{})]}),accessorKey:"name",cell:({row:L})=>{const W=L.original,te=W.key.substring(0,W.key.lastIndexOf("/"))||"/",ie=c.trim()!==""&&te!==f,ge=te.split("/").filter(Boolean);return l.jsxs("div",{className:"flex flex-col",children:[l.jsxs("div",{className:`flex items-center gap-2 ${W.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{W.isFolder&&(a||m(new Set),Xn(W.key))},children:[W.isFolder?l.jsx(li,{className:"h-5 w-5 text-blue-500"}):null,W.name]}),ie&&l.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[l.jsx(li,{className:"h-4 w-4 text-gray-500 my-auto"}),l.jsxs("span",{className:"flex items-center ml-1",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn("")},children:"/"}),ge.map((Se,Ye)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn(ge.slice(0,Ye+1).join("/")+"/")},children:Se}),Ye<ge.length-1&&l.jsx("span",{children:"/"})]},Ye))]})]})]})}}];return r||T.push({id:"size",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Bi,{})]}),accessorKey:"size",cell:({getValue:L,row:W})=>{const te=L();return l.jsx("span",{children:W.original.isFolder?"-":Fv(te)})}},{id:"lastModified",header:({column:L})=>l.jsxs(ve,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",l.jsx(Bi,{})]}),accessorKey:"lastModified",cell:({row:L})=>{const W=L.original.lastModified;return l.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:l.jsx("span",{children:W&&Wl(W).isValid()?Wl(W).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>l.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:L})=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>Ip([L.original.key]),className:"h-8 w-8 p-0",disabled:ue.has(L.original.key),children:ue.has(L.original.key)?l.jsx($e,{className:"h-4 w-4 animate-spin"}):l.jsx(Vs,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Tải xuống"})]})}),f.trim()!==""&&l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>{A(L.original),ee(L.original.name)},className:"h-8 w-8 p-0",children:l.jsx(Jp,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Đổi tên"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>{oe(!0),D(L.original)},className:"h-8 w-8 p-0",children:l.jsx(Dh,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Di chuyển"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ve,{variant:"ghost",size:"icon",onClick:()=>$(L.original),className:"h-8 w-8 p-0",children:l.jsx(js,{className:"h-4 w-4"})})}),l.jsx(on,{children:"Xóa"})]})})]})}),T},[g,un,kr,ue,r]),Ms=el({data:un,columns:$p,state:{rowSelection:kr,sorting:s},onSortingChange:u,enableRowSelection:!0,onRowSelectionChange:oi,getCoreRowModel:Qs(),getSortedRowModel:Lg()}),HE=async T=>{var L,W;We(!0);try{if(br(T)){const te=await me.get(`${t}/api/read-text`,{params:{path:T.key}});K(te.data.content)}try{const te=await me.get(`${t}/api/read-json`,{params:{path:T.key+".metadata.json"}}),ie=((W=(L=te==null?void 0:te.data)==null?void 0:L.content)==null?void 0:W.metadataAttributes)||null;return Q({fullPath:j==null?void 0:j.key,...ie})}catch{return Q("Lỗi phân tích siêu dữ liệu")}}catch(te){console.error("Error loading file content:",te),P({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{We(!1)}},UE=async(T,L)=>{It(!0);try{await me.post(`${t}/api/modify-text`,{path:T.key,content:L}),P({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await tt(),A(null),K(""),S("rename")}catch(W){console.error("Error saving file content:",W),P({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{It(!1)}},WE=async T=>{It(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",B),await me.post(`${t}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:B}}),P({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await tt(),A(null),K(""),S("rename")}catch(L){console.error("Error saving file content:",L),P({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{It(!1)}};_.useEffect(()=>{j&&(j.isFolder||HE(j),S("rename"))},[j]);const qE=async(T,L)=>{var W;if(_e){P({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}xe(!0);try{const{data:te}=await me.post(`${t}/api/crawl`,{url:T,limit:L,prefix:f});if(te.id){ni({id:te.id,url:T,limit:L,prefix:f,taskId:((W=te.task)==null?void 0:W.id)||""});const ie=localStorage.getItem(dp),ge=ie?JSON.parse(ie):[];ge.some(Se=>Se.id===te.id)||(ge.unshift({url:T,id:te.id,limit:L,prefix:f,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(dp,JSON.stringify(ge))),P({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${L}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),V(!1),J(""),z("1")}}catch(te){console.error("Error crawling website:",te),P({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{xe(!1)}},GE=async()=>{try{if(!(_e!=null&&_e.id))return;ni(null),localStorage.removeItem(Gn),P({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${_e.url}`})}catch(T){console.error("Error stopping job:",T),P({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const T=(L=!0)=>{const te=new URL(window.location.href).searchParams.get("prefix")||"";te?Xn(te,!1):(L&&!a&&m(new Set),y(n),v(n),Qe.current=!0,setTimeout(()=>{tt()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const KE=async()=>{Fp(!0);try{const T=await me.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",T),P({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),P({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Fp(!1)}},YE=async()=>{try{const T=await me.post(`${t}/api/start-ingestion-job`,{prefix:f});T.status===200&&(console.log("🚀 ~ Home.tsx:1744 ~ handleSyncKnowledgeBase ~ response:",T),await Ls())}catch(T){console.log(T)}},$s=_.useRef(),Ls=async()=>{try{const T=await me.post(`${t}/api/get-ingestion-job-status`,{prefix:f});(T==null?void 0:T.data)==="FAILED"||(T==null?void 0:T.data)==="COMPLETE"||(T==null?void 0:T.data)==="STOPPED"||(T==null?void 0:T.data)==="STOPPING"||!(T!=null&&T.data)?(Fe(!1),$s.current&&clearInterval($s.current)):(Fe(!0),$s.current=setInterval(()=>Ls(),5e3))}catch(T){console.log(T)}};return _.useEffect(()=>{const T=f==null?void 0:f.split("/")[0];return T&&(PE(T),f&&Ls()),()=>{}},[AE,f]),l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(Sd,{}),l.jsx(jt,{open:TE,onOpenChange:T=>{Ar(T),T||(ri(""),_r(null),Re(!1),F(null))},children:l.jsxs(St,{children:[l.jsxs(Et,{children:[l.jsx(_t,{children:"Cảnh báo trùng lặp"}),l.jsxs(Rn,{children:[Tr&&l.jsxs(l.Fragment,{children:["Folder $",Tr," đã có."]}),cn&&cn.length>0&&l.jsxs(l.Fragment,{children:["Những tệp sau bị lặp:",l.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(cn).map((T,L)=>l.jsx("li",{children:T.name},L))})]})]})]}),l.jsxs(hn,{children:[l.jsx(ve,{variant:"outline",onClick:()=>{Ar(!1),ri(""),_r(null),Re(!1),F(null)},children:"Bỏ qua"}),l.jsx(ve,{variant:"destructive",onClick:()=>RE(),children:"Ghi đè"})]})]})}),l.jsx(uc,{className:"s3-explr-breadcrumb",children:l.jsxs(dc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(Ji,{className:"s3-explr-breadcrumb-item",children:l.jsx(Zi,{onClick:()=>Xn(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),Mp.map((T,L)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(fc,{className:"s3-explr-breadcrumb-separator"},`sep-${L}`),l.jsx(Ji,{className:"s3-explr-breadcrumb-item",children:l.jsx(Zi,{onClick:()=>Xn(n+Mp.slice(0,L+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},L))]})}),l.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[l.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:l.jsx(HC,{ref:q,onChange:T=>d(T)})}),l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{y(f),Qe.current=!0,tt()},disabled:Pr,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Pr?"animate-spin":""}`}),"Làm mới"]}),f&&f!=="/"&&l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{Fe(!0),YE()},disabled:Pr||we,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Pr||we?"animate-spin":""}`}),"Đồng bộ KB"]}),!r&&l.jsxs(l.Fragment,{children:[g.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>Ip(Array.from(g)),disabled:Array.from(g).some(T=>ue.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(g).some(T=>ue.has(T))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(Vs,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",g.size,")"]}),l.jsxs(jt,{open:Z,onOpenChange:k,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx(js,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",g.size,")"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),l.jsxs(Rn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",g.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>k(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{variant:"destructive",onClick:jE,disabled:G,className:"s3-explr-confirm-delete-btn",children:G?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),l.jsxs(jt,{open:b,onOpenChange:w,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!f,children:[l.jsx(qp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsx(Et,{className:"s3-explr-dialog-header",children:l.jsx(_t,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),l.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),l.jsx(en,{disabled:x,id:"name",value:C,onChange:T=>E(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ve,{onClick:()=>{C.trim()&&LE(C,f)},disabled:x,className:"s3-explr-create-btn",children:[x&&l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),x?"Đang tạo...":"Tạo"]})]})]})]}),l.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[l.jsx(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-files-btn",onClick:()=>{const T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=L=>{const W=L.target.files;W&&Is(W,f,"files")},T.click()},disabled:M!==null||!!i&&!f,children:M==="files"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang xử lý..."]}):l.jsxs(l.Fragment,{children:[l.jsx(Up,{className:"h-4 w-4 s3-explr-upload-icon"}),"Tải lên tập tin"]})}),l.jsx(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-folder-btn",onClick:()=>{const T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=L=>{const W=L.target.files;W&&Is(W,f,"folder")},T.click()},disabled:M!==null||!!i&&!f,children:M==="folder"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang tải lên..."]}):l.jsxs(l.Fragment,{children:[l.jsx(li,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),_e?l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[l.jsx($e,{className:"h-4 w-4 animate-spin s3-explr-loader"}),_e.status?l.jsxs(l.Fragment,{children:[_e.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",_e.status.completed,"/",_e.status.total,") -"," ",Math.floor(ln/60),":",String(ln%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ve,{variant:"destructive",size:"sm",onClick:()=>void GE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(Qp,{className:"h-4 w-4"})]})]})}),_e.status&&l.jsx(on,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",_e.url]}),l.jsxs("p",{children:["Tiến độ: ",_e.status.completed,"/",_e.status.total," trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(ln/60),":",String(ln%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",_e.status.status==="scraping"?"Đang thu thập":_e.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):l.jsxs(jt,{open:N,onOpenChange:V,children:[l.jsx(uo,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,children:[l.jsx(Yp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Thêm website"}),l.jsx(Rn,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),l.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),l.jsx(en,{id:"websiteUrl",value:ne,onChange:T=>J(T.target.value),placeholder:"https://example.com",type:"url",disabled:Y,className:"s3-explr-input"})]}),l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),l.jsx(en,{id:"crawlLimit",value:X,onChange:T=>{const L=T.target.value;/^\d*$/.test(L)&&z(L)},placeholder:"1",type:"text",disabled:Y,className:"s3-explr-input"}),l.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)"})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>{V(!1),J(""),z("1")},disabled:Y,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{onClick:()=>{ne.trim()&&qE(ne.trim(),parseInt(X)||1)},disabled:Y||!ne.trim(),className:"s3-explr-crawl-btn",children:Y?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),f.startsWith("BKTTW/")&&l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsxs(ve,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,onClick:KE,children:[Ds&&l.jsx(si,{className:`h-4 w-4 s3-explr-refresh-icon ${Ds?"animate-spin":""}`}),"Xuất báo cáo"]})}),Ds&&l.jsx(on,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>FE(),className:"flex items-center gap-2",children:[l.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",children:[l.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"}),l.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"}),l.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"}),l.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"}),l.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"}),l.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"]})}),l.jsx(jt,{open:!!I,onOpenChange:T=>!T&&$(null),children:l.jsxs(St,{className:"s3-explr-dialog-content",children:[l.jsxs(Et,{className:"s3-explr-dialog-header",children:[l.jsx(_t,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),l.jsxs(Rn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",I==null?void 0:I.name,"? Hành động này không thể hoàn tác."]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>$(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ve,{variant:"destructive",onClick:()=>VE(I),disabled:Mt,className:"s3-explr-confirm-delete-btn",children:Mt?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),l.jsx(jt,{open:!!j,onOpenChange:T=>{T||(A(null),Q(null),ee(""),K(""),S("rename"))},children:l.jsxs(St,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(Et,{className:"s3-explr-dialog-header",children:l.jsx(_t,{className:"s3-explr-dialog-title",children:j!=null&&j.isFolder?"Đổi tên thư mục":br(j)?"Quản lý tập tin":"Đổi tên tập tin"})}),j&&l.jsxs(ab,{value:st,onValueChange:T=>S(T),children:[l.jsxs(Xu,{"aria-checked":!br(j),"aria-disabled":j.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[l.jsx(So,{value:"rename",children:"Đổi tên"}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(So,{value:"edit",children:"Sửa nội dung"}),l.jsx(So,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Eo,{value:"rename",children:l.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:l.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[l.jsx(vn,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),l.jsx(en,{id:"newName",value:re,onChange:T=>ee(T.target.value),placeholder:"Nhập tên mới",disabled:ae,className:"s3-explr-input"})]})})}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(Eo,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:Ee?l.jsx("div",{className:"flex items-center justify-center py-4",children:l.jsx($e,{className:"h-6 w-6 animate-spin"})}):l.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[l.jsx(vn,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),l.jsx(ur,{id:"content",value:Ce,onChange:T=>K(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:qe})]})})}),l.jsx(Eo,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:Ee?l.jsx("div",{className:"flex items-center justify-center py-4",children:l.jsx($e,{className:"h-6 w-6 animate-spin"})}):l.jsx("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:B&&typeof B=="object"&&Object.entries(B).map(([T,L],W)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(vn,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[Yh[T]||T,qi(T)&&l.jsx(Ih,{className:"h-[12px] w-[12px] text-red-500"})]}),Xh(T)?l.jsx(ur,{id:T,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[T]:te.target.value};Q(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:qe||qi(T)}):l.jsx(en,{id:T,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[T]:te.target.value};Q(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:qe||qi(T)})]},W))})})})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ve,{variant:"outline",onClick:()=>{A(null),Q(null),ee(""),K("")},className:"s3-explr-cancel-btn",children:"Hủy"}),st==="edit"?l.jsx(ve,{onClick:()=>j&&UE(j,Ce),disabled:qe||Ee,className:"s3-explr-save-btn",children:qe?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):st==="edit-metadata"?l.jsx(ve,{onClick:()=>B&&typeof B=="object"&&j&&WE(j),disabled:qe||Ee,className:"s3-explr-save-btn",children:qe?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):l.jsx(ve,{onClick:()=>{re.trim()&&j&&zE(j,re.trim())},disabled:ae||!re.trim()||re.trim()===(j==null?void 0:j.name),className:"s3-explr-rename-btn",children:ae?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),H&&ce&&l.jsx(GS,{openDialogRename:ce,setOpenDialogRename:oe,apiBaseUrl:t,setFileToMove:D,fileToMove:H,refreshFiles:tt,ignoreCache:Qe})]})]}),OE&&l.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"}),l.jsx(qS,{onFilesSelected:(T,L)=>Is(T,f,L),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(vo,{className:"s3-explr-table",children:[l.jsx(yo,{className:"s3-explr-table-header",children:Ms.getHeaderGroups().map(T=>l.jsx(ht,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(L=>l.jsx(Tt,{className:"s3-explr-header-cell",children:L.isPlaceholder?null:Vr(L.column.columnDef.header,L.getContext())},L.id))},T.id))}),l.jsx(xo,{className:"s3-explr-table-body",children:Ms.getRowModel().rows.length===0?l.jsx(ht,{className:"s3-explr-empty-row",children:l.jsx(Ze,{colSpan:$p.length,className:"h-24 text-center s3-explr-empty-cell",children:c?l.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 "',c,'"']}):l.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:Pr?"Đ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"})})}):Ms.getRowModel().rows.map(T=>l.jsx(ht,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(L=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Vr(L.column.columnDef.cell,L.getContext())},L.id))},T.id))})]})})}),c&&Nr!==0&&l.jsx(l.Fragment,{children:l.jsx(fo,{children:l.jsxs(po,{children:[l.jsx(go,{onClick:()=>$t(T=>Math.max(T-1,1)),"aria-disabled":Be===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Nr/20)},(T,L)=>{const W=L+1,te=Math.ceil(Nr/20);return te>7&&!(W===1||W===te||W>=Be-1&&W<=Be+1)?W===Be-2&&Be>4||W===Be+2&&Be<te-3?l.jsx(ho,{className:"pointer-events-none",children:"..."},L):null:l.jsx(mt,{className:"cursor-pointer",children:l.jsx(Vn,{isActive:Be===W,onClick:()=>$t(W),className:`${Be===W?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:W})},L)}),l.jsx(mt,{children:l.jsx(mo,{onClick:()=>$t(T=>Math.min(T+1,Math.ceil(Nr/20))),"aria-disabled":Be===Math.ceil(Nr/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),r&&o&&l.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[l.jsxs("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:[g.size," ",(g.size===1,"tập tin")," đã chọn"]}),l.jsx(ve,{variant:"default",onClick:()=>o(BE()),disabled:g.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),tE=e=>l.jsx(ng,{clientId:YS,children:l.jsx(eE,{...e})});var wr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Ke=e=>e==null;const fp=e=>typeof e=="object";var Me=e=>!Ke(e)&&!Array.isArray(e)&&fp(e)&&!Sn(e),nE=e=>Me(e)&&e.target?wr(e.target)?e.target.checked:e.target.value:e,rE=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,oE=(e,t)=>e.has(rE(t)),iE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},_s=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ut(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(_s&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!iE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ut(e[o]));else return e;return t}var Xo=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,se=(e,t,n)=>{if(!t||!Me(e))return n;const r=Xo(t.split(/[,[\].]+?/)).reduce((o,i)=>Ke(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Ot=e=>typeof e=="boolean",Ts=e=>/^\w*$/.test(e),pp=e=>Xo(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Oe=(e,t,n)=>{let r=-1;const o=Ts(t)?[t]:pp(t),i=o.length,a=i-1;for(;++r<i;){const s=o[r];let u=n;if(r!==a){const c=e[s];u=Me(c)||Array.isArray(c)?c:isNaN(+o[r+1])?{}:[]}if(s==="__proto__"||s==="constructor"||s==="prototype")return;e[s]=u,e=e[s]}return e};const gp={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},xt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Ut={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};_.createContext(null);var aE=(e,t,n,r=!0)=>{const o={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(o,i,{get:()=>{const a=i;return t._proxyFormState[a]!==xt.all&&(t._proxyFormState[a]=!r||xt.all),e[a]}});return o},et=e=>Me(e)&&!Object.keys(e).length,sE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return et(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===xt.all)},Jo=e=>Array.isArray(e)?e:[e];function lE(e){const t=_.useRef(e);t.current=e,_.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Ft=e=>typeof e=="string",cE=(e,t,n,r,o)=>Ft(e)?(r&&t.watch.add(e),se(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),se(n,i))):(r&&(t.watchAll=!0),n),uE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},mp=e=>({isOnSubmit:!e||e===xt.onSubmit,isOnBlur:e===xt.onBlur,isOnChange:e===xt.onChange,isOnAll:e===xt.all,isOnTouch:e===xt.onTouched}),hp=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Cr=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=se(e,o);if(i){const{_f:a,...s}=i;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],o)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Cr(s,t))break}else if(Me(s)&&Cr(s,t))break}}};var dE=(e,t,n)=>{const r=Jo(se(e,n));return Oe(r,"root",t[n]),Oe(e,n,r),e},As=e=>e.type==="file",Dt=e=>typeof e=="function",Zo=e=>{if(!_s)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Qo=e=>Ft(e),Ps=e=>e.type==="radio",ei=e=>e instanceof RegExp;const vp={value:!1,isValid:!1},yp={value:!0,isValid:!0};var xp=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Ie(e[0].attributes.value)?Ie(e[0].value)||e[0].value===""?yp:{value:e[0].value,isValid:!0}:yp:vp}return vp};const bp={isValid:!1,value:null};var wp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,bp):bp;function Cp(e,t,n="validate"){if(Qo(e)||Array.isArray(e)&&e.every(Qo)||Ot(e)&&!e)return{type:n,message:Qo(e)?e:"",ref:t}}var Kn=e=>Me(e)&&!ei(e)?e:{value:e,message:""},Sp=async(e,t,n,r,o)=>{const{ref:i,refs:a,required:s,maxLength:u,minLength:c,min:d,max:g,pattern:m,validate:f,name:v,valueAsNumber:h,mount:y,disabled:b}=e._f,w=se(t,v);if(!y||b)return{};const C=a?a[0]:i,E=U=>{r&&C.reportValidity&&(C.setCustomValidity(Ot(U)?"":U||""),C.reportValidity())},x={},O=Ps(i),I=wr(i),$=O||I,H=(h||As(i))&&Ie(i.value)&&Ie(w)||Zo(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,D=uE.bind(null,v,n,x),G=(U,Z,k,M=Ut.maxLength,F=Ut.minLength)=>{const q=U?Z:k;x[v]={type:U?M:F,message:q,ref:i,...D(U?M:F,q)}};if(o?!Array.isArray(w)||!w.length:s&&(!$&&(H||Ke(w))||Ot(w)&&!w||I&&!xp(a).isValid||O&&!wp(a).isValid)){const{value:U,message:Z}=Qo(s)?{value:!!s,message:s}:Kn(s);if(U&&(x[v]={type:Ut.required,message:Z,ref:C,...D(Ut.required,Z)},!n))return E(Z),x}if(!H&&(!Ke(d)||!Ke(g))){let U,Z;const k=Kn(g),M=Kn(d);if(!Ke(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ke(k.value)||(U=F>k.value),Ke(M.value)||(Z=F<M.value)}else{const F=i.valueAsDate||new Date(w),q=A=>new Date(new Date().toDateString()+" "+A),P=i.type=="time",j=i.type=="week";Ft(k.value)&&w&&(U=P?q(w)>q(k.value):j?w>k.value:F>new Date(k.value)),Ft(M.value)&&w&&(Z=P?q(w)<q(M.value):j?w<M.value:F<new Date(M.value))}if((U||Z)&&(G(!!U,k.message,M.message,Ut.max,Ut.min),!n))return E(x[v].message),x}if((u||c)&&!H&&(Ft(w)||o&&Array.isArray(w))){const U=Kn(u),Z=Kn(c),k=!Ke(U.value)&&w.length>+U.value,M=!Ke(Z.value)&&w.length<+Z.value;if((k||M)&&(G(k,U.message,Z.message),!n))return E(x[v].message),x}if(m&&!H&&Ft(w)){const{value:U,message:Z}=Kn(m);if(ei(U)&&!w.match(U)&&(x[v]={type:Ut.pattern,message:Z,ref:i,...D(Ut.pattern,Z)},!n))return E(Z),x}if(f){if(Dt(f)){const U=await f(w,t),Z=Cp(U,C);if(Z&&(x[v]={...Z,...D(Ut.validate,Z.message)},!n))return E(Z.message),x}else if(Me(f)){let U={};for(const Z in f){if(!et(U)&&!n)break;const k=Cp(await f[Z](w,t),C,Z);k&&(U={...k,...D(Z,k.message)},E(k.message),n&&(x[v]=U))}if(!et(U)&&(x[v]={ref:C,...U},!n))return x}}return E(!0),x};function fE(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Ie(e)?r++:e[t[r++]];return e}function pE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ie(e[t]))return!1;return!0}function je(e,t){const n=Array.isArray(t)?t:Ts(t)?[t]:pp(t),r=n.length===1?e:fE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&et(r)||Array.isArray(r)&&pE(r))&&je(e,n.slice(0,-1)),e}var Ns=()=>{let e=[];return{get observers(){return e},next:o=>{for(const i of e)i.next&&i.next(o)},subscribe:o=>(e.push(o),{unsubscribe:()=>{e=e.filter(i=>i!==o)}}),unsubscribe:()=>{e=[]}}},ks=e=>Ke(e)||!fp(e);function an(e,t){if(ks(e)||ks(t))return e===t;if(Sn(e)&&Sn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){const i=e[o];if(!r.includes(o))return!1;if(o!=="ref"){const a=t[o];if(Sn(i)&&Sn(a)||Me(i)&&Me(a)||Array.isArray(i)&&Array.isArray(a)?!an(i,a):i!==a)return!1}}return!0}var Ep=e=>e.type==="select-multiple",gE=e=>Ps(e)||wr(e),Os=e=>Zo(e)&&e.isConnected,_p=e=>{for(const t in e)if(Dt(e[t]))return!0;return!1};function ti(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!_p(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ti(e[r],t[r])):Ke(e[r])||(t[r]=!0);return t}function Tp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!_p(e[o])?Ie(t)||ks(n[o])?n[o]=Array.isArray(e[o])?ti(e[o],[]):{...ti(e[o])}:Tp(e[o],Ke(t)?{}:t[o],n[o]):n[o]=!an(e[o],t[o]);return n}var Sr=(e,t)=>Tp(e,t,ti(t)),Ap=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&Ft(e)?new Date(e):r?r(e):e;function Fs(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return As(t)?t.files:Ps(t)?wp(e.refs).value:Ep(t)?[...t.selectedOptions].map(({value:n})=>n):wr(t)?xp(e.refs).value:Ap(Ie(t.value)?e.ref.value:t.value,e)}var mE=(e,t,n,r)=>{const o={};for(const i of e){const a=se(t,i);a&&Oe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Er=e=>Ie(e)?e:ei(e)?e.source:Me(e)?ei(e.value)?e.value.source:e.value:e;const Pp="AsyncFunction";var hE=e=>!!e&&!!e.validate&&!!(Dt(e.validate)&&e.validate.constructor.name===Pp||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Pp)),vE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Np(e,t,n){const r=se(e,n);if(r||Ts(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),a=se(t,i),s=se(e,i);if(a&&!Array.isArray(a)&&n!==i)return{name:n};if(s&&s.type)return{name:i,error:s};o.pop()}return{name:n}}var yE=(e,t,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(t||e):(n?r.isOnBlur:o.isOnBlur)?!e:(n?r.isOnChange:o.isOnChange)?e:!0,xE=(e,t)=>!Xo(se(e,t)).length&&je(e,t);const bE={mode:xt.onSubmit,reValidateMode:xt.onChange,shouldFocusError:!0};function wE(e={}){let t={...bE,...e},n={submitCount:0,isDirty:!1,isLoading:Dt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},o=Me(t.defaultValues)||Me(t.values)?ut(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ut(o),a={action:!1,mount:!1,watch:!1},s={mount:new Set,unMount:new Set,array:new Set,watch:new Set},u,c=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},g={values:Ns(),array:Ns(),state:Ns()},m=mp(t.mode),f=mp(t.reValidateMode),v=t.criteriaMode===xt.all,h=S=>N=>{clearTimeout(c),c=setTimeout(S,N)},y=async S=>{if(!t.disabled&&(d.isValid||S)){const N=t.resolver?et((await $()).errors):await D(r,!0);N!==n.isValid&&g.state.next({isValid:N})}},b=(S,N)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((S||Array.from(s.mount)).forEach(V=>{V&&(N?Oe(n.validatingFields,V,N):je(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!et(n.validatingFields)}))},w=(S,N=[],V,ne,J=!0,X=!0)=>{if(ne&&V&&!t.disabled){if(a.action=!0,X&&Array.isArray(se(r,S))){const z=V(se(r,S),ne.argA,ne.argB);J&&Oe(r,S,z)}if(X&&Array.isArray(se(n.errors,S))){const z=V(se(n.errors,S),ne.argA,ne.argB);J&&Oe(n.errors,S,z),xE(n.errors,S)}if(d.touchedFields&&X&&Array.isArray(se(n.touchedFields,S))){const z=V(se(n.touchedFields,S),ne.argA,ne.argB);J&&Oe(n.touchedFields,S,z)}d.dirtyFields&&(n.dirtyFields=Sr(o,i)),g.state.next({name:S,isDirty:U(S,N),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Oe(i,S,N)},C=(S,N)=>{Oe(n.errors,S,N),g.state.next({errors:n.errors})},E=S=>{n.errors=S,g.state.next({errors:n.errors,isValid:!1})},x=(S,N,V,ne)=>{const J=se(r,S);if(J){const X=se(i,S,Ie(V)?se(o,S):V);Ie(X)||ne&&ne.defaultChecked||N?Oe(i,S,N?X:Fs(J._f)):M(S,X),a.mount&&y()}},O=(S,N,V,ne,J)=>{let X=!1,z=!1;const Y={name:S};if(!t.disabled){const xe=!!(se(r,S)&&se(r,S)._f&&se(r,S)._f.disabled);if(!V||ne){d.isDirty&&(z=n.isDirty,n.isDirty=Y.isDirty=U(),X=z!==Y.isDirty);const we=xe||an(se(o,S),N);z=!!(!xe&&se(n.dirtyFields,S)),we||xe?je(n.dirtyFields,S):Oe(n.dirtyFields,S,!0),Y.dirtyFields=n.dirtyFields,X=X||d.dirtyFields&&z!==!we}if(V){const we=se(n.touchedFields,S);we||(Oe(n.touchedFields,S,V),Y.touchedFields=n.touchedFields,X=X||d.touchedFields&&we!==V)}X&&J&&g.state.next(Y)}return X?Y:{}},I=(S,N,V,ne)=>{const J=se(n.errors,S),X=d.isValid&&Ot(N)&&n.isValid!==N;if(t.delayError&&V?(u=h(()=>C(S,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Oe(n.errors,S,V):je(n.errors,S)),(V?!an(J,V):J)||!et(ne)||X){const z={...ne,...X&&Ot(N)?{isValid:N}:{},errors:n.errors,name:S};n={...n,...z},g.state.next(z)}},$=async S=>{b(S,!0);const N=await t.resolver(i,t.context,mE(S||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(S),N},H=async S=>{const{errors:N}=await $(S);if(S)for(const V of S){const ne=se(N,V);ne?Oe(n.errors,V,ne):je(n.errors,V)}else n.errors=N;return N},D=async(S,N,V={valid:!0})=>{for(const ne in S){const J=S[ne];if(J){const{_f:X,...z}=J;if(X){const Y=s.array.has(X.name),xe=J._f&&hE(J._f);xe&&d.validatingFields&&b([ne],!0);const we=await Sp(J,i,v,t.shouldUseNativeValidation&&!N,Y);if(xe&&d.validatingFields&&b([ne]),we[X.name]&&(V.valid=!1,N))break;!N&&(se(we,X.name)?Y?dE(n.errors,we,X.name):Oe(n.errors,X.name,we[X.name]):je(n.errors,X.name))}!et(z)&&await D(z,N,V)}}return V.valid},G=()=>{for(const S of s.unMount){const N=se(r,S);N&&(N._f.refs?N._f.refs.every(V=>!Os(V)):!Os(N._f.ref))&&oe(S)}s.unMount=new Set},U=(S,N)=>!t.disabled&&(S&&N&&Oe(i,S,N),!an(B(),o)),Z=(S,N,V)=>cE(S,s,{...a.mount?i:Ie(N)?o:Ft(S)?{[S]:N}:N},V,N),k=S=>Xo(se(a.mount?i:o,S,t.shouldUnregister?se(o,S,[]):[])),M=(S,N,V={})=>{const ne=se(r,S);let J=N;if(ne){const X=ne._f;X&&(!X.disabled&&Oe(i,S,Ap(N,X)),J=Zo(X.ref)&&Ke(N)?"":N,Ep(X.ref)?[...X.ref.options].forEach(z=>z.selected=J.includes(z.value)):X.refs?wr(X.ref)?X.refs.length>1?X.refs.forEach(z=>(!z.defaultChecked||!z.disabled)&&(z.checked=Array.isArray(J)?!!J.find(Y=>Y===z.value):J===z.value)):X.refs[0]&&(X.refs[0].checked=!!J):X.refs.forEach(z=>z.checked=z.value===J):As(X.ref)?X.ref.value="":(X.ref.value=J,X.ref.type||g.values.next({name:S,values:{...i}})))}(V.shouldDirty||V.shouldTouch)&&O(S,J,V.shouldTouch,V.shouldDirty,!0),V.shouldValidate&&A(S)},F=(S,N,V)=>{for(const ne in N){const J=N[ne],X=`${S}.${ne}`,z=se(r,X);(s.array.has(S)||Me(J)||z&&!z._f)&&!Sn(J)?F(X,J,V):M(X,J,V)}},q=(S,N,V={})=>{const ne=se(r,S),J=s.array.has(S),X=ut(N);Oe(i,S,X),J?(g.array.next({name:S,values:{...i}}),(d.isDirty||d.dirtyFields)&&V.shouldDirty&&g.state.next({name:S,dirtyFields:Sr(o,i),isDirty:U(S,X)})):ne&&!ne._f&&!Ke(X)?F(S,X,V):M(S,X,V),hp(S,s)&&g.state.next({...n}),g.values.next({name:a.mount?S:void 0,values:{...i}})},P=async S=>{a.mount=!0;const N=S.target;let V=N.name,ne=!0;const J=se(r,V),X=()=>N.type?Fs(J._f):nE(S),z=Y=>{ne=Number.isNaN(Y)||Sn(Y)&&isNaN(Y.getTime())||an(Y,se(i,V,Y))};if(J){let Y,xe;const we=X(),Fe=S.type===gp.BLUR||S.type===gp.FOCUS_OUT,sn=!vE(J._f)&&!t.resolver&&!se(n.errors,V)&&!J._f.deps||yE(Fe,se(n.touchedFields,V),n.isSubmitted,f,m),Re=hp(V,s,Fe);Oe(i,V,we),Fe?(J._f.onBlur&&J._f.onBlur(S),u&&u(0)):J._f.onChange&&J._f.onChange(S);const Mt=O(V,we,Fe,!1),En=!et(Mt)||Re;if(!Fe&&g.values.next({name:V,type:S.type,values:{...i}}),sn)return d.isValid&&(t.mode==="onBlur"?Fe&&y():y()),En&&g.state.next({name:V,...Re?{}:Mt});if(!Fe&&Re&&g.state.next({...n}),t.resolver){const{errors:Be}=await $([V]);if(z(we),ne){const $t=Np(n.errors,r,V),Wt=Np(Be,r,$t.name||V);Y=Wt.error,V=Wt.name,xe=et(Be)}}else b([V],!0),Y=(await Sp(J,i,v,t.shouldUseNativeValidation))[V],b([V]),z(we),ne&&(Y?xe=!1:d.isValid&&(xe=await D(r,!0)));ne&&(J._f.deps&&A(J._f.deps),I(V,xe,Y,Mt))}},j=(S,N)=>{if(se(n.errors,N)&&S.focus)return S.focus(),1},A=async(S,N={})=>{let V,ne;const J=Jo(S);if(t.resolver){const X=await H(Ie(S)?S:J);V=et(X),ne=S?!J.some(z=>se(X,z)):V}else S?(ne=(await Promise.all(J.map(async X=>{const z=se(r,X);return await D(z&&z._f?{[X]:z}:z)}))).every(Boolean),!(!ne&&!n.isValid)&&y()):ne=V=await D(r);return g.state.next({...!Ft(S)||d.isValid&&V!==n.isValid?{}:{name:S},...t.resolver||!S?{isValid:V}:{},errors:n.errors}),N.shouldFocus&&!ne&&Cr(r,j,S?J:s.mount),ne},B=S=>{const N={...a.mount?i:o};return Ie(S)?N:Ft(S)?se(N,S):S.map(V=>se(N,V))},Q=(S,N)=>({invalid:!!se((N||n).errors,S),isDirty:!!se((N||n).dirtyFields,S),error:se((N||n).errors,S),isValidating:!!se(n.validatingFields,S),isTouched:!!se((N||n).touchedFields,S)}),re=S=>{S&&Jo(S).forEach(N=>je(n.errors,N)),g.state.next({errors:S?n.errors:{}})},ee=(S,N,V)=>{const ne=(se(r,S,{_f:{}})._f||{}).ref,J=se(n.errors,S)||{},{ref:X,message:z,type:Y,...xe}=J;Oe(n.errors,S,{...xe,...N,ref:ne}),g.state.next({name:S,errors:n.errors,isValid:!1}),V&&V.shouldFocus&&ne&&ne.focus&&ne.focus()},ce=(S,N)=>Dt(S)?g.values.subscribe({next:V=>S(Z(void 0,N),V)}):Z(S,N,!0),oe=(S,N={})=>{for(const V of S?Jo(S):s.mount)s.mount.delete(V),s.array.delete(V),N.keepValue||(je(r,V),je(i,V)),!N.keepError&&je(n.errors,V),!N.keepDirty&&je(n.dirtyFields,V),!N.keepTouched&&je(n.touchedFields,V),!N.keepIsValidating&&je(n.validatingFields,V),!t.shouldUnregister&&!N.keepDefaultValue&&je(o,V);g.values.next({values:{...i}}),g.state.next({...n,...N.keepDirty?{isDirty:U()}:{}}),!N.keepIsValid&&y()},ae=({disabled:S,name:N,field:V,fields:ne,value:J})=>{if(Ot(S)&&a.mount||S){const X=S?void 0:Ie(J)?Fs(V?V._f:se(ne,N)._f):J;(S||!S&&!Ie(X))&&Oe(i,N,X),O(N,X,!1,!1,!0)}},de=(S,N={})=>{let V=se(r,S);const ne=Ot(N.disabled)||Ot(t.disabled);return Oe(r,S,{...V||{},_f:{...V&&V._f?V._f:{ref:{name:S}},name:S,mount:!0,...N}}),s.mount.add(S),V?ae({field:V,disabled:Ot(N.disabled)?N.disabled:t.disabled,name:S,value:N.value}):x(S,!0,N.value),{...ne?{disabled:N.disabled||t.disabled}:{},...t.progressive?{required:!!N.required,min:Er(N.min),max:Er(N.max),minLength:Er(N.minLength),maxLength:Er(N.maxLength),pattern:Er(N.pattern)}:{},name:S,onChange:P,onBlur:P,ref:J=>{if(J){de(S,N),V=se(r,S);const X=Ie(J.value)&&J.querySelectorAll&&J.querySelectorAll("input,select,textarea")[0]||J,z=gE(X),Y=V._f.refs||[];if(z?Y.find(xe=>xe===X):X===V._f.ref)return;Oe(r,S,{_f:{...V._f,...z?{refs:[...Y.filter(Os),X,...Array.isArray(se(o,S))?[{}]:[]],ref:{type:X.type,name:S}}:{ref:X}}}),x(S,!1,void 0,X)}else V=se(r,S,{}),V._f&&(V._f.mount=!1),(t.shouldUnregister||N.shouldUnregister)&&!(oE(s.array,S)&&a.action)&&s.unMount.add(S)}}},ue=()=>t.shouldFocusError&&Cr(r,j,s.mount),le=S=>{Ot(S)&&(g.state.next({disabled:S}),Cr(r,(N,V)=>{const ne=se(r,V);ne&&(N.disabled=ne._f.disabled||S,Array.isArray(ne._f.refs)&&ne._f.refs.forEach(J=>{J.disabled=ne._f.disabled||S}))},0,!1))},Ce=(S,N)=>async V=>{let ne;if(V&&(V.preventDefault&&V.preventDefault(),V.persist&&V.persist()),t.disabled){N&&await N({...n.errors},V);return}let J=ut(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:X,values:z}=await $();n.errors=X,J=z}else await D(r);if(je(n.errors,"root"),et(n.errors)){g.state.next({errors:{}});try{await S(J,V)}catch(X){ne=X}}else N&&await N({...n.errors},V),ue(),setTimeout(ue);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:et(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},K=(S,N={})=>{se(r,S)&&(Ie(N.defaultValue)?q(S,ut(se(o,S))):(q(S,N.defaultValue),Oe(o,S,ut(N.defaultValue))),N.keepTouched||je(n.touchedFields,S),N.keepDirty||(je(n.dirtyFields,S),n.isDirty=N.defaultValue?U(S,ut(se(o,S))):U()),N.keepError||(je(n.errors,S),d.isValid&&y()),g.state.next({...n}))},Ee=(S,N={})=>{const V=S?ut(S):o,ne=ut(V),J=et(S),X=J?o:ne;if(N.keepDefaultValues||(o=V),!N.keepValues){if(N.keepDirtyValues){const z=new Set([...s.mount,...Object.keys(Sr(o,i))]);for(const Y of Array.from(z))se(n.dirtyFields,Y)?Oe(X,Y,se(i,Y)):q(Y,se(X,Y))}else{if(_s&&Ie(S))for(const z of s.mount){const Y=se(r,z);if(Y&&Y._f){const xe=Array.isArray(Y._f.refs)?Y._f.refs[0]:Y._f.ref;if(Zo(xe)){const we=xe.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?N.keepDefaultValues?ut(o):{}:ut(X),g.array.next({values:{...X}}),g.values.next({values:{...X}})}s={mount:N.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!N.keepIsValid||!!N.keepDirtyValues,a.watch=!!t.shouldUnregister,g.state.next({submitCount:N.keepSubmitCount?n.submitCount:0,isDirty:J?!1:N.keepDirty?n.isDirty:!!(N.keepDefaultValues&&!an(S,o)),isSubmitted:N.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:J?{}:N.keepDirtyValues?N.keepDefaultValues&&i?Sr(o,i):n.dirtyFields:N.keepDefaultValues&&S?Sr(o,S):N.keepDirty?n.dirtyFields:{},touchedFields:N.keepTouched?n.touchedFields:{},errors:N.keepErrors?n.errors:{},isSubmitSuccessful:N.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},We=(S,N)=>Ee(Dt(S)?S(i):S,N);return{control:{register:de,unregister:oe,getFieldState:Q,handleSubmit:Ce,setError:ee,_executeSchema:$,_getWatch:Z,_getDirty:U,_updateValid:y,_removeUnmounted:G,_updateFieldArray:w,_updateDisabledField:ae,_getFieldArray:k,_reset:Ee,_resetDefaultValues:()=>Dt(t.defaultValues)&&t.defaultValues().then(S=>{We(S,t.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:S=>{n={...n,...S}},_disableForm:le,_subjects:g,_proxyFormState:d,_setErrors:E,get _fields(){return r},get _formValues(){return i},get _state(){return a},set _state(S){a=S},get _defaultValues(){return o},get _names(){return s},set _names(S){s=S},get _formState(){return n},set _formState(S){n=S},get _options(){return t},set _options(S){t={...t,...S}}},trigger:A,register:de,handleSubmit:Ce,watch:ce,setValue:q,getValues:B,reset:We,resetField:K,clearErrors:re,unregister:oe,setError:ee,setFocus:(S,N={})=>{const V=se(r,S),ne=V&&V._f;if(ne){const J=ne.refs?ne.refs[0]:ne.ref;J.focus&&(J.focus(),N.shouldSelect&&Dt(J.select)&&J.select())}},getFieldState:Q}}function CE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:Dt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Dt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...wE(e),formState:r});const i=t.current.control;return i._options=e,lE({subject:i._subjects.state,next:a=>{sE(a,i._proxyFormState,i._updateFormState)&&o({...i._formState})}}),_.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),_.useEffect(()=>{if(i._proxyFormState.isDirty){const a=i._getDirty();a!==r.isDirty&&i._subjects.state.next({isDirty:a})}},[i,r.isDirty]),_.useEffect(()=>{e.values&&!an(e.values,n.current)?(i._reset(e.values,i._options.resetOptions),n.current=e.values,o(a=>({...a}))):i._resetDefaultValues()},[e.values,i]),_.useEffect(()=>{e.errors&&i._setErrors(e.errors)},[e.errors,i]),_.useEffect(()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),_.useEffect(()=>{e.shouldUnregister&&i._subjects.values.next({values:i._getWatch()})},[e.shouldUnregister,i]),_.useMemo(()=>({...t.current,formState:aE(r,i)}),[r,i])}const kp=({className:e,children:t,content:n,side:r})=>{const[o,i]=_.useState(!1);return l.jsx(xn,{delayDuration:0,children:l.jsxs(bn,{open:o,children:[l.jsx(wn,{asChild:!0,children:l.jsx("button",{type:"button",className:he("cursor-pointer",e),onClick:()=>i(!o),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onTouchStart:()=>i(!o),onKeyDown:a=>{a.preventDefault(),a.key==="Enter"&&i(!o)},children:t})}),l.jsx(on,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},SE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},EE=({apiBaseUrl:e="https://vib-s3-explorer.cmcts1.studio.ai.vn"})=>{var O,I;const[t,n]=_.useState([]),[r,o]=_.useState(!1),[i,a]=_.useState([]),[s,u]=_.useState(1),[c,d]=_.useState(1),[g,m]=_.useState(null),[f,v]=_.useState(""),h=SE(f,500),y=$=>{const H=$.match(/\d{6}/);if(!H)return{month:"",year:""};const D=H[0],G=D.substring(0,2),U=D.substring(2);return{month:G,year:U}},b=$=>$.map(D=>{let G=(D==null?void 0:D.month)||"",U=(D==null?void 0:D.year)||"";if((!G||!U)&&(D!=null&&D.file_name)){const Z=y(D.file_name);G=G||Z.month,U=U||Z.year}return{id:D==null?void 0:D.id,prefix:(D==null?void 0:D.prefix)||"",model:(D==null?void 0:D.model)||"",fileName:(D==null?void 0:D.file_name)||"",code:(D==null?void 0:D.stock_id)||"",month:G,year:U,content:(D==null?void 0:D.text_summary)||"",status:(D==null?void 0:D.status)||"",note:(D==null?void 0:D.note)||"",lastUpdate:D==null?void 0:D.updated_at,stock_id:D==null?void 0:D.stock_id}}),w=$=>{if(!($!=null&&$.data))return[];const H=b($==null?void 0:$.data);n(H),d($.pagination.totalPages)},C=async($=1,H=15)=>{m($),o(!0);try{const D=await me.get(`${e}/api/latest-summaries`,{params:{page:$,limit:H,search:f}});(D==null?void 0:D.status)===200?w(D.data):console.error(D)}catch(D){console.error("Error fetching data:",D)}finally{m(null),o(!1)}};_.useEffect(()=>{h&&u(1),C(s)},[s,h]);const E=_.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:H})=>l.jsx("span",{className:"flex flex-col",children:H.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:H})=>{const D=H.original.month,G=H.original.year;return l.jsx("span",{className:"flex flex-col",children:`${D.toString().padStart(2,"0")}/${G}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:H})=>{const D=H.getValue("content");return l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:D})}},{id:"status",header:"Trạng thái",accessorKey:"status",cell:({row:H})=>{const G=H.original.status!=="unpublish";return l.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${G?"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:G?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:H})=>l.jsx(kp,{content:l.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:H.original.note}),children:l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:H.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:H})=>{const D=new Date(H.original.lastUpdate),G=D.getDate(),U=D.getMonth()+1,Z=`ngày ${G} tháng ${U}`;return l.jsx("span",{className:"flex flex-col",children:Z})}},{accessorKey:"actions",header:()=>l.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:H})=>{const[D,G]=_.useState(!1),[U,Z]=_.useState(!1),[k,M]=_.useState(!1),{handleSubmit:F,register:q,reset:P}=CE(),j=H.original.id,A=H.getValue("status"),B=H.getValue("content"),[Q,re]=_.useState(!1),ee=async()=>{try{re(!0);const oe=A==="unpublish"?"published":"unpublish",ae=await me.patch(`${e}/api/toggle-publish/${j}`,{id:j,typeAction:"update",status:A,idInput:j,stock_id:H.original.stock_id,prefix:H.original.prefix,model:H.original.model,summary_result:H.original.content,note:H.original.note});ae.status===200?n(de=>de.map(ue=>ue.id===j?{...ue,status:oe}:ue)):console.error("Failed to toggle publish status:",ae)}catch(oe){console.error("Error toggling publish status:",oe)}finally{re(!1)}},ce=async oe=>{G(!0);try{const ae=await me.patch(`${e}/api/update-summary`,{note:oe.note,text_summary:oe.content,id:j});ae.status===200?(await C(s),Z(!1)):console.error("Failed to update summary:",ae)}catch(ae){console.error("Error updating summary:",ae)}return G(!1)};return l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ve,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"px-2 py-0.5 h-7",children:l.jsx(Fh,{className:"h-4 w-4"})}),l.jsx(jt,{open:k,onOpenChange:M,children:l.jsxs(St,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(Et,{children:l.jsx(_t,{children:"Nội dung chi tiết"})}),l.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:l.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:B})})]})}),l.jsxs(jt,{open:U,onOpenChange:oe=>{Z(oe),oe?P({content:H.original.content,note:H.original.note}):P()},children:[l.jsx(uo,{asChild:!0,children:l.jsx(ve,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),l.jsx(St,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(Et,{className:"flex flex-col gap-3",children:[l.jsx(_t,{className:"max-sm:hidden text-center",children:"Sửa summary"}),l.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:F(ce),children:[l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Nội dung:"}),l.jsx(ur,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.answer||"",rows:10,...q("content")})]}),l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Ghi chú:"}),l.jsx(ur,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.note||"",rows:1,...q("note")})]})]}),l.jsx("div",{className:"flex justify-end",children:l.jsx(ve,{disabled:D,type:"submit",variant:"default",children:D?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ve,{variant:"outline",size:"sm",onClick:ee,disabled:Q,className:"w-[70px] px-2 py-0.5 h-7",children:Q?l.jsx($e,{className:"h-4 w-4 animate-spin"}):A==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=el({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:$g(),getCoreRowModel:Qs()});return l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:l.jsxs("div",{className:"relative max-w-sm",children:[l.jsx(en,{placeholder:"Tìm kiếm theo mã...",value:f,onChange:$=>v($.target.value),className:"pr-8"}),f&&l.jsx(ve,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>v(""),children:l.jsx(Hi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(vo,{className:"s3-explr-table",children:[l.jsx(yo,{className:"s3-explr-table-header",children:x.getHeaderGroups().map($=>l.jsx(ht,{className:"hover:bg-transparent s3-explr-header-row",children:$.headers.map(H=>l.jsx(Tt,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Vr(H.column.columnDef.header,H.getContext())},H.id))},$.id))}),l.jsx(xo,{className:"s3-explr-table-body",children:r?l.jsx(ht,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(O=x.getRowModel().rows)!=null&&O.length?(I=x.getRowModel().rows)==null?void 0:I.map($=>l.jsx(ht,{className:"h-12 s3-explr-row",children:$.getVisibleCells().map(H=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Vr(H.column.columnDef.cell,H.getContext())},H.id))},$.id)):l.jsx(ht,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(fo,{children:l.jsxs(po,{children:[l.jsx(mt,{children:l.jsx(go,{onClick:()=>u($=>Math.max(1,$-1)),className:s===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:c},($,H)=>H+1).filter($=>$===1||$===c||Math.abs($-s)<=1).map(($,H,D)=>l.jsxs(l.Fragment,{children:[H>0&&D[H-1]!==$-1&&l.jsx(mt,{children:l.jsx(ho,{})},$+"..."),l.jsx(mt,{children:l.jsx(Vn,{onClick:()=>u($),isActive:s===$,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===$?l.jsx($e,{className:"h-4 w-4 animate-spin"}):$})},$)]})),l.jsx(mt,{children:l.jsx(mo,{onClick:()=>u($=>Math.min(c,$+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Op=10,_E=_.memo(({apiBaseUrl:e="https://vib-s3-explorer.cmcts1.studio.ai.vn"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Op,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:f}=ko(),[v,h]=_.useState(!1),y=async x=>{try{d(x);const O=await me.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Op.toString()}});o(O.data.data),a(O.data.pagination)}catch{f({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{d(null),u(!1)}};_.useEffect(()=>{y(t)},[t,e]);const b=async x=>{m(O=>new Set(O).add(x.toString()));try{await me.post(`${e}/api/retry-job`,{jobId:x}),f({title:"Job Restarted",description:`Job ${x} has been successfully restarted.`}),y(t)}catch{f({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${x}. Please try again.`})}finally{m(O=>{const I=new Set(O);return I.delete(x.toString()),I})}},w=async()=>{h(!0),n(1),await y(1),h(!1)},C=x=>new Date(x).toLocaleString(),E=x=>{if(x=parseFloat(x),x<60)return`${x.toFixed(2)}s`;const O=Math.floor(x/60),I=(x%60).toFixed(0);return`${O}m ${I}s`};return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[l.jsx(Ph,{className:"w-8 h-8 text-primary"}),l.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),l.jsx(ve,{variant:"outline",size:"icon",onClick:w,disabled:v||s,className:"ml-2",children:l.jsx(Mh,{className:`h-4 w-4 ${v?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(vo,{children:[l.jsx(yo,{children:l.jsxs(ht,{children:[l.jsx(Tt,{children:"ID"}),l.jsx(Tt,{children:"Tên Công Việc"}),l.jsx(Tt,{children:"Thời Gian Bắt Đầu"}),l.jsx(Tt,{children:"Thời Gian Cập Nhật"}),l.jsx(Tt,{children:"Thời Gian Thực Thi"}),l.jsx(Tt,{children:"Trạng Thái"}),l.jsx(Tt,{children:"Thao Tác"})]})}),l.jsx(xo,{children:s&&r.length===0?l.jsx(ht,{children:l.jsx(Ze,{colSpan:7,className:"text-center py-4",children:l.jsx($e,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(x=>{var O,I;return l.jsxs(ht,{children:[l.jsx(Ze,{className:"!w-[100px]",children:x.id}),l.jsx(Ze,{className:"font-medium",children:(O=x.job_name)==null?void 0:O.replace("Upload file","Summary")}),l.jsx(Ze,{className:"!w-[200px]",children:C(x.created_at)}),l.jsx(Ze,{className:"!w-[200px]",children:C(x.updated_at)}),l.jsx(Ze,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Ze,{className:"!w-[200px]",children:l.jsx(kp,{content:x.status==="fail"&&x.error?l.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:x.error}):null,children:l.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]
176
176
  ${x.status==="done"?"bg-green-100 text-green-800":x.status==="fail"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:x.status==="fail"?"FAILED":(I=x.status)==null?void 0:I.toUpperCase()})})}),l.jsx(Ze,{className:"!w-[200px]",children:x.status==="fail"?l.jsx(ve,{variant:"outline",size:"sm",onClick:()=>b(x.id),disabled:g.has(x.id.toString()),className:"h-[32px]",children:g.has(x.id.toString())?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin"}),"Đang thử lại..."]}):"Thử Lại"}):l.jsx("div",{className:"h-[32px]"})})]},x.id)})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(fo,{children:l.jsxs(po,{children:[l.jsx(mt,{children:l.jsx(go,{onClick:()=>n(x=>Math.max(1,x-1)),className:t===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:i.totalPages},(x,O)=>O+1).filter(x=>x===1||x===i.totalPages||Math.abs(x-t)<=1).map((x,O,I)=>l.jsxs(l.Fragment,{children:[O>0&&I[O-1]!==x-1&&l.jsx(mt,{children:l.jsx(ho,{})},x+"..."),l.jsx(mt,{children:l.jsx(Vn,{onClick:()=>n(x),isActive:t===x,className:`cursor-pointer ${c!==null?"pointer-events-none":""}`,children:c===x?l.jsx($e,{className:"h-4 w-4 animate-spin"}):x})},x)]})),l.jsx(mt,{children:l.jsx(mo,{onClick:()=>n(x=>Math.min(i.totalPages,x+1)),className:t===i.totalPages||c!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),l.jsx(Sd,{})]})});dt.Job=_E,dt.S3Explorer=tE,dt.Summary=EE,Object.defineProperty(dt,Symbol.toStringTag,{value:"Module"})});
177
177
  //# sourceMappingURL=s3-explorer.umd.cjs.map