dccxx-s3-explorer 1.0.60 → 1.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -172,6 +172,6 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var X=Se(se,le,te,ce,oe+
172
172
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vC(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function yC(e){if(Array.isArray(e))return Ss(e)}function Jf(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 Zf(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Jf(Object(n),!0).forEach(function(r){Qf(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Jf(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Qf(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Er(e,t){return wC(e)||bC(e,t)||ep(e,t)||xC()}function xC(){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 ep(e,t){if(e){if(typeof e=="string")return Ss(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 Ss(e,t)}}function Ss(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 bC(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 wC(e){if(Array.isArray(e))return e}var SC=typeof ws=="function"?ws:ws.default,CC="file-invalid-type",EC="file-too-large",_C="file-too-small",TC="too-many-files",AC=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:CC,message:"File type must be ".concat(r)}},tp=function(t){return{code:EC,message:"File is larger than ".concat(t," ").concat(t===1?"byte":"bytes")}},np=function(t){return{code:_C,message:"File is smaller than ".concat(t," ").concat(t===1?"byte":"bytes")}},PC={code:TC,message:"Too many files"};function rp(e,t){var n=e.type==="application/x-moz-file"||SC(e,t);return[n,n?null:AC(t)]}function op(e,t,n){if(_n(e.size))if(_n(t)&&_n(n)){if(e.size>n)return[!1,tp(n)];if(e.size<t)return[!1,np(t)]}else{if(_n(t)&&e.size<t)return[!1,np(t)];if(_n(n)&&e.size>n)return[!1,tp(n)]}return[!0,null]}function _n(e){return e!=null}function NC(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=rp(u,n),d=Er(c,1),g=d[0],m=op(u,r,o),p=Er(m,1),h=p[0],v=s?s(u):null;return g&&h&&!v})}function Xo(e){return typeof e.isPropagationStopped=="function"?e.isPropagationStopped():typeof e.cancelBubble<"u"?e.cancelBubble:!1}function Jo(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 ip(e){e.preventDefault()}function kC(e){return e.indexOf("MSIE")!==-1||e.indexOf("Trident/")!==-1}function OC(e){return e.indexOf("Edge/")!==-1}function FC(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return kC(e)||OC(e)}function It(){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!Xo(r)&&s&&s.apply(void 0,[r].concat(i)),Xo(r)})}}function DC(){return"showOpenFilePicker"in window}function IC(e){if(_n(e)){var t=Object.entries(e).filter(function(n){var r=Er(n,2),o=r[0],i=r[1],a=!0;return ap(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(sp))&&(console.warn('Skipped "'.concat(o,'" because an invalid file extension was provided.')),a=!1),a}).reduce(function(n,r){var o=Er(r,2),i=o[0],a=o[1];return Zf(Zf({},n),{},Qf({},i,a))},{});return[{description:"Files",accept:t}]}return e}function MC(e){if(_n(e))return Object.entries(e).reduce(function(t,n){var r=Er(n,2),o=r[0],i=r[1];return[].concat(Xf(t),[o],Xf(i))},[]).filter(function(t){return ap(t)||sp(t)}).join(",")}function $C(e){return e instanceof DOMException&&(e.name==="AbortError"||e.code===e.ABORT_ERR)}function LC(e){return e instanceof DOMException&&(e.name==="SecurityError"||e.code===e.SECURITY_ERR)}function ap(e){return e==="audio/*"||e==="video/*"||e==="image/*"||e==="text/*"||e==="application/*"||/\w+\/[-+.\w]+/g.test(e)}function sp(e){return/^.*\.[\w]+$/.test(e)}var RC=["children"],VC=["open"],jC=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],zC=["refKey","onChange","onClick"];function BC(e){return WC(e)||UC(e)||lp(e)||HC()}function HC(){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 UC(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function WC(e){if(Array.isArray(e))return Es(e)}function Cs(e,t){return KC(e)||GC(e,t)||lp(e,t)||qC()}function qC(){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 lp(e,t){if(e){if(typeof e=="string")return Es(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 Es(e,t)}}function Es(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 GC(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 KC(e){if(Array.isArray(e))return e}function cp(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?cp(Object(n),!0).forEach(function(r){_s(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):cp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function _s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zo(e,t){if(e==null)return{};var n=YC(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 YC(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 Ts=_.forwardRef(function(e,t){var n=e.children,r=Zo(e,RC),o=dp(r),i=o.open,a=Zo(o,VC);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});Ts.displayName="Dropzone";var up={disabled:!1,getFilesFromEvent:sC,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};Ts.defaultProps=up,Ts.propTypes={children:Ne.func,accept:Ne.objectOf(Ne.arrayOf(Ne.string)),multiple:Ne.bool,preventDropOnDocument:Ne.bool,noClick:Ne.bool,noKeyboard:Ne.bool,noDrag:Ne.bool,noDragEventsBubbling:Ne.bool,minSize:Ne.number,maxSize:Ne.number,maxFiles:Ne.number,disabled:Ne.bool,getFilesFromEvent:Ne.func,onFileDialogCancel:Ne.func,onFileDialogOpen:Ne.func,useFsAccessApi:Ne.bool,autoFocus:Ne.bool,onDragEnter:Ne.func,onDragLeave:Ne.func,onDragOver:Ne.func,onDrop:Ne.func,onDropAccepted:Ne.func,onDropRejected:Ne.func,onError:Ne.func,validator:Ne.func};var As={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function dp(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},up),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,p=t.onDropAccepted,h=t.onDropRejected,v=t.onFileDialogCancel,y=t.onFileDialogOpen,b=t.useFsAccessApi,w=t.autoFocus,S=t.preventDropOnDocument,E=t.noClick,x=t.noKeyboard,N=t.noDrag,I=t.noDragEventsBubbling,M=t.onError,H=t.validator,O=_.useMemo(function(){return MC(n)},[n]),G=_.useMemo(function(){return IC(n)},[n]),W=_.useMemo(function(){return typeof y=="function"?y:fp},[y]),Z=_.useMemo(function(){return typeof v=="function"?v:fp},[v]),k=_.useRef(null),$=_.useRef(null),F=_.useReducer(XC,As),U=Cs(F,2),j=U[0],R=U[1],A=j.isFocused,B=j.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&DC()),ne=function(){!Q.current&&B&&setTimeout(function(){if($.current){var Y=$.current.files;Y.length||(R({type:"closeDialog"}),Z())}},300)};_.useEffect(function(){return window.addEventListener("focus",ne,!1),function(){window.removeEventListener("focus",ne,!1)}},[$,B,Z,Q]);var te=_.useRef([]),ce=function(Y){k.current&&k.current.contains(Y.target)||(Y.preventDefault(),te.current=[])};_.useEffect(function(){return S&&(document.addEventListener("dragover",ip,!1),document.addEventListener("drop",ce,!1)),function(){S&&(document.removeEventListener("dragover",ip),document.removeEventListener("drop",ce))}},[k,S]),_.useEffect(function(){return!r&&w&&k.current&&k.current.focus(),function(){}},[k,w,r]);var oe=_.useCallback(function(z){M?M(z):console.error(z)},[M]),se=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),te.current=[].concat(BC(te.current),[z.target]),Jo(z)&&Promise.resolve(o(z)).then(function(Y){if(!(Xo(z)&&!I)){var ve=Y.length,we=ve>0&&NC({files:Y,accept:O,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Fe=ve>0&&!we;R({isDragAccept:we,isDragReject:Fe,isDragActive:!0,type:"setDraggedFiles"}),c&&c(z)}}).catch(function(Y){return oe(Y)})},[o,c,oe,I,O,a,i,s,u,H]),ue=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=Jo(z);if(Y&&z.dataTransfer)try{z.dataTransfer.dropEffect="copy"}catch{}return Y&&g&&g(z),!1},[g,I]),de=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=te.current.filter(function(we){return k.current&&k.current.contains(we)}),ve=Y.indexOf(z.target);ve!==-1&&Y.splice(ve,1),te.current=Y,!(Y.length>0)&&(R({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Jo(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var ve=[],we=[];z.forEach(function(Fe){var ct=rp(Fe,O),Ct=Cs(ct,2),He=Ct[0],dn=Ct[1],fn=op(Fe,a,i),Be=Cs(fn,2),Rt=Be[0],Zn=Be[1],An=H?H(Fe):null;if(He&&Rt&&!An)ve.push(Fe);else{var _e=[dn,Zn];An&&(_e=_e.concat(An)),we.push({file:Fe,errors:_e.filter(function(Qn){return Qn})})}}),(!s&&ve.length>1||s&&u>=1&&ve.length>u)&&(ve.forEach(function(Fe){we.push({file:Fe,errors:[PC]})}),ve.splice(0)),R({acceptedFiles:ve,fileRejections:we,isDragReject:we.length>0,type:"setFiles"}),m&&m(ve,we,Y),we.length>0&&h&&h(we,Y),ve.length>0&&p&&p(ve,Y)},[R,s,O,a,i,u,m,p,h,H]),Se=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),te.current=[],Jo(z)&&Promise.resolve(o(z)).then(function(Y){Xo(z)&&!I||le(Y,z)}).catch(function(Y){return oe(Y)}),R({type:"reset"})},[o,le,oe,I]),X=_.useCallback(function(){if(Q.current){R({type:"openDialog"}),W();var z={multiple:s,types:G};window.showOpenFilePicker(z).then(function(Y){return o(Y)}).then(function(Y){le(Y,null),R({type:"closeDialog"})}).catch(function(Y){$C(Y)?(Z(Y),R({type:"closeDialog"})):LC(Y)?(Q.current=!1,$.current?($.current.value=null,$.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}$.current&&(R({type:"openDialog"}),W(),$.current.value=null,$.current.click())},[R,W,Z,b,le,oe,G,s]),Ce=_.useCallback(function(z){!k.current||!k.current.isEqualNode(z.target)||(z.key===" "||z.key==="Enter"||z.keyCode===32||z.keyCode===13)&&(z.preventDefault(),X())},[k,X]),ze=_.useCallback(function(){R({type:"focus"})},[]),St=_.useCallback(function(){R({type:"blur"})},[]),lt=_.useCallback(function(){E||(FC()?setTimeout(X,0):X())},[E,X]),tt=function(Y){return r?null:Y},C=function(Y){return x?null:tt(Y)},P=function(Y){return N?null:tt(Y)},V=function(Y){I&&Y.stopPropagation()},re=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,ve=Y===void 0?"ref":Y,we=z.role,Fe=z.onKeyDown,ct=z.onFocus,Ct=z.onBlur,He=z.onClick,dn=z.onDragEnter,fn=z.onDragOver,Be=z.onDragLeave,Rt=z.onDrop,Zn=Zo(z,jC);return De(De(_s({onKeyDown:C(It(Fe,Ce)),onFocus:C(It(ct,ze)),onBlur:C(It(Ct,St)),onClick:tt(It(He,lt)),onDragEnter:P(It(dn,se)),onDragOver:P(It(fn,ue)),onDragLeave:P(It(Be,de)),onDrop:P(It(Rt,Se)),role:typeof we=="string"&&we!==""?we:"presentation"},ve,k),!r&&!x?{tabIndex:0}:{}),Zn)}},[k,Ce,ze,St,lt,se,ue,de,Se,x,N,r]),J=_.useCallback(function(z){z.stopPropagation()},[]),K=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,ve=Y===void 0?"ref":Y,we=z.onChange,Fe=z.onClick,ct=Zo(z,zC),Ct=_s({accept:O,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:tt(It(we,Se)),onClick:tt(It(Fe,J)),tabIndex:-1},ve,$);return De(De({},Ct),ct)}},[$,n,s,Se,r]);return De(De({},j),{},{isFocused:A&&!r,getRootProps:re,getInputProps:K,rootRef:k,inputRef:$,open:tt(X)})}function XC(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({},As),{},{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({},As);default:return e}}function fp(){}const JC=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=dp({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()})]})},ZC=({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),[p,h]=_.useState(""),{toast:v}=Io();_.useEffect(()=>{e&&y(p)},[p,e]);const y=async S=>{try{m(!0);const E=await me.get(`${n}/api/list-s3-folders?prefix=${S}`);u(E==null?void 0:E.data)}catch{v({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{m(!1)}},b=async()=>{d(!0);try{const S=o.key,E=S.endsWith("/")?S:`${S}/`,x=p.endsWith("/")?p:`${p}/`;if(E===x||S===p){v({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),d(!1);return}await me.post(`${n}/api/move`,{oldPath:S,newPath:p}),a.current=!0,await i(),v({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${p}"`}),t(!1),r(null),h("")}catch(S){console.error("Error renaming item:",S),v({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{d(!1)}};return l.jsx(Ht,{open:e,onOpenChange:S=>{S||(t(!1),r(null),h(""))},children:l.jsxs(At,{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(Pt,{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:()=>h(""),children:"Root"}),p.split("/").map((S,E,x)=>l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>h(S==="Root"?"":x.slice(0,E+1).join("/")+"/"),children:S},E))]})}),l.jsxs(Nt,{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"," ",p===""?"Root":p," )"]})]}),l.jsx(zn,{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(S=>l.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>h(S),children:S},S))})})]}),l.jsxs(Sn,{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"})]})]})})},QC="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",eE="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",tE="https://www.googleapis.com/auth/drive";zt(me,{retries:3,shouldResetTimeout:!0,retryCondition:e=>zt.isRetryableError(e)&&e.config.method==="get"});const Qe={current:!1},pp="crawl:jobs",Xn="crawl:current_job",nE=e=>{const[t,n]=_.useState(null),[r,o]=_.useState(0);return _.useEffect(()=>{const i=localStorage.getItem(Xn);if(i){const a=JSON.parse(i);n(a),a!=null&&a.startTime&&o(Math.floor((Date.now()-a.startTime)/1e3))}},[]),_.useEffect(()=>{if(!(t!=null&&t.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-t.startTime)/1e3))},1e3);return()=>clearInterval(i)},[t==null?void 0:t.startTime]),_.useEffect(()=>{if(!(t!=null&&t.id))return;const i=async()=>{try{const u=(await me.get(`${e}/api/crawl/${t.id}?taskId=${t.taskId}`)).data;n(c=>{if(!c)return null;const d={...c,status:u};return localStorage.setItem(Xn,JSON.stringify(d)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Xn)},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(Xn,JSON.stringify(i)):localStorage.removeItem(Xn)}}},Qo=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},rE=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Qo(e,o.key))}),n},oE=(e,t,n=[],r,o,i)=>{const[a,s]=_.useState({}),[u,c]=_.useState(!1),[d,g]=_.useState(null),[m,p]=_.useState(0),h=_.useRef(t);_.useEffect(()=>{h.current=t},[t]);const v=async()=>{c(!0);try{const b=await me.get(`${e}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:h.current},timeout:3e5});s(b.data),g(null)}catch(b){g(b instanceof Error?b:new Error("Failed to fetch files"))}finally{c(!1),p(0),i("")}},y=async b=>{var w,S;try{if(!b)return;c(!0);const E=await me.get(`${e}/api/search-db?query=${b}&rootPrefix=${t}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return s({[t]:((w=E==null?void 0:E.data)==null?void 0:w.result)||[]}),p(((S=E==null?void 0:E.data)==null?void 0:S.estimatedTotalHits)||0),E}catch(E){g(E instanceof Error?E:new Error("Failed to fetch files"))}finally{c(!1)}};return _.useEffect(()=>{!r&&!u&&v(),r&&!u&&y(r)},[r,o]),{data:a,isLoading:u,error:d,estimatedTotalHits:m,refetch:v}},_r=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||"")},iE=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="https://s3-explorer.cmcts1.studio.ai.vn",rootPrefix:n="",asSelector:r=!1,onSelected:o=u=>console.log("Đã chọn:",u),displayPrefixes:i,preSelectedFiles:a,idCreator:s})=>{var zp;const[u,c]=_.useState([]),[d,g]=_.useState(""),[m,p]=_.useState(new Set(a)),[h,v]=_.useState(n),[y,b]=_.useState(""),[w,S]=_.useState(!1),[E,x]=_.useState(""),[N,I]=_.useState(!1),[M,H]=_.useState(null),[O,G]=_.useState(null),[W,Z]=_.useState(!1),[k,$]=_.useState(!1),[F,U]=_.useState(null),j=_.useRef(null),{toast:R}=Io(),[A,B]=_.useState(null),[Q,ne]=_.useState(null),[te,ce]=_.useState(""),[oe,se]=_.useState(!1),[ue,de]=_.useState(!1),[le,Se]=_.useState(new Set),[X,Ce]=_.useState(""),[ze,St]=_.useState(!1),[lt,tt]=_.useState(!1),[C,P]=_.useState("rename"),[V,re]=_.useState(!1),[J,K]=_.useState(""),[z,Y]=_.useState("1"),[ve,we]=_.useState(!1),[Fe,ct]=_.useState(!1),[Ct,He]=_.useState(!1),[dn,fn]=_.useState(!1),[Be,Rt]=_.useState(1),[Zn,An]=_.useState(!1),{currentJob:_e,elapsedTime:Qn,setCurrentJob:Ip}=nE(t),[pn,kr]=_.useState(null),[Or,ai]=_.useState(""),[OE,Fr]=_.useState(!1),[$s,Mp]=_.useState(!1),[$p,FE]=_.useState(""),[Ke,Ls]=_.useState(null),DE=new URL(window.location.href).searchParams.get("prefix")||""||y||n,[__,IE]=_.useState(null),{data:Vt,isLoading:er,error:ME,estimatedTotalHits:Dr,refetch:nt}=oE(t,DE,i,d,Be,g),$E=lg({onSuccess:T=>{IE(T.access_token),localStorage.setItem("google_access_token",T.access_token),LE(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:tE}),LE=T=>{const D=document.createElement("script");D.src="https://apis.google.com/js/api.js",D.onload=()=>{window.gapi.load("picker",()=>RE(T))},document.body.appendChild(D)},RE=T=>{const D=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),q=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(QC).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(D).addView(q).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 VE(ge,h)}}).build().setVisible(!0)},VE=async(T,D="")=>{const q=localStorage.getItem("google_access_token");if(!q){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),Pe.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const ee=Pe.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:D,folders:[],files:[]};T.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 me.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${q}`}});Qe.current=!0,nt(),Pe.update(ee,{render:`Đồng bộ thành công! Đã tải lên ${ge.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(ie){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",ie),Pe.update(ee,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const T=D=>{if(D.data.action==="logout"){const q=document.createElement("iframe");q.style.display="none",q.src="https://accounts.google.com/Logout",document.body.appendChild(q),setTimeout(()=>document.body.removeChild(q),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),_.useEffect(()=>{const T=new Set(a);p(T)},[]),_.useEffect(()=>{_e!=null&&_e.status&&(_e.status.status==="completed"?(R({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${_e.url} với ${_e.status.completed} trang`}),Qe.current=!0,nt()):_e.status.status==="failed"&&R({title:"Thu thập website thất bại",description:`Không thể thu thập ${_e.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(zp=_e==null?void 0:_e.status)==null?void 0:zp.status]);const Lp=_.useMemo(()=>Vt[h]||[],[Vt,h]),gn=_.useMemo(()=>Lp,[Lp,h,Vt]),Ir=_.useMemo(()=>{const T={};return gn.forEach((D,q)=>{m.has(D.key)&&(T[q]=!0)}),T},[m,gn]),jE=T=>{const D=Qo(Vt,T);if(D.length===0)return m.has(T)?"all":"none";const q=D.filter(ee=>m.has(ee)).length;return q===0?"none":q===D.length?"all":"partial"},tr=(T,D=!0)=>{if(h!==T){if(s&&!h)An(!0),b(T+s),v(T+s),a||p(new Set);else if(An(!0),b(T),v(T),a||p(new Set),D){const q=window.location.pathname==="/"?"":window.location.pathname,ee=T?`${window.location.origin}${q}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${q}`;window.history.pushState({path:ee},"",ee)}}};_.useEffect(()=>{Zn&&(Qe.current=!0,nt().finally(()=>An(!1)))},[Zn]);const zE=async(T,D)=>{var q,ee;I(!0);try{if(gn.some(Ye=>Ye.isFolder&&Ye.name.toLowerCase()===T.toLowerCase())){R({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),I(!1);return}const ge=`${D}${T}/`;if((await me.post(`${t}/api/create-folder`,{prefix:ge})).status!==200){R({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qe.current=!0,await nt(),R({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),x(""),S(!1)}catch(ie){console.error("Error creating folder:",ie);const ge=((ee=(q=ie==null?void 0:ie.response)==null?void 0:q.data)==null?void 0:ee.error)||"Không thể tạo thư mục";R({title:"Lỗi",description:ge,variant:"destructive"})}finally{I(!1)}},Rs=async(T,D,q)=>{var ee,ie,ge,Ee,Ye,nr,Bp,Hp,Up;U(q),He(!0);try{if(Array.from(T).reduce((Xe,Lr)=>Xe+Lr.size,0)>=100*1024*1024){R({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),U(null),He(!1);return}const li=Array.from(T).filter(Xe=>Xe.size===0);if(li.length>0){const Xe=li.map(Lr=>Lr.name).join(", ");R({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Xe}`,variant:"destructive"}),He(!1),U(null);return}let $r=localStorage.getItem("dataLogin"),rr;try{$r&&($r=JSON.parse($r),rr=$r.user)}catch{$r=null}const Pn=new FormData;if(rr!=null&&rr.id&&Pn.append("metadata",JSON.stringify({creator:rr.username,creatorId:rr.id,DataSource:"Tệp tải lên"})),q==="folder"&&T[0]){const Xe=T[0].webkitRelativePath.split("/")[0];Xe&&Pn.append("folderName",Xe)}Pn.append("prefix",D),Array.from(T).forEach(Xe=>q==="folder"?Pn.append("files",Xe,Xe.webkitRelativePath):Pn.append("files",Xe)),Qe.current=!0;const je=await me.post(`${t}/api/check-files-existed`,Pn,{headers:{"Content-Type":"multipart/form-data"}});if(((ee=je==null?void 0:je.data)==null?void 0:ee.status)===200)await me.post(`${t}/api/upload`,Pn,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),g(""),b(D),setTimeout(async()=>{U(null),await nt(),He(!1),await hn()},500);else{if(((ge=(ie=je==null?void 0:je.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Ee=je==null?void 0:je.data)!=null&&Ee.isFolder)){const Xe=Array.from(T).filter(Lr=>je.data.names.includes(Lr.name));kr(Xe),Fr(!0)}(Ye=je==null?void 0:je.data)!=null&&Ye.isFolder&&((nr=je==null?void 0:je.data)!=null&&nr.name)&&(ai((Bp=je==null?void 0:je.data)==null?void 0:Bp.name),kr(T),Fr(!0))}}catch(Mr){console.error("Lỗi tải lên:",Mr);const li=((Up=(Hp=Mr==null?void 0:Mr.response)==null?void 0:Hp.data)==null?void 0:Up.error)||"Không thể tải lên tập tin";R({title:"Lỗi",description:li,variant:"destructive"}),U(null),He(!1)}},BE=async()=>{var T,D;try{He(!0);const q=new FormData;if(pn){U(Or?"folder":"files"),Fr(!1);let ee=localStorage.getItem("dataLogin"),ie;try{ee&&(ee=JSON.parse(ee),ie=ee.user)}catch{ee=null}if(ie!=null&&ie.id&&(console.log("🚀 ~ uploadFiles ~ user:",ie),q.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"}))),Or&&pn[0]){const ge=pn[0].webkitRelativePath.split("/")[0];ge&&q.append("folderName",ge)}q.append("prefix",h),Array.from(pn).forEach(ge=>Or&&pn[0]?q.append("files",ge,ge.webkitRelativePath):q.append("files",ge)),ie!=null&&ie.id&&q.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"})),await me.post(`${t}/api/upload`,q,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),g(""),b(h),Qe.current=!0}}catch(q){console.error("Lỗi tải lên:",q);const ee=((D=(T=q==null?void 0:q.response)==null?void 0:T.data)==null?void 0:D.error)||"Không thể tải lên tập tin";R({title:"Lỗi",description:ee,variant:"destructive"})}finally{setTimeout(async()=>{U(null),await nt(),He(!1),ai(""),kr(null),await hn()},500)}},HE=async T=>{var D;try{if(await me.delete(`${t}/api/files`,{data:{paths:[T.key]}}),m.has(T.key)){const ee=new Set(m);ee.delete(T.key),p(ee)}const q=((D=T.key)==null?void 0:D.replace(/^(.*?)(\/.*)?$/,(ee,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";b(q),Qe.current=!0,R({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),H(null),await hn()}catch(q){console.error("Error deleting file:",q),R({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{fn(!1),await nt()}},si=T=>{const D=new Set(m),q=typeof T=="function"?T(Ir):T;new Set(Object.keys(Ir).map(Number)).forEach(ie=>{const ge=gn[ie];ge&&(q[ie]||(D.delete(ge.key),ge.isFolder&&Qo(Vt,ge.key).forEach(Ee=>D.delete(Ee))))}),Object.entries(q).forEach(([ie,ge])=>{const Ee=parseInt(ie),Ye=gn[Ee];Ye&&ge&&(D.add(Ye.key),Ye.isFolder&&Qo(Vt,Ye.key).forEach(nr=>D.add(nr)))}),p(D)},UE=async()=>{var T;Z(!0);try{const D=Array.from(m),q=D.map(ie=>Object.values(Vt).flat().find(ge=>ge.key===ie)).filter(ie=>ie!==void 0);if(q.length===0){R({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await me.delete(`${t}/api/files`,{data:{paths:D}});const ee=((T=q[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Ee)=>!Ee||Ee==="/"?"":ge+"/"))||"";b(ee),Qe.current=!0,nt(),R({title:"Đã xóa tập tin",description:`Đã xóa thành công ${q.length} mục`}),$(!1),p(new Set),await hn()}catch(D){console.error("Error deleting files:",D),R({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{Z(!1)}},WE=async(T,D)=>{if(!h.trim()){R({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 q=T.key;let ee;T.isFolder?ee=q.split("/").slice(0,-2).join("/")+"/":ee=q.substring(0,q.lastIndexOf("/")+1);const ie=ee+D+(T.isFolder?"/":"");await me.post(`${t}/api/rename`,{oldPath:q,newPath:ie}),Qe.current=!0,await nt(),R({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${D}"`}),B(null),ce(""),ne(null)}catch(q){console.error("Error renaming item:",q),R({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{de(!1)}},Rp=async T=>{Se(D=>new Set([...D,...T]));try{const D=await me.post(`${t}/api/download`,{paths:T},{responseType:"blob"}),q=window.URL.createObjectURL(D.data),ee=document.createElement("a");ee.href=q;const ie=D.headers["Content-Disposition"]||D.headers["content-disposition"],ge=ie==null?void 0:ie.match(/filename="(.+)"/),Ee=ge?decodeURIComponent(ge[1]):"download.zip";ee.setAttribute("download",Ee),document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),window.URL.revokeObjectURL(q),R({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(D){console.error("Error downloading files:",D),R({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Se(D=>{const q=new Set(D);return T.forEach(ee=>q.delete(ee)),q})}},Vp=h?h.replace(n,"").split("/").filter(Boolean):[],qE=()=>Array.from(m).map(T=>{var D;for(const q in Vt){const ee=(D=Vt[q])==null?void 0:D.find(ie=>ie.key===T);if(ee)return ee}return null}).filter(T=>T!==null),jp=_.useMemo(()=>{const T=[{id:"select",header:()=>{const D=rE(Vt,h),q=D.length>0&&D.every(ie=>m.has(ie)),ee=D.some(ie=>m.has(ie));return l.jsx(ia,{checked:q?!0:ee?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=gn.reduce((Ee,Ye,nr)=>(Ee[nr]=!0,Ee),{});si(ge)}else si({})},"aria-label":"Chọn tất cả"})},cell:({row:D})=>{const q=D.original,ie=q.isFolder?jE(q.key):m.has(q.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(ia,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Ee={...Ir};ge?Ee[D.index]=!0:delete Ee[D.index],si(Ee)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Wi,{})]}),accessorKey:"name",cell:({row:D})=>{const q=D.original,ee=q.key.substring(0,q.key.lastIndexOf("/"))||"/",ie=d.trim()!==""&&ee!==h,ge=ee.split("/").filter(Boolean);return l.jsxs("div",{className:"flex flex-col",children:[l.jsxs("div",{className:`flex items-center gap-2 ${q.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{q.isFolder&&(a||p(new Set),tr(q.key))},children:[q.isFolder?l.jsx(di,{className:"h-5 w-5 text-blue-500"}):null,q.name]}),ie&&l.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[l.jsx(di,{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:()=>{tr("")},children:"/"}),ge.map((Ee,Ye)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{tr(ge.slice(0,Ye+1).join("/")+"/")},children:Ee}),Ye<ge.length-1&&l.jsx("span",{children:"/"})]},Ye))]})]})]})}}];return r||T.push({id:"size",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Wi,{})]}),accessorKey:"size",cell:({getValue:D,row:q})=>{const ee=D();return l.jsx("span",{children:q.original.isFolder?"-":$v(ee)})}},{id:"lastModified",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",l.jsx(Wi,{})]}),accessorKey:"lastModified",cell:({row:D})=>{const q=D.original.lastModified;return l.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:l.jsx("span",{children:q&&Gl(q).isValid()?Gl(q).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>l.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:D})=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>Rp([D.original.key]),className:"h-8 w-8 p-0",disabled:le.has(D.original.key),children:le.has(D.original.key)?l.jsx($e,{className:"h-4 w-4 animate-spin"}):l.jsx(zs,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Tải xuống"})]})}),h.trim()!==""&&l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{B(D.original),ce(D.original.name)},className:"h-8 w-8 p-0",children:l.jsx(tg,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Đổi tên"})]})}),l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{se(!0),G(D.original)},className:"h-8 w-8 p-0",children:l.jsx(Lh,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Di chuyển"})]})}),l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>H(D.original),className:"h-8 w-8 p-0",children:l.jsx(Bs,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Xóa"})]})})]})}),T},[m,gn,Ir,le,r]),Vs=nl({data:gn,columns:jp,state:{rowSelection:Ir,sorting:u},onSortingChange:c,enableRowSelection:!0,onRowSelectionChange:si,getCoreRowModel:tl(),getSortedRowModel:zg()}),GE=async T=>{var D,q;St(!0);try{if(_r(T)){const ee=await me.get(`${t}/api/read-text`,{params:{path:T.key}});Ce(ee.data.content)}try{const ee=await me.get(`${t}/api/read-json`,{params:{path:T.key+".metadata.json"}}),ie=((q=(D=ee==null?void 0:ee.data)==null?void 0:D.content)==null?void 0:q.metadataAttributes)||null;return ne({fullPath:A==null?void 0:A.key,...ie})}catch{return ne("Lỗi phân tích siêu dữ liệu")}}catch(ee){console.error("Error loading file content:",ee),R({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{St(!1)}},KE=async(T,D)=>{tt(!0);try{await me.post(`${t}/api/modify-text`,{path:T.key,content:D}),R({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await nt(),B(null),Ce(""),P("rename"),await hn()}catch(q){console.error("Error saving file content:",q),R({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{tt(!1)}},YE=async T=>{tt(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",Q),await me.post(`${t}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:Q}}),R({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await nt(),B(null),Ce(""),P("rename")}catch(D){console.error("Error saving file content:",D),R({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{tt(!1)}};_.useEffect(()=>{A&&(A.isFolder||GE(A),P("rename"))},[A]);const XE=async(T,D)=>{var q;if(_e){R({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}we(!0);try{const{data:ee}=await me.post(`${t}/api/crawl`,{url:T,limit:D,prefix:h});if(ee.id){Ip({id:ee.id,url:T,limit:D,prefix:h,taskId:((q=ee.task)==null?void 0:q.id)||""});const ie=localStorage.getItem(pp),ge=ie?JSON.parse(ie):[];ge.some(Ee=>Ee.id===ee.id)||(ge.unshift({url:T,id:ee.id,limit:D,prefix:h,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(pp,JSON.stringify(ge))),R({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${D}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),re(!1),K(""),Y("1")}}catch(ee){console.error("Error crawling website:",ee),R({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{we(!1)}},JE=async()=>{try{if(!(_e!=null&&_e.id))return;Ip(null),localStorage.removeItem(Xn),R({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${_e.url}`})}catch(T){console.error("Error stopping job:",T),R({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const T=(D=!0)=>{const ee=new URL(window.location.href).searchParams.get("prefix")||"";ee?tr(ee,!1):(D&&!a&&p(new Set),b(n),v(n),Qe.current=!0,setTimeout(()=>{nt()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const ZE=async()=>{Mp(!0);try{const T=await me.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",T),R({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(T){console.error("Error exporting report:",T),R({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Mp(!1)}},QE=async()=>{try{const T=Lv();T&&(await me.post(`${t}/api/start-ingestion-job`,{prefix:h,user_id:T.id,userName:T.username})).status===200&&await hn()}catch(T){ct(!1),console.log(T)}},mn=_.useRef(),hn=async()=>{try{ct(!0);const T=await me.post(`${t}/api/get-ingestion-job-status`,{prefix:h}),{status:D}=T==null?void 0:T.data;D==="FAILED"||D==="COMPLETE"||D==="STOPPED"||D==="STOPPING"||!D?(ct(!1),mn.current&&(clearInterval(mn.current),mn.current=null),Ls(T==null?void 0:T.data)):(mn.current||(mn.current=setInterval(()=>hn(),5e3)),Ls(T==null?void 0:T.data))}catch(T){console.log(T)}};return console.log(Ke),_.useEffect(()=>{const T=h==null?void 0:h.split("/")[0];return T!==$p&&(ct(!1),mn.current&&(clearInterval(mn.current),mn.current=null),FE(T||""),Ls(null),T&&hn()),()=>{}},[$p,h]),l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(_d,{}),l.jsx(Ht,{open:OE,onOpenChange:T=>{Fr(T),T||(ai(""),kr(null),He(!1),U(null))},children:l.jsxs(At,{children:[l.jsxs(Pt,{children:[l.jsx(Nt,{children:"Cảnh báo trùng lặp"}),l.jsxs(zn,{children:[Or&&l.jsxs(l.Fragment,{children:["Folder $",Or," đã có."]}),pn&&pn.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(pn).map((T,D)=>l.jsx("li",{children:T.name},D))})]})]})]}),l.jsxs(Sn,{children:[l.jsx(ye,{variant:"outline",onClick:()=>{Fr(!1),ai(""),kr(null),He(!1),U(null)},children:"Bỏ qua"}),l.jsx(ye,{variant:"destructive",onClick:()=>BE(),children:"Ghi đè"})]})]})}),l.jsx(fc,{className:"s3-explr-breadcrumb",children:l.jsxs(pc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(ea,{className:"s3-explr-breadcrumb-item",children:l.jsx(ta,{onClick:()=>tr(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),!s&&Vp.map((T,D)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(gc,{className:"s3-explr-breadcrumb-separator"},`sep-${D}`),l.jsx(ea,{className:"s3-explr-breadcrumb-item",children:l.jsx(ta,{onClick:()=>tr(n+Vp.slice(0,D+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},D))]})}),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(KS,{ref:j,onChange:T=>g(T)})}),l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{b(h),Qe.current=!0,nt()},disabled:er,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${er?"animate-spin":""}`}),"Làm mới"]}),h&&h!=="/"&&l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{er||Fe||(ct(!0),QE())},"aria-disabled":er||Fe,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${er||Fe?"animate-spin":""}`}),"Đồng bộ KB"]})}),Ke&&l.jsx(Gt,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsx("p",{className:"font-semibold",children:"Thông tin đồng bộ:"}),l.jsxs("p",{className:"flex items-center gap-2",children:["Trạng thái:"," ",l.jsxs("span",{className:`flex items-center gap-1 ${Ke.status==="COMPLETE"?"text-green-600":Ke.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Ke.status==="COMPLETE"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Ke.status==="FAILED"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Ke.status!=="COMPLETE"&&Ke.status!=="FAILED"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8v4m0 4h.01"})}),Ke.status]})]}),l.jsxs("p",{children:["Ngày tạo:"," ",(()=>{const T=new Date(Ke.created_date),D=new Date(T.getTime()+7*60*60*1e3),ee=Math.floor((new Date().getTime()-T.getTime())/6e4);return ee<1440?`${ee} phút trước`:D.toLocaleString("vi-VN",{timeZone:"UTC"})})()]}),l.jsxs("p",{children:["DataSource ID: ",Ke.dataSourceId]}),l.jsxs("p",{children:["Ingestion Job ID: ",Ke.ingestionJobId]}),l.jsxs("p",{children:["Knowledge Base ID: ",Ke.knowledgeBaseId]}),l.jsxs("p",{children:["Người dùng: ",Ke.user_name]}),l.jsxs("p",{children:["Job trong queue: ",Ke.is_still_in_stock?"Còn":"Không"]})]})})]})}),!r&&l.jsxs(l.Fragment,{children:[m.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>Rp(Array.from(m)),disabled:Array.from(m).some(T=>le.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(m).some(T=>le.has(T))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(zs,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",m.size,")"]}),l.jsxs(Ht,{open:k,onOpenChange:$,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx(Bs,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",m.size,")"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),l.jsxs(zn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",m.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>$(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:UE,disabled:W,className:"s3-explr-confirm-delete-btn",children:W?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"})]})]})]})]}),!s&&l.jsxs(Ht,{open:w,onOpenChange:S,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!h,children:[l.jsx(Xp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsx(Pt,{className:"s3-explr-dialog-header",children:l.jsx(Nt,{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(Cn,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),l.jsx(nn,{disabled:N,id:"name",value:E,onChange:T=>x(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ye,{onClick:()=>{E.trim()&&zE(E,h)},disabled:N,className:"s3-explr-create-btn",children:[N&&l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),N?"Đang tạo...":"Tạo"]})]})]})]}),s&&!h?l.jsx(l.Fragment,{}):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 T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=D=>{const q=D.target.files;q&&Rs(q,h,"files")},T.click()},disabled:F!==null||!!i&&!h,children:F==="files"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang xử lý..."]}):l.jsxs(l.Fragment,{children:[l.jsx(Kp,{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 T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=D=>{const q=D.target.files;q&&Rs(q,h,"folder")},T.click()},disabled:F!==null||!!i&&!h,children:F==="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(di,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),_e?l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{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"}),_e.status?l.jsxs(l.Fragment,{children:[_e.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",_e.status.completed,"/",_e.status.total,") -"," ",Math.floor(Qn/60),":",String(Qn%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ye,{variant:"destructive",size:"sm",onClick:()=>void JE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(rg,{className:"h-4 w-4"})]})]})}),_e.status&&l.jsx(Gt,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",_e.url]}),l.jsxs("p",{children:["Tiến độ: ",_e.status.completed,"/",_e.status.total," ","trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(Qn/60),":",String(Qn%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",_e.status.status==="scraping"?"Đang thu thập":_e.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!s&&l.jsxs(Ht,{open:V,onOpenChange:re,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!h,children:[l.jsx(Qp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Thêm website"}),l.jsx(zn,{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(Cn,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),l.jsx(nn,{id:"websiteUrl",value:J,onChange:T=>K(T.target.value),placeholder:"https://example.com",type:"url",disabled:ve,className:"s3-explr-input"})]}),l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(Cn,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),l.jsx(nn,{id:"crawlLimit",value:z,onChange:T=>{const D=T.target.value;/^\d*$/.test(D)&&Y(D)},placeholder:"1",type:"text",disabled:ve,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(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{re(!1),K(""),Y("1")},disabled:ve,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{onClick:()=>{J.trim()&&XE(J.trim(),parseInt(z)||1)},disabled:ve||!J.trim(),className:"s3-explr-crawl-btn",children:ve?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"})]})]})]}),h.startsWith("BKTTW/")&&l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!h,onClick:ZE,children:[$s&&l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${$s?"animate-spin":""}`}),"Xuất báo cáo"]})}),$s&&l.jsx(Gt,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),!s&&l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>$E(),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(Ht,{open:!!M,onOpenChange:T=>!T&&H(null),children:l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),l.jsxs(zn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",M==null?void 0:M.name,"? Hành động này không thể hoàn tác."]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>H(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:()=>HE(M),disabled:dn,className:"s3-explr-confirm-delete-btn",children:dn?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(Ht,{open:!!A,onOpenChange:T=>{T||(B(null),ne(null),ce(""),Ce(""),P("rename"))},children:l.jsxs(At,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(Pt,{className:"s3-explr-dialog-header",children:l.jsx(Nt,{className:"s3-explr-dialog-title",children:A!=null&&A.isFolder?"Đổi tên thư mục":_r(A)?"Quản lý tập tin":"Đổi tên tập tin"})}),A&&l.jsxs(db,{value:C,onValueChange:T=>P(T),children:[l.jsxs(Zu,{"aria-checked":!_r(A),"aria-disabled":A.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[l.jsx(Ao,{value:"rename",children:"Đổi tên"}),!A.isFolder&&l.jsxs(l.Fragment,{children:[_r(A)&&l.jsx(Ao,{value:"edit",children:"Sửa nội dung"}),l.jsx(Ao,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Po,{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(Cn,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),l.jsx(nn,{id:"newName",value:te,onChange:T=>ce(T.target.value),placeholder:"Nhập tên mới",disabled:ue,className:"s3-explr-input"})]})})}),!A.isFolder&&l.jsxs(l.Fragment,{children:[_r(A)&&l.jsx(Po,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:ze?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(Cn,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),l.jsx(mr,{id:"content",value:X,onChange:T=>Ce(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:lt})]})})}),l.jsx(Po,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:ze?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:Q&&typeof Q=="object"&&Object.entries(Q).map(([T,D],q)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(Cn,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[Qh[T]||T,Yi(T)&&l.jsx(Rh,{className:"h-[12px] w-[12px] text-red-500"})]}),ev(T)?l.jsx(mr,{id:T,value:typeof D=="string"?D:JSON.stringify(D),onChange:ee=>{const ie={...Q,[T]:ee.target.value};ne(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:lt||Yi(T)}):l.jsx(nn,{id:T,value:typeof D=="string"?D:JSON.stringify(D),onChange:ee=>{const ie={...Q,[T]:ee.target.value};ne(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:lt||Yi(T)})]},q))})})})]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{B(null),ne(null),ce(""),Ce("")},className:"s3-explr-cancel-btn",children:"Hủy"}),C==="edit"?l.jsx(ye,{onClick:()=>A&&KE(A,X),disabled:lt||ze,className:"s3-explr-save-btn",children:lt?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"}):C==="edit-metadata"?l.jsx(ye,{onClick:()=>Q&&typeof Q=="object"&&A&&YE(A),disabled:lt||ze,className:"s3-explr-save-btn",children:lt?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:()=>{te.trim()&&A&&WE(A,te.trim())},disabled:ue||!te.trim()||te.trim()===(A==null?void 0:A.name),className:"s3-explr-rename-btn",children:ue?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"})]})]})}),O&&oe&&l.jsx(ZC,{openDialogRename:oe,setOpenDialogRename:se,apiBaseUrl:t,setFileToMove:G,fileToMove:O,refreshFiles:nt,ignoreCache:Qe})]})]}),ME&&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(JC,{onFilesSelected:(T,D)=>Rs(T,h,D),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(wo,{className:"s3-explr-table",children:[l.jsx(So,{className:"s3-explr-table-header",children:Vs.getHeaderGroups().map(T=>l.jsx(yt,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(D=>l.jsx(kt,{className:"s3-explr-header-cell",children:D.isPlaceholder?null:Hr(D.column.columnDef.header,D.getContext())},D.id))},T.id))}),l.jsx(Co,{className:"s3-explr-table-body",children:Vs.getRowModel().rows.length===0?l.jsx(yt,{className:"s3-explr-empty-row",children:l.jsx(Ze,{colSpan:jp.length,className:"h-24 text-center s3-explr-empty-cell",children:d?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 "',d,'"']}):l.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:er?"Đ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"})})}):Vs.getRowModel().rows.map(T=>l.jsx(yt,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(D=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Hr(D.column.columnDef.cell,D.getContext())},D.id))},T.id))})]})})}),d&&Dr!==0&&l.jsx(l.Fragment,{children:l.jsx(ho,{children:l.jsxs(vo,{children:[l.jsx(yo,{onClick:()=>Rt(T=>Math.max(T-1,1)),"aria-disabled":Be===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Dr/20)},(T,D)=>{const q=D+1,ee=Math.ceil(Dr/20);return ee>7&&!(q===1||q===ee||q>=Be-1&&q<=Be+1)?q===Be-2&&Be>4||q===Be+2&&Be<ee-3?l.jsx(bo,{className:"pointer-events-none",children:"..."},D):null:l.jsx(vt,{className:"cursor-pointer",children:l.jsx(Bn,{isActive:Be===q,onClick:()=>Rt(q),className:`${Be===q?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:q})},D)}),l.jsx(vt,{children:l.jsx(xo,{onClick:()=>Rt(T=>Math.min(T+1,Math.ceil(Dr/20))),"aria-disabled":Be===Math.ceil(Dr/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:[m.size," ",(m.size===1,"tập tin")," đã chọn"]}),l.jsx(ye,{variant:"default",onClick:()=>o(qE()),disabled:m.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),aE=e=>l.jsx(ag,{clientId:eE,children:l.jsx(iE,{...e})});var Tr=e=>e.type==="checkbox",Tn=e=>e instanceof Date,Ge=e=>e==null;const gp=e=>typeof e=="object";var Me=e=>!Ge(e)&&!Array.isArray(e)&&gp(e)&&!Tn(e),sE=e=>Me(e)&&e.target?Tr(e.target)?e.target.checked:e.target.value:e,lE=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,cE=(e,t)=>e.has(lE(t)),uE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},Ps=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ft(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(!(Ps&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!uE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ft(e[o]));else return e;return t}var ei=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,ae=(e,t,n)=>{if(!t||!Me(e))return n;const r=ei(t.split(/[,[\].]+?/)).reduce((o,i)=>Ge(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Mt=e=>typeof e=="boolean",Ns=e=>/^\w*$/.test(e),mp=e=>ei(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Oe=(e,t,n)=>{let r=-1;const o=Ns(t)?[t]:mp(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 hp={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},wt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Kt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};_.createContext(null);var dE=(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]!==wt.all&&(t._proxyFormState[a]=!r||wt.all),e[a]}});return o},et=e=>Me(e)&&!Object.keys(e).length,fE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return et(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===wt.all)},ti=e=>Array.isArray(e)?e:[e];function pE(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 $t=e=>typeof e=="string",gE=(e,t,n,r,o)=>$t(e)?(r&&t.watch.add(e),ae(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),ae(n,i))):(r&&(t.watchAll=!0),n),mE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},vp=e=>({isOnSubmit:!e||e===wt.onSubmit,isOnBlur:e===wt.onBlur,isOnChange:e===wt.onChange,isOnAll:e===wt.all,isOnTouch:e===wt.onTouched}),yp=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Ar=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=ae(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(Ar(s,t))break}else if(Me(s)&&Ar(s,t))break}}};var hE=(e,t,n)=>{const r=ti(ae(e,n));return Oe(r,"root",t[n]),Oe(e,n,r),e},ks=e=>e.type==="file",Lt=e=>typeof e=="function",ni=e=>{if(!Ps)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ri=e=>$t(e),Os=e=>e.type==="radio",oi=e=>e instanceof RegExp;const xp={value:!1,isValid:!1},bp={value:!0,isValid:!0};var wp=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===""?bp:{value:e[0].value,isValid:!0}:bp:xp}return xp};const Sp={isValid:!1,value:null};var Cp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Sp):Sp;function Ep(e,t,n="validate"){if(ri(e)||Array.isArray(e)&&e.every(ri)||Mt(e)&&!e)return{type:n,message:ri(e)?e:"",ref:t}}var Jn=e=>Me(e)&&!oi(e)?e:{value:e,message:""},_p=async(e,t,n,r,o)=>{const{ref:i,refs:a,required:s,maxLength:u,minLength:c,min:d,max:g,pattern:m,validate:p,name:h,valueAsNumber:v,mount:y,disabled:b}=e._f,w=ae(t,h);if(!y||b)return{};const S=a?a[0]:i,E=W=>{r&&S.reportValidity&&(S.setCustomValidity(Mt(W)?"":W||""),S.reportValidity())},x={},N=Os(i),I=Tr(i),M=N||I,H=(v||ks(i))&&Ie(i.value)&&Ie(w)||ni(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,O=mE.bind(null,h,n,x),G=(W,Z,k,$=Kt.maxLength,F=Kt.minLength)=>{const U=W?Z:k;x[h]={type:W?$:F,message:U,ref:i,...O(W?$:F,U)}};if(o?!Array.isArray(w)||!w.length:s&&(!M&&(H||Ge(w))||Mt(w)&&!w||I&&!wp(a).isValid||N&&!Cp(a).isValid)){const{value:W,message:Z}=ri(s)?{value:!!s,message:s}:Jn(s);if(W&&(x[h]={type:Kt.required,message:Z,ref:S,...O(Kt.required,Z)},!n))return E(Z),x}if(!H&&(!Ge(d)||!Ge(g))){let W,Z;const k=Jn(g),$=Jn(d);if(!Ge(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ge(k.value)||(W=F>k.value),Ge($.value)||(Z=F<$.value)}else{const F=i.valueAsDate||new Date(w),U=A=>new Date(new Date().toDateString()+" "+A),j=i.type=="time",R=i.type=="week";$t(k.value)&&w&&(W=j?U(w)>U(k.value):R?w>k.value:F>new Date(k.value)),$t($.value)&&w&&(Z=j?U(w)<U($.value):R?w<$.value:F<new Date($.value))}if((W||Z)&&(G(!!W,k.message,$.message,Kt.max,Kt.min),!n))return E(x[h].message),x}if((u||c)&&!H&&($t(w)||o&&Array.isArray(w))){const W=Jn(u),Z=Jn(c),k=!Ge(W.value)&&w.length>+W.value,$=!Ge(Z.value)&&w.length<+Z.value;if((k||$)&&(G(k,W.message,Z.message),!n))return E(x[h].message),x}if(m&&!H&&$t(w)){const{value:W,message:Z}=Jn(m);if(oi(W)&&!w.match(W)&&(x[h]={type:Kt.pattern,message:Z,ref:i,...O(Kt.pattern,Z)},!n))return E(Z),x}if(p){if(Lt(p)){const W=await p(w,t),Z=Ep(W,S);if(Z&&(x[h]={...Z,...O(Kt.validate,Z.message)},!n))return E(Z.message),x}else if(Me(p)){let W={};for(const Z in p){if(!et(W)&&!n)break;const k=Ep(await p[Z](w,t),S,Z);k&&(W={...k,...O(Z,k.message)},E(k.message),n&&(x[h]=W))}if(!et(W)&&(x[h]={ref:S,...W},!n))return x}}return E(!0),x};function vE(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 yE(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:Ns(t)?[t]:mp(t),r=n.length===1?e:vE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&et(r)||Array.isArray(r)&&yE(r))&&Ve(e,n.slice(0,-1)),e}var Fs=()=>{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=[]}}},Ds=e=>Ge(e)||!gp(e);function un(e,t){if(Ds(e)||Ds(t))return e===t;if(Tn(e)&&Tn(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(Tn(i)&&Tn(a)||Me(i)&&Me(a)||Array.isArray(i)&&Array.isArray(a)?!un(i,a):i!==a)return!1}}return!0}var Tp=e=>e.type==="select-multiple",xE=e=>Os(e)||Tr(e),Is=e=>ni(e)&&e.isConnected,Ap=e=>{for(const t in e)if(Lt(e[t]))return!0;return!1};function ii(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!Ap(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ii(e[r],t[r])):Ge(e[r])||(t[r]=!0);return t}function Pp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!Ap(e[o])?Ie(t)||Ds(n[o])?n[o]=Array.isArray(e[o])?ii(e[o],[]):{...ii(e[o])}:Pp(e[o],Ge(t)?{}:t[o],n[o]):n[o]=!un(e[o],t[o]);return n}var Pr=(e,t)=>Pp(e,t,ii(t)),Np=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&$t(e)?new Date(e):r?r(e):e;function Ms(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return ks(t)?t.files:Os(t)?Cp(e.refs).value:Tp(t)?[...t.selectedOptions].map(({value:n})=>n):Tr(t)?wp(e.refs).value:Np(Ie(t.value)?e.ref.value:t.value,e)}var bE=(e,t,n,r)=>{const o={};for(const i of e){const a=ae(t,i);a&&Oe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Nr=e=>Ie(e)?e:oi(e)?e.source:Me(e)?oi(e.value)?e.value.source:e.value:e;const kp="AsyncFunction";var wE=e=>!!e&&!!e.validate&&!!(Lt(e.validate)&&e.validate.constructor.name===kp||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===kp)),SE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Op(e,t,n){const r=ae(e,n);if(r||Ns(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),a=ae(t,i),s=ae(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 CE=(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,EE=(e,t)=>!ei(ae(e,t)).length&&Ve(e,t);const _E={mode:wt.onSubmit,reValidateMode:wt.onChange,shouldFocusError:!0};function TE(e={}){let t={..._E,...e},n={submitCount:0,isDirty:!1,isLoading:Lt(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)?ft(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ft(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:Fs(),array:Fs(),state:Fs()},m=vp(t.mode),p=vp(t.reValidateMode),h=t.criteriaMode===wt.all,v=C=>P=>{clearTimeout(c),c=setTimeout(C,P)},y=async C=>{if(!t.disabled&&(d.isValid||C)){const P=t.resolver?et((await M()).errors):await O(r,!0);P!==n.isValid&&g.state.next({isValid:P})}},b=(C,P)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(s.mount)).forEach(V=>{V&&(P?Oe(n.validatingFields,V,P):Ve(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!et(n.validatingFields)}))},w=(C,P=[],V,re,J=!0,K=!0)=>{if(re&&V&&!t.disabled){if(a.action=!0,K&&Array.isArray(ae(r,C))){const z=V(ae(r,C),re.argA,re.argB);J&&Oe(r,C,z)}if(K&&Array.isArray(ae(n.errors,C))){const z=V(ae(n.errors,C),re.argA,re.argB);J&&Oe(n.errors,C,z),EE(n.errors,C)}if(d.touchedFields&&K&&Array.isArray(ae(n.touchedFields,C))){const z=V(ae(n.touchedFields,C),re.argA,re.argB);J&&Oe(n.touchedFields,C,z)}d.dirtyFields&&(n.dirtyFields=Pr(o,i)),g.state.next({name:C,isDirty:W(C,P),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Oe(i,C,P)},S=(C,P)=>{Oe(n.errors,C,P),g.state.next({errors:n.errors})},E=C=>{n.errors=C,g.state.next({errors:n.errors,isValid:!1})},x=(C,P,V,re)=>{const J=ae(r,C);if(J){const K=ae(i,C,Ie(V)?ae(o,C):V);Ie(K)||re&&re.defaultChecked||P?Oe(i,C,P?K:Ms(J._f)):$(C,K),a.mount&&y()}},N=(C,P,V,re,J)=>{let K=!1,z=!1;const Y={name:C};if(!t.disabled){const ve=!!(ae(r,C)&&ae(r,C)._f&&ae(r,C)._f.disabled);if(!V||re){d.isDirty&&(z=n.isDirty,n.isDirty=Y.isDirty=W(),K=z!==Y.isDirty);const we=ve||un(ae(o,C),P);z=!!(!ve&&ae(n.dirtyFields,C)),we||ve?Ve(n.dirtyFields,C):Oe(n.dirtyFields,C,!0),Y.dirtyFields=n.dirtyFields,K=K||d.dirtyFields&&z!==!we}if(V){const we=ae(n.touchedFields,C);we||(Oe(n.touchedFields,C,V),Y.touchedFields=n.touchedFields,K=K||d.touchedFields&&we!==V)}K&&J&&g.state.next(Y)}return K?Y:{}},I=(C,P,V,re)=>{const J=ae(n.errors,C),K=d.isValid&&Mt(P)&&n.isValid!==P;if(t.delayError&&V?(u=v(()=>S(C,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Oe(n.errors,C,V):Ve(n.errors,C)),(V?!un(J,V):J)||!et(re)||K){const z={...re,...K&&Mt(P)?{isValid:P}:{},errors:n.errors,name:C};n={...n,...z},g.state.next(z)}},M=async C=>{b(C,!0);const P=await t.resolver(i,t.context,bE(C||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(C),P},H=async C=>{const{errors:P}=await M(C);if(C)for(const V of C){const re=ae(P,V);re?Oe(n.errors,V,re):Ve(n.errors,V)}else n.errors=P;return P},O=async(C,P,V={valid:!0})=>{for(const re in C){const J=C[re];if(J){const{_f:K,...z}=J;if(K){const Y=s.array.has(K.name),ve=J._f&&wE(J._f);ve&&d.validatingFields&&b([re],!0);const we=await _p(J,i,h,t.shouldUseNativeValidation&&!P,Y);if(ve&&d.validatingFields&&b([re]),we[K.name]&&(V.valid=!1,P))break;!P&&(ae(we,K.name)?Y?hE(n.errors,we,K.name):Oe(n.errors,K.name,we[K.name]):Ve(n.errors,K.name))}!et(z)&&await O(z,P,V)}}return V.valid},G=()=>{for(const C of s.unMount){const P=ae(r,C);P&&(P._f.refs?P._f.refs.every(V=>!Is(V)):!Is(P._f.ref))&&oe(C)}s.unMount=new Set},W=(C,P)=>!t.disabled&&(C&&P&&Oe(i,C,P),!un(B(),o)),Z=(C,P,V)=>gE(C,s,{...a.mount?i:Ie(P)?o:$t(C)?{[C]:P}:P},V,P),k=C=>ei(ae(a.mount?i:o,C,t.shouldUnregister?ae(o,C,[]):[])),$=(C,P,V={})=>{const re=ae(r,C);let J=P;if(re){const K=re._f;K&&(!K.disabled&&Oe(i,C,Np(P,K)),J=ni(K.ref)&&Ge(P)?"":P,Tp(K.ref)?[...K.ref.options].forEach(z=>z.selected=J.includes(z.value)):K.refs?Tr(K.ref)?K.refs.length>1?K.refs.forEach(z=>(!z.defaultChecked||!z.disabled)&&(z.checked=Array.isArray(J)?!!J.find(Y=>Y===z.value):J===z.value)):K.refs[0]&&(K.refs[0].checked=!!J):K.refs.forEach(z=>z.checked=z.value===J):ks(K.ref)?K.ref.value="":(K.ref.value=J,K.ref.type||g.values.next({name:C,values:{...i}})))}(V.shouldDirty||V.shouldTouch)&&N(C,J,V.shouldTouch,V.shouldDirty,!0),V.shouldValidate&&A(C)},F=(C,P,V)=>{for(const re in P){const J=P[re],K=`${C}.${re}`,z=ae(r,K);(s.array.has(C)||Me(J)||z&&!z._f)&&!Tn(J)?F(K,J,V):$(K,J,V)}},U=(C,P,V={})=>{const re=ae(r,C),J=s.array.has(C),K=ft(P);Oe(i,C,K),J?(g.array.next({name:C,values:{...i}}),(d.isDirty||d.dirtyFields)&&V.shouldDirty&&g.state.next({name:C,dirtyFields:Pr(o,i),isDirty:W(C,K)})):re&&!re._f&&!Ge(K)?F(C,K,V):$(C,K,V),yp(C,s)&&g.state.next({...n}),g.values.next({name:a.mount?C:void 0,values:{...i}})},j=async C=>{a.mount=!0;const P=C.target;let V=P.name,re=!0;const J=ae(r,V),K=()=>P.type?Ms(J._f):sE(C),z=Y=>{re=Number.isNaN(Y)||Tn(Y)&&isNaN(Y.getTime())||un(Y,ae(i,V,Y))};if(J){let Y,ve;const we=K(),Fe=C.type===hp.BLUR||C.type===hp.FOCUS_OUT,ct=!SE(J._f)&&!t.resolver&&!ae(n.errors,V)&&!J._f.deps||CE(Fe,ae(n.touchedFields,V),n.isSubmitted,p,m),Ct=yp(V,s,Fe);Oe(i,V,we),Fe?(J._f.onBlur&&J._f.onBlur(C),u&&u(0)):J._f.onChange&&J._f.onChange(C);const He=N(V,we,Fe,!1),dn=!et(He)||Ct;if(!Fe&&g.values.next({name:V,type:C.type,values:{...i}}),ct)return d.isValid&&(t.mode==="onBlur"?Fe&&y():y()),dn&&g.state.next({name:V,...Ct?{}:He});if(!Fe&&Ct&&g.state.next({...n}),t.resolver){const{errors:fn}=await M([V]);if(z(we),re){const Be=Op(n.errors,r,V),Rt=Op(fn,r,Be.name||V);Y=Rt.error,V=Rt.name,ve=et(fn)}}else b([V],!0),Y=(await _p(J,i,h,t.shouldUseNativeValidation))[V],b([V]),z(we),re&&(Y?ve=!1:d.isValid&&(ve=await O(r,!0)));re&&(J._f.deps&&A(J._f.deps),I(V,ve,Y,He))}},R=(C,P)=>{if(ae(n.errors,P)&&C.focus)return C.focus(),1},A=async(C,P={})=>{let V,re;const J=ti(C);if(t.resolver){const K=await H(Ie(C)?C:J);V=et(K),re=C?!J.some(z=>ae(K,z)):V}else C?(re=(await Promise.all(J.map(async K=>{const z=ae(r,K);return await O(z&&z._f?{[K]:z}:z)}))).every(Boolean),!(!re&&!n.isValid)&&y()):re=V=await O(r);return g.state.next({...!$t(C)||d.isValid&&V!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:V}:{},errors:n.errors}),P.shouldFocus&&!re&&Ar(r,R,C?J:s.mount),re},B=C=>{const P={...a.mount?i:o};return Ie(C)?P:$t(C)?ae(P,C):C.map(V=>ae(P,V))},Q=(C,P)=>({invalid:!!ae((P||n).errors,C),isDirty:!!ae((P||n).dirtyFields,C),error:ae((P||n).errors,C),isValidating:!!ae(n.validatingFields,C),isTouched:!!ae((P||n).touchedFields,C)}),ne=C=>{C&&ti(C).forEach(P=>Ve(n.errors,P)),g.state.next({errors:C?n.errors:{}})},te=(C,P,V)=>{const re=(ae(r,C,{_f:{}})._f||{}).ref,J=ae(n.errors,C)||{},{ref:K,message:z,type:Y,...ve}=J;Oe(n.errors,C,{...ve,...P,ref:re}),g.state.next({name:C,errors:n.errors,isValid:!1}),V&&V.shouldFocus&&re&&re.focus&&re.focus()},ce=(C,P)=>Lt(C)?g.values.subscribe({next:V=>C(Z(void 0,P),V)}):Z(C,P,!0),oe=(C,P={})=>{for(const V of C?ti(C):s.mount)s.mount.delete(V),s.array.delete(V),P.keepValue||(Ve(r,V),Ve(i,V)),!P.keepError&&Ve(n.errors,V),!P.keepDirty&&Ve(n.dirtyFields,V),!P.keepTouched&&Ve(n.touchedFields,V),!P.keepIsValidating&&Ve(n.validatingFields,V),!t.shouldUnregister&&!P.keepDefaultValue&&Ve(o,V);g.values.next({values:{...i}}),g.state.next({...n,...P.keepDirty?{isDirty:W()}:{}}),!P.keepIsValid&&y()},se=({disabled:C,name:P,field:V,fields:re,value:J})=>{if(Mt(C)&&a.mount||C){const K=C?void 0:Ie(J)?Ms(V?V._f:ae(re,P)._f):J;(C||!C&&!Ie(K))&&Oe(i,P,K),N(P,K,!1,!1,!0)}},ue=(C,P={})=>{let V=ae(r,C);const re=Mt(P.disabled)||Mt(t.disabled);return Oe(r,C,{...V||{},_f:{...V&&V._f?V._f:{ref:{name:C}},name:C,mount:!0,...P}}),s.mount.add(C),V?se({field:V,disabled:Mt(P.disabled)?P.disabled:t.disabled,name:C,value:P.value}):x(C,!0,P.value),{...re?{disabled:P.disabled||t.disabled}:{},...t.progressive?{required:!!P.required,min:Nr(P.min),max:Nr(P.max),minLength:Nr(P.minLength),maxLength:Nr(P.maxLength),pattern:Nr(P.pattern)}:{},name:C,onChange:j,onBlur:j,ref:J=>{if(J){ue(C,P),V=ae(r,C);const K=Ie(J.value)&&J.querySelectorAll&&J.querySelectorAll("input,select,textarea")[0]||J,z=xE(K),Y=V._f.refs||[];if(z?Y.find(ve=>ve===K):K===V._f.ref)return;Oe(r,C,{_f:{...V._f,...z?{refs:[...Y.filter(Is),K,...Array.isArray(ae(o,C))?[{}]:[]],ref:{type:K.type,name:C}}:{ref:K}}}),x(C,!1,void 0,K)}else V=ae(r,C,{}),V._f&&(V._f.mount=!1),(t.shouldUnregister||P.shouldUnregister)&&!(cE(s.array,C)&&a.action)&&s.unMount.add(C)}}},de=()=>t.shouldFocusError&&Ar(r,R,s.mount),le=C=>{Mt(C)&&(g.state.next({disabled:C}),Ar(r,(P,V)=>{const re=ae(r,V);re&&(P.disabled=re._f.disabled||C,Array.isArray(re._f.refs)&&re._f.refs.forEach(J=>{J.disabled=re._f.disabled||C}))},0,!1))},Se=(C,P)=>async V=>{let re;if(V&&(V.preventDefault&&V.preventDefault(),V.persist&&V.persist()),t.disabled){P&&await P({...n.errors},V);return}let J=ft(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:z}=await M();n.errors=K,J=z}else await O(r);if(Ve(n.errors,"root"),et(n.errors)){g.state.next({errors:{}});try{await C(J,V)}catch(K){re=K}}else P&&await P({...n.errors},V),de(),setTimeout(de);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:et(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},X=(C,P={})=>{ae(r,C)&&(Ie(P.defaultValue)?U(C,ft(ae(o,C))):(U(C,P.defaultValue),Oe(o,C,ft(P.defaultValue))),P.keepTouched||Ve(n.touchedFields,C),P.keepDirty||(Ve(n.dirtyFields,C),n.isDirty=P.defaultValue?W(C,ft(ae(o,C))):W()),P.keepError||(Ve(n.errors,C),d.isValid&&y()),g.state.next({...n}))},Ce=(C,P={})=>{const V=C?ft(C):o,re=ft(V),J=et(C),K=J?o:re;if(P.keepDefaultValues||(o=V),!P.keepValues){if(P.keepDirtyValues){const z=new Set([...s.mount,...Object.keys(Pr(o,i))]);for(const Y of Array.from(z))ae(n.dirtyFields,Y)?Oe(K,Y,ae(i,Y)):U(Y,ae(K,Y))}else{if(Ps&&Ie(C))for(const z of s.mount){const Y=ae(r,z);if(Y&&Y._f){const ve=Array.isArray(Y._f.refs)?Y._f.refs[0]:Y._f.ref;if(ni(ve)){const we=ve.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?P.keepDefaultValues?ft(o):{}:ft(K),g.array.next({values:{...K}}),g.values.next({values:{...K}})}s={mount:P.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!P.keepIsValid||!!P.keepDirtyValues,a.watch=!!t.shouldUnregister,g.state.next({submitCount:P.keepSubmitCount?n.submitCount:0,isDirty:J?!1:P.keepDirty?n.isDirty:!!(P.keepDefaultValues&&!un(C,o)),isSubmitted:P.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:J?{}:P.keepDirtyValues?P.keepDefaultValues&&i?Pr(o,i):n.dirtyFields:P.keepDefaultValues&&C?Pr(o,C):P.keepDirty?n.dirtyFields:{},touchedFields:P.keepTouched?n.touchedFields:{},errors:P.keepErrors?n.errors:{},isSubmitSuccessful:P.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},ze=(C,P)=>Ce(Lt(C)?C(i):C,P);return{control:{register:ue,unregister:oe,getFieldState:Q,handleSubmit:Se,setError:te,_executeSchema:M,_getWatch:Z,_getDirty:W,_updateValid:y,_removeUnmounted:G,_updateFieldArray:w,_updateDisabledField:se,_getFieldArray:k,_reset:Ce,_resetDefaultValues:()=>Lt(t.defaultValues)&&t.defaultValues().then(C=>{ze(C,t.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:le,_subjects:g,_proxyFormState:d,_setErrors:E,get _fields(){return r},get _formValues(){return i},get _state(){return a},set _state(C){a=C},get _defaultValues(){return o},get _names(){return s},set _names(C){s=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:A,register:ue,handleSubmit:Se,watch:ce,setValue:U,getValues:B,reset:ze,resetField:X,clearErrors:ne,unregister:oe,setError:te,setFocus:(C,P={})=>{const V=ae(r,C),re=V&&V._f;if(re){const J=re.refs?re.refs[0]:re.ref;J.focus&&(J.focus(),P.shouldSelect&&Lt(J.select)&&J.select())}},getFieldState:Q}}function AE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:Lt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Lt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...TE(e),formState:r});const i=t.current.control;return i._options=e,pE({subject:i._subjects.state,next:a=>{fE(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&&!un(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:dE(r,i)}),[r,i])}const Fp=({className:e,children:t,content:n,side:r})=>{const[o,i]=_.useState(!1);return l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{open:o,children:[l.jsx(cn,{asChild:!0,children:l.jsx("button",{type:"button",className:he("cursor-pointer",e),onClick:()=>i(!o),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onTouchStart:()=>i(!o),onKeyDown:a=>{a.preventDefault(),a.key==="Enter"&&i(!o)},children:t})}),l.jsx(Gt,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},PE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},NE=({apiBaseUrl:e="https://s3-explorer.cmcts1.studio.ai.vn"})=>{var N,I;const[t,n]=_.useState([]),[r,o]=_.useState(!1),[i,a]=_.useState([]),[s,u]=_.useState(1),[c,d]=_.useState(1),[g,m]=_.useState(null),[p,h]=_.useState(""),v=PE(p,500),y=M=>{const H=M.match(/\d{6}/);if(!H)return{month:"",year:""};const O=H[0],G=O.substring(0,2),W=O.substring(2);return{month:G,year:W}},b=M=>M.map(O=>{let G=(O==null?void 0:O.month)||"",W=(O==null?void 0:O.year)||"";if((!G||!W)&&(O!=null&&O.file_name)){const Z=y(O.file_name);G=G||Z.month,W=W||Z.year}return{id:O==null?void 0:O.id,prefix:(O==null?void 0:O.prefix)||"",model:(O==null?void 0:O.model)||"",fileName:(O==null?void 0:O.file_name)||"",code:(O==null?void 0:O.stock_id)||"",month:G,year:W,content:(O==null?void 0:O.text_summary)||"",status:(O==null?void 0:O.status)||"",note:(O==null?void 0:O.note)||"",lastUpdate:O==null?void 0:O.updated_at,stock_id:O==null?void 0:O.stock_id}}),w=M=>{if(!(M!=null&&M.data))return[];const H=b(M==null?void 0:M.data);n(H),d(M.pagination.totalPages)},S=async(M=1,H=15)=>{m(M),o(!0);try{const O=await me.get(`${e}/api/latest-summaries`,{params:{page:M,limit:H,search:p}});(O==null?void 0:O.status)===200?w(O.data):console.error(O)}catch(O){console.error("Error fetching data:",O)}finally{m(null),o(!1)}};_.useEffect(()=>{v&&u(1),S(s)},[s,v]);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 O=H.original.month,G=H.original.year;return l.jsx("span",{className:"flex flex-col",children:`${O.toString().padStart(2,"0")}/${G}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:H})=>{const O=H.getValue("content");return l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:O})}},{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(Fp,{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 O=new Date(H.original.lastUpdate),G=O.getDate(),W=O.getMonth()+1,Z=`ngày ${G} tháng ${W}`;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[O,G]=_.useState(!1),[W,Z]=_.useState(!1),[k,$]=_.useState(!1),{handleSubmit:F,register:U,reset:j}=AE(),R=H.original.id,A=H.getValue("status"),B=H.getValue("content"),[Q,ne]=_.useState(!1),te=async()=>{try{ne(!0);const oe=A==="unpublish"?"published":"unpublish",se=await me.patch(`${e}/api/toggle-publish/${R}`,{id:R,typeAction:"update",status:A,idInput:R,stock_id:H.original.stock_id,prefix:H.original.prefix,model:H.original.model,summary_result:H.original.content,note:H.original.note});se.status===200?n(ue=>ue.map(de=>de.id===R?{...de,status:oe}:de)):console.error("Failed to toggle publish status:",se)}catch(oe){console.error("Error toggling publish status:",oe)}finally{ne(!1)}},ce=async oe=>{G(!0);try{const se=await me.patch(`${e}/api/update-summary`,{note:oe.note,text_summary:oe.content,id:R});se.status===200?(await S(s),Z(!1)):console.error("Failed to update summary:",se)}catch(se){console.error("Error updating summary:",se)}return G(!1)};return l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ye,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"px-2 py-0.5 h-7",children:l.jsx($h,{className:"h-4 w-4"})}),l.jsx(Ht,{open:k,onOpenChange:$,children:l.jsxs(At,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(Pt,{children:l.jsx(Nt,{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(Ht,{open:W,onOpenChange:oe=>{Z(oe),oe?j({content:H.original.content,note:H.original.note}):j()},children:[l.jsx(mo,{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(At,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(Pt,{className:"flex flex-col gap-3",children:[l.jsx(Nt,{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(mr,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.answer||"",rows:10,...U("content")})]}),l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Ghi chú:"}),l.jsx(mr,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.note||"",rows:1,...U("note")})]})]}),l.jsx("div",{className:"flex justify-end",children:l.jsx(ye,{disabled:O,type:"submit",variant:"default",children:O?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ye,{variant:"outline",size:"sm",onClick:te,disabled:Q,className:"w-[70px] px-2 py-0.5 h-7",children:Q?l.jsx($e,{className:"h-4 w-4 animate-spin"}):A==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=nl({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:jg(),getCoreRowModel:tl()});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:p,onChange:M=>h(M.target.value),className:"pr-8"}),p&&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:()=>h(""),children:l.jsx(qi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(wo,{className:"s3-explr-table",children:[l.jsx(So,{className:"s3-explr-table-header",children:x.getHeaderGroups().map(M=>l.jsx(yt,{className:"hover:bg-transparent s3-explr-header-row",children:M.headers.map(H=>l.jsx(kt,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Hr(H.column.columnDef.header,H.getContext())},H.id))},M.id))}),l.jsx(Co,{className:"s3-explr-table-body",children:r?l.jsx(yt,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(N=x.getRowModel().rows)!=null&&N.length?(I=x.getRowModel().rows)==null?void 0:I.map(M=>l.jsx(yt,{className:"h-12 s3-explr-row",children:M.getVisibleCells().map(H=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Hr(H.column.columnDef.cell,H.getContext())},H.id))},M.id)):l.jsx(yt,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(ho,{children:l.jsxs(vo,{children:[l.jsx(vt,{children:l.jsx(yo,{onClick:()=>u(M=>Math.max(1,M-1)),className:s===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:c},(M,H)=>H+1).filter(M=>M===1||M===c||Math.abs(M-s)<=1).map((M,H,O)=>l.jsxs(l.Fragment,{children:[H>0&&O[H-1]!==M-1&&l.jsx(vt,{children:l.jsx(bo,{})},M+"..."),l.jsx(vt,{children:l.jsx(Bn,{onClick:()=>u(M),isActive:s===M,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===M?l.jsx($e,{className:"h-4 w-4 animate-spin"}):M})},M)]})),l.jsx(vt,{children:l.jsx(xo,{onClick:()=>u(M=>Math.min(c,M+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Dp=10,kE=_.memo(({apiBaseUrl:e="https://s3-explorer.cmcts1.studio.ai.vn"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Dp,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:p}=Io(),[h,v]=_.useState(!1),y=async x=>{try{d(x);const N=await me.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Dp.toString()}});o(N.data.data),a(N.data.pagination)}catch{p({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(N=>new Set(N).add(x.toString()));try{await me.post(`${e}/api/retry-job`,{jobId:x}),p({title:"Job Restarted",description:`Job ${x} has been successfully restarted.`}),y(t)}catch{p({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${x}. Please try again.`})}finally{m(N=>{const I=new Set(N);return I.delete(x.toString()),I})}},w=async()=>{v(!0),n(1),await y(1),v(!1)},S=x=>new Date(x).toLocaleString(),E=x=>{if(x=parseFloat(x),x<60)return`${x.toFixed(2)}s`;const N=Math.floor(x/60),I=(x%60).toFixed(0);return`${N}m ${I}s`};return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[l.jsx(Fh,{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:h||s,className:"ml-2",children:l.jsx(Vh,{className:`h-4 w-4 ${h?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(wo,{children:[l.jsx(So,{children:l.jsxs(yt,{children:[l.jsx(kt,{children:"ID"}),l.jsx(kt,{children:"Tên Công Việc"}),l.jsx(kt,{children:"Thời Gian Bắt Đầu"}),l.jsx(kt,{children:"Thời Gian Cập Nhật"}),l.jsx(kt,{children:"Thời Gian Thực Thi"}),l.jsx(kt,{children:"Trạng Thái"}),l.jsx(kt,{children:"Thao Tác"})]})}),l.jsx(Co,{children:s&&r.length===0?l.jsx(yt,{children:l.jsx(Ze,{colSpan:7,className:"text-center py-4",children:l.jsx($e,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(x=>{var N,I;return l.jsxs(yt,{children:[l.jsx(Ze,{className:"!w-[100px]",children:x.id}),l.jsx(Ze,{className:"font-medium",children:(N=x.job_name)==null?void 0:N.replace("Upload file","Summary")}),l.jsx(Ze,{className:"!w-[200px]",children:S(x.created_at)}),l.jsx(Ze,{className:"!w-[200px]",children:S(x.updated_at)}),l.jsx(Ze,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Ze,{className:"!w-[200px]",children:l.jsx(Fp,{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 lp(e,t){if(e){if(typeof e=="string")return Es(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 Es(e,t)}}function Es(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 GC(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 KC(e){if(Array.isArray(e))return e}function cp(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?cp(Object(n),!0).forEach(function(r){_s(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):cp(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function _s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zo(e,t){if(e==null)return{};var n=YC(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 YC(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 Ts=_.forwardRef(function(e,t){var n=e.children,r=Zo(e,RC),o=dp(r),i=o.open,a=Zo(o,VC);return _.useImperativeHandle(t,function(){return{open:i}},[i]),_.createElement(_.Fragment,null,n(De(De({},a),{},{open:i})))});Ts.displayName="Dropzone";var up={disabled:!1,getFilesFromEvent:sC,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};Ts.defaultProps=up,Ts.propTypes={children:Ne.func,accept:Ne.objectOf(Ne.arrayOf(Ne.string)),multiple:Ne.bool,preventDropOnDocument:Ne.bool,noClick:Ne.bool,noKeyboard:Ne.bool,noDrag:Ne.bool,noDragEventsBubbling:Ne.bool,minSize:Ne.number,maxSize:Ne.number,maxFiles:Ne.number,disabled:Ne.bool,getFilesFromEvent:Ne.func,onFileDialogCancel:Ne.func,onFileDialogOpen:Ne.func,useFsAccessApi:Ne.bool,autoFocus:Ne.bool,onDragEnter:Ne.func,onDragLeave:Ne.func,onDragOver:Ne.func,onDrop:Ne.func,onDropAccepted:Ne.func,onDropRejected:Ne.func,onError:Ne.func,validator:Ne.func};var As={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function dp(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=De(De({},up),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,p=t.onDropAccepted,h=t.onDropRejected,v=t.onFileDialogCancel,y=t.onFileDialogOpen,b=t.useFsAccessApi,w=t.autoFocus,S=t.preventDropOnDocument,E=t.noClick,x=t.noKeyboard,N=t.noDrag,I=t.noDragEventsBubbling,M=t.onError,H=t.validator,O=_.useMemo(function(){return MC(n)},[n]),G=_.useMemo(function(){return IC(n)},[n]),W=_.useMemo(function(){return typeof y=="function"?y:fp},[y]),Z=_.useMemo(function(){return typeof v=="function"?v:fp},[v]),k=_.useRef(null),$=_.useRef(null),F=_.useReducer(XC,As),U=Cs(F,2),j=U[0],R=U[1],A=j.isFocused,B=j.isFileDialogActive,Q=_.useRef(typeof window<"u"&&window.isSecureContext&&b&&DC()),ne=function(){!Q.current&&B&&setTimeout(function(){if($.current){var Y=$.current.files;Y.length||(R({type:"closeDialog"}),Z())}},300)};_.useEffect(function(){return window.addEventListener("focus",ne,!1),function(){window.removeEventListener("focus",ne,!1)}},[$,B,Z,Q]);var te=_.useRef([]),ce=function(Y){k.current&&k.current.contains(Y.target)||(Y.preventDefault(),te.current=[])};_.useEffect(function(){return S&&(document.addEventListener("dragover",ip,!1),document.addEventListener("drop",ce,!1)),function(){S&&(document.removeEventListener("dragover",ip),document.removeEventListener("drop",ce))}},[k,S]),_.useEffect(function(){return!r&&w&&k.current&&k.current.focus(),function(){}},[k,w,r]);var oe=_.useCallback(function(z){M?M(z):console.error(z)},[M]),se=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),te.current=[].concat(BC(te.current),[z.target]),Jo(z)&&Promise.resolve(o(z)).then(function(Y){if(!(Xo(z)&&!I)){var ve=Y.length,we=ve>0&&NC({files:Y,accept:O,minSize:a,maxSize:i,multiple:s,maxFiles:u,validator:H}),Fe=ve>0&&!we;R({isDragAccept:we,isDragReject:Fe,isDragActive:!0,type:"setDraggedFiles"}),c&&c(z)}}).catch(function(Y){return oe(Y)})},[o,c,oe,I,O,a,i,s,u,H]),ue=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=Jo(z);if(Y&&z.dataTransfer)try{z.dataTransfer.dropEffect="copy"}catch{}return Y&&g&&g(z),!1},[g,I]),de=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z);var Y=te.current.filter(function(we){return k.current&&k.current.contains(we)}),ve=Y.indexOf(z.target);ve!==-1&&Y.splice(ve,1),te.current=Y,!(Y.length>0)&&(R({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Jo(z)&&d&&d(z))},[k,d,I]),le=_.useCallback(function(z,Y){var ve=[],we=[];z.forEach(function(Fe){var ct=rp(Fe,O),Ct=Cs(ct,2),He=Ct[0],dn=Ct[1],fn=op(Fe,a,i),Be=Cs(fn,2),Rt=Be[0],Zn=Be[1],An=H?H(Fe):null;if(He&&Rt&&!An)ve.push(Fe);else{var _e=[dn,Zn];An&&(_e=_e.concat(An)),we.push({file:Fe,errors:_e.filter(function(Qn){return Qn})})}}),(!s&&ve.length>1||s&&u>=1&&ve.length>u)&&(ve.forEach(function(Fe){we.push({file:Fe,errors:[PC]})}),ve.splice(0)),R({acceptedFiles:ve,fileRejections:we,isDragReject:we.length>0,type:"setFiles"}),m&&m(ve,we,Y),we.length>0&&h&&h(we,Y),ve.length>0&&p&&p(ve,Y)},[R,s,O,a,i,u,m,p,h,H]),Se=_.useCallback(function(z){z.preventDefault(),z.persist(),V(z),te.current=[],Jo(z)&&Promise.resolve(o(z)).then(function(Y){Xo(z)&&!I||le(Y,z)}).catch(function(Y){return oe(Y)}),R({type:"reset"})},[o,le,oe,I]),X=_.useCallback(function(){if(Q.current){R({type:"openDialog"}),W();var z={multiple:s,types:G};window.showOpenFilePicker(z).then(function(Y){return o(Y)}).then(function(Y){le(Y,null),R({type:"closeDialog"})}).catch(function(Y){$C(Y)?(Z(Y),R({type:"closeDialog"})):LC(Y)?(Q.current=!1,$.current?($.current.value=null,$.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}$.current&&(R({type:"openDialog"}),W(),$.current.value=null,$.current.click())},[R,W,Z,b,le,oe,G,s]),Ce=_.useCallback(function(z){!k.current||!k.current.isEqualNode(z.target)||(z.key===" "||z.key==="Enter"||z.keyCode===32||z.keyCode===13)&&(z.preventDefault(),X())},[k,X]),ze=_.useCallback(function(){R({type:"focus"})},[]),St=_.useCallback(function(){R({type:"blur"})},[]),lt=_.useCallback(function(){E||(FC()?setTimeout(X,0):X())},[E,X]),tt=function(Y){return r?null:Y},C=function(Y){return x?null:tt(Y)},P=function(Y){return N?null:tt(Y)},V=function(Y){I&&Y.stopPropagation()},re=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,ve=Y===void 0?"ref":Y,we=z.role,Fe=z.onKeyDown,ct=z.onFocus,Ct=z.onBlur,He=z.onClick,dn=z.onDragEnter,fn=z.onDragOver,Be=z.onDragLeave,Rt=z.onDrop,Zn=Zo(z,jC);return De(De(_s({onKeyDown:C(It(Fe,Ce)),onFocus:C(It(ct,ze)),onBlur:C(It(Ct,St)),onClick:tt(It(He,lt)),onDragEnter:P(It(dn,se)),onDragOver:P(It(fn,ue)),onDragLeave:P(It(Be,de)),onDrop:P(It(Rt,Se)),role:typeof we=="string"&&we!==""?we:"presentation"},ve,k),!r&&!x?{tabIndex:0}:{}),Zn)}},[k,Ce,ze,St,lt,se,ue,de,Se,x,N,r]),J=_.useCallback(function(z){z.stopPropagation()},[]),K=_.useMemo(function(){return function(){var z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Y=z.refKey,ve=Y===void 0?"ref":Y,we=z.onChange,Fe=z.onClick,ct=Zo(z,zC),Ct=_s({accept:O,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:tt(It(we,Se)),onClick:tt(It(Fe,J)),tabIndex:-1},ve,$);return De(De({},Ct),ct)}},[$,n,s,Se,r]);return De(De({},j),{},{isFocused:A&&!r,getRootProps:re,getInputProps:K,rootRef:k,inputRef:$,open:tt(X)})}function XC(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({},As),{},{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({},As);default:return e}}function fp(){}const JC=({onFilesSelected:e,children:t})=>{const[n,r]=_.useState(!1),{getRootProps:o,getInputProps:i}=dp({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()})]})},ZC=({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),[p,h]=_.useState(""),{toast:v}=Io();_.useEffect(()=>{e&&y(p)},[p,e]);const y=async S=>{try{m(!0);const E=await me.get(`${n}/api/list-s3-folders?prefix=${S}`);u(E==null?void 0:E.data)}catch{v({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{m(!1)}},b=async()=>{d(!0);try{const S=o.key,E=S.endsWith("/")?S:`${S}/`,x=p.endsWith("/")?p:`${p}/`;if(E===x||S===p){v({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),d(!1);return}await me.post(`${n}/api/move`,{oldPath:S,newPath:p}),a.current=!0,await i(),v({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${p}"`}),t(!1),r(null),h("")}catch(S){console.error("Error renaming item:",S),v({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{d(!1)}};return l.jsx(Ht,{open:e,onOpenChange:S=>{S||(t(!1),r(null),h(""))},children:l.jsxs(At,{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(Pt,{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:()=>h(""),children:"Root"}),p.split("/").map((S,E,x)=>l.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>h(S==="Root"?"":x.slice(0,E+1).join("/")+"/"),children:S},E))]})}),l.jsxs(Nt,{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"," ",p===""?"Root":p," )"]})]}),l.jsx(zn,{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(S=>l.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>h(S),children:S},S))})})]}),l.jsxs(Sn,{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"})]})]})})},QC="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",eE="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",tE="https://www.googleapis.com/auth/drive";zt(me,{retries:3,shouldResetTimeout:!0,retryCondition:e=>zt.isRetryableError(e)&&e.config.method==="get"});const Qe={current:!1},pp="crawl:jobs",Xn="crawl:current_job",nE=e=>{const[t,n]=_.useState(null),[r,o]=_.useState(0);return _.useEffect(()=>{const i=localStorage.getItem(Xn);if(i){const a=JSON.parse(i);n(a),a!=null&&a.startTime&&o(Math.floor((Date.now()-a.startTime)/1e3))}},[]),_.useEffect(()=>{if(!(t!=null&&t.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-t.startTime)/1e3))},1e3);return()=>clearInterval(i)},[t==null?void 0:t.startTime]),_.useEffect(()=>{if(!(t!=null&&t.id))return;const i=async()=>{try{const u=(await me.get(`${e}/api/crawl/${t.id}?taskId=${t.taskId}`)).data;n(c=>{if(!c)return null;const d={...c,status:u};return localStorage.setItem(Xn,JSON.stringify(d)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Xn)},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(Xn,JSON.stringify(i)):localStorage.removeItem(Xn)}}},Qo=(e,t)=>{const n=[],r=o=>{(e[o]||[]).forEach(a=>{n.push(a.key),a.isFolder&&r(a.key)})};return r(t),n},rE=(e,t)=>{const n=[];return(e[t]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...Qo(e,o.key))}),n},oE=(e,t,n=[],r,o,i,a)=>{const[s,u]=_.useState({}),[c,d]=_.useState(!1),[g,m]=_.useState(null),[p,h]=_.useState(0),v=_.useRef(t);_.useEffect(()=>{v.current=t},[t]);const y=async()=>{d(!0);try{const w=await me.get(`${e}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:v.current,excludePrivateFiles:a?"false":"true"},timeout:3e5});u(w.data),m(null)}catch(w){m(w instanceof Error?w:new Error("Failed to fetch files"))}finally{d(!1),h(0),i("")}},b=async w=>{var S,E;try{if(!w)return;d(!0);const x=await me.get(`${e}/api/search-db?query=${w}&rootPrefix=${t}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return u({[t]:((S=x==null?void 0:x.data)==null?void 0:S.result)||[]}),h(((E=x==null?void 0:x.data)==null?void 0:E.estimatedTotalHits)||0),x}catch(x){m(x instanceof Error?x:new Error("Failed to fetch files"))}finally{d(!1)}};return _.useEffect(()=>{!r&&!c&&y(),r&&!c&&b(r)},[r,o]),{data:s,isLoading:c,error:g,estimatedTotalHits:p,refetch:y}},_r=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||"")},iE=_.memo(({homeLabel:e="Kho tài liệu",apiBaseUrl:t="https://s3-explorer.cmcts1.studio.ai.vn",rootPrefix:n="",asSelector:r=!1,onSelected:o=u=>console.log("Đã chọn:",u),displayPrefixes:i,preSelectedFiles:a,idCreator:s})=>{var zp;const[u,c]=_.useState([]),[d,g]=_.useState(""),[m,p]=_.useState(new Set(a)),[h,v]=_.useState(n),[y,b]=_.useState(""),[w,S]=_.useState(!1),[E,x]=_.useState(""),[N,I]=_.useState(!1),[M,H]=_.useState(null),[O,G]=_.useState(null),[W,Z]=_.useState(!1),[k,$]=_.useState(!1),[F,U]=_.useState(null),j=_.useRef(null),{toast:R}=Io(),[A,B]=_.useState(null),[Q,ne]=_.useState(null),[te,ce]=_.useState(""),[oe,se]=_.useState(!1),[ue,de]=_.useState(!1),[le,Se]=_.useState(new Set),[X,Ce]=_.useState(""),[ze,St]=_.useState(!1),[lt,tt]=_.useState(!1),[C,P]=_.useState("rename"),[V,re]=_.useState(!1),[J,K]=_.useState(""),[z,Y]=_.useState("1"),[ve,we]=_.useState(!1),[Fe,ct]=_.useState(!1),[Ct,He]=_.useState(!1),[dn,fn]=_.useState(!1),[Be,Rt]=_.useState(1),[Zn,An]=_.useState(!1),{currentJob:_e,elapsedTime:Qn,setCurrentJob:Ip}=nE(t),[pn,kr]=_.useState(null),[Or,ai]=_.useState(""),[OE,Fr]=_.useState(!1),[$s,Mp]=_.useState(!1),[$p,FE]=_.useState(""),[Ke,Ls]=_.useState(null),DE=new URL(window.location.href).searchParams.get("prefix")||""||y||n,[__,IE]=_.useState(null),{data:Vt,isLoading:er,error:ME,estimatedTotalHits:Dr,refetch:nt}=oE(t,DE,i,d,Be,g,s),$E=lg({onSuccess:T=>{IE(T.access_token),localStorage.setItem("google_access_token",T.access_token),LE(T.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:tE}),LE=T=>{const D=document.createElement("script");D.src="https://apis.google.com/js/api.js",D.onload=()=>{window.gapi.load("picker",()=>RE(T))},document.body.appendChild(D)},RE=T=>{const D=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),q=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(QC).setOAuthToken(T).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(D).addView(q).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 VE(ge,h)}}).build().setVisible(!0)},VE=async(T,D="")=>{const q=localStorage.getItem("google_access_token");if(!q){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),Pe.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const ee=Pe.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const ie={prefix:D,folders:[],files:[]};T.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 me.post(`${t}/api/sync-drive-to-s3`,ie,{headers:{Authorization:`Bearer ${q}`}});Qe.current=!0,nt(),Pe.update(ee,{render:`Đồng bộ thành công! Đã tải lên ${ge.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(ie){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",ie),Pe.update(ee,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};_.useEffect(()=>{const T=D=>{if(D.data.action==="logout"){const q=document.createElement("iframe");q.style.display="none",q.src="https://accounts.google.com/Logout",document.body.appendChild(q),setTimeout(()=>document.body.removeChild(q),2e3)}};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[]),_.useEffect(()=>{const T=new Set(a);p(T)},[]),_.useEffect(()=>{_e!=null&&_e.status&&(_e.status.status==="completed"?(R({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${_e.url} với ${_e.status.completed} trang`}),Qe.current=!0,nt()):_e.status.status==="failed"&&R({title:"Thu thập website thất bại",description:`Không thể thu thập ${_e.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(zp=_e==null?void 0:_e.status)==null?void 0:zp.status]);const Lp=_.useMemo(()=>Vt[h]||[],[Vt,h]),gn=_.useMemo(()=>Lp,[Lp,h,Vt]),Ir=_.useMemo(()=>{const T={};return gn.forEach((D,q)=>{m.has(D.key)&&(T[q]=!0)}),T},[m,gn]),jE=T=>{const D=Qo(Vt,T);if(D.length===0)return m.has(T)?"all":"none";const q=D.filter(ee=>m.has(ee)).length;return q===0?"none":q===D.length?"all":"partial"},tr=(T,D=!0)=>{if(h!==T){if(s&&!h)An(!0),b(T+s),v(T+s),a||p(new Set);else if(An(!0),b(T),v(T),a||p(new Set),D){const q=window.location.pathname==="/"?"":window.location.pathname,ee=T?`${window.location.origin}${q}?prefix=${encodeURIComponent(T)}`:`${window.location.origin}${q}`;window.history.pushState({path:ee},"",ee)}}};_.useEffect(()=>{Zn&&(Qe.current=!0,nt().finally(()=>An(!1)))},[Zn]);const zE=async(T,D)=>{var q,ee;I(!0);try{if(gn.some(Ye=>Ye.isFolder&&Ye.name.toLowerCase()===T.toLowerCase())){R({title:"Lỗi",description:`Thư mục "${T}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),I(!1);return}const ge=`${D}${T}/`;if((await me.post(`${t}/api/create-folder`,{prefix:ge})).status!==200){R({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qe.current=!0,await nt(),R({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${T}"`}),x(""),S(!1)}catch(ie){console.error("Error creating folder:",ie);const ge=((ee=(q=ie==null?void 0:ie.response)==null?void 0:q.data)==null?void 0:ee.error)||"Không thể tạo thư mục";R({title:"Lỗi",description:ge,variant:"destructive"})}finally{I(!1)}},Rs=async(T,D,q)=>{var ee,ie,ge,Ee,Ye,nr,Bp,Hp,Up;U(q),He(!0);try{if(Array.from(T).reduce((Xe,Lr)=>Xe+Lr.size,0)>=100*1024*1024){R({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),U(null),He(!1);return}const li=Array.from(T).filter(Xe=>Xe.size===0);if(li.length>0){const Xe=li.map(Lr=>Lr.name).join(", ");R({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Xe}`,variant:"destructive"}),He(!1),U(null);return}let $r=localStorage.getItem("dataLogin"),rr;try{$r&&($r=JSON.parse($r),rr=$r.user)}catch{$r=null}const Pn=new FormData;if(rr!=null&&rr.id&&Pn.append("metadata",JSON.stringify({creator:rr.username,creatorId:rr.id,DataSource:"Tệp tải lên"})),q==="folder"&&T[0]){const Xe=T[0].webkitRelativePath.split("/")[0];Xe&&Pn.append("folderName",Xe)}Pn.append("prefix",D),Array.from(T).forEach(Xe=>q==="folder"?Pn.append("files",Xe,Xe.webkitRelativePath):Pn.append("files",Xe)),Qe.current=!0;const je=await me.post(`${t}/api/check-files-existed`,Pn,{headers:{"Content-Type":"multipart/form-data"}});if(((ee=je==null?void 0:je.data)==null?void 0:ee.status)===200)await me.post(`${t}/api/upload`,Pn,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),g(""),b(D),setTimeout(async()=>{U(null),await nt(),He(!1),await hn()},500);else{if(((ge=(ie=je==null?void 0:je.data)==null?void 0:ie.names)==null?void 0:ge.length)>0&&!((Ee=je==null?void 0:je.data)!=null&&Ee.isFolder)){const Xe=Array.from(T).filter(Lr=>je.data.names.includes(Lr.name));kr(Xe),Fr(!0)}(Ye=je==null?void 0:je.data)!=null&&Ye.isFolder&&((nr=je==null?void 0:je.data)!=null&&nr.name)&&(ai((Bp=je==null?void 0:je.data)==null?void 0:Bp.name),kr(T),Fr(!0))}}catch(Mr){console.error("Lỗi tải lên:",Mr);const li=((Up=(Hp=Mr==null?void 0:Mr.response)==null?void 0:Hp.data)==null?void 0:Up.error)||"Không thể tải lên tập tin";R({title:"Lỗi",description:li,variant:"destructive"}),U(null),He(!1)}},BE=async()=>{var T,D;try{He(!0);const q=new FormData;if(pn){U(Or?"folder":"files"),Fr(!1);let ee=localStorage.getItem("dataLogin"),ie;try{ee&&(ee=JSON.parse(ee),ie=ee.user)}catch{ee=null}if(ie!=null&&ie.id&&(console.log("🚀 ~ uploadFiles ~ user:",ie),q.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"}))),Or&&pn[0]){const ge=pn[0].webkitRelativePath.split("/")[0];ge&&q.append("folderName",ge)}q.append("prefix",h),Array.from(pn).forEach(ge=>Or&&pn[0]?q.append("files",ge,ge.webkitRelativePath):q.append("files",ge)),ie!=null&&ie.id&&q.append("metadata",JSON.stringify({creator:ie.username,creatorId:ie.id,DataSource:"Tệp tải lên"})),await me.post(`${t}/api/upload`,q,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),g(""),b(h),Qe.current=!0}}catch(q){console.error("Lỗi tải lên:",q);const ee=((D=(T=q==null?void 0:q.response)==null?void 0:T.data)==null?void 0:D.error)||"Không thể tải lên tập tin";R({title:"Lỗi",description:ee,variant:"destructive"})}finally{setTimeout(async()=>{U(null),await nt(),He(!1),ai(""),kr(null),await hn()},500)}},HE=async T=>{var D;try{if(await me.delete(`${t}/api/files`,{data:{paths:[T.key]}}),m.has(T.key)){const ee=new Set(m);ee.delete(T.key),p(ee)}const q=((D=T.key)==null?void 0:D.replace(/^(.*?)(\/.*)?$/,(ee,ie,ge)=>!ge||ge==="/"?"":ie+"/"))||"";b(q),Qe.current=!0,R({title:"Đã xóa tập tin",description:`Đã xóa thành công "${T.name}"`}),H(null),await hn()}catch(q){console.error("Error deleting file:",q),R({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{fn(!1),await nt()}},si=T=>{const D=new Set(m),q=typeof T=="function"?T(Ir):T;new Set(Object.keys(Ir).map(Number)).forEach(ie=>{const ge=gn[ie];ge&&(q[ie]||(D.delete(ge.key),ge.isFolder&&Qo(Vt,ge.key).forEach(Ee=>D.delete(Ee))))}),Object.entries(q).forEach(([ie,ge])=>{const Ee=parseInt(ie),Ye=gn[Ee];Ye&&ge&&(D.add(Ye.key),Ye.isFolder&&Qo(Vt,Ye.key).forEach(nr=>D.add(nr)))}),p(D)},UE=async()=>{var T;Z(!0);try{const D=Array.from(m),q=D.map(ie=>Object.values(Vt).flat().find(ge=>ge.key===ie)).filter(ie=>ie!==void 0);if(q.length===0){R({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await me.delete(`${t}/api/files`,{data:{paths:D}});const ee=((T=q[0])==null?void 0:T.key.replace(/^(.*?)(\/.*)?$/,(ie,ge,Ee)=>!Ee||Ee==="/"?"":ge+"/"))||"";b(ee),Qe.current=!0,nt(),R({title:"Đã xóa tập tin",description:`Đã xóa thành công ${q.length} mục`}),$(!1),p(new Set),await hn()}catch(D){console.error("Error deleting files:",D),R({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{Z(!1)}},WE=async(T,D)=>{if(!h.trim()){R({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 q=T.key;let ee;T.isFolder?ee=q.split("/").slice(0,-2).join("/")+"/":ee=q.substring(0,q.lastIndexOf("/")+1);const ie=ee+D+(T.isFolder?"/":"");await me.post(`${t}/api/rename`,{oldPath:q,newPath:ie}),Qe.current=!0,await nt(),R({title:"Đã đổi tên",description:`Đã đổi tên thành công "${T.name}" thành "${D}"`}),B(null),ce(""),ne(null)}catch(q){console.error("Error renaming item:",q),R({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{de(!1)}},Rp=async T=>{Se(D=>new Set([...D,...T]));try{const D=await me.post(`${t}/api/download`,{paths:T},{responseType:"blob"}),q=window.URL.createObjectURL(D.data),ee=document.createElement("a");ee.href=q;const ie=D.headers["Content-Disposition"]||D.headers["content-disposition"],ge=ie==null?void 0:ie.match(/filename="(.+)"/),Ee=ge?decodeURIComponent(ge[1]):"download.zip";ee.setAttribute("download",Ee),document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),window.URL.revokeObjectURL(q),R({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${T.length} mục${T.length>1,""}`})}catch(D){console.error("Error downloading files:",D),R({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Se(D=>{const q=new Set(D);return T.forEach(ee=>q.delete(ee)),q})}},Vp=h?h.replace(n,"").split("/").filter(Boolean):[],qE=()=>Array.from(m).map(T=>{var D;for(const q in Vt){const ee=(D=Vt[q])==null?void 0:D.find(ie=>ie.key===T);if(ee)return ee}return null}).filter(T=>T!==null),jp=_.useMemo(()=>{const T=[{id:"select",header:()=>{const D=rE(Vt,h),q=D.length>0&&D.every(ie=>m.has(ie)),ee=D.some(ie=>m.has(ie));return l.jsx(ia,{checked:q?!0:ee?"indeterminate":!1,onCheckedChange:ie=>{if(ie){const ge=gn.reduce((Ee,Ye,nr)=>(Ee[nr]=!0,Ee),{});si(ge)}else si({})},"aria-label":"Chọn tất cả"})},cell:({row:D})=>{const q=D.original,ie=q.isFolder?jE(q.key):m.has(q.key)?"all":"none";return l.jsx("div",{className:"flex items-center",children:l.jsx(ia,{checked:ie==="partial"?"indeterminate":ie==="all",onCheckedChange:ge=>{const Ee={...Ir};ge?Ee[D.index]=!0:delete Ee[D.index],si(Ee)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),children:["Tên tập tin",l.jsx(Wi,{})]}),accessorKey:"name",cell:({row:D})=>{const q=D.original,ee=q.key.substring(0,q.key.lastIndexOf("/"))||"/",ie=d.trim()!==""&&ee!==h,ge=ee.split("/").filter(Boolean);return l.jsxs("div",{className:"flex flex-col",children:[l.jsxs("div",{className:`flex items-center gap-2 ${q.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{q.isFolder&&(a||p(new Set),tr(q.key))},children:[q.isFolder?l.jsx(di,{className:"h-5 w-5 text-blue-500"}):null,q.name]}),ie&&l.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[l.jsx(di,{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:()=>{tr("")},children:"/"}),ge.map((Ee,Ye)=>l.jsxs("span",{className:"flex items-center",children:[l.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{tr(ge.slice(0,Ye+1).join("/")+"/")},children:Ee}),Ye<ge.length-1&&l.jsx("span",{children:"/"})]},Ye))]})]})]})}}];return r||T.push({id:"size",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),children:["Kích thước",l.jsx(Wi,{})]}),accessorKey:"size",cell:({getValue:D,row:q})=>{const ee=D();return l.jsx("span",{children:q.original.isFolder?"-":$v(ee)})}},{id:"lastModified",header:({column:D})=>l.jsxs(ye,{variant:"ghost",onClick:()=>D.toggleSorting(D.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",l.jsx(Wi,{})]}),accessorKey:"lastModified",cell:({row:D})=>{const q=D.original.lastModified;return l.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:l.jsx("span",{children:q&&Gl(q).isValid()?Gl(q).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>l.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:D})=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>Rp([D.original.key]),className:"h-8 w-8 p-0",disabled:le.has(D.original.key),children:le.has(D.original.key)?l.jsx($e,{className:"h-4 w-4 animate-spin"}):l.jsx(zs,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Tải xuống"})]})}),h.trim()!==""&&l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{B(D.original),ce(D.original.name)},className:"h-8 w-8 p-0",children:l.jsx(tg,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Đổi tên"})]})}),l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>{se(!0),G(D.original)},className:"h-8 w-8 p-0",children:l.jsx(Lh,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Di chuyển"})]})}),l.jsx(sn,{children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>H(D.original),className:"h-8 w-8 p-0",children:l.jsx(Bs,{className:"h-4 w-4"})})}),l.jsx(Gt,{children:"Xóa"})]})})]})}),T},[m,gn,Ir,le,r]),Vs=nl({data:gn,columns:jp,state:{rowSelection:Ir,sorting:u},onSortingChange:c,enableRowSelection:!0,onRowSelectionChange:si,getCoreRowModel:tl(),getSortedRowModel:zg()}),GE=async T=>{var D,q;St(!0);try{if(_r(T)){const ee=await me.get(`${t}/api/read-text`,{params:{path:T.key}});Ce(ee.data.content)}try{const ee=await me.get(`${t}/api/read-json`,{params:{path:T.key+".metadata.json"}}),ie=((q=(D=ee==null?void 0:ee.data)==null?void 0:D.content)==null?void 0:q.metadataAttributes)||null;return ne({fullPath:A==null?void 0:A.key,...ie})}catch{return ne("Lỗi phân tích siêu dữ liệu")}}catch(ee){console.error("Error loading file content:",ee),R({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{St(!1)}},KE=async(T,D)=>{tt(!0);try{await me.post(`${t}/api/modify-text`,{path:T.key,content:D}),R({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await nt(),B(null),Ce(""),P("rename"),await hn()}catch(q){console.error("Error saving file content:",q),R({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{tt(!1)}},YE=async T=>{tt(!0);try{console.log("🚀 ~ saveJsonFile ~ metadataForEdit:",Q),await me.post(`${t}/api/modify-json`,{path:T.key+".metadata.json",content:{metadataAttributes:Q}}),R({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qe.current=!0,await nt(),B(null),Ce(""),P("rename")}catch(D){console.error("Error saving file content:",D),R({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{tt(!1)}};_.useEffect(()=>{A&&(A.isFolder||GE(A),P("rename"))},[A]);const XE=async(T,D)=>{var q;if(_e){R({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}we(!0);try{const{data:ee}=await me.post(`${t}/api/crawl`,{url:T,limit:D,prefix:h});if(ee.id){Ip({id:ee.id,url:T,limit:D,prefix:h,taskId:((q=ee.task)==null?void 0:q.id)||""});const ie=localStorage.getItem(pp),ge=ie?JSON.parse(ie):[];ge.some(Ee=>Ee.id===ee.id)||(ge.unshift({url:T,id:ee.id,limit:D,prefix:h,timestamp:Date.now()}),ge.length>20&&(ge.length=20),localStorage.setItem(pp,JSON.stringify(ge))),R({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${T} với giới hạn ${D}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),re(!1),K(""),Y("1")}}catch(ee){console.error("Error crawling website:",ee),R({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{we(!1)}},JE=async()=>{try{if(!(_e!=null&&_e.id))return;Ip(null),localStorage.removeItem(Xn),R({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${_e.url}`})}catch(T){console.error("Error stopping job:",T),R({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};_.useEffect(()=>{const T=(D=!0)=>{const ee=new URL(window.location.href).searchParams.get("prefix")||"";ee?tr(ee,!1):(D&&!a&&p(new Set),b(n),v(n),Qe.current=!0,setTimeout(()=>{nt()},0))};return T(!1),window.addEventListener("popstate",()=>T(!0)),()=>{window.removeEventListener("popstate",()=>T(!0))}},[]);const ZE=async()=>{Mp(!0);try{const T=await me.post(`${t}/api/prediction-report`);console.log("🚀 ~ Home.tsx:1585 ~ handleExportReport ~ response:",T),R({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(T){console.error("Error exporting report:",T),R({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Mp(!1)}},QE=async()=>{try{const T=Lv();T&&(await me.post(`${t}/api/start-ingestion-job`,{prefix:h,user_id:T.id,userName:T.username})).status===200&&await hn()}catch(T){ct(!1),console.log(T)}},mn=_.useRef(),hn=async()=>{try{ct(!0);const T=await me.post(`${t}/api/get-ingestion-job-status`,{prefix:h}),{status:D}=T==null?void 0:T.data;D==="FAILED"||D==="COMPLETE"||D==="STOPPED"||D==="STOPPING"||!D?(ct(!1),mn.current&&(clearInterval(mn.current),mn.current=null),Ls(T==null?void 0:T.data)):(mn.current||(mn.current=setInterval(()=>hn(),5e3)),Ls(T==null?void 0:T.data))}catch(T){console.log(T)}};return console.log(Ke),_.useEffect(()=>{const T=h==null?void 0:h.split("/")[0];return T!==$p&&(ct(!1),mn.current&&(clearInterval(mn.current),mn.current=null),FE(T||""),Ls(null),T&&hn()),()=>{}},[$p,h]),l.jsxs("div",{className:"space-y-4 s3-explr-container",children:[l.jsx(_d,{}),l.jsx(Ht,{open:OE,onOpenChange:T=>{Fr(T),T||(ai(""),kr(null),He(!1),U(null))},children:l.jsxs(At,{children:[l.jsxs(Pt,{children:[l.jsx(Nt,{children:"Cảnh báo trùng lặp"}),l.jsxs(zn,{children:[Or&&l.jsxs(l.Fragment,{children:["Folder $",Or," đã có."]}),pn&&pn.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(pn).map((T,D)=>l.jsx("li",{children:T.name},D))})]})]})]}),l.jsxs(Sn,{children:[l.jsx(ye,{variant:"outline",onClick:()=>{Fr(!1),ai(""),kr(null),He(!1),U(null)},children:"Bỏ qua"}),l.jsx(ye,{variant:"destructive",onClick:()=>BE(),children:"Ghi đè"})]})]})}),l.jsx(fc,{className:"s3-explr-breadcrumb",children:l.jsxs(pc,{className:"s3-explr-breadcrumb-list",children:[l.jsx(ea,{className:"s3-explr-breadcrumb-item",children:l.jsx(ta,{onClick:()=>tr(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:e})}),!s&&Vp.map((T,D)=>l.jsxs("div",{className:"flex items-center",children:[l.jsx(gc,{className:"s3-explr-breadcrumb-separator"},`sep-${D}`),l.jsx(ea,{className:"s3-explr-breadcrumb-item",children:l.jsx(ta,{onClick:()=>tr(n+Vp.slice(0,D+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:T})},`item-${T}`)]},D))]})}),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(KS,{ref:j,onChange:T=>g(T)})}),l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{b(h),Qe.current=!0,nt()},disabled:er,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${er?"animate-spin":""}`}),"Làm mới"]}),h&&h!=="/"&&l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>{er||Fe||(ct(!0),QE())},"aria-disabled":er||Fe,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${er||Fe?"animate-spin":""}`}),"Đồng bộ KB"]})}),Ke&&l.jsx(Gt,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsx("p",{className:"font-semibold",children:"Thông tin đồng bộ:"}),l.jsxs("p",{className:"flex items-center gap-2",children:["Trạng thái:"," ",l.jsxs("span",{className:`flex items-center gap-1 ${Ke.status==="COMPLETE"?"text-green-600":Ke.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Ke.status==="COMPLETE"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Ke.status==="FAILED"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Ke.status!=="COMPLETE"&&Ke.status!=="FAILED"&&l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8v4m0 4h.01"})}),Ke.status]})]}),l.jsxs("p",{children:["Ngày tạo:"," ",(()=>{const T=new Date(Ke.created_date),D=new Date(T.getTime()+7*60*60*1e3),ee=Math.floor((new Date().getTime()-T.getTime())/6e4);return ee<1440?`${ee} phút trước`:D.toLocaleString("vi-VN",{timeZone:"UTC"})})()]}),l.jsxs("p",{children:["DataSource ID: ",Ke.dataSourceId]}),l.jsxs("p",{children:["Ingestion Job ID: ",Ke.ingestionJobId]}),l.jsxs("p",{children:["Knowledge Base ID: ",Ke.knowledgeBaseId]}),l.jsxs("p",{children:["Người dùng: ",Ke.user_name]}),l.jsxs("p",{children:["Job trong queue: ",Ke.is_still_in_stock?"Còn":"Không"]})]})})]})}),!r&&l.jsxs(l.Fragment,{children:[m.size>0&&l.jsxs(l.Fragment,{children:[l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>Rp(Array.from(m)),disabled:Array.from(m).some(T=>le.has(T)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(m).some(T=>le.has(T))?l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):l.jsx(zs,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",m.size,")"]}),l.jsxs(Ht,{open:k,onOpenChange:$,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[l.jsx(Bs,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",m.size,")"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),l.jsxs(zn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",m.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>$(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:UE,disabled:W,className:"s3-explr-confirm-delete-btn",children:W?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"})]})]})]})]}),!s&&l.jsxs(Ht,{open:w,onOpenChange:S,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-new-folder-btn",disabled:!!i&&!h,children:[l.jsx(Xp,{className:"h-4 w-4 s3-explr-folder-plus-icon"}),"Thư mục mới"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsx(Pt,{className:"s3-explr-dialog-header",children:l.jsx(Nt,{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(Cn,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),l.jsx(nn,{disabled:N,id:"name",value:E,onChange:T=>x(T.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),l.jsxs(ye,{onClick:()=>{E.trim()&&zE(E,h)},disabled:N,className:"s3-explr-create-btn",children:[N&&l.jsx($e,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),N?"Đang tạo...":"Tạo"]})]})]})]}),s&&!h?l.jsx(l.Fragment,{}):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 T=document.createElement("input");T.type="file",T.multiple=!0,T.onchange=D=>{const q=D.target.files;q&&Rs(q,h,"files")},T.click()},disabled:F!==null||!!i&&!h,children:F==="files"?l.jsxs(l.Fragment,{children:[l.jsx($e,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}),"Đang xử lý..."]}):l.jsxs(l.Fragment,{children:[l.jsx(Kp,{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 T=document.createElement("input");T.type="file",T.multiple=!0,T.webkitdirectory=!0,T.onchange=D=>{const q=D.target.files;q&&Rs(q,h,"folder")},T.click()},disabled:F!==null||!!i&&!h,children:F==="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(di,{className:"h-4 w-4 s3-explr-folder-icon"}),"Tải lên thư mục"]})}),_e?l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{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"}),_e.status?l.jsxs(l.Fragment,{children:[_e.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",_e.status.completed,"/",_e.status.total,") -"," ",Math.floor(Qn/60),":",String(Qn%60).padStart(2,"0")]}):"Đang thu thập..."]}),l.jsxs(ye,{variant:"destructive",size:"sm",onClick:()=>void JE(),className:"flex items-center gap-2",children:[l.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),l.jsx(rg,{className:"h-4 w-4"})]})]})}),_e.status&&l.jsx(Gt,{side:"right",sideOffset:5,children:l.jsxs("div",{className:"space-y-1 p-2",children:[l.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",_e.url]}),l.jsxs("p",{children:["Tiến độ: ",_e.status.completed,"/",_e.status.total," ","trang"]}),l.jsxs("p",{children:["Thời gian: ",Math.floor(Qn/60),":",String(Qn%60).padStart(2,"0")]}),l.jsxs("p",{children:["Trạng thái:"," ",_e.status.status==="scraping"?"Đang thu thập":_e.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!s&&l.jsxs(Ht,{open:V,onOpenChange:re,children:[l.jsx(mo,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!h,children:[l.jsx(Qp,{className:"h-4 w-4 s3-explr-globe-icon"}),"Thêm website"]})}),l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Thêm website"}),l.jsx(zn,{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(Cn,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),l.jsx(nn,{id:"websiteUrl",value:J,onChange:T=>K(T.target.value),placeholder:"https://example.com",type:"url",disabled:ve,className:"s3-explr-input"})]}),l.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[l.jsx(Cn,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),l.jsx(nn,{id:"crawlLimit",value:z,onChange:T=>{const D=T.target.value;/^\d*$/.test(D)&&Y(D)},placeholder:"1",type:"text",disabled:ve,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(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{re(!1),K(""),Y("1")},disabled:ve,className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{onClick:()=>{J.trim()&&XE(J.trim(),parseInt(z)||1)},disabled:ve||!J.trim(),className:"s3-explr-crawl-btn",children:ve?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"})]})]})]}),h.startsWith("BKTTW/")&&l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{children:[l.jsx(cn,{asChild:!0,children:l.jsxs(ye,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!i&&!h,onClick:ZE,children:[$s&&l.jsx(ui,{className:`h-4 w-4 s3-explr-refresh-icon ${$s?"animate-spin":""}`}),"Xuất báo cáo"]})}),$s&&l.jsx(Gt,{sideOffset:5,children:"Đang xuất báo cáo"})]})})]}),!s&&l.jsx("div",{className:"flex items-center gap-4",children:l.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>$E(),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(Ht,{open:!!M,onOpenChange:T=>!T&&H(null),children:l.jsxs(At,{className:"s3-explr-dialog-content",children:[l.jsxs(Pt,{className:"s3-explr-dialog-header",children:[l.jsx(Nt,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),l.jsxs(zn,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",M==null?void 0:M.name,"? Hành động này không thể hoàn tác."]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>H(null),className:"s3-explr-cancel-btn",children:"Hủy"}),l.jsx(ye,{variant:"destructive",onClick:()=>HE(M),disabled:dn,className:"s3-explr-confirm-delete-btn",children:dn?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(Ht,{open:!!A,onOpenChange:T=>{T||(B(null),ne(null),ce(""),Ce(""),P("rename"))},children:l.jsxs(At,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[l.jsx(Pt,{className:"s3-explr-dialog-header",children:l.jsx(Nt,{className:"s3-explr-dialog-title",children:A!=null&&A.isFolder?"Đổi tên thư mục":_r(A)?"Quản lý tập tin":"Đổi tên tập tin"})}),A&&l.jsxs(db,{value:C,onValueChange:T=>P(T),children:[l.jsxs(Zu,{"aria-checked":!_r(A),"aria-disabled":A.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[l.jsx(Ao,{value:"rename",children:"Đổi tên"}),!A.isFolder&&l.jsxs(l.Fragment,{children:[_r(A)&&l.jsx(Ao,{value:"edit",children:"Sửa nội dung"}),l.jsx(Ao,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),l.jsx(Po,{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(Cn,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),l.jsx(nn,{id:"newName",value:te,onChange:T=>ce(T.target.value),placeholder:"Nhập tên mới",disabled:ue,className:"s3-explr-input"})]})})}),!A.isFolder&&l.jsxs(l.Fragment,{children:[_r(A)&&l.jsx(Po,{value:"edit",children:l.jsx("div",{className:"space-y-4 py-4",children:ze?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(Cn,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),l.jsx(mr,{id:"content",value:X,onChange:T=>Ce(T.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:lt})]})})}),l.jsx(Po,{value:"edit-metadata",children:l.jsx("div",{className:"space-y-4 py-4",children:ze?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:Q&&typeof Q=="object"&&Object.entries(Q).map(([T,D],q)=>l.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[l.jsxs(Cn,{htmlFor:T,className:"s3-explr-label flex items-center gap-1",children:[Qh[T]||T,Yi(T)&&l.jsx(Rh,{className:"h-[12px] w-[12px] text-red-500"})]}),ev(T)?l.jsx(mr,{id:T,value:typeof D=="string"?D:JSON.stringify(D),onChange:ee=>{const ie={...Q,[T]:ee.target.value};ne(ie)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:lt||Yi(T)}):l.jsx(nn,{id:T,value:typeof D=="string"?D:JSON.stringify(D),onChange:ee=>{const ie={...Q,[T]:ee.target.value};ne(ie)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:lt||Yi(T)})]},q))})})})]})]}),l.jsxs(Sn,{className:"s3-explr-dialog-footer",children:[l.jsx(ye,{variant:"outline",onClick:()=>{B(null),ne(null),ce(""),Ce("")},className:"s3-explr-cancel-btn",children:"Hủy"}),C==="edit"?l.jsx(ye,{onClick:()=>A&&KE(A,X),disabled:lt||ze,className:"s3-explr-save-btn",children:lt?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"}):C==="edit-metadata"?l.jsx(ye,{onClick:()=>Q&&typeof Q=="object"&&A&&YE(A),disabled:lt||ze,className:"s3-explr-save-btn",children:lt?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:()=>{te.trim()&&A&&WE(A,te.trim())},disabled:ue||!te.trim()||te.trim()===(A==null?void 0:A.name),className:"s3-explr-rename-btn",children:ue?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"})]})]})}),O&&oe&&l.jsx(ZC,{openDialogRename:oe,setOpenDialogRename:se,apiBaseUrl:t,setFileToMove:G,fileToMove:O,refreshFiles:nt,ignoreCache:Qe})]})]}),ME&&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(JC,{onFilesSelected:(T,D)=>Rs(T,h,D),children:l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(wo,{className:"s3-explr-table",children:[l.jsx(So,{className:"s3-explr-table-header",children:Vs.getHeaderGroups().map(T=>l.jsx(yt,{className:"hover:bg-transparent s3-explr-header-row",children:T.headers.map(D=>l.jsx(kt,{className:"s3-explr-header-cell",children:D.isPlaceholder?null:Hr(D.column.columnDef.header,D.getContext())},D.id))},T.id))}),l.jsx(Co,{className:"s3-explr-table-body",children:Vs.getRowModel().rows.length===0?l.jsx(yt,{className:"s3-explr-empty-row",children:l.jsx(Ze,{colSpan:jp.length,className:"h-24 text-center s3-explr-empty-cell",children:d?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 "',d,'"']}):l.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:er?"Đ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"})})}):Vs.getRowModel().rows.map(T=>l.jsx(yt,{className:"h-12 s3-explr-row",children:T.getVisibleCells().map(D=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Hr(D.column.columnDef.cell,D.getContext())},D.id))},T.id))})]})})}),d&&Dr!==0&&l.jsx(l.Fragment,{children:l.jsx(ho,{children:l.jsxs(vo,{children:[l.jsx(yo,{onClick:()=>Rt(T=>Math.max(T-1,1)),"aria-disabled":Be===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Dr/20)},(T,D)=>{const q=D+1,ee=Math.ceil(Dr/20);return ee>7&&!(q===1||q===ee||q>=Be-1&&q<=Be+1)?q===Be-2&&Be>4||q===Be+2&&Be<ee-3?l.jsx(bo,{className:"pointer-events-none",children:"..."},D):null:l.jsx(vt,{className:"cursor-pointer",children:l.jsx(Bn,{isActive:Be===q,onClick:()=>Rt(q),className:`${Be===q?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:q})},D)}),l.jsx(vt,{children:l.jsx(xo,{onClick:()=>Rt(T=>Math.min(T+1,Math.ceil(Dr/20))),"aria-disabled":Be===Math.ceil(Dr/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:[m.size," ",(m.size===1,"tập tin")," đã chọn"]}),l.jsx(ye,{variant:"default",onClick:()=>o(qE()),disabled:m.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),aE=e=>l.jsx(ag,{clientId:eE,children:l.jsx(iE,{...e})});var Tr=e=>e.type==="checkbox",Tn=e=>e instanceof Date,Ge=e=>e==null;const gp=e=>typeof e=="object";var Me=e=>!Ge(e)&&!Array.isArray(e)&&gp(e)&&!Tn(e),sE=e=>Me(e)&&e.target?Tr(e.target)?e.target.checked:e.target.value:e,lE=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,cE=(e,t)=>e.has(lE(t)),uE=e=>{const t=e.constructor&&e.constructor.prototype;return Me(t)&&t.hasOwnProperty("isPrototypeOf")},Ps=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ft(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(!(Ps&&(e instanceof Blob||r))&&(n||Me(e)))if(t=n?[]:{},!n&&!uE(e))t=e;else for(const o in e)e.hasOwnProperty(o)&&(t[o]=ft(e[o]));else return e;return t}var ei=e=>Array.isArray(e)?e.filter(Boolean):[],Ie=e=>e===void 0,ae=(e,t,n)=>{if(!t||!Me(e))return n;const r=ei(t.split(/[,[\].]+?/)).reduce((o,i)=>Ge(o)?o:o[i],e);return Ie(r)||r===e?Ie(e[t])?n:e[t]:r},Mt=e=>typeof e=="boolean",Ns=e=>/^\w*$/.test(e),mp=e=>ei(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Oe=(e,t,n)=>{let r=-1;const o=Ns(t)?[t]:mp(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 hp={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},wt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Kt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};_.createContext(null);var dE=(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]!==wt.all&&(t._proxyFormState[a]=!r||wt.all),e[a]}});return o},et=e=>Me(e)&&!Object.keys(e).length,fE=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return et(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(a=>t[a]===wt.all)},ti=e=>Array.isArray(e)?e:[e];function pE(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 $t=e=>typeof e=="string",gE=(e,t,n,r,o)=>$t(e)?(r&&t.watch.add(e),ae(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),ae(n,i))):(r&&(t.watchAll=!0),n),mE=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},vp=e=>({isOnSubmit:!e||e===wt.onSubmit,isOnBlur:e===wt.onBlur,isOnChange:e===wt.onChange,isOnAll:e===wt.all,isOnTouch:e===wt.onTouched}),yp=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Ar=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=ae(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(Ar(s,t))break}else if(Me(s)&&Ar(s,t))break}}};var hE=(e,t,n)=>{const r=ti(ae(e,n));return Oe(r,"root",t[n]),Oe(e,n,r),e},ks=e=>e.type==="file",Lt=e=>typeof e=="function",ni=e=>{if(!Ps)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ri=e=>$t(e),Os=e=>e.type==="radio",oi=e=>e instanceof RegExp;const xp={value:!1,isValid:!1},bp={value:!0,isValid:!0};var wp=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===""?bp:{value:e[0].value,isValid:!0}:bp:xp}return xp};const Sp={isValid:!1,value:null};var Cp=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Sp):Sp;function Ep(e,t,n="validate"){if(ri(e)||Array.isArray(e)&&e.every(ri)||Mt(e)&&!e)return{type:n,message:ri(e)?e:"",ref:t}}var Jn=e=>Me(e)&&!oi(e)?e:{value:e,message:""},_p=async(e,t,n,r,o)=>{const{ref:i,refs:a,required:s,maxLength:u,minLength:c,min:d,max:g,pattern:m,validate:p,name:h,valueAsNumber:v,mount:y,disabled:b}=e._f,w=ae(t,h);if(!y||b)return{};const S=a?a[0]:i,E=W=>{r&&S.reportValidity&&(S.setCustomValidity(Mt(W)?"":W||""),S.reportValidity())},x={},N=Os(i),I=Tr(i),M=N||I,H=(v||ks(i))&&Ie(i.value)&&Ie(w)||ni(i)&&i.value===""||w===""||Array.isArray(w)&&!w.length,O=mE.bind(null,h,n,x),G=(W,Z,k,$=Kt.maxLength,F=Kt.minLength)=>{const U=W?Z:k;x[h]={type:W?$:F,message:U,ref:i,...O(W?$:F,U)}};if(o?!Array.isArray(w)||!w.length:s&&(!M&&(H||Ge(w))||Mt(w)&&!w||I&&!wp(a).isValid||N&&!Cp(a).isValid)){const{value:W,message:Z}=ri(s)?{value:!!s,message:s}:Jn(s);if(W&&(x[h]={type:Kt.required,message:Z,ref:S,...O(Kt.required,Z)},!n))return E(Z),x}if(!H&&(!Ge(d)||!Ge(g))){let W,Z;const k=Jn(g),$=Jn(d);if(!Ge(w)&&!isNaN(w)){const F=i.valueAsNumber||w&&+w;Ge(k.value)||(W=F>k.value),Ge($.value)||(Z=F<$.value)}else{const F=i.valueAsDate||new Date(w),U=A=>new Date(new Date().toDateString()+" "+A),j=i.type=="time",R=i.type=="week";$t(k.value)&&w&&(W=j?U(w)>U(k.value):R?w>k.value:F>new Date(k.value)),$t($.value)&&w&&(Z=j?U(w)<U($.value):R?w<$.value:F<new Date($.value))}if((W||Z)&&(G(!!W,k.message,$.message,Kt.max,Kt.min),!n))return E(x[h].message),x}if((u||c)&&!H&&($t(w)||o&&Array.isArray(w))){const W=Jn(u),Z=Jn(c),k=!Ge(W.value)&&w.length>+W.value,$=!Ge(Z.value)&&w.length<+Z.value;if((k||$)&&(G(k,W.message,Z.message),!n))return E(x[h].message),x}if(m&&!H&&$t(w)){const{value:W,message:Z}=Jn(m);if(oi(W)&&!w.match(W)&&(x[h]={type:Kt.pattern,message:Z,ref:i,...O(Kt.pattern,Z)},!n))return E(Z),x}if(p){if(Lt(p)){const W=await p(w,t),Z=Ep(W,S);if(Z&&(x[h]={...Z,...O(Kt.validate,Z.message)},!n))return E(Z.message),x}else if(Me(p)){let W={};for(const Z in p){if(!et(W)&&!n)break;const k=Ep(await p[Z](w,t),S,Z);k&&(W={...k,...O(Z,k.message)},E(k.message),n&&(x[h]=W))}if(!et(W)&&(x[h]={ref:S,...W},!n))return x}}return E(!0),x};function vE(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 yE(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:Ns(t)?[t]:mp(t),r=n.length===1?e:vE(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Me(r)&&et(r)||Array.isArray(r)&&yE(r))&&Ve(e,n.slice(0,-1)),e}var Fs=()=>{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=[]}}},Ds=e=>Ge(e)||!gp(e);function un(e,t){if(Ds(e)||Ds(t))return e===t;if(Tn(e)&&Tn(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(Tn(i)&&Tn(a)||Me(i)&&Me(a)||Array.isArray(i)&&Array.isArray(a)?!un(i,a):i!==a)return!1}}return!0}var Tp=e=>e.type==="select-multiple",xE=e=>Os(e)||Tr(e),Is=e=>ni(e)&&e.isConnected,Ap=e=>{for(const t in e)if(Lt(e[t]))return!0;return!1};function ii(e,t={}){const n=Array.isArray(e);if(Me(e)||n)for(const r in e)Array.isArray(e[r])||Me(e[r])&&!Ap(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ii(e[r],t[r])):Ge(e[r])||(t[r]=!0);return t}function Pp(e,t,n){const r=Array.isArray(e);if(Me(e)||r)for(const o in e)Array.isArray(e[o])||Me(e[o])&&!Ap(e[o])?Ie(t)||Ds(n[o])?n[o]=Array.isArray(e[o])?ii(e[o],[]):{...ii(e[o])}:Pp(e[o],Ge(t)?{}:t[o],n[o]):n[o]=!un(e[o],t[o]);return n}var Pr=(e,t)=>Pp(e,t,ii(t)),Np=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ie(e)?e:t?e===""?NaN:e&&+e:n&&$t(e)?new Date(e):r?r(e):e;function Ms(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return ks(t)?t.files:Os(t)?Cp(e.refs).value:Tp(t)?[...t.selectedOptions].map(({value:n})=>n):Tr(t)?wp(e.refs).value:Np(Ie(t.value)?e.ref.value:t.value,e)}var bE=(e,t,n,r)=>{const o={};for(const i of e){const a=ae(t,i);a&&Oe(o,i,a._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},Nr=e=>Ie(e)?e:oi(e)?e.source:Me(e)?oi(e.value)?e.value.source:e.value:e;const kp="AsyncFunction";var wE=e=>!!e&&!!e.validate&&!!(Lt(e.validate)&&e.validate.constructor.name===kp||Me(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===kp)),SE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Op(e,t,n){const r=ae(e,n);if(r||Ns(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),a=ae(t,i),s=ae(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 CE=(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,EE=(e,t)=>!ei(ae(e,t)).length&&Ve(e,t);const _E={mode:wt.onSubmit,reValidateMode:wt.onChange,shouldFocusError:!0};function TE(e={}){let t={..._E,...e},n={submitCount:0,isDirty:!1,isLoading:Lt(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)?ft(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:ft(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:Fs(),array:Fs(),state:Fs()},m=vp(t.mode),p=vp(t.reValidateMode),h=t.criteriaMode===wt.all,v=C=>P=>{clearTimeout(c),c=setTimeout(C,P)},y=async C=>{if(!t.disabled&&(d.isValid||C)){const P=t.resolver?et((await M()).errors):await O(r,!0);P!==n.isValid&&g.state.next({isValid:P})}},b=(C,P)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(s.mount)).forEach(V=>{V&&(P?Oe(n.validatingFields,V,P):Ve(n.validatingFields,V))}),g.state.next({validatingFields:n.validatingFields,isValidating:!et(n.validatingFields)}))},w=(C,P=[],V,re,J=!0,K=!0)=>{if(re&&V&&!t.disabled){if(a.action=!0,K&&Array.isArray(ae(r,C))){const z=V(ae(r,C),re.argA,re.argB);J&&Oe(r,C,z)}if(K&&Array.isArray(ae(n.errors,C))){const z=V(ae(n.errors,C),re.argA,re.argB);J&&Oe(n.errors,C,z),EE(n.errors,C)}if(d.touchedFields&&K&&Array.isArray(ae(n.touchedFields,C))){const z=V(ae(n.touchedFields,C),re.argA,re.argB);J&&Oe(n.touchedFields,C,z)}d.dirtyFields&&(n.dirtyFields=Pr(o,i)),g.state.next({name:C,isDirty:W(C,P),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Oe(i,C,P)},S=(C,P)=>{Oe(n.errors,C,P),g.state.next({errors:n.errors})},E=C=>{n.errors=C,g.state.next({errors:n.errors,isValid:!1})},x=(C,P,V,re)=>{const J=ae(r,C);if(J){const K=ae(i,C,Ie(V)?ae(o,C):V);Ie(K)||re&&re.defaultChecked||P?Oe(i,C,P?K:Ms(J._f)):$(C,K),a.mount&&y()}},N=(C,P,V,re,J)=>{let K=!1,z=!1;const Y={name:C};if(!t.disabled){const ve=!!(ae(r,C)&&ae(r,C)._f&&ae(r,C)._f.disabled);if(!V||re){d.isDirty&&(z=n.isDirty,n.isDirty=Y.isDirty=W(),K=z!==Y.isDirty);const we=ve||un(ae(o,C),P);z=!!(!ve&&ae(n.dirtyFields,C)),we||ve?Ve(n.dirtyFields,C):Oe(n.dirtyFields,C,!0),Y.dirtyFields=n.dirtyFields,K=K||d.dirtyFields&&z!==!we}if(V){const we=ae(n.touchedFields,C);we||(Oe(n.touchedFields,C,V),Y.touchedFields=n.touchedFields,K=K||d.touchedFields&&we!==V)}K&&J&&g.state.next(Y)}return K?Y:{}},I=(C,P,V,re)=>{const J=ae(n.errors,C),K=d.isValid&&Mt(P)&&n.isValid!==P;if(t.delayError&&V?(u=v(()=>S(C,V)),u(t.delayError)):(clearTimeout(c),u=null,V?Oe(n.errors,C,V):Ve(n.errors,C)),(V?!un(J,V):J)||!et(re)||K){const z={...re,...K&&Mt(P)?{isValid:P}:{},errors:n.errors,name:C};n={...n,...z},g.state.next(z)}},M=async C=>{b(C,!0);const P=await t.resolver(i,t.context,bE(C||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(C),P},H=async C=>{const{errors:P}=await M(C);if(C)for(const V of C){const re=ae(P,V);re?Oe(n.errors,V,re):Ve(n.errors,V)}else n.errors=P;return P},O=async(C,P,V={valid:!0})=>{for(const re in C){const J=C[re];if(J){const{_f:K,...z}=J;if(K){const Y=s.array.has(K.name),ve=J._f&&wE(J._f);ve&&d.validatingFields&&b([re],!0);const we=await _p(J,i,h,t.shouldUseNativeValidation&&!P,Y);if(ve&&d.validatingFields&&b([re]),we[K.name]&&(V.valid=!1,P))break;!P&&(ae(we,K.name)?Y?hE(n.errors,we,K.name):Oe(n.errors,K.name,we[K.name]):Ve(n.errors,K.name))}!et(z)&&await O(z,P,V)}}return V.valid},G=()=>{for(const C of s.unMount){const P=ae(r,C);P&&(P._f.refs?P._f.refs.every(V=>!Is(V)):!Is(P._f.ref))&&oe(C)}s.unMount=new Set},W=(C,P)=>!t.disabled&&(C&&P&&Oe(i,C,P),!un(B(),o)),Z=(C,P,V)=>gE(C,s,{...a.mount?i:Ie(P)?o:$t(C)?{[C]:P}:P},V,P),k=C=>ei(ae(a.mount?i:o,C,t.shouldUnregister?ae(o,C,[]):[])),$=(C,P,V={})=>{const re=ae(r,C);let J=P;if(re){const K=re._f;K&&(!K.disabled&&Oe(i,C,Np(P,K)),J=ni(K.ref)&&Ge(P)?"":P,Tp(K.ref)?[...K.ref.options].forEach(z=>z.selected=J.includes(z.value)):K.refs?Tr(K.ref)?K.refs.length>1?K.refs.forEach(z=>(!z.defaultChecked||!z.disabled)&&(z.checked=Array.isArray(J)?!!J.find(Y=>Y===z.value):J===z.value)):K.refs[0]&&(K.refs[0].checked=!!J):K.refs.forEach(z=>z.checked=z.value===J):ks(K.ref)?K.ref.value="":(K.ref.value=J,K.ref.type||g.values.next({name:C,values:{...i}})))}(V.shouldDirty||V.shouldTouch)&&N(C,J,V.shouldTouch,V.shouldDirty,!0),V.shouldValidate&&A(C)},F=(C,P,V)=>{for(const re in P){const J=P[re],K=`${C}.${re}`,z=ae(r,K);(s.array.has(C)||Me(J)||z&&!z._f)&&!Tn(J)?F(K,J,V):$(K,J,V)}},U=(C,P,V={})=>{const re=ae(r,C),J=s.array.has(C),K=ft(P);Oe(i,C,K),J?(g.array.next({name:C,values:{...i}}),(d.isDirty||d.dirtyFields)&&V.shouldDirty&&g.state.next({name:C,dirtyFields:Pr(o,i),isDirty:W(C,K)})):re&&!re._f&&!Ge(K)?F(C,K,V):$(C,K,V),yp(C,s)&&g.state.next({...n}),g.values.next({name:a.mount?C:void 0,values:{...i}})},j=async C=>{a.mount=!0;const P=C.target;let V=P.name,re=!0;const J=ae(r,V),K=()=>P.type?Ms(J._f):sE(C),z=Y=>{re=Number.isNaN(Y)||Tn(Y)&&isNaN(Y.getTime())||un(Y,ae(i,V,Y))};if(J){let Y,ve;const we=K(),Fe=C.type===hp.BLUR||C.type===hp.FOCUS_OUT,ct=!SE(J._f)&&!t.resolver&&!ae(n.errors,V)&&!J._f.deps||CE(Fe,ae(n.touchedFields,V),n.isSubmitted,p,m),Ct=yp(V,s,Fe);Oe(i,V,we),Fe?(J._f.onBlur&&J._f.onBlur(C),u&&u(0)):J._f.onChange&&J._f.onChange(C);const He=N(V,we,Fe,!1),dn=!et(He)||Ct;if(!Fe&&g.values.next({name:V,type:C.type,values:{...i}}),ct)return d.isValid&&(t.mode==="onBlur"?Fe&&y():y()),dn&&g.state.next({name:V,...Ct?{}:He});if(!Fe&&Ct&&g.state.next({...n}),t.resolver){const{errors:fn}=await M([V]);if(z(we),re){const Be=Op(n.errors,r,V),Rt=Op(fn,r,Be.name||V);Y=Rt.error,V=Rt.name,ve=et(fn)}}else b([V],!0),Y=(await _p(J,i,h,t.shouldUseNativeValidation))[V],b([V]),z(we),re&&(Y?ve=!1:d.isValid&&(ve=await O(r,!0)));re&&(J._f.deps&&A(J._f.deps),I(V,ve,Y,He))}},R=(C,P)=>{if(ae(n.errors,P)&&C.focus)return C.focus(),1},A=async(C,P={})=>{let V,re;const J=ti(C);if(t.resolver){const K=await H(Ie(C)?C:J);V=et(K),re=C?!J.some(z=>ae(K,z)):V}else C?(re=(await Promise.all(J.map(async K=>{const z=ae(r,K);return await O(z&&z._f?{[K]:z}:z)}))).every(Boolean),!(!re&&!n.isValid)&&y()):re=V=await O(r);return g.state.next({...!$t(C)||d.isValid&&V!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:V}:{},errors:n.errors}),P.shouldFocus&&!re&&Ar(r,R,C?J:s.mount),re},B=C=>{const P={...a.mount?i:o};return Ie(C)?P:$t(C)?ae(P,C):C.map(V=>ae(P,V))},Q=(C,P)=>({invalid:!!ae((P||n).errors,C),isDirty:!!ae((P||n).dirtyFields,C),error:ae((P||n).errors,C),isValidating:!!ae(n.validatingFields,C),isTouched:!!ae((P||n).touchedFields,C)}),ne=C=>{C&&ti(C).forEach(P=>Ve(n.errors,P)),g.state.next({errors:C?n.errors:{}})},te=(C,P,V)=>{const re=(ae(r,C,{_f:{}})._f||{}).ref,J=ae(n.errors,C)||{},{ref:K,message:z,type:Y,...ve}=J;Oe(n.errors,C,{...ve,...P,ref:re}),g.state.next({name:C,errors:n.errors,isValid:!1}),V&&V.shouldFocus&&re&&re.focus&&re.focus()},ce=(C,P)=>Lt(C)?g.values.subscribe({next:V=>C(Z(void 0,P),V)}):Z(C,P,!0),oe=(C,P={})=>{for(const V of C?ti(C):s.mount)s.mount.delete(V),s.array.delete(V),P.keepValue||(Ve(r,V),Ve(i,V)),!P.keepError&&Ve(n.errors,V),!P.keepDirty&&Ve(n.dirtyFields,V),!P.keepTouched&&Ve(n.touchedFields,V),!P.keepIsValidating&&Ve(n.validatingFields,V),!t.shouldUnregister&&!P.keepDefaultValue&&Ve(o,V);g.values.next({values:{...i}}),g.state.next({...n,...P.keepDirty?{isDirty:W()}:{}}),!P.keepIsValid&&y()},se=({disabled:C,name:P,field:V,fields:re,value:J})=>{if(Mt(C)&&a.mount||C){const K=C?void 0:Ie(J)?Ms(V?V._f:ae(re,P)._f):J;(C||!C&&!Ie(K))&&Oe(i,P,K),N(P,K,!1,!1,!0)}},ue=(C,P={})=>{let V=ae(r,C);const re=Mt(P.disabled)||Mt(t.disabled);return Oe(r,C,{...V||{},_f:{...V&&V._f?V._f:{ref:{name:C}},name:C,mount:!0,...P}}),s.mount.add(C),V?se({field:V,disabled:Mt(P.disabled)?P.disabled:t.disabled,name:C,value:P.value}):x(C,!0,P.value),{...re?{disabled:P.disabled||t.disabled}:{},...t.progressive?{required:!!P.required,min:Nr(P.min),max:Nr(P.max),minLength:Nr(P.minLength),maxLength:Nr(P.maxLength),pattern:Nr(P.pattern)}:{},name:C,onChange:j,onBlur:j,ref:J=>{if(J){ue(C,P),V=ae(r,C);const K=Ie(J.value)&&J.querySelectorAll&&J.querySelectorAll("input,select,textarea")[0]||J,z=xE(K),Y=V._f.refs||[];if(z?Y.find(ve=>ve===K):K===V._f.ref)return;Oe(r,C,{_f:{...V._f,...z?{refs:[...Y.filter(Is),K,...Array.isArray(ae(o,C))?[{}]:[]],ref:{type:K.type,name:C}}:{ref:K}}}),x(C,!1,void 0,K)}else V=ae(r,C,{}),V._f&&(V._f.mount=!1),(t.shouldUnregister||P.shouldUnregister)&&!(cE(s.array,C)&&a.action)&&s.unMount.add(C)}}},de=()=>t.shouldFocusError&&Ar(r,R,s.mount),le=C=>{Mt(C)&&(g.state.next({disabled:C}),Ar(r,(P,V)=>{const re=ae(r,V);re&&(P.disabled=re._f.disabled||C,Array.isArray(re._f.refs)&&re._f.refs.forEach(J=>{J.disabled=re._f.disabled||C}))},0,!1))},Se=(C,P)=>async V=>{let re;if(V&&(V.preventDefault&&V.preventDefault(),V.persist&&V.persist()),t.disabled){P&&await P({...n.errors},V);return}let J=ft(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:z}=await M();n.errors=K,J=z}else await O(r);if(Ve(n.errors,"root"),et(n.errors)){g.state.next({errors:{}});try{await C(J,V)}catch(K){re=K}}else P&&await P({...n.errors},V),de(),setTimeout(de);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:et(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},X=(C,P={})=>{ae(r,C)&&(Ie(P.defaultValue)?U(C,ft(ae(o,C))):(U(C,P.defaultValue),Oe(o,C,ft(P.defaultValue))),P.keepTouched||Ve(n.touchedFields,C),P.keepDirty||(Ve(n.dirtyFields,C),n.isDirty=P.defaultValue?W(C,ft(ae(o,C))):W()),P.keepError||(Ve(n.errors,C),d.isValid&&y()),g.state.next({...n}))},Ce=(C,P={})=>{const V=C?ft(C):o,re=ft(V),J=et(C),K=J?o:re;if(P.keepDefaultValues||(o=V),!P.keepValues){if(P.keepDirtyValues){const z=new Set([...s.mount,...Object.keys(Pr(o,i))]);for(const Y of Array.from(z))ae(n.dirtyFields,Y)?Oe(K,Y,ae(i,Y)):U(Y,ae(K,Y))}else{if(Ps&&Ie(C))for(const z of s.mount){const Y=ae(r,z);if(Y&&Y._f){const ve=Array.isArray(Y._f.refs)?Y._f.refs[0]:Y._f.ref;if(ni(ve)){const we=ve.closest("form");if(we){we.reset();break}}}}r={}}i=t.shouldUnregister?P.keepDefaultValues?ft(o):{}:ft(K),g.array.next({values:{...K}}),g.values.next({values:{...K}})}s={mount:P.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!P.keepIsValid||!!P.keepDirtyValues,a.watch=!!t.shouldUnregister,g.state.next({submitCount:P.keepSubmitCount?n.submitCount:0,isDirty:J?!1:P.keepDirty?n.isDirty:!!(P.keepDefaultValues&&!un(C,o)),isSubmitted:P.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:J?{}:P.keepDirtyValues?P.keepDefaultValues&&i?Pr(o,i):n.dirtyFields:P.keepDefaultValues&&C?Pr(o,C):P.keepDirty?n.dirtyFields:{},touchedFields:P.keepTouched?n.touchedFields:{},errors:P.keepErrors?n.errors:{},isSubmitSuccessful:P.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},ze=(C,P)=>Ce(Lt(C)?C(i):C,P);return{control:{register:ue,unregister:oe,getFieldState:Q,handleSubmit:Se,setError:te,_executeSchema:M,_getWatch:Z,_getDirty:W,_updateValid:y,_removeUnmounted:G,_updateFieldArray:w,_updateDisabledField:se,_getFieldArray:k,_reset:Ce,_resetDefaultValues:()=>Lt(t.defaultValues)&&t.defaultValues().then(C=>{ze(C,t.resetOptions),g.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:le,_subjects:g,_proxyFormState:d,_setErrors:E,get _fields(){return r},get _formValues(){return i},get _state(){return a},set _state(C){a=C},get _defaultValues(){return o},get _names(){return s},set _names(C){s=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:A,register:ue,handleSubmit:Se,watch:ce,setValue:U,getValues:B,reset:ze,resetField:X,clearErrors:ne,unregister:oe,setError:te,setFocus:(C,P={})=>{const V=ae(r,C),re=V&&V._f;if(re){const J=re.refs?re.refs[0]:re.ref;J.focus&&(J.focus(),P.shouldSelect&&Lt(J.select)&&J.select())}},getFieldState:Q}}function AE(e={}){const t=_.useRef(),n=_.useRef(),[r,o]=_.useState({isDirty:!1,isValidating:!1,isLoading:Lt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Lt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...TE(e),formState:r});const i=t.current.control;return i._options=e,pE({subject:i._subjects.state,next:a=>{fE(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&&!un(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:dE(r,i)}),[r,i])}const Fp=({className:e,children:t,content:n,side:r})=>{const[o,i]=_.useState(!1);return l.jsx(sn,{delayDuration:0,children:l.jsxs(ln,{open:o,children:[l.jsx(cn,{asChild:!0,children:l.jsx("button",{type:"button",className:he("cursor-pointer",e),onClick:()=>i(!o),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onTouchStart:()=>i(!o),onKeyDown:a=>{a.preventDefault(),a.key==="Enter"&&i(!o)},children:t})}),l.jsx(Gt,{side:r,className:n?"":"hidden",children:l.jsx("span",{className:"inline-block",children:n})})]})})},PE=(e,t)=>{const[n,r]=_.useState(e);return _.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n},NE=({apiBaseUrl:e="https://s3-explorer.cmcts1.studio.ai.vn"})=>{var N,I;const[t,n]=_.useState([]),[r,o]=_.useState(!1),[i,a]=_.useState([]),[s,u]=_.useState(1),[c,d]=_.useState(1),[g,m]=_.useState(null),[p,h]=_.useState(""),v=PE(p,500),y=M=>{const H=M.match(/\d{6}/);if(!H)return{month:"",year:""};const O=H[0],G=O.substring(0,2),W=O.substring(2);return{month:G,year:W}},b=M=>M.map(O=>{let G=(O==null?void 0:O.month)||"",W=(O==null?void 0:O.year)||"";if((!G||!W)&&(O!=null&&O.file_name)){const Z=y(O.file_name);G=G||Z.month,W=W||Z.year}return{id:O==null?void 0:O.id,prefix:(O==null?void 0:O.prefix)||"",model:(O==null?void 0:O.model)||"",fileName:(O==null?void 0:O.file_name)||"",code:(O==null?void 0:O.stock_id)||"",month:G,year:W,content:(O==null?void 0:O.text_summary)||"",status:(O==null?void 0:O.status)||"",note:(O==null?void 0:O.note)||"",lastUpdate:O==null?void 0:O.updated_at,stock_id:O==null?void 0:O.stock_id}}),w=M=>{if(!(M!=null&&M.data))return[];const H=b(M==null?void 0:M.data);n(H),d(M.pagination.totalPages)},S=async(M=1,H=15)=>{m(M),o(!0);try{const O=await me.get(`${e}/api/latest-summaries`,{params:{page:M,limit:H,search:p}});(O==null?void 0:O.status)===200?w(O.data):console.error(O)}catch(O){console.error("Error fetching data:",O)}finally{m(null),o(!1)}};_.useEffect(()=>{v&&u(1),S(s)},[s,v]);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 O=H.original.month,G=H.original.year;return l.jsx("span",{className:"flex flex-col",children:`${O.toString().padStart(2,"0")}/${G}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:H})=>{const O=H.getValue("content");return l.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:O})}},{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(Fp,{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 O=new Date(H.original.lastUpdate),G=O.getDate(),W=O.getMonth()+1,Z=`ngày ${G} tháng ${W}`;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[O,G]=_.useState(!1),[W,Z]=_.useState(!1),[k,$]=_.useState(!1),{handleSubmit:F,register:U,reset:j}=AE(),R=H.original.id,A=H.getValue("status"),B=H.getValue("content"),[Q,ne]=_.useState(!1),te=async()=>{try{ne(!0);const oe=A==="unpublish"?"published":"unpublish",se=await me.patch(`${e}/api/toggle-publish/${R}`,{id:R,typeAction:"update",status:A,idInput:R,stock_id:H.original.stock_id,prefix:H.original.prefix,model:H.original.model,summary_result:H.original.content,note:H.original.note});se.status===200?n(ue=>ue.map(de=>de.id===R?{...de,status:oe}:de)):console.error("Failed to toggle publish status:",se)}catch(oe){console.error("Error toggling publish status:",oe)}finally{ne(!1)}},ce=async oe=>{G(!0);try{const se=await me.patch(`${e}/api/update-summary`,{note:oe.note,text_summary:oe.content,id:R});se.status===200?(await S(s),Z(!1)):console.error("Failed to update summary:",se)}catch(se){console.error("Error updating summary:",se)}return G(!1)};return l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ye,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"px-2 py-0.5 h-7",children:l.jsx($h,{className:"h-4 w-4"})}),l.jsx(Ht,{open:k,onOpenChange:$,children:l.jsxs(At,{className:"max-w-3xl max-h-[80vh]",children:[l.jsx(Pt,{children:l.jsx(Nt,{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(Ht,{open:W,onOpenChange:oe=>{Z(oe),oe?j({content:H.original.content,note:H.original.note}):j()},children:[l.jsx(mo,{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(At,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:l.jsxs(Pt,{className:"flex flex-col gap-3",children:[l.jsx(Nt,{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(mr,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.answer||"",rows:10,...U("content")})]}),l.jsxs("div",{className:"flex flex-col items-start",children:[l.jsx("span",{children:"Ghi chú:"}),l.jsx(mr,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:H.original.note||"",rows:1,...U("note")})]})]}),l.jsx("div",{className:"flex justify-end",children:l.jsx(ye,{disabled:O,type:"submit",variant:"default",children:O?l.jsx($e,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),l.jsx(ye,{variant:"outline",size:"sm",onClick:te,disabled:Q,className:"w-[70px] px-2 py-0.5 h-7",children:Q?l.jsx($e,{className:"h-4 w-4 animate-spin"}):A==="unpublish"?"Publish":"Unpublish"})]})}}],[]),x=nl({data:t,columns:E,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:a,getFilteredRowModel:jg(),getCoreRowModel:tl()});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:p,onChange:M=>h(M.target.value),className:"pr-8"}),p&&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:()=>h(""),children:l.jsx(qi,{className:"h-4 w-4"})})]})}),l.jsx("div",{className:"rounded-md border s3-explr-table-container",children:l.jsxs(wo,{className:"s3-explr-table",children:[l.jsx(So,{className:"s3-explr-table-header",children:x.getHeaderGroups().map(M=>l.jsx(yt,{className:"hover:bg-transparent s3-explr-header-row",children:M.headers.map(H=>l.jsx(kt,{className:"s3-explr-header-cell",children:H.isPlaceholder?null:Hr(H.column.columnDef.header,H.getContext())},H.id))},M.id))}),l.jsx(Co,{className:"s3-explr-table-body",children:r?l.jsx(yt,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(N=x.getRowModel().rows)!=null&&N.length?(I=x.getRowModel().rows)==null?void 0:I.map(M=>l.jsx(yt,{className:"h-12 s3-explr-row",children:M.getVisibleCells().map(H=>l.jsx(Ze,{className:"align-middle s3-explr-cell",children:Hr(H.column.columnDef.cell,H.getContext())},H.id))},M.id)):l.jsx(yt,{children:l.jsx(Ze,{colSpan:E.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),l.jsx("div",{className:"mt-4",children:l.jsx(ho,{children:l.jsxs(vo,{children:[l.jsx(vt,{children:l.jsx(yo,{onClick:()=>u(M=>Math.max(1,M-1)),className:s===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:c},(M,H)=>H+1).filter(M=>M===1||M===c||Math.abs(M-s)<=1).map((M,H,O)=>l.jsxs(l.Fragment,{children:[H>0&&O[H-1]!==M-1&&l.jsx(vt,{children:l.jsx(bo,{})},M+"..."),l.jsx(vt,{children:l.jsx(Bn,{onClick:()=>u(M),isActive:s===M,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===M?l.jsx($e,{className:"h-4 w-4 animate-spin"}):M})},M)]})),l.jsx(vt,{children:l.jsx(xo,{onClick:()=>u(M=>Math.min(c,M+1)),className:s===c||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},Dp=10,kE=_.memo(({apiBaseUrl:e="https://s3-explorer.cmcts1.studio.ai.vn"})=>{const[t,n]=_.useState(1),[r,o]=_.useState([]),[i,a]=_.useState({total:0,page:1,limit:Dp,totalPages:1}),[s,u]=_.useState(!0),[c,d]=_.useState(null),[g,m]=_.useState(new Set),{toast:p}=Io(),[h,v]=_.useState(!1),y=async x=>{try{d(x);const N=await me.get(`${e}/api/jobs`,{params:{page:x.toString(),limit:Dp.toString()}});o(N.data.data),a(N.data.pagination)}catch{p({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(N=>new Set(N).add(x.toString()));try{await me.post(`${e}/api/retry-job`,{jobId:x}),p({title:"Job Restarted",description:`Job ${x} has been successfully restarted.`}),y(t)}catch{p({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${x}. Please try again.`})}finally{m(N=>{const I=new Set(N);return I.delete(x.toString()),I})}},w=async()=>{v(!0),n(1),await y(1),v(!1)},S=x=>new Date(x).toLocaleString(),E=x=>{if(x=parseFloat(x),x<60)return`${x.toFixed(2)}s`;const N=Math.floor(x/60),I=(x%60).toFixed(0);return`${N}m ${I}s`};return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[l.jsx(Fh,{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:h||s,className:"ml-2",children:l.jsx(Vh,{className:`h-4 w-4 ${h?"animate-spin":""}`})})]}),l.jsx("div",{className:"rounded-md border",children:l.jsxs(wo,{children:[l.jsx(So,{children:l.jsxs(yt,{children:[l.jsx(kt,{children:"ID"}),l.jsx(kt,{children:"Tên Công Việc"}),l.jsx(kt,{children:"Thời Gian Bắt Đầu"}),l.jsx(kt,{children:"Thời Gian Cập Nhật"}),l.jsx(kt,{children:"Thời Gian Thực Thi"}),l.jsx(kt,{children:"Trạng Thái"}),l.jsx(kt,{children:"Thao Tác"})]})}),l.jsx(Co,{children:s&&r.length===0?l.jsx(yt,{children:l.jsx(Ze,{colSpan:7,className:"text-center py-4",children:l.jsx($e,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(x=>{var N,I;return l.jsxs(yt,{children:[l.jsx(Ze,{className:"!w-[100px]",children:x.id}),l.jsx(Ze,{className:"font-medium",children:(N=x.job_name)==null?void 0:N.replace("Upload file","Summary")}),l.jsx(Ze,{className:"!w-[200px]",children:S(x.created_at)}),l.jsx(Ze,{className:"!w-[200px]",children:S(x.updated_at)}),l.jsx(Ze,{className:"!w-[150px]",children:E(x.execution_time_seconds)}),l.jsx(Ze,{className:"!w-[200px]",children:l.jsx(Fp,{content:x.status==="fail"&&x.error?l.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:x.error}):null,children:l.jsx("div",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]
176
176
  ${x.status==="done"?"bg-green-100 text-green-800":x.status==="fail"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:x.status==="fail"?"FAILED":(I=x.status)==null?void 0:I.toUpperCase()})})}),l.jsx(Ze,{className:"!w-[200px]",children:x.status==="fail"?l.jsx(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(ho,{children:l.jsxs(vo,{children:[l.jsx(vt,{children:l.jsx(yo,{onClick:()=>n(x=>Math.max(1,x-1)),className:t===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:i.totalPages},(x,N)=>N+1).filter(x=>x===1||x===i.totalPages||Math.abs(x-t)<=1).map((x,N,I)=>l.jsxs(l.Fragment,{children:[N>0&&I[N-1]!==x-1&&l.jsx(vt,{children:l.jsx(bo,{})},x+"..."),l.jsx(vt,{children:l.jsx(Bn,{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(vt,{children:l.jsx(xo,{onClick:()=>n(x=>Math.min(i.totalPages,x+1)),className:t===i.totalPages||c!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),l.jsx(_d,{})]})});pt.Job=kE,pt.S3Explorer=aE,pt.Summary=NE,Object.defineProperty(pt,Symbol.toStringTag,{value:"Module"})});
177
177
  //# sourceMappingURL=s3-explorer.umd.cjs.map