dccxx-s3-explorer 1.0.46 → 1.0.48
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.
- package/dist/s3-explorer.js +4 -2
- package/dist/s3-explorer.js.map +1 -1
- package/dist/s3-explorer.umd.cjs +1 -1
- package/dist/s3-explorer.umd.cjs.map +1 -1
- package/package.json +135 -135
package/dist/s3-explorer.umd.cjs
CHANGED
|
@@ -172,6 +172,6 @@ Valid keys: `+JSON.stringify(Object.keys(T),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 lS(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function cS(e){if(Array.isArray(e))return ms(e)}function Wf(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 qf(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Wf(Object(n),!0).forEach(function(r){Gf(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Wf(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Gf(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 fS(e)||dS(e,t)||Kf(e,t)||uS()}function uS(){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 Kf(e,t){if(e){if(typeof e=="string")return ms(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 ms(e,t)}}function ms(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 dS(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 fS(e){if(Array.isArray(e))return e}var pS=typeof gs=="function"?gs:gs.default,gS="file-invalid-type",mS="file-too-large",hS="file-too-small",vS="too-many-files",yS=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:gS,message:"File type must be ".concat(r)}},Yf=function(t){return{code:mS,message:"File is larger than ".concat(t," ").concat(t===1?"byte":"bytes")}},Xf=function(t){return{code:hS,message:"File is smaller than ".concat(t," ").concat(t===1?"byte":"bytes")}},xS={code:vS,message:"Too many files"};function Jf(e,t){var n=e.type==="application/x-moz-file"||pS(e,t);return[n,n?null:yS(t)]}function Zf(e,t,n){if(Cn(e.size))if(Cn(t)&&Cn(n)){if(e.size>n)return[!1,Yf(n)];if(e.size<t)return[!1,Xf(t)]}else{if(Cn(t)&&e.size<t)return[!1,Xf(t)];if(Cn(n)&&e.size>n)return[!1,Yf(n)]}return[!0,null]}function Cn(e){return e!=null}function bS(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=Jf(u,n),d=xr(c,1),g=d[0],m=Zf(u,r,o),f=xr(m,1),v=f[0],h=s?s(u):null;return g&&v&&!h})}function Uo(e){return typeof e.isPropagationStopped=="function"?e.isPropagationStopped():typeof e.cancelBubble<"u"?e.cancelBubble:!1}function Wo(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 Qf(e){e.preventDefault()}function wS(e){return e.indexOf("MSIE")!==-1||e.indexOf("Trident/")!==-1}function CS(e){return e.indexOf("Edge/")!==-1}function SS(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return wS(e)||CS(e)}function Ot(){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!Uo(r)&&s&&s.apply(void 0,[r].concat(i)),Uo(r)})}}function ES(){return"showOpenFilePicker"in window}function _S(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 ep(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(tp))&&(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 qf(qf({},n),{},Gf({},i,a))},{});return[{description:"Files",accept:t}]}return e}function TS(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(Uf(t),[o],Uf(i))},[]).filter(function(t){return ep(t)||tp(t)}).join(",")}function AS(e){return e instanceof DOMException&&(e.name==="AbortError"||e.code===e.ABORT_ERR)}function PS(e){return e instanceof DOMException&&(e.name==="SecurityError"||e.code===e.SECURITY_ERR)}function ep(e){return e==="audio/*"||e==="video/*"||e==="image/*"||e==="text/*"||e==="application/*"||/\w+\/[-+.\w]+/g.test(e)}function tp(e){return/^.*\.[\w]+$/.test(e)}var NS=["children"],kS=["open"],OS=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],FS=["refKey","onChange","onClick"];function DS(e){return $S(e)||MS(e)||np(e)||IS()}function IS(){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 MS(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function $S(e){if(Array.isArray(e))return vs(e)}function hs(e,t){return VS(e)||RS(e,t)||np(e,t)||LS()}function LS(){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 np(e,t){if(e){if(typeof e=="string")return vs(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 vs(e,t)}}function vs(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 RS(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 VS(e){if(Array.isArray(e))return e}function rp(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?rp(Object(n),!0).forEach(function(r){ys(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ys(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function qo(e,t){if(e==null)return{};var n=jS(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 jS(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 xs=_.forwardRef(function(e,t){var n=e.children,r=qo(e,NS),o=ip(r),i=o.open,a=qo(o,kS);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});xs.displayName="Dropzone";var op={disabled:!1,getFilesFromEvent:ZC,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};xs.defaultProps=op,xs.propTypes={children:ke.func,accept:ke.objectOf(ke.arrayOf(ke.string)),multiple:ke.bool,preventDropOnDocument:ke.bool,noClick:ke.bool,noKeyboard:ke.bool,noDrag:ke.bool,noDragEventsBubbling:ke.bool,minSize:ke.number,maxSize:ke.number,maxFiles:ke.number,disabled:ke.bool,getFilesFromEvent:ke.func,onFileDialogCancel:ke.func,onFileDialogOpen:ke.func,useFsAccessApi:ke.bool,autoFocus:ke.bool,onDragEnter:ke.func,onDragLeave:ke.func,onDragOver:ke.func,onDrop:ke.func,onDropAccepted:ke.func,onDropRejected:ke.func,onError:ke.func,validator:ke.func};var bs={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function ip(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},op),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 TS(n)},[n]),G=_.useMemo(function(){return _S(n)},[n]),U=_.useMemo(function(){return typeof y=="function"?y:ap},[y]),Z=_.useMemo(function(){return typeof h=="function"?h:ap},[h]),k=_.useRef(null),M=_.useRef(null),F=_.useReducer(zS,bs),q=hs(F,2),P=q[0],j=q[1],T=P.isFocused,B=P.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&ES()),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",Qf,!1),document.addEventListener("drop",ce,!1)),function(){C&&(document.removeEventListener("dragover",Qf),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(DS(ee.current),[z.target]),Wo(z)&&Promise.resolve(o(z)).then(function(Y){if(!(Uo(z)&&!I)){var xe=Y.length,we=xe>0&&bS({files:Y,accept:D,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Te=xe>0&&!we;j({isDragAccept:we,isDragReject:Te,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=Wo(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}),Wo(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var xe=[],we=[];z.forEach(function(Te){var $t=Jf(Te,D),ut=hs($t,2),je=ut[0],Wt=ut[1],qt=Zf(Te,a,i),Gt=hs(qt,2),Se=Gt[0],cn=Gt[1],Yn=H?H(Te):null;if(je&&Se&&!Yn)xe.push(Te);else{var dt=[Wt,cn];Yn&&(dt=dt.concat(Yn)),we.push({file:Te,errors:dt.filter(function(En){return En})})}}),(!s&&xe.length>1||s&&u>=1&&xe.length>u)&&(xe.forEach(function(Te){we.push({file:Te,errors:[xS]})}),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=[],Wo(z)&&Promise.resolve(o(z)).then(function(Y){Uo(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){AS(Y)?(Z(Y),j({type:"closeDialog"})):PS(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]),_e=_.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]),Ue=_.useCallback(function(){j({type:"focus"})},[]),We=_.useCallback(function(){j({type:"blur"})},[]),Mt=_.useCallback(function(){E||(SS()?setTimeout(K,0):K())},[E,K]),at=function(Y){return r?null:Y},S=function(Y){return x?null:at(Y)},N=function(Y){return O?null:at(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,Te=z.onKeyDown,$t=z.onFocus,ut=z.onBlur,je=z.onClick,Wt=z.onDragEnter,qt=z.onDragOver,Gt=z.onDragLeave,Se=z.onDrop,cn=qo(z,OS);return De(De(ys({onKeyDown:S(Ot(Te,_e)),onFocus:S(Ot($t,Ue)),onBlur:S(Ot(ut,We)),onClick:at(Ot(je,Mt)),onDragEnter:N(Ot(Wt,ae)),onDragOver:N(Ot(qt,de)),onDragLeave:N(Ot(Gt,ue)),onDrop:N(Ot(Se,Ce)),role:typeof we=="string"&&we!==""?we:"presentation"},xe,k),!r&&!x?{tabIndex:0}:{}),cn)}},[k,_e,Ue,We,Mt,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,Te=z.onClick,$t=qo(z,FS),ut=ys({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:at(Ot(we,Ce)),onClick:at(Ot(Te,J)),tabIndex:-1},xe,M);return De(De({},ut),$t)}},[M,n,s,Ce,r]);return De(De({},P),{},{isFocused:T&&!r,getRootProps:ne,getInputProps:X,rootRef:k,inputRef:M,open:at(K)})}function zS(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({},bs),{},{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({},bs);default:return e}}function ap(){}const BS=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=ip({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()})]})},HS=({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}=Po();_.useEffect(()=>{e&&y(f)},[f,e]);const y=async C=>{try{m(!0);const E=await he.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 he.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(Et,{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(_t,{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(Tt,{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(ye,{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(ye,{onClick:b,disabled:c,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},US="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",WS="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",qS="https://www.googleapis.com/auth/drive";Xt(he,{retries:3});const Ze={current:!1},sp="crawl:jobs",Gn="crawl:current_job",GS=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 he.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)}}},Go=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},KS=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Go(e,o.key))}),n},YS=(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 he.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 he.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||"")},XS=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="http://localhost:3002",rootPrefix:n="",asSelector:r=!1,onSelected:o=s=>console.log("Đã chọn:",s),displayPrefixes:i,preSelectedFiles:a})=>{var Dp;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}=Po(),[j,T]=_.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(""),[_e,Ue]=_.useState(!1),[We,Mt]=_.useState(!1),[at,S]=_.useState("rename"),[N,V]=_.useState(!1),[ne,J]=_.useState(""),[X,z]=_.useState("1"),[Y,xe]=_.useState(!1),[we,Te]=_.useState(!1),[$t,ut]=_.useState(!1),[je,Wt]=_.useState(1),[qt,Gt]=_.useState(!1),{currentJob:Se,elapsedTime:cn,setCurrentJob:Yn}=GS(t),[dt,En]=_.useState(null),[_r,ei]=_.useState(""),[CE,Tr]=_.useState(!1),[Ns,Pp]=_.useState(!1),SE=new URL(window.location.href).searchParams.get("prefix")||"",EE=n+SE||h||n,[g_,_E]=_.useState(null),{data:Lt,isLoading:ks,error:TE,estimatedTotalHits:Ar,refetch:et}=YS(t,EE,i,c,je,d),AE=eg({onSuccess:A=>{_E(A.access_token),localStorage.setItem("google_access_token",A.access_token),PE(A.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:qS}),PE=A=>{const L=document.createElement("script");L.src="https://apis.google.com/js/api.js",L.onload=()=>{window.gapi.load("picker",()=>NE(A))},document.body.appendChild(L)},NE=A=>{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(US).setOAuthToken(A).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(Ee=>({id:Ee.id,name:Ee.name,mimeType:Ee.mimeType}));await kE(ge,f)}}).build().setVisible(!0)},kE=async(A,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."),Ne.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const te=Ne.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:L,folders:[],files:[]};A.forEach(Ee=>{Ee.mimeType==="application/vnd.google-apps.folder"?ie.folders.push({id:Ee.id,name:Ee.name}):ie.files.push({id:Ee.id,name:Ee.name})});const ge=await he.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${W}`}});Ze.current=!0,et(),Ne.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),Ne.update(te,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const A=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",A),()=>window.removeEventListener("message",A)},[]),_.useEffect(()=>{const A=new Set(a);m(A)},[]),_.useEffect(()=>{Se!=null&&Se.status&&(Se.status.status==="completed"?(P({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${Se.url} với ${Se.status.completed} trang`}),Ze.current=!0,et()):Se.status.status==="failed"&&P({title:"Thu thập website thất bại",description:`Không thể thu thập ${Se.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(Dp=Se==null?void 0:Se.status)==null?void 0:Dp.status]);const Np=_.useMemo(()=>Lt[f]||[],[Lt,f]),un=_.useMemo(()=>Np,[Np,f,Lt]),Pr=_.useMemo(()=>{const A={};return un.forEach((L,W)=>{g.has(L.key)&&(A[W]=!0)}),A},[g,un]),OE=A=>{const L=Go(Lt,A);if(L.length===0)return g.has(A)?"all":"none";const W=L.filter(te=>g.has(te)).length;return W===0?"none":W===L.length?"all":"partial"},Xn=(A,L=!0)=>{if(f!==A&&(Gt(!0),y(A),v(A),a||m(new Set),L)){const W=window.location.pathname==="/"?"":window.location.pathname,te=A?`${window.location.origin}${W}?prefix=${encodeURIComponent(A)}`:`${window.location.origin}${W}`;window.history.pushState({path:te},"",te)}};_.useEffect(()=>{qt&&(Ze.current=!0,et().finally(()=>Gt(!1)))},[qt]);const FE=async(A,L)=>{var W,te;O(!0);try{if(un.some(Ke=>Ke.isFolder&&Ke.name.toLowerCase()===A.toLowerCase())){P({title:"Lỗi",description:`Thư mục "${A}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),O(!1);return}const ge=`${L}${A}/`;if((await he.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}Ze.current=!0,await et(),P({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${A}"`}),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)}},Os=async(A,L,W)=>{var te,ie,ge,Ee,Ke,Jn,Ip,Mp,$p;F(W),Te(!0);try{if(Array.from(A).reduce((Ye,Or)=>Ye+Or.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),Te(!1);return}const ni=Array.from(A).filter(Ye=>Ye.size===0);if(ni.length>0){const Ye=ni.map(Or=>Or.name).join(", ");P({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Ye}`,variant:"destructive"}),Te(!1),F(null);return}let kr=localStorage.getItem("dataLogin"),Zn;try{kr&&(kr=JSON.parse(kr),Zn=kr.user)}catch{kr=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"&&A[0]){const Ye=A[0].webkitRelativePath.split("/")[0];Ye&&_n.append("folderName",Ye)}_n.append("prefix",L),Array.from(A).forEach(Ye=>W==="folder"?_n.append("files",Ye,Ye.webkitRelativePath):_n.append("files",Ye)),Ze.current=!0;const ze=await he.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 he.post(`${t}/api/upload`,_n,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(L),setTimeout(async()=>{F(null),await et(),Te(!1)},500);else{if(((ge=(ie=ze==null?void 0:ze.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Ee=ze==null?void 0:ze.data)!=null&&Ee.isFolder)){const Ye=Array.from(A).filter(Or=>ze.data.names.includes(Or.name));En(Ye),Tr(!0)}(Ke=ze==null?void 0:ze.data)!=null&&Ke.isFolder&&((Jn=ze==null?void 0:ze.data)!=null&&Jn.name)&&(ei((Ip=ze==null?void 0:ze.data)==null?void 0:Ip.name),En(A),Tr(!0))}}catch(Nr){console.error("Lỗi tải lên:",Nr);const ni=(($p=(Mp=Nr==null?void 0:Nr.response)==null?void 0:Mp.data)==null?void 0:$p.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:ni,variant:"destructive"}),F(null),Te(!1)}},DE=async()=>{var A,L;try{Te(!0);const W=new FormData;if(dt){F(_r?"folder":"files"),Tr(!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"}))),_r&&dt[0]){const ge=dt[0].webkitRelativePath.split("/")[0];ge&&W.append("folderName",ge)}W.append("prefix",f),Array.from(dt).forEach(ge=>_r&&dt[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 he.post(`${t}/api/upload`,W,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(f),Ze.current=!0}}catch(W){console.error("Lỗi tải lên:",W);const te=((L=(A=W==null?void 0:W.response)==null?void 0:A.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 et(),Te(!1),ei(""),En(null)},500)}},IE=async A=>{var L;try{if(await he.delete(`${t}/api/files`,{data:{paths:[A.key]}}),g.has(A.key)){const te=new Set(g);te.delete(A.key),m(te)}const W=((L=A.key)==null?void 0:L.replace(/^(.*?)(\/.*)?$/,(te,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";y(W),Ze.current=!0,P({title:"Đã xóa tập tin",description:`Đã xóa thành công "${A.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{ut(!1),await et()}},ti=A=>{const L=new Set(g),W=typeof A=="function"?A(Pr):A;new Set(Object.keys(Pr).map(Number)).forEach(ie=>{const ge=un[ie];ge&&(W[ie]||(L.delete(ge.key),ge.isFolder&&Go(Lt,ge.key).forEach(Ee=>L.delete(Ee))))}),Object.entries(W).forEach(([ie,ge])=>{const Ee=parseInt(ie),Ke=un[Ee];Ke&&ge&&(L.add(Ke.key),Ke.isFolder&&Go(Lt,Ke.key).forEach(Jn=>L.add(Jn)))}),m(L)},ME=async()=>{var A;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 he.delete(`${t}/api/files`,{data:{paths:L}});const te=((A=W[0])==null?void 0:A.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Ee)=>!Ee||Ee==="/"?"":ge+"/"))||"";y(te),Ze.current=!0,et(),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)}},$E=async(A,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=A.key;let te;A.isFolder?te=W.split("/").slice(0,-2).join("/")+"/":te=W.substring(0,W.lastIndexOf("/")+1);const ie=te+L+(A.isFolder?"/":"");await he.post(`${t}/api/rename`,{oldPath:W,newPath:ie}),Ze.current=!0,await et(),P({title:"Đã đổi tên",description:`Đã đổi tên thành công "${A.name}" thành "${L}"`}),T(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)}},kp=async A=>{le(L=>new Set([...L,...A]));try{const L=await he.post(`${t}/api/download`,{paths:A},{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="(.+)"/),Ee=ge?decodeURIComponent(ge[1]):"download.zip";te.setAttribute("download",Ee),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 ${A.length} mục${A.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 A.forEach(te=>W.delete(te)),W})}},Op=f?f.replace(n,"").split("/").filter(Boolean):[],LE=()=>Array.from(g).map(A=>{var L;for(const W in Lt){const te=(L=Lt[W])==null?void 0:L.find(ie=>ie.key===A);if(te)return te}return null}).filter(A=>A!==null),Fp=_.useMemo(()=>{const A=[{id:"select",header:()=>{const L=KS(Lt,f),W=L.length>0&&L.every(ie=>g.has(ie)),te=L.some(ie=>g.has(ie));return l.jsx(Zi,{checked:W?!0:te?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=un.reduce((Ee,Ke,Jn)=>(Ee[Jn]=!0,Ee),{});ti(ge)}else ti({})},"aria-label":"Chọn tất cả"})},cell:({row:L})=>{const W=L.original,ie=W.isFolder?OE(W.key):g.has(W.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(Zi,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Ee={...Pr};ge?Ee[L.index]=!0:delete Ee[L.index],ti(Ee)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:L})=>l.jsxs(ye,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Ri,{})]}),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(oi,{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(oi,{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((Ee,Ke)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn(ge.slice(0,Ke+1).join("/")+"/")},children:Ee}),Ke<ge.length-1&&l.jsx("span",{children:"/"})]},Ke))]})]})]})}}];return r||A.push({id:"size",header:({column:L})=>l.jsxs(ye,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Ri,{})]}),accessorKey:"size",cell:({getValue:L,row:W})=>{const te=L();return l.jsx("span",{children:W.original.isFolder?"-":Pv(te)})}},{id:"lastModified",header:({column:L})=>l.jsxs(ye,{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(Ri,{})]}),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&&zl(W).isValid()?zl(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(ye,{variant:"ghost",size:"icon",onClick:()=>kp([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(Is,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Tải xuống"})]})}),f.trim()!==""&&l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{T(L.original),ee(L.original.name)},className:"h-8 w-8 p-0",children:l.jsx(Gp,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Đổi tên"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{oe(!0),D(L.original)},className:"h-8 w-8 p-0",children:l.jsx(Nh,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Di chuyển"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>$(L.original),className:"h-8 w-8 p-0",children:l.jsx($s,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Xóa"})]})})]})}),A},[g,un,Pr,ue,r]),Fs=Xs({data:un,columns:Fp,state:{rowSelection:Pr,sorting:s},onSortingChange:u,enableRowSelection:!0,onRowSelectionChange:ti,getCoreRowModel:Ys(),getSortedRowModel:Dg()}),RE=async A=>{var L,W;Ue(!0);try{if(br(A)){const te=await he.get(`${t}/api/read-text`,{params:{path:A.key}});K(te.data.content)}try{const te=await he.get(`${t}/api/read-json`,{params:{path:A.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{Ue(!1)}},VE=async(A,L)=>{Mt(!0);try{await he.post(`${t}/api/modify-text`,{path:A.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"}),Ze.current=!0,await et(),T(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{Mt(!1)}},jE=async A=>{Mt(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",B),await he.post(`${t}/api/modify-json`,{path:A.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"}),Ze.current=!0,await et(),T(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{Mt(!1)}};_.useEffect(()=>{j&&(j.isFolder||RE(j),S("rename"))},[j]);const zE=async(A,L)=>{var W;if(Se){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 he.post(`${t}/api/crawl`,{url:A,limit:L,prefix:f});if(te.id){Yn({id:te.id,url:A,limit:L,prefix:f,taskId:((W=te.task)==null?void 0:W.id)||""});const ie=localStorage.getItem(sp),ge=ie?JSON.parse(ie):[];ge.some(Ee=>Ee.id===te.id)||(ge.unshift({url:A,id:te.id,limit:L,prefix:f,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(sp,JSON.stringify(ge))),P({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${A} 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)}},BE=async()=>{try{if(!(Se!=null&&Se.id))return;Yn(null),localStorage.removeItem(Gn),P({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${Se.url}`})}catch(A){console.error("Error stopping job:",A),P({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const A=(L=!0)=>{const te=new URL(window.location.href).searchParams.get("prefix")||"";te?Xn(n+te,!1):(L&&!a&&m(new Set),y(""),v(""),Ze.current=!0,setTimeout(()=>{et()},0))};return A(!1),window.addEventListener("popstate",()=>A(!0)),()=>{window.removeEventListener("popstate",()=>A(!0))}},[]);const HE=async()=>{Pp(!0);try{const A=await he.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",A),P({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(A){console.error("Error exporting report:",A),P({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Pp(!1)}};return l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(xd,{}),l.jsx(jt,{open:CE,onOpenChange:A=>{Tr(A),A||(ei(""),En(null),Te(!1),F(null))},children:l.jsxs(Et,{children:[l.jsxs(_t,{children:[l.jsx(Tt,{children:"Cảnh báo trùng lặp"}),l.jsxs(Rn,{children:[_r&&l.jsxs(l.Fragment,{children:["Folder $",_r," đã có."]}),dt&&dt.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(dt).map((A,L)=>l.jsx("li",{children:A.name},L))})]})]})]}),l.jsxs(hn,{children:[l.jsx(ye,{variant:"outline",onClick:()=>{Tr(!1),ei(""),En(null),Te(!1),F(null)},children:"Bỏ qua"}),l.jsx(ye,{variant:"destructive",onClick:()=>DE(),children:"Ghi đè"})]})]})}),l.jsx(ac,{className:"s3-explr-breadcrumb",children:l.jsxs(sc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(Gi,{className:"s3-explr-breadcrumb-item",children:l.jsx(Ki,{onClick:()=>Xn(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),Op.map((A,L)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(lc,{className:"s3-explr-breadcrumb-separator"},`sep-${L}`),l.jsx(Gi,{className:"s3-explr-breadcrumb-item",children:l.jsx(Ki,{onClick:()=>Xn(n+Op.slice(0,L+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:A})},`item-${A}`)]},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(VC,{ref:q,onChange:A=>d(A)})}),l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{y(f),Ze.current=!0,et()},disabled:ks,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(Ms,{className:`h-4 w-4 s3-explr-refresh-icon ${ks?"animate-spin":""}`}),"Làm mới"]}),!r&&l.jsxs(l.Fragment,{children:[g.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>kp(Array.from(g)),disabled:Array.from(g).some(A=>ue.has(A)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(g).some(A=>ue.has(A))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(Is,{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(lo,{asChild:!0,children:l.jsxs(ye,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx($s,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",g.size,")"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(ye,{variant:"outline",onClick:()=>k(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:ME,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(lo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!f,children:[l.jsx(Bp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsx(_t,{className:"s3-explr-dialog-header",children:l.jsx(Tt,{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(nn,{disabled:x,id:"name",value:C,onChange:A=>E(A.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ye,{onClick:()=>{C.trim()&&FE(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(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-files-btn",onClick:()=>{const A=document.createElement("input");A.type="file",A.multiple=!0,A.onchange=L=>{const W=L.target.files;W&&Os(W,f,"files")},A.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(jp,{className:"h-4 w-4 s3-explr-upload-icon"}),"Tải lên tập tin"]})}),l.jsx(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-folder-btn",onClick:()=>{const A=document.createElement("input");A.type="file",A.multiple=!0,A.webkitdirectory=!0,A.onchange=L=>{const W=L.target.files;W&&Os(W,f,"folder")},A.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(oi,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),Se?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(ye,{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"}),Se.status?l.jsxs(l.Fragment,{children:["Đang thu thập (",Se.status.completed,"/",Se.status.total,") - ",Math.floor(cn/60),":",String(cn%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ye,{variant:"destructive",size:"sm",onClick:()=>void BE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(Yp,{className:"h-4 w-4"})]})]})}),Se.status&&l.jsx(sn,{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 ",Se.url]}),l.jsxs("p",{children:["Tiến độ: ",Se.status.completed,"/",Se.status.total," trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(cn/60),":",String(cn%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",Se.status.status==="scraping"?"Đang thu thập":Se.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):l.jsxs(jt,{open:N,onOpenChange:V,children:[l.jsx(lo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,children:[l.jsx(Wp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(nn,{id:"websiteUrl",value:ne,onChange:A=>J(A.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(nn,{id:"crawlLimit",value:X,onChange:A=>{const L=A.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(ye,{variant:"outline",onClick:()=>{V(!1),J(""),z("1")},disabled:Y,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{onClick:()=>{ne.trim()&&zE(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(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,onClick:HE,children:[Ns&&l.jsx(Ms,{className:`h-4 w-4 s3-explr-refresh-icon ${Ns?"animate-spin":""}`}),"Xuất báo cáo"]})}),Ns&&l.jsx(sn,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>AE(),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:A=>!A&&$(null),children:l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(ye,{variant:"outline",onClick:()=>$(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:()=>IE(I),disabled:$t,className:"s3-explr-confirm-delete-btn",children:$t?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:A=>{A||(T(null),Q(null),ee(""),K(""),S("rename"))},children:l.jsxs(Et,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(_t,{className:"s3-explr-dialog-header",children:l.jsx(Tt,{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(nb,{value:at,onValueChange:A=>S(A),children:[l.jsxs(qu,{"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(wo,{value:"rename",children:"Đổi tên"}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(wo,{value:"edit",children:"Sửa nội dung"}),l.jsx(wo,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Co,{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(nn,{id:"newName",value:re,onChange:A=>ee(A.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(Co,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:_e?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:A=>K(A.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:We})]})})}),l.jsx(Co,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:_e?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(([A,L],W)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(vn,{htmlFor:A,className:"s3-explr-label flex items-center gap-1",children:[Wh[A]||A,Bi(A)&&l.jsx(kh,{className:"h-[12px] w-[12px] text-red-500"})]}),qh(A)?l.jsx(ur,{id:A,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[A]:te.target.value};Q(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:We||Bi(A)}):l.jsx(nn,{id:A,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[A]:te.target.value};Q(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:We||Bi(A)})]},W))})})})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{T(null),Q(null),ee(""),K("")},className:"s3-explr-cancel-btn",children:"Hủy"}),at==="edit"?l.jsx(ye,{onClick:()=>j&&VE(j,Ce),disabled:We||_e,className:"s3-explr-save-btn",children:We?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"}):at==="edit-metadata"?l.jsx(ye,{onClick:()=>B&&typeof B=="object"&&j&&jE(j),disabled:We||_e,className:"s3-explr-save-btn",children:We?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(ye,{onClick:()=>{re.trim()&&j&&$E(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(HS,{openDialogRename:ce,setOpenDialogRename:oe,apiBaseUrl:t,setFileToMove:D,fileToMove:H,refreshFiles:et,ignoreCache:Ze})]})]}),TE&&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(BS,{onFilesSelected:(A,L)=>Os(A,f,L),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(mo,{className:"s3-explr-table",children:[l.jsx(ho,{className:"s3-explr-table-header",children:Fs.getHeaderGroups().map(A=>l.jsx(vt,{className:"hover:bg-transparent s3-explr-header-row",children:A.headers.map(L=>l.jsx(At,{className:"s3-explr-header-cell",children:L.isPlaceholder?null:Lr(L.column.columnDef.header,L.getContext())},L.id))},A.id))}),l.jsx(vo,{className:"s3-explr-table-body",children:Fs.getRowModel().rows.length===0?l.jsx(vt,{className:"s3-explr-empty-row",children:l.jsx(Je,{colSpan:Fp.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:ks?"Đ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"})})}):Fs.getRowModel().rows.map(A=>l.jsx(vt,{className:"h-12 s3-explr-row",children:A.getVisibleCells().map(L=>l.jsx(Je,{className:"align-middle s3-explr-cell",children:Lr(L.column.columnDef.cell,L.getContext())},L.id))},A.id))})]})})}),c&&Ar!==0&&l.jsx(l.Fragment,{children:l.jsx(co,{children:l.jsxs(uo,{children:[l.jsx(fo,{onClick:()=>Wt(A=>Math.max(A-1,1)),"aria-disabled":je===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Ar/20)},(A,L)=>{const W=L+1,te=Math.ceil(Ar/20);return te>7&&!(W===1||W===te||W>=je-1&&W<=je+1)?W===je-2&&je>4||W===je+2&&je<te-3?l.jsx(go,{className:"pointer-events-none",children:"..."},L):null:l.jsx(ht,{className:"cursor-pointer",children:l.jsx(Vn,{isActive:je===W,onClick:()=>Wt(W),className:`${je===W?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:W})},L)}),l.jsx(ht,{children:l.jsx(po,{onClick:()=>Wt(A=>Math.min(A+1,Math.ceil(Ar/20))),"aria-disabled":je===Math.ceil(Ar/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(ye,{variant:"default",onClick:()=>o(LE()),disabled:g.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),JS=e=>l.jsx(Zp,{clientId:WS,children:l.jsx(XS,{...e})});var wr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Ge=e=>e==null;const lp=e=>typeof e=="object";var Me=e=>!Ge(e)&&!Array.isArray(e)&&lp(e)&&!Sn(e),ZS=e=>Me(e)&&e.target?wr(e.target)?e.target.checked:e.target.value:e,QS=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,eE=(e,t)=>e.has(QS(t)),tE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},ws=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ct(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(!(ws&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!tE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ct(e[o]));else return e;return t}var Ko=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,se=(e,t,n)=>{if(!t||!Me(e))return n;const r=Ko(t.split(/[,[\].]+?/)).reduce((o,i)=>Ge(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Ft=e=>typeof e=="boolean",Cs=e=>/^\w*$/.test(e),cp=e=>Ko(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Fe=(e,t,n)=>{let r=-1;const o=Cs(t)?[t]:cp(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 up={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},bt={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 nE=(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]!==bt.all&&(t._proxyFormState[a]=!r||bt.all),e[a]}});return o},Qe=e=>Me(e)&&!Object.keys(e).length,rE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return Qe(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===bt.all)},Yo=e=>Array.isArray(e)?e:[e];function oE(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 Dt=e=>typeof e=="string",iE=(e,t,n,r,o)=>Dt(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),aE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},dp=e=>({isOnSubmit:!e||e===bt.onSubmit,isOnBlur:e===bt.onBlur,isOnChange:e===bt.onChange,isOnAll:e===bt.all,isOnTouch:e===bt.onTouched}),fp=(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 sE=(e,t,n)=>{const r=Yo(se(e,n));return Fe(r,"root",t[n]),Fe(e,n,r),e},Ss=e=>e.type==="file",It=e=>typeof e=="function",Xo=e=>{if(!ws)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Jo=e=>Dt(e),Es=e=>e.type==="radio",Zo=e=>e instanceof RegExp;const pp={value:!1,isValid:!1},gp={value:!0,isValid:!0};var mp=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===""?gp:{value:e[0].value,isValid:!0}:gp:pp}return pp};const hp={isValid:!1,value:null};var vp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,hp):hp;function yp(e,t,n="validate"){if(Jo(e)||Array.isArray(e)&&e.every(Jo)||Ft(e)&&!e)return{type:n,message:Jo(e)?e:"",ref:t}}var Kn=e=>Me(e)&&!Zo(e)?e:{value:e,message:""},xp=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(Ft(U)?"":U||""),C.reportValidity())},x={},O=Es(i),I=wr(i),$=O||I,H=(h||Ss(i))&&Ie(i.value)&&Ie(w)||Xo(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,D=aE.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||Ge(w))||Ft(w)&&!w||I&&!mp(a).isValid||O&&!vp(a).isValid)){const{value:U,message:Z}=Jo(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&&(!Ge(d)||!Ge(g))){let U,Z;const k=Kn(g),M=Kn(d);if(!Ge(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ge(k.value)||(U=F>k.value),Ge(M.value)||(Z=F<M.value)}else{const F=i.valueAsDate||new Date(w),q=T=>new Date(new Date().toDateString()+" "+T),P=i.type=="time",j=i.type=="week";Dt(k.value)&&w&&(U=P?q(w)>q(k.value):j?w>k.value:F>new Date(k.value)),Dt(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&&(Dt(w)||o&&Array.isArray(w))){const U=Kn(u),Z=Kn(c),k=!Ge(U.value)&&w.length>+U.value,M=!Ge(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&&Dt(w)){const{value:U,message:Z}=Kn(m);if(Zo(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(It(f)){const U=await f(w,t),Z=yp(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(!Qe(U)&&!n)break;const k=yp(await f[Z](w,t),C,Z);k&&(U={...k,...D(Z,k.message)},E(k.message),n&&(x[v]=U))}if(!Qe(U)&&(x[v]={ref:C,...U},!n))return x}}return E(!0),x};function lE(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 cE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ie(e[t]))return!1;return!0}function Ve(e,t){const n=Array.isArray(t)?t:Cs(t)?[t]:cp(t),r=n.length===1?e:lE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&Qe(r)||Array.isArray(r)&&cE(r))&&Ve(e,n.slice(0,-1)),e}var _s=()=>{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=[]}}},Ts=e=>Ge(e)||!lp(e);function ln(e,t){if(Ts(e)||Ts(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)?!ln(i,a):i!==a)return!1}}return!0}var bp=e=>e.type==="select-multiple",uE=e=>Es(e)||wr(e),As=e=>Xo(e)&&e.isConnected,wp=e=>{for(const t in e)if(It(e[t]))return!0;return!1};function Qo(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!wp(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Qo(e[r],t[r])):Ge(e[r])||(t[r]=!0);return t}function Cp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!wp(e[o])?Ie(t)||Ts(n[o])?n[o]=Array.isArray(e[o])?Qo(e[o],[]):{...Qo(e[o])}:Cp(e[o],Ge(t)?{}:t[o],n[o]):n[o]=!ln(e[o],t[o]);return n}var Sr=(e,t)=>Cp(e,t,Qo(t)),Sp=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&Dt(e)?new Date(e):r?r(e):e;function Ps(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return Ss(t)?t.files:Es(t)?vp(e.refs).value:bp(t)?[...t.selectedOptions].map(({value:n})=>n):wr(t)?mp(e.refs).value:Sp(Ie(t.value)?e.ref.value:t.value,e)}var dE=(e,t,n,r)=>{const o={};for(const i of e){const a=se(t,i);a&&Fe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Er=e=>Ie(e)?e:Zo(e)?e.source:Me(e)?Zo(e.value)?e.value.source:e.value:e;const Ep="AsyncFunction";var fE=e=>!!e&&!!e.validate&&!!(It(e.validate)&&e.validate.constructor.name===Ep||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Ep)),pE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function _p(e,t,n){const r=se(e,n);if(r||Cs(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 gE=(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,mE=(e,t)=>!Ko(se(e,t)).length&&Ve(e,t);const hE={mode:bt.onSubmit,reValidateMode:bt.onChange,shouldFocusError:!0};function vE(e={}){let t={...hE,...e},n={submitCount:0,isDirty:!1,isLoading:It(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)?ct(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ct(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:_s(),array:_s(),state:_s()},m=dp(t.mode),f=dp(t.reValidateMode),v=t.criteriaMode===bt.all,h=S=>N=>{clearTimeout(c),c=setTimeout(S,N)},y=async S=>{if(!t.disabled&&(d.isValid||S)){const N=t.resolver?Qe((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?Fe(n.validatingFields,V,N):Ve(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!Qe(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&&Fe(r,S,z)}if(X&&Array.isArray(se(n.errors,S))){const z=V(se(n.errors,S),ne.argA,ne.argB);J&&Fe(n.errors,S,z),mE(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&&Fe(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 Fe(i,S,N)},C=(S,N)=>{Fe(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?Fe(i,S,N?X:Ps(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||ln(se(o,S),N);z=!!(!xe&&se(n.dirtyFields,S)),we||xe?Ve(n.dirtyFields,S):Fe(n.dirtyFields,S,!0),Y.dirtyFields=n.dirtyFields,X=X||d.dirtyFields&&z!==!we}if(V){const we=se(n.touchedFields,S);we||(Fe(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&&Ft(N)&&n.isValid!==N;if(t.delayError&&V?(u=h(()=>C(S,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Fe(n.errors,S,V):Ve(n.errors,S)),(V?!ln(J,V):J)||!Qe(ne)||X){const z={...ne,...X&&Ft(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,dE(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?Fe(n.errors,V,ne):Ve(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&&fE(J._f);xe&&d.validatingFields&&b([ne],!0);const we=await xp(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?sE(n.errors,we,X.name):Fe(n.errors,X.name,we[X.name]):Ve(n.errors,X.name))}!Qe(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=>!As(V)):!As(N._f.ref))&&oe(S)}s.unMount=new Set},U=(S,N)=>!t.disabled&&(S&&N&&Fe(i,S,N),!ln(B(),o)),Z=(S,N,V)=>iE(S,s,{...a.mount?i:Ie(N)?o:Dt(S)?{[S]:N}:N},V,N),k=S=>Ko(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&&Fe(i,S,Sp(N,X)),J=Xo(X.ref)&&Ge(N)?"":N,bp(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):Ss(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&&T(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=ct(N);Fe(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&&!Ge(X)?F(S,X,V):M(S,X,V),fp(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?Ps(J._f):ZS(S),z=Y=>{ne=Number.isNaN(Y)||Sn(Y)&&isNaN(Y.getTime())||ln(Y,se(i,V,Y))};if(J){let Y,xe;const we=X(),Te=S.type===up.BLUR||S.type===up.FOCUS_OUT,$t=!pE(J._f)&&!t.resolver&&!se(n.errors,V)&&!J._f.deps||gE(Te,se(n.touchedFields,V),n.isSubmitted,f,m),ut=fp(V,s,Te);Fe(i,V,we),Te?(J._f.onBlur&&J._f.onBlur(S),u&&u(0)):J._f.onChange&&J._f.onChange(S);const je=O(V,we,Te,!1),Wt=!Qe(je)||ut;if(!Te&&g.values.next({name:V,type:S.type,values:{...i}}),$t)return d.isValid&&(t.mode==="onBlur"?Te&&y():y()),Wt&&g.state.next({name:V,...ut?{}:je});if(!Te&&ut&&g.state.next({...n}),t.resolver){const{errors:qt}=await $([V]);if(z(we),ne){const Gt=_p(n.errors,r,V),Se=_p(qt,r,Gt.name||V);Y=Se.error,V=Se.name,xe=Qe(qt)}}else b([V],!0),Y=(await xp(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&&T(J._f.deps),I(V,xe,Y,je))}},j=(S,N)=>{if(se(n.errors,N)&&S.focus)return S.focus(),1},T=async(S,N={})=>{let V,ne;const J=Yo(S);if(t.resolver){const X=await H(Ie(S)?S:J);V=Qe(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({...!Dt(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:Dt(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&&Yo(S).forEach(N=>Ve(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;Fe(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)=>It(S)?g.values.subscribe({next:V=>S(Z(void 0,N),V)}):Z(S,N,!0),oe=(S,N={})=>{for(const V of S?Yo(S):s.mount)s.mount.delete(V),s.array.delete(V),N.keepValue||(Ve(r,V),Ve(i,V)),!N.keepError&&Ve(n.errors,V),!N.keepDirty&&Ve(n.dirtyFields,V),!N.keepTouched&&Ve(n.touchedFields,V),!N.keepIsValidating&&Ve(n.validatingFields,V),!t.shouldUnregister&&!N.keepDefaultValue&&Ve(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(Ft(S)&&a.mount||S){const X=S?void 0:Ie(J)?Ps(V?V._f:se(ne,N)._f):J;(S||!S&&!Ie(X))&&Fe(i,N,X),O(N,X,!1,!1,!0)}},de=(S,N={})=>{let V=se(r,S);const ne=Ft(N.disabled)||Ft(t.disabled);return Fe(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:Ft(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=uE(X),Y=V._f.refs||[];if(z?Y.find(xe=>xe===X):X===V._f.ref)return;Fe(r,S,{_f:{...V._f,...z?{refs:[...Y.filter(As),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)&&!(eE(s.array,S)&&a.action)&&s.unMount.add(S)}}},ue=()=>t.shouldFocusError&&Cr(r,j,s.mount),le=S=>{Ft(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=ct(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(Ve(n.errors,"root"),Qe(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:Qe(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},K=(S,N={})=>{se(r,S)&&(Ie(N.defaultValue)?q(S,ct(se(o,S))):(q(S,N.defaultValue),Fe(o,S,ct(N.defaultValue))),N.keepTouched||Ve(n.touchedFields,S),N.keepDirty||(Ve(n.dirtyFields,S),n.isDirty=N.defaultValue?U(S,ct(se(o,S))):U()),N.keepError||(Ve(n.errors,S),d.isValid&&y()),g.state.next({...n}))},_e=(S,N={})=>{const V=S?ct(S):o,ne=ct(V),J=Qe(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)?Fe(X,Y,se(i,Y)):q(Y,se(X,Y))}else{if(ws&&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(Xo(xe)){const we=xe.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?N.keepDefaultValues?ct(o):{}:ct(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&&!ln(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})},Ue=(S,N)=>_e(It(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:_e,_resetDefaultValues:()=>It(t.defaultValues)&&t.defaultValues().then(S=>{Ue(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:T,register:de,handleSubmit:Ce,watch:ce,setValue:q,getValues:B,reset:Ue,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&&It(J.select)&&J.select())}},getFieldState:Q}}function yE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:It(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:It(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...vE(e),formState:r});const i=t.current.control;return i._options=e,oE({subject:i._subjects.state,next:a=>{rE(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&&!ln(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:nE(r,i)}),[r,i])}const Tp=({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:me("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(sn,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},xE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},bE=({apiBaseUrl:e="http://localhost:3002"})=>{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=xE(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 he.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(Tp,{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}=yE(),j=H.original.id,T=H.getValue("status"),B=H.getValue("content"),[Q,re]=_.useState(!1),ee=async()=>{try{re(!0);const oe=T==="unpublish"?"published":"unpublish",ae=await he.patch(`${e}/api/toggle-publish/${j}`,{id:j,typeAction:"update",status:T,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 he.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(ye,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"px-2 py-0.5 h-7",children:l.jsx(Ph,{className:"h-4 w-4"})}),l.jsx(jt,{open:k,onOpenChange:M,children:l.jsxs(Et,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(_t,{children:l.jsx(Tt,{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(lo,{asChild:!0,children:l.jsx(ye,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),l.jsx(Et,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(_t,{className:"flex flex-col gap-3",children:[l.jsx(Tt,{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(ye,{disabled:D,type:"submit",variant:"default",children:D?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ye,{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"}):T==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=Xs({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:Fg(),getCoreRowModel:Ys()});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(nn,{placeholder:"Tìm kiếm theo mã...",value:f,onChange:$=>v($.target.value),className:"pr-8"}),f&&l.jsx(ye,{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(Vi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(mo,{className:"s3-explr-table",children:[l.jsx(ho,{className:"s3-explr-table-header",children:x.getHeaderGroups().map($=>l.jsx(vt,{className:"hover:bg-transparent s3-explr-header-row",children:$.headers.map(H=>l.jsx(At,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Lr(H.column.columnDef.header,H.getContext())},H.id))},$.id))}),l.jsx(vo,{className:"s3-explr-table-body",children:r?l.jsx(vt,{children:l.jsx(Je,{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(vt,{className:"h-12 s3-explr-row",children:$.getVisibleCells().map(H=>l.jsx(Je,{className:"align-middle s3-explr-cell",children:Lr(H.column.columnDef.cell,H.getContext())},H.id))},$.id)):l.jsx(vt,{children:l.jsx(Je,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(co,{children:l.jsxs(uo,{children:[l.jsx(ht,{children:l.jsx(fo,{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(ht,{children:l.jsx(go,{})},$+"..."),l.jsx(ht,{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(ht,{children:l.jsx(po,{onClick:()=>u($=>Math.min(c,$+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Ap=10,wE=_.memo(({apiBaseUrl:e="http://localhost:3002"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Ap,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:f}=Po(),[v,h]=_.useState(!1),y=async x=>{try{d(x);const O=await he.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Ap.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 he.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(Eh,{className:"w-8 h-8 text-primary"}),l.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),l.jsx(ye,{variant:"outline",size:"icon",onClick:w,disabled:v||s,className:"ml-2",children:l.jsx(Oh,{className:`h-4 w-4 ${v?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(mo,{children:[l.jsx(ho,{children:l.jsxs(vt,{children:[l.jsx(At,{children:"ID"}),l.jsx(At,{children:"Tên Công Việc"}),l.jsx(At,{children:"Thời Gian Bắt Đầu"}),l.jsx(At,{children:"Thời Gian Cập Nhật"}),l.jsx(At,{children:"Thời Gian Thực Thi"}),l.jsx(At,{children:"Trạng Thái"}),l.jsx(At,{children:"Thao Tác"})]})}),l.jsx(vo,{children:s&&r.length===0?l.jsx(vt,{children:l.jsx(Je,{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(vt,{children:[l.jsx(Je,{className:"!w-[100px]",children:x.id}),l.jsx(Je,{className:"font-medium",children:(O=x.job_name)==null?void 0:O.replace("Upload file","Summary")}),l.jsx(Je,{className:"!w-[200px]",children:C(x.created_at)}),l.jsx(Je,{className:"!w-[200px]",children:C(x.updated_at)}),l.jsx(Je,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Je,{className:"!w-[200px]",children:l.jsx(Tp,{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 np(e,t){if(e){if(typeof e=="string")return vs(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 vs(e,t)}}function vs(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 RS(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 VS(e){if(Array.isArray(e))return e}function rp(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?rp(Object(n),!0).forEach(function(r){ys(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ys(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function qo(e,t){if(e==null)return{};var n=jS(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 jS(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 xs=_.forwardRef(function(e,t){var n=e.children,r=qo(e,NS),o=ip(r),i=o.open,a=qo(o,kS);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});xs.displayName="Dropzone";var op={disabled:!1,getFilesFromEvent:ZC,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};xs.defaultProps=op,xs.propTypes={children:ke.func,accept:ke.objectOf(ke.arrayOf(ke.string)),multiple:ke.bool,preventDropOnDocument:ke.bool,noClick:ke.bool,noKeyboard:ke.bool,noDrag:ke.bool,noDragEventsBubbling:ke.bool,minSize:ke.number,maxSize:ke.number,maxFiles:ke.number,disabled:ke.bool,getFilesFromEvent:ke.func,onFileDialogCancel:ke.func,onFileDialogOpen:ke.func,useFsAccessApi:ke.bool,autoFocus:ke.bool,onDragEnter:ke.func,onDragLeave:ke.func,onDragOver:ke.func,onDrop:ke.func,onDropAccepted:ke.func,onDropRejected:ke.func,onError:ke.func,validator:ke.func};var bs={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function ip(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},op),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 TS(n)},[n]),G=_.useMemo(function(){return _S(n)},[n]),U=_.useMemo(function(){return typeof y=="function"?y:ap},[y]),Z=_.useMemo(function(){return typeof h=="function"?h:ap},[h]),k=_.useRef(null),M=_.useRef(null),F=_.useReducer(zS,bs),q=hs(F,2),P=q[0],j=q[1],T=P.isFocused,B=P.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&ES()),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",Qf,!1),document.addEventListener("drop",ce,!1)),function(){C&&(document.removeEventListener("dragover",Qf),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(DS(ee.current),[z.target]),Wo(z)&&Promise.resolve(o(z)).then(function(Y){if(!(Uo(z)&&!I)){var xe=Y.length,we=xe>0&&bS({files:Y,accept:D,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Te=xe>0&&!we;j({isDragAccept:we,isDragReject:Te,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=Wo(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}),Wo(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var xe=[],we=[];z.forEach(function(Te){var $t=Jf(Te,D),ut=hs($t,2),je=ut[0],Wt=ut[1],qt=Zf(Te,a,i),Gt=hs(qt,2),Se=Gt[0],cn=Gt[1],Yn=H?H(Te):null;if(je&&Se&&!Yn)xe.push(Te);else{var dt=[Wt,cn];Yn&&(dt=dt.concat(Yn)),we.push({file:Te,errors:dt.filter(function(En){return En})})}}),(!s&&xe.length>1||s&&u>=1&&xe.length>u)&&(xe.forEach(function(Te){we.push({file:Te,errors:[xS]})}),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=[],Wo(z)&&Promise.resolve(o(z)).then(function(Y){Uo(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){AS(Y)?(Z(Y),j({type:"closeDialog"})):PS(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]),_e=_.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]),Ue=_.useCallback(function(){j({type:"focus"})},[]),We=_.useCallback(function(){j({type:"blur"})},[]),Mt=_.useCallback(function(){E||(SS()?setTimeout(K,0):K())},[E,K]),at=function(Y){return r?null:Y},S=function(Y){return x?null:at(Y)},N=function(Y){return O?null:at(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,Te=z.onKeyDown,$t=z.onFocus,ut=z.onBlur,je=z.onClick,Wt=z.onDragEnter,qt=z.onDragOver,Gt=z.onDragLeave,Se=z.onDrop,cn=qo(z,OS);return De(De(ys({onKeyDown:S(Ot(Te,_e)),onFocus:S(Ot($t,Ue)),onBlur:S(Ot(ut,We)),onClick:at(Ot(je,Mt)),onDragEnter:N(Ot(Wt,ae)),onDragOver:N(Ot(qt,de)),onDragLeave:N(Ot(Gt,ue)),onDrop:N(Ot(Se,Ce)),role:typeof we=="string"&&we!==""?we:"presentation"},xe,k),!r&&!x?{tabIndex:0}:{}),cn)}},[k,_e,Ue,We,Mt,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,Te=z.onClick,$t=qo(z,FS),ut=ys({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:at(Ot(we,Ce)),onClick:at(Ot(Te,J)),tabIndex:-1},xe,M);return De(De({},ut),$t)}},[M,n,s,Ce,r]);return De(De({},P),{},{isFocused:T&&!r,getRootProps:ne,getInputProps:X,rootRef:k,inputRef:M,open:at(K)})}function zS(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({},bs),{},{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({},bs);default:return e}}function ap(){}const BS=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=ip({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()})]})},HS=({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}=Po();_.useEffect(()=>{e&&y(f)},[f,e]);const y=async C=>{try{m(!0);const E=await he.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 he.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(Et,{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(_t,{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(Tt,{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(ye,{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(ye,{onClick:b,disabled:c,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},US="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",WS="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",qS="https://www.googleapis.com/auth/drive";Xt(he,{retries:3});const Ze={current:!1},sp="crawl:jobs",Gn="crawl:current_job",GS=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 he.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)}}},Go=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},KS=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Go(e,o.key))}),n},YS=(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 he.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 he.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||"")},XS=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="http://localhost:3002",rootPrefix:n="",asSelector:r=!1,onSelected:o=s=>console.log("Đã chọn:",s),displayPrefixes:i,preSelectedFiles:a})=>{var Dp;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}=Po(),[j,T]=_.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(""),[_e,Ue]=_.useState(!1),[We,Mt]=_.useState(!1),[at,S]=_.useState("rename"),[N,V]=_.useState(!1),[ne,J]=_.useState(""),[X,z]=_.useState("1"),[Y,xe]=_.useState(!1),[we,Te]=_.useState(!1),[$t,ut]=_.useState(!1),[je,Wt]=_.useState(1),[qt,Gt]=_.useState(!1),{currentJob:Se,elapsedTime:cn,setCurrentJob:Yn}=GS(t),[dt,En]=_.useState(null),[_r,ei]=_.useState(""),[CE,Tr]=_.useState(!1),[Ns,Pp]=_.useState(!1),SE=new URL(window.location.href).searchParams.get("prefix")||"",EE=n+SE||h||n,[g_,_E]=_.useState(null),{data:Lt,isLoading:ks,error:TE,estimatedTotalHits:Ar,refetch:et}=YS(t,EE,i,c,je,d),AE=eg({onSuccess:A=>{_E(A.access_token),localStorage.setItem("google_access_token",A.access_token),PE(A.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:qS}),PE=A=>{const L=document.createElement("script");L.src="https://apis.google.com/js/api.js",L.onload=()=>{window.gapi.load("picker",()=>NE(A))},document.body.appendChild(L)},NE=A=>{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(US).setOAuthToken(A).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(Ee=>({id:Ee.id,name:Ee.name,mimeType:Ee.mimeType}));await kE(ge,f)}}).build().setVisible(!0)},kE=async(A,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."),Ne.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const te=Ne.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:L,folders:[],files:[]};A.forEach(Ee=>{Ee.mimeType==="application/vnd.google-apps.folder"?ie.folders.push({id:Ee.id,name:Ee.name}):ie.files.push({id:Ee.id,name:Ee.name})});const ge=await he.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${W}`}});Ze.current=!0,et(),Ne.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),Ne.update(te,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const A=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",A),()=>window.removeEventListener("message",A)},[]),_.useEffect(()=>{const A=new Set(a);m(A)},[]),_.useEffect(()=>{Se!=null&&Se.status&&(Se.status.status==="completed"?(P({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${Se.url} với ${Se.status.completed} trang`}),Ze.current=!0,et()):Se.status.status==="failed"&&P({title:"Thu thập website thất bại",description:`Không thể thu thập ${Se.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(Dp=Se==null?void 0:Se.status)==null?void 0:Dp.status]);const Np=_.useMemo(()=>Lt[f]||[],[Lt,f]),un=_.useMemo(()=>Np,[Np,f,Lt]),Pr=_.useMemo(()=>{const A={};return un.forEach((L,W)=>{g.has(L.key)&&(A[W]=!0)}),A},[g,un]),OE=A=>{const L=Go(Lt,A);if(L.length===0)return g.has(A)?"all":"none";const W=L.filter(te=>g.has(te)).length;return W===0?"none":W===L.length?"all":"partial"},Xn=(A,L=!0)=>{if(f!==A&&(Gt(!0),y(A),v(A),a||m(new Set),L)){const W=window.location.pathname==="/"?"":window.location.pathname,te=A?`${window.location.origin}${W}?prefix=${encodeURIComponent(A)}`:`${window.location.origin}${W}`;window.history.pushState({path:te},"",te)}};_.useEffect(()=>{qt&&(Ze.current=!0,et().finally(()=>Gt(!1)))},[qt]);const FE=async(A,L)=>{var W,te;O(!0);try{if(un.some(Ke=>Ke.isFolder&&Ke.name.toLowerCase()===A.toLowerCase())){P({title:"Lỗi",description:`Thư mục "${A}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),O(!1);return}const ge=`${L}${A}/`;if((await he.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}Ze.current=!0,await et(),P({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${A}"`}),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)}},Os=async(A,L,W)=>{var te,ie,ge,Ee,Ke,Jn,Ip,Mp,$p;F(W),Te(!0);try{if(Array.from(A).reduce((Ye,Or)=>Ye+Or.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),Te(!1);return}const ni=Array.from(A).filter(Ye=>Ye.size===0);if(ni.length>0){const Ye=ni.map(Or=>Or.name).join(", ");P({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Ye}`,variant:"destructive"}),Te(!1),F(null);return}let kr=localStorage.getItem("dataLogin"),Zn;try{kr&&(kr=JSON.parse(kr),Zn=kr.user)}catch{kr=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"&&A[0]){const Ye=A[0].webkitRelativePath.split("/")[0];Ye&&_n.append("folderName",Ye)}_n.append("prefix",L),Array.from(A).forEach(Ye=>W==="folder"?_n.append("files",Ye,Ye.webkitRelativePath):_n.append("files",Ye)),Ze.current=!0;const ze=await he.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 he.post(`${t}/api/upload`,_n,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(L),setTimeout(async()=>{F(null),await et(),Te(!1)},500);else{if(((ge=(ie=ze==null?void 0:ze.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Ee=ze==null?void 0:ze.data)!=null&&Ee.isFolder)){const Ye=Array.from(A).filter(Or=>ze.data.names.includes(Or.name));En(Ye),Tr(!0)}(Ke=ze==null?void 0:ze.data)!=null&&Ke.isFolder&&((Jn=ze==null?void 0:ze.data)!=null&&Jn.name)&&(ei((Ip=ze==null?void 0:ze.data)==null?void 0:Ip.name),En(A),Tr(!0))}}catch(Nr){console.error("Lỗi tải lên:",Nr);const ni=(($p=(Mp=Nr==null?void 0:Nr.response)==null?void 0:Mp.data)==null?void 0:$p.error)||"Không thể tải lên tập tin";P({title:"Lỗi",description:ni,variant:"destructive"}),F(null),Te(!1)}},DE=async()=>{var A,L;try{Te(!0);const W=new FormData;if(dt){F(_r?"folder":"files"),Tr(!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"}))),_r&&dt[0]){const ge=dt[0].webkitRelativePath.split("/")[0];ge&&W.append("folderName",ge)}W.append("prefix",f),Array.from(dt).forEach(ge=>_r&&dt[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 he.post(`${t}/api/upload`,W,{headers:{"Content-Type":"multipart/form-data"}}),d(""),y(f),Ze.current=!0}}catch(W){console.error("Lỗi tải lên:",W);const te=((L=(A=W==null?void 0:W.response)==null?void 0:A.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 et(),Te(!1),ei(""),En(null)},500)}},IE=async A=>{var L;try{if(await he.delete(`${t}/api/files`,{data:{paths:[A.key]}}),g.has(A.key)){const te=new Set(g);te.delete(A.key),m(te)}const W=((L=A.key)==null?void 0:L.replace(/^(.*?)(\/.*)?$/,(te,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";y(W),Ze.current=!0,P({title:"Đã xóa tập tin",description:`Đã xóa thành công "${A.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{ut(!1),await et()}},ti=A=>{const L=new Set(g),W=typeof A=="function"?A(Pr):A;new Set(Object.keys(Pr).map(Number)).forEach(ie=>{const ge=un[ie];ge&&(W[ie]||(L.delete(ge.key),ge.isFolder&&Go(Lt,ge.key).forEach(Ee=>L.delete(Ee))))}),Object.entries(W).forEach(([ie,ge])=>{const Ee=parseInt(ie),Ke=un[Ee];Ke&&ge&&(L.add(Ke.key),Ke.isFolder&&Go(Lt,Ke.key).forEach(Jn=>L.add(Jn)))}),m(L)},ME=async()=>{var A;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 he.delete(`${t}/api/files`,{data:{paths:L}});const te=((A=W[0])==null?void 0:A.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Ee)=>!Ee||Ee==="/"?"":ge+"/"))||"";y(te),Ze.current=!0,et(),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)}},$E=async(A,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=A.key;let te;A.isFolder?te=W.split("/").slice(0,-2).join("/")+"/":te=W.substring(0,W.lastIndexOf("/")+1);const ie=te+L+(A.isFolder?"/":"");await he.post(`${t}/api/rename`,{oldPath:W,newPath:ie}),Ze.current=!0,await et(),P({title:"Đã đổi tên",description:`Đã đổi tên thành công "${A.name}" thành "${L}"`}),T(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)}},kp=async A=>{le(L=>new Set([...L,...A]));try{const L=await he.post(`${t}/api/download`,{paths:A},{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="(.+)"/),Ee=ge?decodeURIComponent(ge[1]):"download.zip";te.setAttribute("download",Ee),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 ${A.length} mục${A.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 A.forEach(te=>W.delete(te)),W})}},Op=f?f.replace(n,"").split("/").filter(Boolean):[],LE=()=>Array.from(g).map(A=>{var L;for(const W in Lt){const te=(L=Lt[W])==null?void 0:L.find(ie=>ie.key===A);if(te)return te}return null}).filter(A=>A!==null),Fp=_.useMemo(()=>{const A=[{id:"select",header:()=>{const L=KS(Lt,f),W=L.length>0&&L.every(ie=>g.has(ie)),te=L.some(ie=>g.has(ie));return l.jsx(Zi,{checked:W?!0:te?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=un.reduce((Ee,Ke,Jn)=>(Ee[Jn]=!0,Ee),{});ti(ge)}else ti({})},"aria-label":"Chọn tất cả"})},cell:({row:L})=>{const W=L.original,ie=W.isFolder?OE(W.key):g.has(W.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(Zi,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Ee={...Pr};ge?Ee[L.index]=!0:delete Ee[L.index],ti(Ee)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:L})=>l.jsxs(ye,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Ri,{})]}),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(oi,{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(oi,{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((Ee,Ke)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Xn(ge.slice(0,Ke+1).join("/")+"/")},children:Ee}),Ke<ge.length-1&&l.jsx("span",{children:"/"})]},Ke))]})]})]})}}];return r||A.push({id:"size",header:({column:L})=>l.jsxs(ye,{variant:"ghost",onClick:()=>L.toggleSorting(L.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Ri,{})]}),accessorKey:"size",cell:({getValue:L,row:W})=>{const te=L();return l.jsx("span",{children:W.original.isFolder?"-":Pv(te)})}},{id:"lastModified",header:({column:L})=>l.jsxs(ye,{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(Ri,{})]}),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&&zl(W).isValid()?zl(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(ye,{variant:"ghost",size:"icon",onClick:()=>kp([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(Is,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Tải xuống"})]})}),f.trim()!==""&&l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{T(L.original),ee(L.original.name)},className:"h-8 w-8 p-0",children:l.jsx(Gp,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Đổi tên"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{oe(!0),D(L.original)},className:"h-8 w-8 p-0",children:l.jsx(Nh,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Di chuyển"})]})}),l.jsx(xn,{children:l.jsxs(bn,{children:[l.jsx(wn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>$(L.original),className:"h-8 w-8 p-0",children:l.jsx($s,{className:"h-4 w-4"})})}),l.jsx(sn,{children:"Xóa"})]})})]})}),A},[g,un,Pr,ue,r]),Fs=Xs({data:un,columns:Fp,state:{rowSelection:Pr,sorting:s},onSortingChange:u,enableRowSelection:!0,onRowSelectionChange:ti,getCoreRowModel:Ys(),getSortedRowModel:Dg()}),RE=async A=>{var L,W;Ue(!0);try{if(br(A)){const te=await he.get(`${t}/api/read-text`,{params:{path:A.key}});K(te.data.content)}try{const te=await he.get(`${t}/api/read-json`,{params:{path:A.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{Ue(!1)}},VE=async(A,L)=>{Mt(!0);try{await he.post(`${t}/api/modify-text`,{path:A.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"}),Ze.current=!0,await et(),T(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{Mt(!1)}},jE=async A=>{Mt(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",B),await he.post(`${t}/api/modify-json`,{path:A.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"}),Ze.current=!0,await et(),T(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{Mt(!1)}};_.useEffect(()=>{j&&(j.isFolder||RE(j),S("rename"))},[j]);const zE=async(A,L)=>{var W;if(Se){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 he.post(`${t}/api/crawl`,{url:A,limit:L,prefix:f});if(te.id){Yn({id:te.id,url:A,limit:L,prefix:f,taskId:((W=te.task)==null?void 0:W.id)||""});const ie=localStorage.getItem(sp),ge=ie?JSON.parse(ie):[];ge.some(Ee=>Ee.id===te.id)||(ge.unshift({url:A,id:te.id,limit:L,prefix:f,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(sp,JSON.stringify(ge))),P({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${A} 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)}},BE=async()=>{try{if(!(Se!=null&&Se.id))return;Yn(null),localStorage.removeItem(Gn),P({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${Se.url}`})}catch(A){console.error("Error stopping job:",A),P({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const A=(L=!0)=>{const te=new URL(window.location.href).searchParams.get("prefix")||"";te?Xn(n+te,!1):(L&&!a&&m(new Set),y(""),v(""),Ze.current=!0,setTimeout(()=>{et()},0))};return A(!1),window.addEventListener("popstate",()=>A(!0)),()=>{window.removeEventListener("popstate",()=>A(!0))}},[]);const HE=async()=>{Pp(!0);try{const A=await he.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",A),P({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(A){console.error("Error exporting report:",A),P({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Pp(!1)}};return l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(xd,{}),l.jsx(jt,{open:CE,onOpenChange:A=>{Tr(A),A||(ei(""),En(null),Te(!1),F(null))},children:l.jsxs(Et,{children:[l.jsxs(_t,{children:[l.jsx(Tt,{children:"Cảnh báo trùng lặp"}),l.jsxs(Rn,{children:[_r&&l.jsxs(l.Fragment,{children:["Folder $",_r," đã có."]}),dt&&dt.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(dt).map((A,L)=>l.jsx("li",{children:A.name},L))})]})]})]}),l.jsxs(hn,{children:[l.jsx(ye,{variant:"outline",onClick:()=>{Tr(!1),ei(""),En(null),Te(!1),F(null)},children:"Bỏ qua"}),l.jsx(ye,{variant:"destructive",onClick:()=>DE(),children:"Ghi đè"})]})]})}),l.jsx(ac,{className:"s3-explr-breadcrumb",children:l.jsxs(sc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(Gi,{className:"s3-explr-breadcrumb-item",children:l.jsx(Ki,{onClick:()=>Xn(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),Op.map((A,L)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(lc,{className:"s3-explr-breadcrumb-separator"},`sep-${L}`),l.jsx(Gi,{className:"s3-explr-breadcrumb-item",children:l.jsx(Ki,{onClick:()=>Xn(n+Op.slice(0,L+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:A})},`item-${A}`)]},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(VC,{ref:q,onChange:A=>d(A)})}),l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{y(f),Ze.current=!0,et()},disabled:ks,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(Ms,{className:`h-4 w-4 s3-explr-refresh-icon ${ks?"animate-spin":""}`}),"Làm mới"]}),!r&&l.jsxs(l.Fragment,{children:[g.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>kp(Array.from(g)),disabled:Array.from(g).some(A=>ue.has(A)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(g).some(A=>ue.has(A))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(Is,{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(lo,{asChild:!0,children:l.jsxs(ye,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx($s,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",g.size,")"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(ye,{variant:"outline",onClick:()=>k(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:ME,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(lo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!f,children:[l.jsx(Bp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsx(_t,{className:"s3-explr-dialog-header",children:l.jsx(Tt,{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(nn,{disabled:x,id:"name",value:C,onChange:A=>E(A.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ye,{onClick:()=>{C.trim()&&FE(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(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-files-btn",onClick:()=>{const A=document.createElement("input");A.type="file",A.multiple=!0,A.onchange=L=>{const W=L.target.files;W&&Os(W,f,"files")},A.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(jp,{className:"h-4 w-4 s3-explr-upload-icon"}),"Tải lên tập tin"]})}),l.jsx(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-upload-folder-btn",onClick:()=>{const A=document.createElement("input");A.type="file",A.multiple=!0,A.webkitdirectory=!0,A.onchange=L=>{const W=L.target.files;W&&Os(W,f,"folder")},A.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(oi,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),Se?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(ye,{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"}),Se.status?l.jsxs(l.Fragment,{children:[Se.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",Se.status.completed,"/",Se.status.total,") -"," ",Math.floor(cn/60),":",String(cn%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ye,{variant:"destructive",size:"sm",onClick:()=>void BE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(Yp,{className:"h-4 w-4"})]})]})}),Se.status&&l.jsx(sn,{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 ",Se.url]}),l.jsxs("p",{children:["Tiến độ: ",Se.status.completed,"/",Se.status.total," trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(cn/60),":",String(cn%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",Se.status.status==="scraping"?"Đang thu thập":Se.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):l.jsxs(jt,{open:N,onOpenChange:V,children:[l.jsx(lo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,children:[l.jsx(Wp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(nn,{id:"websiteUrl",value:ne,onChange:A=>J(A.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(nn,{id:"crawlLimit",value:X,onChange:A=>{const L=A.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(ye,{variant:"outline",onClick:()=>{V(!1),J(""),z("1")},disabled:Y,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{onClick:()=>{ne.trim()&&zE(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(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!f,onClick:HE,children:[Ns&&l.jsx(Ms,{className:`h-4 w-4 s3-explr-refresh-icon ${Ns?"animate-spin":""}`}),"Xuất báo cáo"]})}),Ns&&l.jsx(sn,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>AE(),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:A=>!A&&$(null),children:l.jsxs(Et,{className:"s3-explr-dialog-content",children:[l.jsxs(_t,{className:"s3-explr-dialog-header",children:[l.jsx(Tt,{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(ye,{variant:"outline",onClick:()=>$(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:()=>IE(I),disabled:$t,className:"s3-explr-confirm-delete-btn",children:$t?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:A=>{A||(T(null),Q(null),ee(""),K(""),S("rename"))},children:l.jsxs(Et,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(_t,{className:"s3-explr-dialog-header",children:l.jsx(Tt,{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(nb,{value:at,onValueChange:A=>S(A),children:[l.jsxs(qu,{"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(wo,{value:"rename",children:"Đổi tên"}),!j.isFolder&&l.jsxs(l.Fragment,{children:[br(j)&&l.jsx(wo,{value:"edit",children:"Sửa nội dung"}),l.jsx(wo,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Co,{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(nn,{id:"newName",value:re,onChange:A=>ee(A.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(Co,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:_e?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:A=>K(A.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:We})]})})}),l.jsx(Co,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:_e?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(([A,L],W)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(vn,{htmlFor:A,className:"s3-explr-label flex items-center gap-1",children:[Wh[A]||A,Bi(A)&&l.jsx(kh,{className:"h-[12px] w-[12px] text-red-500"})]}),qh(A)?l.jsx(ur,{id:A,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[A]:te.target.value};Q(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:We||Bi(A)}):l.jsx(nn,{id:A,value:typeof L=="string"?L:JSON.stringify(L),onChange:te=>{const ie={...B,[A]:te.target.value};Q(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:We||Bi(A)})]},W))})})})]})]}),l.jsxs(hn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{T(null),Q(null),ee(""),K("")},className:"s3-explr-cancel-btn",children:"Hủy"}),at==="edit"?l.jsx(ye,{onClick:()=>j&&VE(j,Ce),disabled:We||_e,className:"s3-explr-save-btn",children:We?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"}):at==="edit-metadata"?l.jsx(ye,{onClick:()=>B&&typeof B=="object"&&j&&jE(j),disabled:We||_e,className:"s3-explr-save-btn",children:We?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(ye,{onClick:()=>{re.trim()&&j&&$E(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(HS,{openDialogRename:ce,setOpenDialogRename:oe,apiBaseUrl:t,setFileToMove:D,fileToMove:H,refreshFiles:et,ignoreCache:Ze})]})]}),TE&&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(BS,{onFilesSelected:(A,L)=>Os(A,f,L),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(mo,{className:"s3-explr-table",children:[l.jsx(ho,{className:"s3-explr-table-header",children:Fs.getHeaderGroups().map(A=>l.jsx(vt,{className:"hover:bg-transparent s3-explr-header-row",children:A.headers.map(L=>l.jsx(At,{className:"s3-explr-header-cell",children:L.isPlaceholder?null:Lr(L.column.columnDef.header,L.getContext())},L.id))},A.id))}),l.jsx(vo,{className:"s3-explr-table-body",children:Fs.getRowModel().rows.length===0?l.jsx(vt,{className:"s3-explr-empty-row",children:l.jsx(Je,{colSpan:Fp.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:ks?"Đ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"})})}):Fs.getRowModel().rows.map(A=>l.jsx(vt,{className:"h-12 s3-explr-row",children:A.getVisibleCells().map(L=>l.jsx(Je,{className:"align-middle s3-explr-cell",children:Lr(L.column.columnDef.cell,L.getContext())},L.id))},A.id))})]})})}),c&&Ar!==0&&l.jsx(l.Fragment,{children:l.jsx(co,{children:l.jsxs(uo,{children:[l.jsx(fo,{onClick:()=>Wt(A=>Math.max(A-1,1)),"aria-disabled":je===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Ar/20)},(A,L)=>{const W=L+1,te=Math.ceil(Ar/20);return te>7&&!(W===1||W===te||W>=je-1&&W<=je+1)?W===je-2&&je>4||W===je+2&&je<te-3?l.jsx(go,{className:"pointer-events-none",children:"..."},L):null:l.jsx(ht,{className:"cursor-pointer",children:l.jsx(Vn,{isActive:je===W,onClick:()=>Wt(W),className:`${je===W?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:W})},L)}),l.jsx(ht,{children:l.jsx(po,{onClick:()=>Wt(A=>Math.min(A+1,Math.ceil(Ar/20))),"aria-disabled":je===Math.ceil(Ar/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(ye,{variant:"default",onClick:()=>o(LE()),disabled:g.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),JS=e=>l.jsx(Zp,{clientId:WS,children:l.jsx(XS,{...e})});var wr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Ge=e=>e==null;const lp=e=>typeof e=="object";var Me=e=>!Ge(e)&&!Array.isArray(e)&&lp(e)&&!Sn(e),ZS=e=>Me(e)&&e.target?wr(e.target)?e.target.checked:e.target.value:e,QS=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,eE=(e,t)=>e.has(QS(t)),tE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},ws=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ct(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(!(ws&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!tE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ct(e[o]));else return e;return t}var Ko=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,se=(e,t,n)=>{if(!t||!Me(e))return n;const r=Ko(t.split(/[,[\].]+?/)).reduce((o,i)=>Ge(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Ft=e=>typeof e=="boolean",Cs=e=>/^\w*$/.test(e),cp=e=>Ko(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Fe=(e,t,n)=>{let r=-1;const o=Cs(t)?[t]:cp(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 up={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},bt={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 nE=(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]!==bt.all&&(t._proxyFormState[a]=!r||bt.all),e[a]}});return o},Qe=e=>Me(e)&&!Object.keys(e).length,rE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return Qe(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===bt.all)},Yo=e=>Array.isArray(e)?e:[e];function oE(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 Dt=e=>typeof e=="string",iE=(e,t,n,r,o)=>Dt(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),aE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},dp=e=>({isOnSubmit:!e||e===bt.onSubmit,isOnBlur:e===bt.onBlur,isOnChange:e===bt.onChange,isOnAll:e===bt.all,isOnTouch:e===bt.onTouched}),fp=(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 sE=(e,t,n)=>{const r=Yo(se(e,n));return Fe(r,"root",t[n]),Fe(e,n,r),e},Ss=e=>e.type==="file",It=e=>typeof e=="function",Xo=e=>{if(!ws)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Jo=e=>Dt(e),Es=e=>e.type==="radio",Zo=e=>e instanceof RegExp;const pp={value:!1,isValid:!1},gp={value:!0,isValid:!0};var mp=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===""?gp:{value:e[0].value,isValid:!0}:gp:pp}return pp};const hp={isValid:!1,value:null};var vp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,hp):hp;function yp(e,t,n="validate"){if(Jo(e)||Array.isArray(e)&&e.every(Jo)||Ft(e)&&!e)return{type:n,message:Jo(e)?e:"",ref:t}}var Kn=e=>Me(e)&&!Zo(e)?e:{value:e,message:""},xp=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(Ft(U)?"":U||""),C.reportValidity())},x={},O=Es(i),I=wr(i),$=O||I,H=(h||Ss(i))&&Ie(i.value)&&Ie(w)||Xo(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,D=aE.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||Ge(w))||Ft(w)&&!w||I&&!mp(a).isValid||O&&!vp(a).isValid)){const{value:U,message:Z}=Jo(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&&(!Ge(d)||!Ge(g))){let U,Z;const k=Kn(g),M=Kn(d);if(!Ge(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ge(k.value)||(U=F>k.value),Ge(M.value)||(Z=F<M.value)}else{const F=i.valueAsDate||new Date(w),q=T=>new Date(new Date().toDateString()+" "+T),P=i.type=="time",j=i.type=="week";Dt(k.value)&&w&&(U=P?q(w)>q(k.value):j?w>k.value:F>new Date(k.value)),Dt(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&&(Dt(w)||o&&Array.isArray(w))){const U=Kn(u),Z=Kn(c),k=!Ge(U.value)&&w.length>+U.value,M=!Ge(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&&Dt(w)){const{value:U,message:Z}=Kn(m);if(Zo(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(It(f)){const U=await f(w,t),Z=yp(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(!Qe(U)&&!n)break;const k=yp(await f[Z](w,t),C,Z);k&&(U={...k,...D(Z,k.message)},E(k.message),n&&(x[v]=U))}if(!Qe(U)&&(x[v]={ref:C,...U},!n))return x}}return E(!0),x};function lE(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 cE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ie(e[t]))return!1;return!0}function Ve(e,t){const n=Array.isArray(t)?t:Cs(t)?[t]:cp(t),r=n.length===1?e:lE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&Qe(r)||Array.isArray(r)&&cE(r))&&Ve(e,n.slice(0,-1)),e}var _s=()=>{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=[]}}},Ts=e=>Ge(e)||!lp(e);function ln(e,t){if(Ts(e)||Ts(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)?!ln(i,a):i!==a)return!1}}return!0}var bp=e=>e.type==="select-multiple",uE=e=>Es(e)||wr(e),As=e=>Xo(e)&&e.isConnected,wp=e=>{for(const t in e)if(It(e[t]))return!0;return!1};function Qo(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!wp(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Qo(e[r],t[r])):Ge(e[r])||(t[r]=!0);return t}function Cp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!wp(e[o])?Ie(t)||Ts(n[o])?n[o]=Array.isArray(e[o])?Qo(e[o],[]):{...Qo(e[o])}:Cp(e[o],Ge(t)?{}:t[o],n[o]):n[o]=!ln(e[o],t[o]);return n}var Sr=(e,t)=>Cp(e,t,Qo(t)),Sp=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&Dt(e)?new Date(e):r?r(e):e;function Ps(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return Ss(t)?t.files:Es(t)?vp(e.refs).value:bp(t)?[...t.selectedOptions].map(({value:n})=>n):wr(t)?mp(e.refs).value:Sp(Ie(t.value)?e.ref.value:t.value,e)}var dE=(e,t,n,r)=>{const o={};for(const i of e){const a=se(t,i);a&&Fe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Er=e=>Ie(e)?e:Zo(e)?e.source:Me(e)?Zo(e.value)?e.value.source:e.value:e;const Ep="AsyncFunction";var fE=e=>!!e&&!!e.validate&&!!(It(e.validate)&&e.validate.constructor.name===Ep||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Ep)),pE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function _p(e,t,n){const r=se(e,n);if(r||Cs(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 gE=(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,mE=(e,t)=>!Ko(se(e,t)).length&&Ve(e,t);const hE={mode:bt.onSubmit,reValidateMode:bt.onChange,shouldFocusError:!0};function vE(e={}){let t={...hE,...e},n={submitCount:0,isDirty:!1,isLoading:It(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)?ct(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ct(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:_s(),array:_s(),state:_s()},m=dp(t.mode),f=dp(t.reValidateMode),v=t.criteriaMode===bt.all,h=S=>N=>{clearTimeout(c),c=setTimeout(S,N)},y=async S=>{if(!t.disabled&&(d.isValid||S)){const N=t.resolver?Qe((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?Fe(n.validatingFields,V,N):Ve(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!Qe(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&&Fe(r,S,z)}if(X&&Array.isArray(se(n.errors,S))){const z=V(se(n.errors,S),ne.argA,ne.argB);J&&Fe(n.errors,S,z),mE(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&&Fe(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 Fe(i,S,N)},C=(S,N)=>{Fe(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?Fe(i,S,N?X:Ps(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||ln(se(o,S),N);z=!!(!xe&&se(n.dirtyFields,S)),we||xe?Ve(n.dirtyFields,S):Fe(n.dirtyFields,S,!0),Y.dirtyFields=n.dirtyFields,X=X||d.dirtyFields&&z!==!we}if(V){const we=se(n.touchedFields,S);we||(Fe(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&&Ft(N)&&n.isValid!==N;if(t.delayError&&V?(u=h(()=>C(S,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Fe(n.errors,S,V):Ve(n.errors,S)),(V?!ln(J,V):J)||!Qe(ne)||X){const z={...ne,...X&&Ft(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,dE(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?Fe(n.errors,V,ne):Ve(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&&fE(J._f);xe&&d.validatingFields&&b([ne],!0);const we=await xp(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?sE(n.errors,we,X.name):Fe(n.errors,X.name,we[X.name]):Ve(n.errors,X.name))}!Qe(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=>!As(V)):!As(N._f.ref))&&oe(S)}s.unMount=new Set},U=(S,N)=>!t.disabled&&(S&&N&&Fe(i,S,N),!ln(B(),o)),Z=(S,N,V)=>iE(S,s,{...a.mount?i:Ie(N)?o:Dt(S)?{[S]:N}:N},V,N),k=S=>Ko(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&&Fe(i,S,Sp(N,X)),J=Xo(X.ref)&&Ge(N)?"":N,bp(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):Ss(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&&T(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=ct(N);Fe(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&&!Ge(X)?F(S,X,V):M(S,X,V),fp(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?Ps(J._f):ZS(S),z=Y=>{ne=Number.isNaN(Y)||Sn(Y)&&isNaN(Y.getTime())||ln(Y,se(i,V,Y))};if(J){let Y,xe;const we=X(),Te=S.type===up.BLUR||S.type===up.FOCUS_OUT,$t=!pE(J._f)&&!t.resolver&&!se(n.errors,V)&&!J._f.deps||gE(Te,se(n.touchedFields,V),n.isSubmitted,f,m),ut=fp(V,s,Te);Fe(i,V,we),Te?(J._f.onBlur&&J._f.onBlur(S),u&&u(0)):J._f.onChange&&J._f.onChange(S);const je=O(V,we,Te,!1),Wt=!Qe(je)||ut;if(!Te&&g.values.next({name:V,type:S.type,values:{...i}}),$t)return d.isValid&&(t.mode==="onBlur"?Te&&y():y()),Wt&&g.state.next({name:V,...ut?{}:je});if(!Te&&ut&&g.state.next({...n}),t.resolver){const{errors:qt}=await $([V]);if(z(we),ne){const Gt=_p(n.errors,r,V),Se=_p(qt,r,Gt.name||V);Y=Se.error,V=Se.name,xe=Qe(qt)}}else b([V],!0),Y=(await xp(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&&T(J._f.deps),I(V,xe,Y,je))}},j=(S,N)=>{if(se(n.errors,N)&&S.focus)return S.focus(),1},T=async(S,N={})=>{let V,ne;const J=Yo(S);if(t.resolver){const X=await H(Ie(S)?S:J);V=Qe(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({...!Dt(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:Dt(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&&Yo(S).forEach(N=>Ve(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;Fe(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)=>It(S)?g.values.subscribe({next:V=>S(Z(void 0,N),V)}):Z(S,N,!0),oe=(S,N={})=>{for(const V of S?Yo(S):s.mount)s.mount.delete(V),s.array.delete(V),N.keepValue||(Ve(r,V),Ve(i,V)),!N.keepError&&Ve(n.errors,V),!N.keepDirty&&Ve(n.dirtyFields,V),!N.keepTouched&&Ve(n.touchedFields,V),!N.keepIsValidating&&Ve(n.validatingFields,V),!t.shouldUnregister&&!N.keepDefaultValue&&Ve(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(Ft(S)&&a.mount||S){const X=S?void 0:Ie(J)?Ps(V?V._f:se(ne,N)._f):J;(S||!S&&!Ie(X))&&Fe(i,N,X),O(N,X,!1,!1,!0)}},de=(S,N={})=>{let V=se(r,S);const ne=Ft(N.disabled)||Ft(t.disabled);return Fe(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:Ft(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=uE(X),Y=V._f.refs||[];if(z?Y.find(xe=>xe===X):X===V._f.ref)return;Fe(r,S,{_f:{...V._f,...z?{refs:[...Y.filter(As),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)&&!(eE(s.array,S)&&a.action)&&s.unMount.add(S)}}},ue=()=>t.shouldFocusError&&Cr(r,j,s.mount),le=S=>{Ft(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=ct(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(Ve(n.errors,"root"),Qe(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:Qe(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},K=(S,N={})=>{se(r,S)&&(Ie(N.defaultValue)?q(S,ct(se(o,S))):(q(S,N.defaultValue),Fe(o,S,ct(N.defaultValue))),N.keepTouched||Ve(n.touchedFields,S),N.keepDirty||(Ve(n.dirtyFields,S),n.isDirty=N.defaultValue?U(S,ct(se(o,S))):U()),N.keepError||(Ve(n.errors,S),d.isValid&&y()),g.state.next({...n}))},_e=(S,N={})=>{const V=S?ct(S):o,ne=ct(V),J=Qe(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)?Fe(X,Y,se(i,Y)):q(Y,se(X,Y))}else{if(ws&&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(Xo(xe)){const we=xe.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?N.keepDefaultValues?ct(o):{}:ct(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&&!ln(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})},Ue=(S,N)=>_e(It(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:_e,_resetDefaultValues:()=>It(t.defaultValues)&&t.defaultValues().then(S=>{Ue(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:T,register:de,handleSubmit:Ce,watch:ce,setValue:q,getValues:B,reset:Ue,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&&It(J.select)&&J.select())}},getFieldState:Q}}function yE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:It(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:It(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...vE(e),formState:r});const i=t.current.control;return i._options=e,oE({subject:i._subjects.state,next:a=>{rE(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&&!ln(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:nE(r,i)}),[r,i])}const Tp=({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:me("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(sn,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},xE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},bE=({apiBaseUrl:e="http://localhost:3002"})=>{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=xE(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 he.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(Tp,{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}=yE(),j=H.original.id,T=H.getValue("status"),B=H.getValue("content"),[Q,re]=_.useState(!1),ee=async()=>{try{re(!0);const oe=T==="unpublish"?"published":"unpublish",ae=await he.patch(`${e}/api/toggle-publish/${j}`,{id:j,typeAction:"update",status:T,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 he.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(ye,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"px-2 py-0.5 h-7",children:l.jsx(Ph,{className:"h-4 w-4"})}),l.jsx(jt,{open:k,onOpenChange:M,children:l.jsxs(Et,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(_t,{children:l.jsx(Tt,{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(lo,{asChild:!0,children:l.jsx(ye,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),l.jsx(Et,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(_t,{className:"flex flex-col gap-3",children:[l.jsx(Tt,{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(ye,{disabled:D,type:"submit",variant:"default",children:D?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ye,{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"}):T==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=Xs({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:Fg(),getCoreRowModel:Ys()});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(nn,{placeholder:"Tìm kiếm theo mã...",value:f,onChange:$=>v($.target.value),className:"pr-8"}),f&&l.jsx(ye,{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(Vi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(mo,{className:"s3-explr-table",children:[l.jsx(ho,{className:"s3-explr-table-header",children:x.getHeaderGroups().map($=>l.jsx(vt,{className:"hover:bg-transparent s3-explr-header-row",children:$.headers.map(H=>l.jsx(At,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Lr(H.column.columnDef.header,H.getContext())},H.id))},$.id))}),l.jsx(vo,{className:"s3-explr-table-body",children:r?l.jsx(vt,{children:l.jsx(Je,{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(vt,{className:"h-12 s3-explr-row",children:$.getVisibleCells().map(H=>l.jsx(Je,{className:"align-middle s3-explr-cell",children:Lr(H.column.columnDef.cell,H.getContext())},H.id))},$.id)):l.jsx(vt,{children:l.jsx(Je,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(co,{children:l.jsxs(uo,{children:[l.jsx(ht,{children:l.jsx(fo,{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(ht,{children:l.jsx(go,{})},$+"..."),l.jsx(ht,{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(ht,{children:l.jsx(po,{onClick:()=>u($=>Math.min(c,$+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Ap=10,wE=_.memo(({apiBaseUrl:e="http://localhost:3002"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Ap,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:f}=Po(),[v,h]=_.useState(!1),y=async x=>{try{d(x);const O=await he.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Ap.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 he.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(Eh,{className:"w-8 h-8 text-primary"}),l.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),l.jsx(ye,{variant:"outline",size:"icon",onClick:w,disabled:v||s,className:"ml-2",children:l.jsx(Oh,{className:`h-4 w-4 ${v?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(mo,{children:[l.jsx(ho,{children:l.jsxs(vt,{children:[l.jsx(At,{children:"ID"}),l.jsx(At,{children:"Tên Công Việc"}),l.jsx(At,{children:"Thời Gian Bắt Đầu"}),l.jsx(At,{children:"Thời Gian Cập Nhật"}),l.jsx(At,{children:"Thời Gian Thực Thi"}),l.jsx(At,{children:"Trạng Thái"}),l.jsx(At,{children:"Thao Tác"})]})}),l.jsx(vo,{children:s&&r.length===0?l.jsx(vt,{children:l.jsx(Je,{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(vt,{children:[l.jsx(Je,{className:"!w-[100px]",children:x.id}),l.jsx(Je,{className:"font-medium",children:(O=x.job_name)==null?void 0:O.replace("Upload file","Summary")}),l.jsx(Je,{className:"!w-[200px]",children:C(x.created_at)}),l.jsx(Je,{className:"!w-[200px]",children:C(x.updated_at)}),l.jsx(Je,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Je,{className:"!w-[200px]",children:l.jsx(Tp,{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(Je,{className:"!w-[200px]",children:x.status==="fail"?l.jsx(ye,{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(co,{children:l.jsxs(uo,{children:[l.jsx(ht,{children:l.jsx(fo,{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(ht,{children:l.jsx(go,{})},x+"..."),l.jsx(ht,{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(ht,{children:l.jsx(po,{onClick:()=>n(x=>Math.min(i.totalPages,x+1)),className:t===i.totalPages||c!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),l.jsx(xd,{})]})});ft.Job=wE,ft.S3Explorer=JS,ft.Summary=bE,Object.defineProperty(ft,Symbol.toStringTag,{value:"Module"})});
|
|
177
177
|
//# sourceMappingURL=s3-explorer.umd.cjs.map
|