dccxx-s3-explorer 1.0.83 → 1.0.85

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.
@@ -224,7 +224,7 @@ Valid keys: `+JSON.stringify(Object.keys($),null," "));var ne=Ne(z,Ce,xe,Pe,Te+
224
224
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function lU(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function dU(t){if(Array.isArray(t))return lm(t)}function ME(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function RE(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?ME(Object(n),!0).forEach(function(r){DE(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ME(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function DE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function vc(t,e){return hU(t)||fU(t,e)||LE(t,e)||uU()}function uU(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
225
225
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function LE(t,e){if(t){if(typeof t=="string")return lm(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return lm(t,e)}}function lm(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function fU(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,s,l;try{for(n=n.call(t);!(o=(s=n.next()).done)&&(r.push(s.value),!(e&&r.length===e));o=!0);}catch(u){i=!0,l=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw l}}return r}}function hU(t){if(Array.isArray(t))return t}var pU=typeof cm=="function"?cm:cm.default,gU="file-invalid-type",mU="file-too-large",vU="file-too-small",yU="too-many-files",wU=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=e.split(","),r=n.length>1?"one of ".concat(n.join(", ")):n[0];return{code:gU,message:"File type must be ".concat(r)}},FE=function(e){return{code:mU,message:"File is larger than ".concat(e," ").concat(e===1?"byte":"bytes")}},$E=function(e){return{code:vU,message:"File is smaller than ".concat(e," ").concat(e===1?"byte":"bytes")}},CU={code:yU,message:"Too many files"};function HE(t,e){var n=t.type==="application/x-moz-file"||pU(t,e);return[n,n?null:wU(e)]}function UE(t,e,n){if(Wi(t.size))if(Wi(e)&&Wi(n)){if(t.size>n)return[!1,FE(n)];if(t.size<e)return[!1,$E(e)]}else{if(Wi(e)&&t.size<e)return[!1,$E(e)];if(Wi(n)&&t.size>n)return[!1,FE(n)]}return[!0,null]}function Wi(t){return t!=null}function bU(t){var e=t.files,n=t.accept,r=t.minSize,o=t.maxSize,i=t.multiple,s=t.maxFiles,l=t.validator;return!i&&e.length>1||i&&s>=1&&e.length>s?!1:e.every(function(u){var h=HE(u,n),p=vc(h,1),g=p[0],C=UE(u,r,o),w=vc(C,1),x=w[0],y=l?l(u):null;return g&&x&&!y})}function hu(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function pu(t){return t.dataTransfer?Array.prototype.some.call(t.dataTransfer.types,function(e){return e==="Files"||e==="application/x-moz-file"}):!!t.target&&!!t.target.files}function BE(t){t.preventDefault()}function xU(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function SU(t){return t.indexOf("Edge/")!==-1}function _U(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return xU(t)||SU(t)}function vo(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return function(r){for(var o=arguments.length,i=new Array(o>1?o-1:0),s=1;s<o;s++)i[s-1]=arguments[s];return e.some(function(l){return!hu(r)&&l&&l.apply(void 0,[r].concat(i)),hu(r)})}}function EU(){return"showOpenFilePicker"in window}function TU(t){if(Wi(t)){var e=Object.entries(t).filter(function(n){var r=vc(n,2),o=r[0],i=r[1],s=!0;return zE(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.')),s=!1),(!Array.isArray(i)||!i.every(VE))&&(console.warn('Skipped "'.concat(o,'" because an invalid file extension was provided.')),s=!1),s}).reduce(function(n,r){var o=vc(r,2),i=o[0],s=o[1];return RE(RE({},n),{},DE({},i,s))},{});return[{description:"Files",accept:e}]}return t}function AU(t){if(Wi(t))return Object.entries(t).reduce(function(e,n){var r=vc(n,2),o=r[0],i=r[1];return[].concat(OE(e),[o],OE(i))},[]).filter(function(e){return zE(e)||VE(e)}).join(",")}function IU(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function kU(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function zE(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function VE(t){return/^.*\.[\w]+$/.test(t)}var NU=["children"],PU=["open"],OU=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],MU=["refKey","onChange","onClick"];function RU(t){return FU(t)||LU(t)||KE(t)||DU()}function DU(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
226
226
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function LU(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function FU(t){if(Array.isArray(t))return um(t)}function dm(t,e){return UU(t)||HU(t,e)||KE(t,e)||$U()}function $U(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
227
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function KE(t,e){if(t){if(typeof t=="string")return um(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return um(t,e)}}function um(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function HU(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,s,l;try{for(n=n.call(t);!(o=(s=n.next()).done)&&(r.push(s.value),!(e&&r.length===e));o=!0);}catch(u){i=!0,l=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw l}}return r}}function UU(t){if(Array.isArray(t))return t}function GE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Bt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?GE(Object(n),!0).forEach(function(r){fm(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):GE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function fm(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function gu(t,e){if(t==null)return{};var n=BU(t,e),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function BU(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,i;for(i=0;i<r.length;i++)o=r[i],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var hm=M.forwardRef(function(t,e){var n=t.children,r=gu(t,NU),o=WE(r),i=o.open,s=gu(o,PU);return M.useImperativeHandle(e,function(){return{open:i}},[i]),M.createElement(M.Fragment,null,n(Bt(Bt({},s),{},{open:i})))});hm.displayName="Dropzone";var jE={disabled:!1,getFilesFromEvent:ZH,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};hm.defaultProps=jE,hm.propTypes={children:Ot.func,accept:Ot.objectOf(Ot.arrayOf(Ot.string)),multiple:Ot.bool,preventDropOnDocument:Ot.bool,noClick:Ot.bool,noKeyboard:Ot.bool,noDrag:Ot.bool,noDragEventsBubbling:Ot.bool,minSize:Ot.number,maxSize:Ot.number,maxFiles:Ot.number,disabled:Ot.bool,getFilesFromEvent:Ot.func,onFileDialogCancel:Ot.func,onFileDialogOpen:Ot.func,useFsAccessApi:Ot.bool,autoFocus:Ot.bool,onDragEnter:Ot.func,onDragLeave:Ot.func,onDragOver:Ot.func,onDrop:Ot.func,onDropAccepted:Ot.func,onDropRejected:Ot.func,onError:Ot.func,validator:Ot.func};var pm={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function WE(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Bt(Bt({},jE),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,i=e.maxSize,s=e.minSize,l=e.multiple,u=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,g=e.onDragOver,C=e.onDrop,w=e.onDropAccepted,x=e.onDropRejected,y=e.onFileDialogCancel,b=e.onFileDialogOpen,E=e.useFsAccessApi,T=e.autoFocus,N=e.preventDropOnDocument,P=e.noClick,_=e.noKeyboard,D=e.noDrag,H=e.noDragEventsBubbling,K=e.onError,ee=e.validator,W=M.useMemo(function(){return AU(n)},[n]),de=M.useMemo(function(){return TU(n)},[n]),se=M.useMemo(function(){return typeof b=="function"?b:qE},[b]),fe=M.useMemo(function(){return typeof y=="function"?y:qE},[y]),q=M.useRef(null),Z=M.useRef(null),Y=M.useReducer(zU,pm),oe=dm(Y,2),Q=oe[0],X=oe[1],$=Q.isFocused,te=Q.isFileDialogActive,_e=M.useRef(typeof window<"u"&&window.isSecureContext&&E&&EU()),ke=function(){!_e.current&&te&&setTimeout(function(){if(Z.current){var ae=Z.current.files;ae.length||(X({type:"closeDialog"}),fe())}},300)};M.useEffect(function(){return window.addEventListener("focus",ke,!1),function(){window.removeEventListener("focus",ke,!1)}},[Z,te,fe,_e]);var xe=M.useRef([]),Pe=function(ae){q.current&&q.current.contains(ae.target)||(ae.preventDefault(),xe.current=[])};M.useEffect(function(){return N&&(document.addEventListener("dragover",BE,!1),document.addEventListener("drop",Pe,!1)),function(){N&&(document.removeEventListener("dragover",BE),document.removeEventListener("drop",Pe))}},[q,N]),M.useEffect(function(){return!r&&T&&q.current&&q.current.focus(),function(){}},[q,T,r]);var Te=M.useCallback(function(U){K?K(U):console.error(U)},[K]),z=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U),xe.current=[].concat(RU(xe.current),[U.target]),pu(U)&&Promise.resolve(o(U)).then(function(ae){if(!(hu(U)&&!H)){var ye=ae.length,he=ye>0&&bU({files:ae,accept:W,minSize:s,maxSize:i,multiple:l,maxFiles:u,validator:ee}),Ee=ye>0&&!he;X({isDragAccept:he,isDragReject:Ee,isDragActive:!0,type:"setDraggedFiles"}),h&&h(U)}}).catch(function(ae){return Te(ae)})},[o,h,Te,H,W,s,i,l,u,ee]),ce=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U);var ae=pu(U);if(ae&&U.dataTransfer)try{U.dataTransfer.dropEffect="copy"}catch{}return ae&&g&&g(U),!1},[g,H]),Ae=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U);var ae=xe.current.filter(function(he){return q.current&&q.current.contains(he)}),ye=ae.indexOf(U.target);ye!==-1&&ae.splice(ye,1),xe.current=ae,!(ae.length>0)&&(X({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),pu(U)&&p&&p(U))},[q,p,H]),Ce=M.useCallback(function(U,ae){var ye=[],he=[];U.forEach(function(Ee){var Xe=HE(Ee,W),ft=dm(Xe,2),xt=ft[0],Co=ft[1],Qt=UE(Ee,s,i),vn=dm(Qt,2),qr=vn[0],Gt=vn[1],dr=ee?ee(Ee):null;if(xt&&qr&&!dr)ye.push(Ee);else{var Yr=[Co,Gt];dr&&(Yr=Yr.concat(dr)),he.push({file:Ee,errors:Yr.filter(function(ea){return ea})})}}),(!l&&ye.length>1||l&&u>=1&&ye.length>u)&&(ye.forEach(function(Ee){he.push({file:Ee,errors:[CU]})}),ye.splice(0)),X({acceptedFiles:ye,fileRejections:he,isDragReject:he.length>0,type:"setFiles"}),C&&C(ye,he,ae),he.length>0&&x&&x(he,ae),ye.length>0&&w&&w(ye,ae)},[X,l,W,s,i,u,C,w,x,ee]),Ne=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U),xe.current=[],pu(U)&&Promise.resolve(o(U)).then(function(ae){hu(U)&&!H||Ce(ae,U)}).catch(function(ae){return Te(ae)}),X({type:"reset"})},[o,Ce,Te,H]),ne=M.useCallback(function(){if(_e.current){X({type:"openDialog"}),se();var U={multiple:l,types:de};window.showOpenFilePicker(U).then(function(ae){return o(ae)}).then(function(ae){Ce(ae,null),X({type:"closeDialog"})}).catch(function(ae){IU(ae)?(fe(ae),X({type:"closeDialog"})):kU(ae)?(_e.current=!1,Z.current?(Z.current.value=null,Z.current.click()):Te(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."))):Te(ae)});return}Z.current&&(X({type:"openDialog"}),se(),Z.current.value=null,Z.current.click())},[X,se,fe,E,Ce,Te,de,l]),Ve=M.useCallback(function(U){!q.current||!q.current.isEqualNode(U.target)||(U.key===" "||U.key==="Enter"||U.keyCode===32||U.keyCode===13)&&(U.preventDefault(),ne())},[q,ne]),Qe=M.useCallback(function(){X({type:"focus"})},[]),Ct=M.useCallback(function(){X({type:"blur"})},[]),Jt=M.useCallback(function(){P||(_U()?setTimeout(ne,0):ne())},[P,ne]),bt=function(ae){return r?null:ae},an=function(ae){return _?null:bt(ae)},zt=function(ae){return D?null:bt(ae)},$n=function(ae){H&&ae.stopPropagation()},Kt=M.useMemo(function(){return function(){var U=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=U.refKey,ye=ae===void 0?"ref":ae,he=U.role,Ee=U.onKeyDown,Xe=U.onFocus,ft=U.onBlur,xt=U.onClick,Co=U.onDragEnter,Qt=U.onDragOver,vn=U.onDragLeave,qr=U.onDrop,Gt=gu(U,OU);return Bt(Bt(fm({onKeyDown:an(vo(Ee,Ve)),onFocus:an(vo(Xe,Qe)),onBlur:an(vo(ft,Ct)),onClick:bt(vo(xt,Jt)),onDragEnter:zt(vo(Co,z)),onDragOver:zt(vo(Qt,ce)),onDragLeave:zt(vo(vn,Ae)),onDrop:zt(vo(qr,Ne)),role:typeof he=="string"&&he!==""?he:"presentation"},ye,q),!r&&!_?{tabIndex:0}:{}),Gt)}},[q,Ve,Qe,Ct,Jt,z,ce,Ae,Ne,_,D,r]),L=M.useCallback(function(U){U.stopPropagation()},[]),J=M.useMemo(function(){return function(){var U=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=U.refKey,ye=ae===void 0?"ref":ae,he=U.onChange,Ee=U.onClick,Xe=gu(U,MU),ft=fm({accept:W,multiple:l,type:"file",style:{border:0,clip:"rect(0, 0, 0, 0)",clipPath:"inset(50%)",height:"1px",margin:"0 -1px -1px 0",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"},onChange:bt(vo(he,Ne)),onClick:bt(vo(Ee,L)),tabIndex:-1},ye,Z);return Bt(Bt({},ft),Xe)}},[Z,n,l,Ne,r]);return Bt(Bt({},Q),{},{isFocused:$&&!r,getRootProps:Kt,getInputProps:J,rootRef:q,inputRef:Z,open:bt(ne)})}function zU(t,e){switch(e.type){case"focus":return Bt(Bt({},t),{},{isFocused:!0});case"blur":return Bt(Bt({},t),{},{isFocused:!1});case"openDialog":return Bt(Bt({},pm),{},{isFileDialogActive:!0});case"closeDialog":return Bt(Bt({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Bt(Bt({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Bt(Bt({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Bt({},pm);default:return t}}function qE(){}const VU=({onFilesSelected:t,children:e})=>{const[n,r]=M.useState(!1),{getRootProps:o,getInputProps:i}=WE({noClick:!0,onDrop:s=>{if(s&&s.length>0)if(s[0].path.split("/").length>2){const u=s.map(h=>{const g=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),h});t(u,"folder")}else t(s,"files");r(!1)},onDragOver:s=>{s.preventDefault(),n||r(!0)},multiple:!0});return M.useEffect(()=>{const s=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",s),()=>{document.removeEventListener("dragleave",s)}},[]),d.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?d.jsx("div",{className:"flex flex-col items-center justify-center p-4 border-2 border-dashed border-gray-300 rounded-lg bg-gray-50 h-screen"}):e,d.jsx("input",{...i()})]})},KU=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:i,ignoreCache:s,autoSyncAfterFileOperation:l})=>{var N;const[u,h]=M.useState({}),[p,g]=M.useState(!1),[C,w]=M.useState(!1),[x,y]=M.useState(""),{toast:b}=dc();M.useEffect(()=>{t&&E(x)},[x,t]);const E=async P=>{try{w(!0);const _=await Le.get(`${n}/api/list-s3-folders?prefix=${P}`);h(_==null?void 0:_.data)}catch{b({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{w(!1)}},T=async()=>{g(!0);try{const P=o.key,_=P.endsWith("/")?P:`${P}/`,D=x.endsWith("/")?x:`${x}/`;if(_===D||P===x){b({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),g(!1);return}await Le.post(`${n}/api/move`,{oldPath:P,newPath:x}),s.current=!0,await i(),b({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${x}"`}),e(!1),r(null),y(""),l&&await l("move")}catch(P){console.error("Error renaming item:",P),b({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{g(!1)}};return d.jsx(ar,{open:t,onOpenChange:P=>{P||(e(!1),r(null),y(""))},children:d.jsxs(jn,{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:[d.jsxs(Wn,{className:"mb-4 w-full h-full",children:[d.jsx("nav",{className:"mb-4",children:d.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[d.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(""),children:"Root"}),x.split("/").map((P,_,D)=>d.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(P==="Root"?"":D.slice(0,_+1).join("/")+"/"),children:P},_))]})}),d.jsxs(qn,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",d.jsxs("span",{className:"text-sm text-gray-500",children:["( file hoặc folder sẽ được di chuyển đến thư mục"," ",x===""?"Root":x," )"]})]}),d.jsx(vi,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:C?d.jsx("div",{className:"flex justify-center items-center py-4",children:d.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):d.jsx("ul",{className:"space-y-2",children:(N=Object.keys(u))==null?void 0:N.map(P=>d.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>y(P),children:P},P))})})]}),d.jsxs(Hr,{className:"flex justify-end space-x-2",children:[d.jsx(He,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),d.jsx(He,{onClick:T,disabled:p,className:"s3-explr-crawl-btn",children:"Move"})]})]})})};function YE(t,[e,n]){return Math.min(n,Math.max(e,t))}function JE(t){const e=GU(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(WU);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function GU(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=YU(o),l=qU(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var jU=Symbol("radix.slottable");function WU(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===jU}function qU(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function YU(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}function JU(t){const e=t+"CollectionProvider",[n,r]=gr(e),[o,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),s=y=>{const{scope:b,children:E}=y,T=M.useRef(null),N=M.useRef(new Map).current;return d.jsx(o,{scope:b,itemMap:N,collectionRef:T,children:E})};s.displayName=e;const l=t+"CollectionSlot",u=JE(l),h=M.forwardRef((y,b)=>{const{scope:E,children:T}=y,N=i(l,E),P=rt(b,N.collectionRef);return d.jsx(u,{ref:P,children:T})});h.displayName=l;const p=t+"CollectionItemSlot",g="data-radix-collection-item",C=JE(p),w=M.forwardRef((y,b)=>{const{scope:E,children:T,...N}=y,P=M.useRef(null),_=rt(b,P),D=i(p,E);return M.useEffect(()=>(D.itemMap.set(P,{ref:P,...N}),()=>void D.itemMap.delete(P))),d.jsx(C,{[g]:"",ref:_,children:T})});w.displayName=p;function x(y){const b=i(t+"CollectionConsumer",y);return M.useCallback(()=>{const T=b.collectionRef.current;if(!T)return[];const N=Array.from(T.querySelectorAll(`[${g}]`));return Array.from(b.itemMap.values()).sort((D,H)=>N.indexOf(D.ref.current)-N.indexOf(H.ref.current))},[b.collectionRef,b.itemMap])}return[{Provider:s,Slot:h,ItemSlot:w},x,r]}function QE(t){const e=QU(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(ZU);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function QU(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=tB(o),l=eB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var XU=Symbol("radix.slottable");function ZU(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===XU}function eB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function tB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var nB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],mn=nB.reduce((t,e)=>{const n=QE(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function rB(t,e){t&&_a.flushSync(()=>t.dispatchEvent(e))}var oB="DismissableLayer",gm="dismissableLayer.update",iB="dismissableLayer.pointerDownOutside",aB="dismissableLayer.focusOutside",XE,ZE=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),eT=m.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:s,onDismiss:l,...u}=t,h=m.useContext(ZE),[p,g]=m.useState(null),C=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,w]=m.useState({}),x=rt(e,H=>g(H)),y=Array.from(h.layers),[b]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),E=y.indexOf(b),T=p?y.indexOf(p):-1,N=h.layersWithOutsidePointerEventsDisabled.size>0,P=T>=E,_=lB(H=>{const K=H.target,ee=[...h.branches].some(W=>W.contains(K));!P||ee||(o==null||o(H),s==null||s(H),H.defaultPrevented||l==null||l())},C),D=dB(H=>{const K=H.target;[...h.branches].some(W=>W.contains(K))||(i==null||i(H),s==null||s(H),H.defaultPrevented||l==null||l())},C);return $C(H=>{T===h.layers.size-1&&(r==null||r(H),!H.defaultPrevented&&l&&(H.preventDefault(),l()))},C),m.useEffect(()=>{if(p)return n&&(h.layersWithOutsidePointerEventsDisabled.size===0&&(XE=C.body.style.pointerEvents,C.body.style.pointerEvents="none"),h.layersWithOutsidePointerEventsDisabled.add(p)),h.layers.add(p),tT(),()=>{n&&h.layersWithOutsidePointerEventsDisabled.size===1&&(C.body.style.pointerEvents=XE)}},[p,C,n,h]),m.useEffect(()=>()=>{p&&(h.layers.delete(p),h.layersWithOutsidePointerEventsDisabled.delete(p),tT())},[p,h]),m.useEffect(()=>{const H=()=>w({});return document.addEventListener(gm,H),()=>document.removeEventListener(gm,H)},[]),d.jsx(mn.div,{...u,ref:x,style:{pointerEvents:N?P?"auto":"none":void 0,...t.style},onFocusCapture:Ue(t.onFocusCapture,D.onFocusCapture),onBlurCapture:Ue(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:Ue(t.onPointerDownCapture,_.onPointerDownCapture)})});eT.displayName=oB;var sB="DismissableLayerBranch",cB=m.forwardRef((t,e)=>{const n=m.useContext(ZE),r=m.useRef(null),o=rt(e,r);return m.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),d.jsx(mn.div,{...t,ref:o})});cB.displayName=sB;function lB(t,e=globalThis==null?void 0:globalThis.document){const n=gn(t),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const i=l=>{if(l.target&&!r.current){let u=function(){nT(iB,n,h,{discrete:!0})};const h={originalEvent:l};l.pointerType==="touch"?(e.removeEventListener("click",o.current),o.current=u,e.addEventListener("click",o.current,{once:!0})):u()}else e.removeEventListener("click",o.current);r.current=!1},s=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(s),e.removeEventListener("pointerdown",i),e.removeEventListener("click",o.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function dB(t,e=globalThis==null?void 0:globalThis.document){const n=gn(t),r=m.useRef(!1);return m.useEffect(()=>{const o=i=>{i.target&&!r.current&&nT(aB,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",o),()=>e.removeEventListener("focusin",o)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function tT(){const t=new CustomEvent(gm);document.dispatchEvent(t)}function nT(t,e,n,{discrete:r}){const o=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&o.addEventListener(t,e,{once:!0}),r?rB(o,i):o.dispatchEvent(i)}var mm="focusScope.autoFocusOnMount",vm="focusScope.autoFocusOnUnmount",rT={bubbles:!1,cancelable:!0},uB="FocusScope",oT=m.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:i,...s}=t,[l,u]=m.useState(null),h=gn(o),p=gn(i),g=m.useRef(null),C=rt(e,y=>u(y)),w=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let y=function(N){if(w.paused||!l)return;const P=N.target;l.contains(P)?g.current=P:Ci(g.current,{select:!0})},b=function(N){if(w.paused||!l)return;const P=N.relatedTarget;P!==null&&(l.contains(P)||Ci(g.current,{select:!0}))},E=function(N){if(document.activeElement===document.body)for(const _ of N)_.removedNodes.length>0&&Ci(l)};document.addEventListener("focusin",y),document.addEventListener("focusout",b);const T=new MutationObserver(E);return l&&T.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",b),T.disconnect()}}},[r,l,w.paused]),m.useEffect(()=>{if(l){sT.add(w);const y=document.activeElement;if(!l.contains(y)){const E=new CustomEvent(mm,rT);l.addEventListener(mm,h),l.dispatchEvent(E),E.defaultPrevented||(fB(vB(iT(l)),{select:!0}),document.activeElement===y&&Ci(l))}return()=>{l.removeEventListener(mm,h),setTimeout(()=>{const E=new CustomEvent(vm,rT);l.addEventListener(vm,p),l.dispatchEvent(E),E.defaultPrevented||Ci(y??document.body,{select:!0}),l.removeEventListener(vm,p),sT.remove(w)},0)}}},[l,h,p,w]);const x=m.useCallback(y=>{if(!n&&!r||w.paused)return;const b=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,E=document.activeElement;if(b&&E){const T=y.currentTarget,[N,P]=hB(T);N&&P?!y.shiftKey&&E===P?(y.preventDefault(),n&&Ci(N,{select:!0})):y.shiftKey&&E===N&&(y.preventDefault(),n&&Ci(P,{select:!0})):E===T&&y.preventDefault()}},[n,r,w.paused]);return d.jsx(mn.div,{tabIndex:-1,...s,ref:C,onKeyDown:x})});oT.displayName=uB;function fB(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Ci(r,{select:e}),document.activeElement!==n)return}function hB(t){const e=iT(t),n=aT(e,t),r=aT(e.reverse(),t);return[n,r]}function iT(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function aT(t,e){for(const n of t)if(!pB(n,{upTo:e}))return n}function pB(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function gB(t){return t instanceof HTMLInputElement&&"select"in t}function Ci(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&gB(t)&&e&&t.select()}}var sT=mB();function mB(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=cT(t,e),t.unshift(e)},remove(e){var n;t=cT(t,e),(n=t[0])==null||n.resume()}}}function cT(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function vB(t){return t.filter(e=>e.tagName!=="A")}function yB(t){const e=wB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(bB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function wB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=SB(o),l=xB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var CB=Symbol("radix.slottable");function bB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===CB}function xB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function SB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var _B=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],EB=_B.reduce((t,e)=>{const n=yB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),TB="Arrow",lT=m.forwardRef((t,e)=>{const{children:n,width:r=10,height:o=5,...i}=t;return d.jsx(EB.svg,{...i,ref:e,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});lT.displayName=TB;var AB=lT;function IB(t){const e=kB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(PB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function kB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=MB(o),l=OB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var NB=Symbol("radix.slottable");function PB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===NB}function OB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function MB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var RB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],dT=RB.reduce((t,e)=>{const n=IB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),ym="Popper",[uT,fT]=gr(ym),[DB,hT]=uT(ym),pT=t=>{const{__scopePopper:e,children:n}=t,[r,o]=m.useState(null);return d.jsx(DB,{scope:e,anchor:r,onAnchorChange:o,children:n})};pT.displayName=ym;var gT="PopperAnchor",mT=m.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,i=hT(gT,n),s=m.useRef(null),l=rt(e,s);return m.useEffect(()=>{i.onAnchorChange((r==null?void 0:r.current)||s.current)}),r?null:d.jsx(dT.div,{...o,ref:l})});mT.displayName=gT;var wm="PopperContent",[LB,FB]=uT(wm),vT=m.forwardRef((t,e)=>{var z,ce,Ae,Ce,Ne,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:i="center",alignOffset:s=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:p=0,sticky:g="partial",hideWhenDetached:C=!1,updatePositionStrategy:w="optimized",onPlaced:x,...y}=t,b=hT(wm,n),[E,T]=m.useState(null),N=rt(e,Ve=>T(Ve)),[P,_]=m.useState(null),D=mg(P),H=(D==null?void 0:D.width)??0,K=(D==null?void 0:D.height)??0,ee=r+(i!=="center"?"-"+i:""),W=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},de=Array.isArray(h)?h:[h],se=de.length>0,fe={padding:W,boundary:de.filter(HB),altBoundary:se},{refs:q,floatingStyles:Z,placement:Y,isPositioned:oe,middlewareData:Q}=I_({strategy:"fixed",placement:ee,whileElementsMounted:(...Ve)=>__(...Ve,{animationFrame:w==="always"}),elements:{reference:b.anchor},middleware:[k_({mainAxis:o+K,alignmentAxis:s}),u&&N_({mainAxis:!0,crossAxis:!1,limiter:g==="partial"?P_():void 0,...fe}),u&&O_({...fe}),M_({...fe,apply:({elements:Ve,rects:Qe,availableWidth:Ct,availableHeight:Jt})=>{const{width:bt,height:an}=Qe.reference,zt=Ve.floating.style;zt.setProperty("--radix-popper-available-width",`${Ct}px`),zt.setProperty("--radix-popper-available-height",`${Jt}px`),zt.setProperty("--radix-popper-anchor-width",`${bt}px`),zt.setProperty("--radix-popper-anchor-height",`${an}px`)}}),P&&D_({element:P,padding:l}),UB({arrowWidth:H,arrowHeight:K}),C&&R_({strategy:"referenceHidden",...fe})]}),[X,$]=CT(Y),te=gn(x);rn(()=>{oe&&(te==null||te())},[oe,te]);const _e=(z=Q.arrow)==null?void 0:z.x,ke=(ce=Q.arrow)==null?void 0:ce.y,xe=((Ae=Q.arrow)==null?void 0:Ae.centerOffset)!==0,[Pe,Te]=m.useState();return rn(()=>{E&&Te(window.getComputedStyle(E).zIndex)},[E]),d.jsx("div",{ref:q.setFloating,"data-radix-popper-content-wrapper":"",style:{...Z,transform:oe?Z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Pe,"--radix-popper-transform-origin":[(Ce=Q.transformOrigin)==null?void 0:Ce.x,(Ne=Q.transformOrigin)==null?void 0:Ne.y].join(" "),...((ne=Q.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(LB,{scope:n,placedSide:X,onArrowChange:_,arrowX:_e,arrowY:ke,shouldHideArrow:xe,children:d.jsx(dT.div,{"data-side":X,"data-align":$,...y,ref:N,style:{...y.style,animation:oe?void 0:"none"}})})})});vT.displayName=wm;var yT="PopperArrow",$B={top:"bottom",right:"left",bottom:"top",left:"right"},wT=m.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,i=FB(yT,r),s=$B[i.placedSide];return d.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:d.jsx(AB,{...o,ref:n,style:{...o.style,display:"block"}})})});wT.displayName=yT;function HB(t){return t!==null}var UB=t=>({name:"transformOrigin",options:t,fn(e){var b,E,T;const{placement:n,rects:r,middlewareData:o}=e,s=((b=o.arrow)==null?void 0:b.centerOffset)!==0,l=s?0:t.arrowWidth,u=s?0:t.arrowHeight,[h,p]=CT(n),g={start:"0%",center:"50%",end:"100%"}[p],C=(((E=o.arrow)==null?void 0:E.x)??0)+l/2,w=(((T=o.arrow)==null?void 0:T.y)??0)+u/2;let x="",y="";return h==="bottom"?(x=s?g:`${C}px`,y=`${-u}px`):h==="top"?(x=s?g:`${C}px`,y=`${r.floating.height+u}px`):h==="right"?(x=`${-u}px`,y=s?g:`${w}px`):h==="left"&&(x=`${r.floating.width+u}px`,y=s?g:`${w}px`),{data:{x,y}}}});function CT(t){const[e,n="center"]=t.split("-");return[e,n]}var BB=pT,zB=mT,VB=vT,KB=wT,GB="Portal",bT=m.forwardRef((t,e)=>{var l;const{container:n,...r}=t,[o,i]=m.useState(!1);rn(()=>i(!0),[]);const s=n||o&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return s?zf.createPortal(d.jsx(mn.div,{...r,ref:e}),s):null});bT.displayName=GB;function jB(t){const e=WB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(YB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function WB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=QB(o),l=JB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var qB=Symbol("radix.slottable");function YB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qB}function JB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function QB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var XB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ZB=XB.reduce((t,e)=>{const n=jB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),xT=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),e3="VisuallyHidden",t3=m.forwardRef((t,e)=>d.jsx(ZB.span,{...t,ref:e,style:{...xT,...t.style}}));t3.displayName=e3;var n3=[" ","Enter","ArrowUp","ArrowDown"],r3=[" ","Enter"],qi="Select",[mu,vu,o3]=JU(qi),[ts,yW]=gr(qi,[o3,fT]),yu=fT(),[i3,bi]=ts(qi),[a3,s3]=ts(qi),ST=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:o,onOpenChange:i,value:s,defaultValue:l,onValueChange:u,dir:h,name:p,autoComplete:g,disabled:C,required:w,form:x}=t,y=yu(e),[b,E]=m.useState(null),[T,N]=m.useState(null),[P,_]=m.useState(!1),D=wg(h),[H,K]=li({prop:r,defaultProp:o??!1,onChange:i,caller:qi}),[ee,W]=li({prop:s,defaultProp:l,onChange:u,caller:qi}),de=m.useRef(null),se=b?x||!!b.closest("form"):!0,[fe,q]=m.useState(new Set),Z=Array.from(fe).map(Y=>Y.props.value).join(";");return d.jsx(BB,{...y,children:d.jsxs(i3,{required:w,scope:e,trigger:b,onTriggerChange:E,valueNode:T,onValueNodeChange:N,valueNodeHasChildren:P,onValueNodeHasChildrenChange:_,contentId:Oo(),value:ee,onValueChange:W,open:H,onOpenChange:K,dir:D,triggerPointerDownPosRef:de,disabled:C,children:[d.jsx(mu.Provider,{scope:e,children:d.jsx(a3,{scope:t.__scopeSelect,onNativeOptionAdd:m.useCallback(Y=>{q(oe=>new Set(oe).add(Y))},[]),onNativeOptionRemove:m.useCallback(Y=>{q(oe=>{const Q=new Set(oe);return Q.delete(Y),Q})},[]),children:n})}),se?d.jsxs(GT,{"aria-hidden":!0,required:w,tabIndex:-1,name:p,autoComplete:g,value:ee,onChange:Y=>W(Y.target.value),disabled:C,form:x,children:[ee===void 0?d.jsx("option",{value:""}):null,Array.from(fe)]},Z):null]})})};ST.displayName=qi;var _T="SelectTrigger",ET=m.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,i=yu(n),s=bi(_T,n),l=s.disabled||r,u=rt(e,s.onTriggerChange),h=vu(n),p=m.useRef("touch"),[g,C,w]=WT(y=>{const b=h().filter(N=>!N.disabled),E=b.find(N=>N.value===s.value),T=qT(b,y,E);T!==void 0&&s.onValueChange(T.value)}),x=y=>{l||(s.onOpenChange(!0),w()),y&&(s.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return d.jsx(zB,{asChild:!0,...i,children:d.jsx(mn.button,{type:"button",role:"combobox","aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":"none",dir:s.dir,"data-state":s.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":jT(s.value)?"":void 0,...o,ref:u,onClick:Ue(o.onClick,y=>{y.currentTarget.focus(),p.current!=="mouse"&&x(y)}),onPointerDown:Ue(o.onPointerDown,y=>{p.current=y.pointerType;const b=y.target;b.hasPointerCapture(y.pointerId)&&b.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(x(y),y.preventDefault())}),onKeyDown:Ue(o.onKeyDown,y=>{const b=g.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&C(y.key),!(b&&y.key===" ")&&n3.includes(y.key)&&(x(),y.preventDefault())})})})});ET.displayName=_T;var TT="SelectValue",AT=m.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:i,placeholder:s="",...l}=t,u=bi(TT,n),{onValueNodeHasChildrenChange:h}=u,p=i!==void 0,g=rt(e,u.onValueNodeChange);return rn(()=>{h(p)},[h,p]),d.jsx(mn.span,{...l,ref:g,style:{pointerEvents:"none"},children:jT(u.value)?d.jsx(d.Fragment,{children:s}):i})});AT.displayName=TT;var c3="SelectIcon",IT=m.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return d.jsx(mn.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});IT.displayName=c3;var l3="SelectPortal",kT=t=>d.jsx(bT,{asChild:!0,...t});kT.displayName=l3;var Yi="SelectContent",NT=m.forwardRef((t,e)=>{const n=bi(Yi,t.__scopeSelect),[r,o]=m.useState();if(rn(()=>{o(new DocumentFragment)},[]),!n.open){const i=r;return i?_a.createPortal(d.jsx(PT,{scope:t.__scopeSelect,children:d.jsx(mu.Slot,{scope:t.__scopeSelect,children:d.jsx("div",{children:t.children})})}),i):null}return d.jsx(OT,{...t,ref:e})});NT.displayName=Yi;var Gr=10,[PT,xi]=ts(Yi),d3="SelectContentImpl",u3=QE("SelectContent.RemoveScroll"),OT=m.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:i,onPointerDownOutside:s,side:l,sideOffset:u,align:h,alignOffset:p,arrowPadding:g,collisionBoundary:C,collisionPadding:w,sticky:x,hideWhenDetached:y,avoidCollisions:b,...E}=t,T=bi(Yi,n),[N,P]=m.useState(null),[_,D]=m.useState(null),H=rt(e,z=>P(z)),[K,ee]=m.useState(null),[W,de]=m.useState(null),se=vu(n),[fe,q]=m.useState(!1),Z=m.useRef(!1);m.useEffect(()=>{if(N)return hb(N)},[N]),JC();const Y=m.useCallback(z=>{const[ce,...Ae]=se().map(ne=>ne.ref.current),[Ce]=Ae.slice(-1),Ne=document.activeElement;for(const ne of z)if(ne===Ne||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===ce&&_&&(_.scrollTop=0),ne===Ce&&_&&(_.scrollTop=_.scrollHeight),ne==null||ne.focus(),document.activeElement!==Ne))return},[se,_]),oe=m.useCallback(()=>Y([K,N]),[Y,K,N]);m.useEffect(()=>{fe&&oe()},[fe,oe]);const{onOpenChange:Q,triggerPointerDownPosRef:X}=T;m.useEffect(()=>{if(N){let z={x:0,y:0};const ce=Ce=>{var Ne,ne;z={x:Math.abs(Math.round(Ce.pageX)-(((Ne=X.current)==null?void 0:Ne.x)??0)),y:Math.abs(Math.round(Ce.pageY)-(((ne=X.current)==null?void 0:ne.y)??0))}},Ae=Ce=>{z.x<=10&&z.y<=10?Ce.preventDefault():N.contains(Ce.target)||Q(!1),document.removeEventListener("pointermove",ce),X.current=null};return X.current!==null&&(document.addEventListener("pointermove",ce),document.addEventListener("pointerup",Ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ce),document.removeEventListener("pointerup",Ae,{capture:!0})}}},[N,Q,X]),m.useEffect(()=>{const z=()=>Q(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[Q]);const[$,te]=WT(z=>{const ce=se().filter(Ne=>!Ne.disabled),Ae=ce.find(Ne=>Ne.ref.current===document.activeElement),Ce=qT(ce,z,Ae);Ce&&setTimeout(()=>Ce.ref.current.focus())}),_e=m.useCallback((z,ce,Ae)=>{const Ce=!Z.current&&!Ae;(T.value!==void 0&&T.value===ce||Ce)&&(ee(z),Ce&&(Z.current=!0))},[T.value]),ke=m.useCallback(()=>N==null?void 0:N.focus(),[N]),xe=m.useCallback((z,ce,Ae)=>{const Ce=!Z.current&&!Ae;(T.value!==void 0&&T.value===ce||Ce)&&de(z)},[T.value]),Pe=r==="popper"?Cm:MT,Te=Pe===Cm?{side:l,sideOffset:u,align:h,alignOffset:p,arrowPadding:g,collisionBoundary:C,collisionPadding:w,sticky:x,hideWhenDetached:y,avoidCollisions:b}:{};return d.jsx(PT,{scope:n,content:N,viewport:_,onViewportChange:D,itemRefCallback:_e,selectedItem:K,onItemLeave:ke,itemTextRefCallback:xe,focusSelectedItem:oe,selectedItemText:W,position:r,isPositioned:fe,searchRef:$,children:d.jsx(Sp,{as:u3,allowPinchZoom:!0,children:d.jsx(oT,{asChild:!0,trapped:T.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:Ue(o,z=>{var ce;(ce=T.trigger)==null||ce.focus({preventScroll:!0}),z.preventDefault()}),children:d.jsx(eT,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:d.jsx(Pe,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:z=>z.preventDefault(),...E,...Te,onPlaced:()=>q(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:Ue(E.onKeyDown,z=>{const ce=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!ce&&z.key.length===1&&te(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let Ce=se().filter(Ne=>!Ne.disabled).map(Ne=>Ne.ref.current);if(["ArrowUp","End"].includes(z.key)&&(Ce=Ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const Ne=z.target,ne=Ce.indexOf(Ne);Ce=Ce.slice(ne+1)}setTimeout(()=>Y(Ce)),z.preventDefault()}})})})})})})});OT.displayName=d3;var f3="SelectItemAlignedPosition",MT=m.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,i=bi(Yi,n),s=xi(Yi,n),[l,u]=m.useState(null),[h,p]=m.useState(null),g=rt(e,H=>p(H)),C=vu(n),w=m.useRef(!1),x=m.useRef(!0),{viewport:y,selectedItem:b,selectedItemText:E,focusSelectedItem:T}=s,N=m.useCallback(()=>{if(i.trigger&&i.valueNode&&l&&h&&y&&b&&E){const H=i.trigger.getBoundingClientRect(),K=h.getBoundingClientRect(),ee=i.valueNode.getBoundingClientRect(),W=E.getBoundingClientRect();if(i.dir!=="rtl"){const Ne=W.left-K.left,ne=ee.left-Ne,Ve=H.left-ne,Qe=H.width+Ve,Ct=Math.max(Qe,K.width),Jt=window.innerWidth-Gr,bt=YE(ne,[Gr,Math.max(Gr,Jt-Ct)]);l.style.minWidth=Qe+"px",l.style.left=bt+"px"}else{const Ne=K.right-W.right,ne=window.innerWidth-ee.right-Ne,Ve=window.innerWidth-H.right-ne,Qe=H.width+Ve,Ct=Math.max(Qe,K.width),Jt=window.innerWidth-Gr,bt=YE(ne,[Gr,Math.max(Gr,Jt-Ct)]);l.style.minWidth=Qe+"px",l.style.right=bt+"px"}const de=C(),se=window.innerHeight-Gr*2,fe=y.scrollHeight,q=window.getComputedStyle(h),Z=parseInt(q.borderTopWidth,10),Y=parseInt(q.paddingTop,10),oe=parseInt(q.borderBottomWidth,10),Q=parseInt(q.paddingBottom,10),X=Z+Y+fe+Q+oe,$=Math.min(b.offsetHeight*5,X),te=window.getComputedStyle(y),_e=parseInt(te.paddingTop,10),ke=parseInt(te.paddingBottom,10),xe=H.top+H.height/2-Gr,Pe=se-xe,Te=b.offsetHeight/2,z=b.offsetTop+Te,ce=Z+Y+z,Ae=X-ce;if(ce<=xe){const Ne=de.length>0&&b===de[de.length-1].ref.current;l.style.bottom="0px";const ne=h.clientHeight-y.offsetTop-y.offsetHeight,Ve=Math.max(Pe,Te+(Ne?ke:0)+ne+oe),Qe=ce+Ve;l.style.height=Qe+"px"}else{const Ne=de.length>0&&b===de[0].ref.current;l.style.top="0px";const Ve=Math.max(xe,Z+y.offsetTop+(Ne?_e:0)+Te)+Ae;l.style.height=Ve+"px",y.scrollTop=ce-xe+y.offsetTop}l.style.margin=`${Gr}px 0`,l.style.minHeight=$+"px",l.style.maxHeight=se+"px",r==null||r(),requestAnimationFrame(()=>w.current=!0)}},[C,i.trigger,i.valueNode,l,h,y,b,E,i.dir,r]);rn(()=>N(),[N]);const[P,_]=m.useState();rn(()=>{h&&_(window.getComputedStyle(h).zIndex)},[h]);const D=m.useCallback(H=>{H&&x.current===!0&&(N(),T==null||T(),x.current=!1)},[N,T]);return d.jsx(p3,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:w,onScrollButtonChange:D,children:d.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:P},children:d.jsx(mn.div,{...o,ref:g,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});MT.displayName=f3;var h3="SelectPopperPosition",Cm=m.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Gr,...i}=t,s=yu(n);return d.jsx(VB,{...s,...i,ref:e,align:r,collisionPadding:o,style:{boxSizing:"border-box",...i.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Cm.displayName=h3;var[p3,bm]=ts(Yi,{}),xm="SelectViewport",RT=m.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,i=xi(xm,n),s=bm(xm,n),l=rt(e,i.onViewportChange),u=m.useRef(0);return d.jsxs(d.Fragment,{children:[d.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),d.jsx(mu.Slot,{scope:n,children:d.jsx(mn.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:Ue(o.onScroll,h=>{const p=h.currentTarget,{contentWrapper:g,shouldExpandOnScrollRef:C}=s;if(C!=null&&C.current&&g){const w=Math.abs(u.current-p.scrollTop);if(w>0){const x=window.innerHeight-Gr*2,y=parseFloat(g.style.minHeight),b=parseFloat(g.style.height),E=Math.max(y,b);if(E<x){const T=E+w,N=Math.min(x,T),P=T-N;g.style.height=N+"px",g.style.bottom==="0px"&&(p.scrollTop=P>0?P:0,g.style.justifyContent="flex-end")}}}u.current=p.scrollTop})})})]})});RT.displayName=xm;var DT="SelectGroup",[g3,m3]=ts(DT),v3=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Oo();return d.jsx(g3,{scope:n,id:o,children:d.jsx(mn.div,{role:"group","aria-labelledby":o,...r,ref:e})})});v3.displayName=DT;var LT="SelectLabel",FT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=m3(LT,n);return d.jsx(mn.div,{id:o.id,...r,ref:e})});FT.displayName=LT;var wu="SelectItem",[y3,$T]=ts(wu),HT=m.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:i,...s}=t,l=bi(wu,n),u=xi(wu,n),h=l.value===r,[p,g]=m.useState(i??""),[C,w]=m.useState(!1),x=rt(e,T=>{var N;return(N=u.itemRefCallback)==null?void 0:N.call(u,T,r,o)}),y=Oo(),b=m.useRef("touch"),E=()=>{o||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return d.jsx(y3,{scope:n,value:r,disabled:o,textId:y,isSelected:h,onItemTextChange:m.useCallback(T=>{g(N=>N||((T==null?void 0:T.textContent)??"").trim())},[]),children:d.jsx(mu.ItemSlot,{scope:n,value:r,disabled:o,textValue:p,children:d.jsx(mn.div,{role:"option","aria-labelledby":y,"data-highlighted":C?"":void 0,"aria-selected":h&&C,"data-state":h?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...s,ref:x,onFocus:Ue(s.onFocus,()=>w(!0)),onBlur:Ue(s.onBlur,()=>w(!1)),onClick:Ue(s.onClick,()=>{b.current!=="mouse"&&E()}),onPointerUp:Ue(s.onPointerUp,()=>{b.current==="mouse"&&E()}),onPointerDown:Ue(s.onPointerDown,T=>{b.current=T.pointerType}),onPointerMove:Ue(s.onPointerMove,T=>{var N;b.current=T.pointerType,o?(N=u.onItemLeave)==null||N.call(u):b.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Ue(s.onPointerLeave,T=>{var N;T.currentTarget===document.activeElement&&((N=u.onItemLeave)==null||N.call(u))}),onKeyDown:Ue(s.onKeyDown,T=>{var P;((P=u.searchRef)==null?void 0:P.current)!==""&&T.key===" "||(r3.includes(T.key)&&E(),T.key===" "&&T.preventDefault())})})})})});HT.displayName=wu;var yc="SelectItemText",UT=m.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...i}=t,s=bi(yc,n),l=xi(yc,n),u=$T(yc,n),h=s3(yc,n),[p,g]=m.useState(null),C=rt(e,E=>g(E),u.onItemTextChange,E=>{var T;return(T=l.itemTextRefCallback)==null?void 0:T.call(l,E,u.value,u.disabled)}),w=p==null?void 0:p.textContent,x=m.useMemo(()=>d.jsx("option",{value:u.value,disabled:u.disabled,children:w},u.value),[u.disabled,u.value,w]),{onNativeOptionAdd:y,onNativeOptionRemove:b}=h;return rn(()=>(y(x),()=>b(x)),[y,b,x]),d.jsxs(d.Fragment,{children:[d.jsx(mn.span,{id:u.textId,...i,ref:C}),u.isSelected&&s.valueNode&&!s.valueNodeHasChildren?_a.createPortal(i.children,s.valueNode):null]})});UT.displayName=yc;var BT="SelectItemIndicator",zT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return $T(BT,n).isSelected?d.jsx(mn.span,{"aria-hidden":!0,...r,ref:e}):null});zT.displayName=BT;var Sm="SelectScrollUpButton",w3=m.forwardRef((t,e)=>{const n=xi(Sm,t.__scopeSelect),r=bm(Sm,t.__scopeSelect),[o,i]=m.useState(!1),s=rt(e,r.onScrollButtonChange);return rn(()=>{if(n.viewport&&n.isPositioned){let l=function(){const h=u.scrollTop>0;i(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),o?d.jsx(VT,{...t,ref:s,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});w3.displayName=Sm;var _m="SelectScrollDownButton",C3=m.forwardRef((t,e)=>{const n=xi(_m,t.__scopeSelect),r=bm(_m,t.__scopeSelect),[o,i]=m.useState(!1),s=rt(e,r.onScrollButtonChange);return rn(()=>{if(n.viewport&&n.isPositioned){let l=function(){const h=u.scrollHeight-u.clientHeight,p=Math.ceil(u.scrollTop)<h;i(p)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),o?d.jsx(VT,{...t,ref:s,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});C3.displayName=_m;var VT=m.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=t,i=xi("SelectScrollButton",n),s=m.useRef(null),l=vu(n),u=m.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return m.useEffect(()=>()=>u(),[u]),rn(()=>{var p;const h=l().find(g=>g.ref.current===document.activeElement);(p=h==null?void 0:h.ref.current)==null||p.scrollIntoView({block:"nearest"})},[l]),d.jsx(mn.div,{"aria-hidden":!0,...o,ref:e,style:{flexShrink:0,...o.style},onPointerDown:Ue(o.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(r,50))}),onPointerMove:Ue(o.onPointerMove,()=>{var h;(h=i.onItemLeave)==null||h.call(i),s.current===null&&(s.current=window.setInterval(r,50))}),onPointerLeave:Ue(o.onPointerLeave,()=>{u()})})}),b3="SelectSeparator",KT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return d.jsx(mn.div,{"aria-hidden":!0,...r,ref:e})});KT.displayName=b3;var Em="SelectArrow",x3=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=yu(n),i=bi(Em,n),s=xi(Em,n);return i.open&&s.position==="popper"?d.jsx(KB,{...o,...r,ref:e}):null});x3.displayName=Em;var S3="SelectBubbleInput",GT=m.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=m.useRef(null),i=rt(r,o),s=oS(e);return m.useEffect(()=>{const l=o.current;if(!l)return;const u=window.HTMLSelectElement.prototype,p=Object.getOwnPropertyDescriptor(u,"value").set;if(s!==e&&p){const g=new Event("change",{bubbles:!0});p.call(l,e),l.dispatchEvent(g)}},[s,e]),d.jsx(mn.select,{...n,style:{...xT,...n.style},ref:i,defaultValue:e})});GT.displayName=S3;function jT(t){return t===""||t===void 0}function WT(t){const e=gn(t),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(s=>{const l=n.current+s;e(l),function u(h){n.current=h,window.clearTimeout(r.current),h!==""&&(r.current=window.setTimeout(()=>u(""),1e3))}(l)},[e]),i=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,i]}function qT(t,e,n){const o=e.length>1&&Array.from(e).every(h=>h===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let s=_3(t,Math.max(i,0));o.length===1&&(s=s.filter(h=>h!==n));const u=s.find(h=>h.textValue.toLowerCase().startsWith(o.toLowerCase()));return u!==n?u:void 0}function _3(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var E3=ST,YT=ET,T3=AT,A3=IT,I3=kT,JT=NT,k3=RT,QT=FT,XT=HT,N3=UT,P3=zT,ZT=KT;const Tm=E3,Am=T3,Cu=m.forwardRef(({className:t,children:e,...n},r)=>d.jsxs(YT,{ref:r,className:ze("flex h-9 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50",t),...n,children:[e,d.jsx(A3,{asChild:!0,children:d.jsx(UD,{className:"h-4 w-4 opacity-50"})})]}));Cu.displayName=YT.displayName;const bu=m.forwardRef(({className:t,children:e,position:n="popper",...r},o)=>d.jsx(I3,{children:d.jsx(JT,{ref:o,className:ze("relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,...r,children:d.jsx(k3,{className:ze("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e})})}));bu.displayName=JT.displayName;const O3=m.forwardRef(({className:t,...e},n)=>d.jsx(QT,{ref:n,className:ze("px-2 py-1.5 text-sm font-semibold",t),...e}));O3.displayName=QT.displayName;const Ji=m.forwardRef(({className:t,children:e,...n},r)=>d.jsxs(XT,{ref:r,className:ze("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[d.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(P3,{children:d.jsx(Fx,{className:"h-4 w-4"})})}),d.jsx(N3,{children:e})]}));Ji.displayName=XT.displayName;const M3=m.forwardRef(({className:t,...e},n)=>d.jsx(ZT,{ref:n,className:ze("-mx-1 my-1 h-px bg-muted",t),...e}));M3.displayName=ZT.displayName;const Im=[{value:"VIEW_DOCUMENT",label:"Chỉ xem"},{value:"EDIT_DOCUMENT",label:"Chỉnh sửa"},{value:"DOWNLOAD_DOCUMENT",label:"Tải xuống"}];function R3({onClose:t,open:e,file:n,apiBaseUrl:r,rootUrlHostApi:o}){const[i,s]=M.useState("users"),[l,u]=M.useState(""),[h,p]=M.useState(""),[g,C]=M.useState(""),[w,x]=M.useState(""),[y,b]=M.useState(Kr.VIEW_DOCUMENT),[E,T]=M.useState([]),{users:N,groups:P,sharedUsers:_,sharedGroups:D,fetchData:H,loading:K,postGranted:ee,loadingGrandted:W,setSharedGroups:de,setSharedUsers:se}=HH(r,o),fe=Vi(),q=n?n.key:"",Z=N.filter(z=>{var ce;return(fe==null?void 0:fe.id)!==z.id&&(z.username.toLowerCase().includes(l.toLowerCase())||((ce=z.email)==null?void 0:ce.toLowerCase().includes(l.toLowerCase())))}),Y=P.filter(z=>z.groupname.toLowerCase().includes(h.toLowerCase())),oe=_.filter(z=>{var ce,Ae;return((ce=z.username)==null?void 0:ce.toLowerCase().includes(g.toLowerCase()))||((Ae=z.email)==null?void 0:Ae.toLowerCase().includes(g.toLowerCase()))}),Q=D.filter(z=>{var ce;return(ce=z.groupname)==null?void 0:ce.toLowerCase().includes(w.toLowerCase())}),X=z=>{b(z),T(ce=>ce.map(Ae=>({...Ae,permissions:z})))},$=()=>{i==="users"?(u(""),C("")):(p(""),x(""),s("users")),T([]),b(Kr.VIEW_DOCUMENT)};M.useEffect(()=>{e?H(q):$()},[e,q]);const te=z=>{z!==i&&(i==="users"?(u(""),C("")):(p(""),x(""))),s(z)},_e=z=>{n&&T(ce=>{if(ce.find(ne=>ne.userId===z))return ce.filter(ne=>ne.userId!==z);const Ne={path:n.key+n.name,permissions:y,userId:z,grandtedBy:fe==null?void 0:fe.id};return[...ce,Ne]})},ke=z=>{if(!n)return;const ce=z.groupname;T(Ae=>{if(Ae.find(Ve=>Ve.groupname===ce))return Ae.filter(Ve=>Ve.groupname!==ce);const ne={path:n.key+n.name,permissions:y,groupname:ce,groupId:z.id,grandtedBy:fe==null?void 0:fe.id,users:z.users};return[...Ae,ne]})},xe=async(z,ce,Ae)=>{const Ce={...z,permissions:ce};T(Ne=>{const ne=Ne.map(Qe=>Qe.id===Ce.id?Ce:Qe);return Ne.some(Qe=>Qe.id===Ce.id)||ne.push(Ce),ne}),Ae==="users"?se(Ne=>Ne.map(ne=>ne.id===z.id?Ce:ne)):de(Ne=>Ne.map(ne=>ne.id===z.id?Ce:ne))},Pe=async()=>{if(n){const z=(n==null?void 0:n.key)||""+(n==null?void 0:n.name),ce=await ee(z,fe==null?void 0:fe.id,E);(ce==null?void 0:ce.status)==200&&T([])}},Te="flex-1 min-h-0 overflow-y-auto border rounded-lg px-3 py-2 bg-background shadow-sm";return n?d.jsx(ar,{open:e,onOpenChange:t,children:d.jsxs(jn,{className:"max-w-5xl h-[70vh] flex flex-col overflow-hidden",children:[d.jsx(Wn,{children:d.jsxs(qn,{className:"text-lg font-semibold",children:["Chia sẻ tài liệu: ",n.name]})}),d.jsxs(Sg,{defaultValue:"users",className:"mt-6 flex-1 flex flex-col overflow-hidden",children:[d.jsxs(Yd,{className:"grid grid-cols-2 w-1/2 mx-auto mb-4 bg-muted rounded-lg",children:[d.jsx(Ki,{value:"users",className:"py-2",onClick:()=>te("users"),children:"Người dùng"}),d.jsx(Ki,{value:"groups",className:"py-2",onClick:()=>te("groups"),children:"Nhóm"})]}),d.jsx(Gi,{value:"users",className:"flex-1 h-full min-h-0 overflow-hidden",children:d.jsxs("div",{className:"grid grid-cols-2 gap-6 h-full",children:[d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Chia sẻ với người dùng:"}),d.jsx(Yn,{placeholder:"Tìm người dùng...",className:"mb-3 border-input bg-background shadow-sm",value:l,onChange:z=>u(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Z.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Không tìm thấy người dùng."}):d.jsx("ul",{className:"space-y-2",children:Z.map(z=>d.jsx("li",{onClick:()=>_e(z.id),className:"flex flex-col space-y-1 cursor-pointer hover:bg-accent p-2 rounded-md transition-colors",children:d.jsxs("div",{className:"flex items-center space-x-3",children:[d.jsx(oc,{id:`user-${z.id}`,checked:!!E.find(ce=>ce.userId===z.id)}),d.jsxs(mr,{className:"flex-1",children:[d.jsx("p",{className:"font-medium",children:z.username}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.email}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.groupname})]})]})},z.id))})})]}),d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Đã chia sẻ với người dùng:"}),d.jsx(Yn,{placeholder:"Tìm người dùng đã chia sẻ...",className:"mb-3 border-input bg-background shadow-sm",value:g,onChange:z=>C(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):oe.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Chưa chia sẻ với người dùng nào."}):d.jsx("ul",{className:"space-y-2",children:oe.map(z=>d.jsxs("li",{className:"flex items-center justify-between gap-4 hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsxs("div",{className:"flex flex-col",children:[d.jsx("p",{className:"font-medium",children:z.username}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.email}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.groupname})]}),d.jsxs(Tm,{value:z.permissions,onValueChange:ce=>xe(z,ce,"users"),disabled:z.permissions===Kr.OWNER_DOCUMENT,children:[d.jsx(Cu,{className:"w-[120px]",children:d.jsx(Am,{placeholder:"Chọn quyền"})}),d.jsxs(bu,{children:[Im.map(ce=>d.jsx(Ji,{value:ce.value,children:ce.label},ce.value)),z.permissions===Kr.OWNER_DOCUMENT&&d.jsx(Ji,{value:Kr.OWNER_DOCUMENT,children:"Chủ sở hữu"},Kr.OWNER_DOCUMENT),d.jsx(Ji,{value:"None",children:"Thu hồi"},"None")]})]})]},z.id))})})]})]})}),d.jsx(Gi,{value:"groups",className:"flex-1 h-full min-h-0 overflow-hidden",children:d.jsxs("div",{className:"grid grid-cols-2 gap-6 h-full",children:[d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Chia sẻ với nhóm:"}),d.jsx(Yn,{placeholder:"Tìm nhóm...",className:"mb-3 border-input bg-background shadow-sm",value:h,onChange:z=>p(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Y.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Không tìm thấy nhóm."}):d.jsx("ul",{className:"space-y-2",children:Y.map(z=>d.jsxs("li",{onClick:()=>ke(z),className:"flex items-center space-x-3 cursor-pointer hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsx(oc,{id:`group-${z.groupname}`,checked:!!E.find(ce=>ce.groupname===z.groupname)}),d.jsxs(mr,{className:"font-medium",children:[d.jsx("p",{className:"font-medium",children:z.groupname}),d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Số lượng: ",z.users||0]})]})]},z.groupname))})})]}),d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Đã chia sẻ với nhóm:"}),d.jsx(Yn,{placeholder:"Tìm nhóm đã chia sẻ...",className:"mb-3 border-input bg-background shadow-sm",value:w,onChange:z=>x(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Q.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Chưa chia sẻ với nhóm nào."}):d.jsx("ul",{className:"space-y-2",children:Q.map(z=>d.jsxs("li",{className:"flex items-center justify-between gap-4 hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsxs("div",{className:"flex flex-col",children:[d.jsx("p",{className:"font-medium",children:z.groupname}),d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Số lượng: ",z.users||0]})]}),d.jsxs(Tm,{value:z.permissions,onValueChange:ce=>xe(z,ce,"groups"),children:[d.jsx(Cu,{className:"w-[120px]",children:d.jsx(Am,{placeholder:"Chọn quyền"})}),d.jsxs(bu,{children:[Im.map(ce=>d.jsx(Ji,{value:ce.value,children:ce.label},ce.value)),d.jsx(Ji,{value:"None",children:"Thu hồi"},"None")]})]})]},z.groupname))})})]})]})})]}),d.jsxs("div",{className:"mt-4 bg-muted/50 p-4 rounded-lg",children:[d.jsx(mr,{className:"font-medium mb-2 block",children:"Phân quyền:"}),d.jsxs(Tm,{value:y,onValueChange:X,children:[d.jsx(Cu,{className:"w-1/2 border border-input bg-background shadow-sm hover:bg-accent",children:d.jsx(Am,{placeholder:"Chọn quyền truy cập"})}),d.jsx(bu,{children:Im.map(z=>d.jsx(Ji,{value:z.value,className:"flex items-center gap-2",children:z.label}))})]})]}),d.jsxs(Hr,{children:[d.jsx(He,{variant:"outline",onClick:t,children:"Huỷ"}),d.jsx(He,{variant:"default",onClick:Pe,disabled:E.length===0||W,className:"w-[120px] justify-center",children:W?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):"Lưu thay đổi"})]})]})}):null}const D3={},L3="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",F3="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",$3="https://www.googleapis.com/auth/drive";Do(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Do.isRetryableError(t)&&t.config.method==="get"});const Qn={current:!1},e0="crawl:jobs",ns="crawl:current_job",H3=t=>{const[e,n]=M.useState(null),[r,o]=M.useState(0);return M.useEffect(()=>{const i=localStorage.getItem(ns);if(i){const s=JSON.parse(i);n(s),s!=null&&s.startTime&&o(Math.floor((Date.now()-s.startTime)/1e3))}},[]),M.useEffect(()=>{if(!(e!=null&&e.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(i)},[e==null?void 0:e.startTime]),M.useEffect(()=>{if(!(e!=null&&e.id))return;const i=async()=>{try{const u=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:u};return localStorage.setItem(ns,JSON.stringify(p)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(ns)},100),p})}catch(l){console.error("Error polling job status:",l)}},s=setInterval(i,3e3);return i(),()=>clearInterval(s)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:i=>{i&&!i.startTime&&(i.startTime=Date.now()),n(i),i?localStorage.setItem(ns,JSON.stringify(i)):localStorage.removeItem(ns)}}},xu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(s=>{n.push(s.key),s.isFolder&&r(s.key)})};return r(e),n},U3=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...xu(t,o.key))}),n},B3=(t,e,n=[],r,o,i,s,l,u,h)=>{const[p,g]=M.useState({}),[C,w]=M.useState(!1),[x,y]=M.useState(null),[b,E]=M.useState(0),T=M.useRef(e);M.useEffect(()=>{T.current=e},[e]);const N=async()=>{var _;w(!0);try{const D=Vi(),H=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:T.current,userId:(D==null?void 0:D.id)||"",groupId:((_=D==null?void 0:D.group)==null?void 0:_.id)||"",groupname:(D==null?void 0:D.groupname)||""},timeout:3e5}),K=[];Md.forEach(H.data,(ee,W)=>{l!=null&&l.has(W)&&Md.forEach(ee,de=>{(u==null?void 0:u.current[de.key])!==!1&&K.push(de.key)})}),K.length&&(h==null||h(ee=>{const W=new Set(ee);return K.forEach(de=>W.add(de)),W})),g(H.data),y(null)}catch(D){y(D instanceof Error?D:new Error("Failed to fetch files"))}finally{w(!1),E(0),i("")}},P=async _=>{var D,H;try{if(!_)return;w(!0);const K=await Le.get(`${t}/api/search-db?query=${_}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return g({[e]:((D=K==null?void 0:K.data)==null?void 0:D.result)||[]}),E(((H=K==null?void 0:K.data)==null?void 0:H.estimatedTotalHits)||0),K}catch(K){y(K instanceof Error?K:new Error("Failed to fetch files"))}finally{w(!1)}};return M.useEffect(()=>{!r&&!C&&N(),r&&!C&&P(r)},[r,o]),{data:p,isLoading:C,error:x,estimatedTotalHits:b,refetch:N}},Qi=t=>{var r,o,i;const e=((i=(o=(r=t==null?void 0:t.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(e||"")},z3={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:D3.VITE_ONE_DRIVE_REDIRECT_URI||"https://s3-explorer.cmcts1.studio.ai.vn/sharepoint/redirect"}},V3=new hp(z3),km={[Kr.VIEW_DOCUMENT]:1,[Kr.DOWNLOAD_DOCUMENT]:2,[Kr.EDIT_DOCUMENT]:10,[Kr.OWNER_DOCUMENT]:100},Xi=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=10:!1},K3=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=2:!1},G3=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=1:!1},j3=M.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3000",rootPrefix:n="",rootUrlHostApi:r="http://localhost:3003/api/v1",asSelector:o=!1,onSelected:i=h=>console.log("Đã chọn:",h),displayPrefixes:s,preSelectedFiles:l,idCreator:u})=>{var In;const[h,p]=M.useState([]),[g,C]=M.useState(""),[w,x]=M.useState(new Set(l)),[y,b]=M.useState(n),[E,T]=M.useState(""),[N,P]=M.useState(!1),[_,D]=M.useState(""),[H,K]=M.useState(!1),[ee,W]=M.useState(null),[de,se]=M.useState(null),[fe,q]=M.useState(!1),[Z,Y]=M.useState(!1),[,oe]=M.useState(null),Q=M.useRef(null),{toast:X}=dc(),[$,te]=M.useState(null),[_e,ke]=M.useState(null),[xe,Pe]=M.useState(null),[Te,z]=M.useState(""),[ce,Ae]=M.useState(!1),[Ce,Ne]=M.useState(!1),[ne,Ve]=M.useState(new Set),[Qe,Ct]=M.useState(""),[Jt,bt]=M.useState(!1),[an,zt]=M.useState(!1),[$n,Kt]=M.useState("rename"),[L,J]=M.useState(!1),[U,ae]=M.useState(""),[ye,he]=M.useState("1"),[Ee,Xe]=M.useState(!1),[ft,xt]=M.useState(!1),[Co,Qt]=M.useState(!1),[vn,qr]=M.useState(!1),[Gt,dr]=M.useState(1),[Yr,ea]=M.useState(!1),{currentJob:Je,elapsedTime:Bo,setCurrentJob:_c}=H3(e),[bo,ta]=M.useState(null),[na,os]=M.useState(""),[Iu,ra]=M.useState(!1),[is,ku]=M.useState(""),[Ec,Nu]=M.useState(!1),[Tc,Pu]=M.useState(!1),[as,Ou]=M.useState([]),[oa,Mu]=M.useState(!1),[ss,Lm]=M.useState(""),zo=M.useRef({}),[Ac,Ic]=M.useState(null),Fm=async A=>{Pu(!0);try{const O=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${A}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});O.status===200&&Ou(O.data.knowledgeBase.chatflows.map(G=>({...G,KnowledgeBaseId:O.data.knowledgeBase.knowledge_base_id})))}catch{}finally{Pu(!1)}};M.useEffect(()=>{is&&r&&Fm(is)},[is]),M.useEffect(()=>{console.log("pre selected files",l)},[l]);const[Mt,kc]=M.useState(null),[S0,$m]=M.useState(!1),[Nc,Pc]=M.useState(!1),[ia,cs]=M.useState(!1),[Ru,Du]=M.useState([]),[Oc,Mc]=M.useState([]),[aa,Rc]=M.useState([{id:"root",name:"OneDrive"}]),[Hm,ls]=M.useState(!1),[ds,Dc]=M.useState([]),[Lu,Vo]=M.useState(!1),[us,Lc]=M.useState([]),[Fc,fs]=M.useState([]),[hs,Fu]=M.useState([]),[$c,sa]=M.useState([{id:"root",name:"SharePoint"}]),[xo,ca]=M.useState(!1),[Hc,Uc]=M.useState([]),[gt,Jr]=M.useState(null),[$u,la]=M.useState(!1),[Um,da]=M.useState(!1),Hu=new URL(window.location.href).searchParams.get("prefix")||""||E||n,[_0,Vm]=M.useState(null),{data:Tn,isLoading:Ko,error:Km,estimatedTotalHits:ua,refetch:dn}=B3(e,Hu,s,g,Gt,C,u,w,zo,x),[Bc,Cr]=M.useState(!1),zc=M.useRef(null),Vc=Vi(),$t=(()=>{const A=localStorage.getItem("dataLogin");try{if(A){const O=JSON.parse(A);return(O==null?void 0:O.user)??null}}catch{return null}return null})();M.useEffect(()=>{if(!Bc)return;function A(O){zc.current&&!zc.current.contains(O.target)&&Cr(!1)}return document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[Bc]);const Gm=async()=>{try{const A=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:O}=A.data,G=window.open(O,"SharePoint Login","width=600,height=600");if(!G)throw new Error("Không thể mở cửa sổ pop-up");G.focus();const pe=setInterval(()=>{try{if(G.closed){clearInterval(pe);return}const be=G.location.href;if(be.includes("code=")){const Ie=new URL(be).searchParams.get("code");Ie&&(At(Ie),G.close(),clearInterval(pe))}}catch(be){be instanceof Error&&!be.message.includes("cross-origin")&&console.error("SharePoint login error:",be)}},1e3)}catch(A){st.error("Lỗi khi đăng nhập SharePoint: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},jm=async()=>{try{Lc([]),sa([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),X({title:"Success",description:"Logged out from SharePoint"})}catch(A){console.error("Error logging out from SharePoint:",A),X({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},At=async A=>{try{const O=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:A,userId:"1"}),{accessToken:G}=O.data;localStorage.setItem("sharepoint_access_token",G),Pc(!0),ca(!0)}catch(O){console.error("❌ Error fetching SharePoint access token:",O),X({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},It=async()=>{try{Vo(!0);const O=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map(G=>{const pe=new URL(G.webUrl);return{id:G.id,name:G.name,description:G.description,hostname:G.hostname||pe.hostname,sitePath:G.sitePath||pe.pathname.replace(/^\/+/,"")}});console.log("data",O),Uc(O),Vo(!1)}catch(A){console.error("❌ Error fetching SharePoint sites:",A),X({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),Vo(!1)}},Wm=async A=>{Jr(A),console.log(A),await ps("root",A.name,A.hostname||"",A.sitePath||"")},ps=async(A,O,G,pe)=>{try{Vo(!0);const Ie=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:A,userId:"1",hostname:G,sitePath:pe})).data.files.map(Me=>({id:Me.id,name:Me.name,size:Me.size??0,lastModified:Me.lastModifiedDateTime?new Date(Me.lastModifiedDateTime):new Date,contentType:Me.mimeType??void 0,isFolder:Me.type==="folder",parentId:Me.parentId??""}));fs(Ie.filter(Me=>Me.isFolder)),Lc(Ie.filter(Me=>!Me.isFolder)),ca(!0),sa(Me=>Me.some(jt=>jt.id===A)?Me:[...Me,{id:A,name:O==="root"?"SharePoint":O}]),Vo(!1)}catch(be){console.error("❌ Error fetching SharePoint files:",be),X({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),Vo(!1)}},qm=A=>{Fu(O=>O.some(pe=>pe.id===A.id)?O.filter(pe=>pe.id!==A.id):[...O,{id:A.id,name:A.name,size:A.size,lastModified:A.lastModified,contentType:A.contentType,isFolder:A.isFolder,parentId:A.parentId}])},Ym=A=>{var G;sa(pe=>pe.slice(0,A+1));const O=(G=$c[A])==null?void 0:G.id;O&&ps(O,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},Jm=async(A,O)=>{const G=localStorage.getItem("sharepoint_access_token");if(!G){st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const pe=st.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};A.forEach(Me=>{Me.isFolder?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-sharepoint-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),ca(!1)}catch(be){console.error("Lỗi khi đồng bộ file từ SharePoint:",be),st.update(pe,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},Uu=()=>{ca(!1),Lc([]),Fu([]),sa([{id:"root",name:"SharePoint"}])};M.useEffect(()=>{if(xo){const O=new URLSearchParams(window.location.search).get("code");O&&(At(O),window.history.replaceState({},document.title,window.location.pathname))}},[xo]),M.useEffect(()=>{V3.initialize().then(()=>{$m(!0)}).catch(A=>console.error("❌ Lỗi khởi tạo MSAL:",A))},[]),M.useEffect(()=>{Bu()},[]);async function Bu(){localStorage.getItem("onedrive_access_token")&&Pc(!0)}const zu=A=>{Dc(O=>O.some(pe=>pe.id===A.id)?O.filter(pe=>pe.id!==A.id):[...O,{id:A.id,name:A.name,size:A.size,lastModified:A.lastModified,contentType:A.contentType,isFolder:A.isFolder,parentId:A.parentId}])};function Xt(A){if(A===0)return"0 B";const O=1024,G=["B","KB","MB","GB","TB"],pe=Math.floor(Math.log(A)/Math.log(O));return parseFloat((A/Math.pow(O,pe)).toFixed(1))+" "+G[pe]}function Kc(A){const O=new Date(A);return O.toLocaleDateString()+" "+O.toLocaleTimeString()}const Go=async()=>{try{const A=await Le.get(`${e}/api/login-one-drive`),{loginUrl:O}=A.data,G=window.open(O,"OneDrive Login","width=600,height=600");if(!G)throw new Error("Không thể mở cửa sổ pop-up");G.focus();const pe=setInterval(()=>{try{if(G.closed){clearInterval(pe);return}const be=G.location.href;if(be.includes("code=")){const Ie=new URL(be).searchParams.get("code");Ie&&(Gc(Ie),G.close(),clearInterval(pe))}}catch(be){be instanceof Error&&!be.message.includes("cross-origin")&&console.error("OneDrive login error:",be)}},1e3)}catch(A){st.error("Lỗi khi đăng nhập OneDrive: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},Vu=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),st.success("Đã đăng xuất khỏi OneDrive"),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin)}catch(A){st.error("Lỗi khi đăng xuất OneDrive: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},Gc=async A=>{try{const G=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:A,userId:"1"}),{accessToken:pe}=G.data;localStorage.setItem("onedrive_access_token",pe),Pc(!0),cs(!0),await yn("root","One Drive")}catch(O){console.error("❌ Lỗi khi lấy Access Token:",O)}},yn=async(A,O)=>{try{ls(!0);const be=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:A,userId:"1"})).data.map(Ie=>({id:Ie.id,name:Ie.name,size:Ie.size??0,lastModified:Ie.lastModifiedDateTime?new Date(Ie.lastModifiedDateTime):new Date,contentType:Ie.mimeType??void 0,isFolder:Ie.type==="folder",parentId:Ie.parentId??""}));Du(be.filter(Ie=>Ie.isFolder)),Mc(be.filter(Ie=>!Ie.isFolder)),cs(!0),Rc(Ie=>Ie.some(Me=>Me.id===A)?Ie:[...Ie,{id:A,name:O==="root"?"OneDrive":O}]),ls(!1)}catch(G){console.error("Lỗi lấy danh sách file:",G),ls(!1)}},Ku=A=>{if(A===aa.length-1)return;const O=aa[A];O&&(Rc(aa.slice(0,A+1)),yn(O.id,O.name))},Gu=async(A,O)=>{const G=localStorage.getItem("onedrive_access_token");if(!G){st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const pe=st.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[]};A.forEach(Me=>{Me.isFolder?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-one-drive-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(be){console.error("Lỗi khi đồng bộ file từ OneDrive:",be),st.update(pe,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},jc=()=>{cs(!1),Rc([{id:"root",name:"OneDrive"}]),Du([]),Mc([]),Dc([]),ls(!1)},ju=pM({onSuccess:A=>{Vm(A.access_token),localStorage.setItem("google_access_token",A.access_token),Wu(A.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:$3}),Wu=A=>{const O=document.createElement("script");O.src="https://apis.google.com/js/api.js",O.onload=()=>{window.gapi.load("picker",()=>qu(A))},document.body.appendChild(O)},qu=A=>{const O=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),G=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(L3).setOAuthToken(A).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(O).addView(G).setCallback(async be=>{if(be.action===window.google.picker.Action.PICKED){const Ie=be.docs.map(Me=>({id:Me.id,name:Me.name,mimeType:Me.mimeType}));await Hn(Ie,y)}}).build().setVisible(!0)},Hn=async(A,O="")=>{const G=localStorage.getItem("google_access_token");if(!G){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const pe=st.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[]};A.forEach(Me=>{Me.mimeType==="application/vnd.google-apps.folder"?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-drive-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});Qn.current=!0,dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(be){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",be),st.update(pe,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};M.useEffect(()=>{const A=O=>{if(O.data.action==="logout"){const G=document.createElement("iframe");G.style.display="none",G.src="https://accounts.google.com/Logout",document.body.appendChild(G),setTimeout(()=>document.body.removeChild(G),2e3)}};return window.addEventListener("message",A),()=>window.removeEventListener("message",A)},[]),M.useEffect(()=>{const A=new Set(l);x(A)},[]),M.useEffect(()=>{Je!=null&&Je.status&&(Je.status.status==="completed"?(X({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${Je.url} với ${Je.status.completed} trang`}),Qn.current=!0,dn()):Je.status.status==="failed"&&X({title:"Thu thập website thất bại",description:`Không thể thu thập ${Je.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(In=Je==null?void 0:Je.status)==null?void 0:In.status]);const Yu=M.useMemo(()=>Tn[y]||[],[Tn,y]),Zt=M.useMemo(()=>Yu.filter(A=>G3(A.permission)),[Yu,y,Tn]),fa=M.useMemo(()=>{const A={};return Zt.forEach((O,G)=>{w.has(O.key)&&(A[G]=!0)}),A},[w,Zt]),Ju=A=>{const O=xu(Tn,A);if(O.length===0)return w.has(A)?"all":"none";const G=O.filter(pe=>w.has(pe)).length;return G===0?"none":G===O.length?"all":"partial"},An=(A,O=!0)=>{if(y!==A){if(u&&!y)ea(!0),T(A+u),b(A+u);else if(ea(!0),T(A),b(A),O&&!o){const G=window.location.pathname==="/"?"":window.location.pathname,pe=A?`${window.location.origin}${G}?prefix=${encodeURIComponent(A)}`:`${window.location.origin}${G}`;window.history.pushState({path:pe},"",pe)}}},gs=A=>{const O=A.lastIndexOf("/"),G=O>0?A.substring(0,O+1):"";G?(An(G),setTimeout(()=>{x(new Set([A]))},500)):x(new Set([A]))};M.useEffect(()=>{Yr&&(Qn.current=!0,dn().finally(()=>ea(!1)))},[Yr]);const Wc=async(A,O)=>{var G,pe;K(!0);try{if(Zt.some(jt=>jt.isFolder&&jt.name.toLowerCase()===A.toLowerCase())){X({title:"Lỗi",description:`Thư mục "${A}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),K(!1);return}const Ie=`${O}${A}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ie,userId:(Vc==null?void 0:Vc.id)||""})).status!==200){X({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qn.current=!0,await dn(),X({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${A}"`}),D(""),P(!1)}catch(be){console.error("Error creating folder:",be);const Ie=((pe=(G=be==null?void 0:be.response)==null?void 0:G.data)==null?void 0:pe.error)||"Không thể tạo thư mục";X({title:"Lỗi",description:Ie,variant:"destructive"})}finally{K(!1)}},kt=async(A,O,G)=>{var pe,be,Ie,Me,jt,Xr,xr,rf,of;oe(G),Qt(!0);try{if(Array.from(A).reduce((Nn,ga)=>Nn+ga.size,0)>=100*1024*1024){X({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),oe(null),Qt(!1);return}const pa=Array.from(A).filter(Nn=>Nn.size===0);if(pa.length>0){const Nn=pa.map(ga=>ga.name).join(", ");X({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Nn}`,variant:"destructive"}),Qt(!1),oe(null);return}const kn=new FormData;if($t!=null&&$t.id&&kn.append("metadata",JSON.stringify({creator:$t.username,creatorId:$t.id,DataSource:"Tệp tải lên"})),G==="folder"&&A[0]){const Nn=A[0].webkitRelativePath.split("/")[0];Nn&&kn.append("folderName",Nn)}kn.append("prefix",O),Array.from(A).forEach(Nn=>G==="folder"?kn.append("files",Nn,Nn.webkitRelativePath):kn.append("files",Nn)),Qn.current=!0;const Ut=await Le.post(`${e}/api/check-files-existed`,kn,{headers:{"Content-Type":"multipart/form-data"}});if(((pe=Ut==null?void 0:Ut.data)==null?void 0:pe.status)===200)await Le.post(`${e}/api/upload`,kn,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),C(""),T(O),setTimeout(async()=>{oe(null),await dn(),Qt(!1),await Qr("upload")},500);else{if(((Ie=(be=Ut==null?void 0:Ut.data)==null?void 0:be.names)==null?void 0:Ie.length)>0&&!((Me=Ut==null?void 0:Ut.data)!=null&&Me.isFolder)){const Nn=Array.from(A).filter(ga=>Ut.data.names.includes(ga.name));ta(Nn),ra(!0)}(jt=Ut==null?void 0:Ut.data)!=null&&jt.isFolder&&((Xr=Ut==null?void 0:Ut.data)!=null&&Xr.name)&&(os((xr=Ut==null?void 0:Ut.data)==null?void 0:xr.name),ta(A),ra(!0))}}catch(jo){console.error("Lỗi tải lên:",jo);const pa=((of=(rf=jo==null?void 0:jo.response)==null?void 0:rf.data)==null?void 0:of.error)||"Không thể tải lên tập tin";X({title:"Lỗi",description:pa,variant:"destructive"}),oe(null),Qt(!1)}},So=async()=>{var A,O;try{Qt(!0);const G=new FormData;if(bo){oe(na?"folder":"files"),ra(!1);let pe=localStorage.getItem("dataLogin"),be;try{pe&&(pe=JSON.parse(pe),be=pe.user)}catch{pe=null}if(na&&bo[0]){const Ie=bo[0].webkitRelativePath.split("/")[0];Ie&&G.append("folderName",Ie)}G.append("prefix",y),Array.from(bo).forEach(Ie=>na&&bo[0]?G.append("files",Ie,Ie.webkitRelativePath):G.append("files",Ie)),be!=null&&be.id&&G.append("metadata",JSON.stringify({creator:be.username,creatorId:be.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,G,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),C(""),T(y),Qn.current=!0}}catch(G){console.error("Lỗi tải lên:",G);const pe=((O=(A=G==null?void 0:G.response)==null?void 0:A.data)==null?void 0:O.error)||"Không thể tải lên tập tin";X({title:"Lỗi",description:pe,variant:"destructive"})}finally{setTimeout(async()=>{oe(null),await dn(),Qt(!1),os(""),ta(null),await Qr("overwrite")},500)}},ms=async A=>{var O;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[A.key]}}),w.has(A.key)){const pe=new Set(w);pe.delete(A.key),x(pe)}const G=((O=A.key)==null?void 0:O.replace(/^(.*?)(\/.*)?$/,(pe,be,Ie)=>!Ie||Ie==="/"?"":be+"/"))||"";T(G),Qn.current=!0,X({title:"Đã xóa tập tin",description:`Đã xóa thành công "${A.name}"`}),W(null),await Qr("delete")}catch(G){console.error("Error deleting file:",G),X({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{qr(!1),await dn()}},vs=A=>{const O=new Set(w),G=typeof A=="function"?A(fa):A;new Set(Object.keys(fa).map(Number)).forEach(be=>{const Ie=Zt[be];Ie&&(G[be]||(O.delete(Ie.key),Ie.isFolder&&xu(Tn,Ie.key).forEach(Me=>O.delete(Me))))}),Object.entries(G).forEach(([be,Ie])=>{const Me=parseInt(be),jt=Zt[Me];jt&&Ie&&(O.add(jt.key),jt.isFolder&&xu(Tn,jt.key).forEach(Xr=>O.add(Xr)))}),x(O)},qc=async()=>{var A;q(!0);try{const O=Array.from(w),G=O.map(be=>Object.values(Tn).flat().find(Ie=>Ie.key===be)).filter(be=>be!==void 0);if(G.length===0){X({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:O}});const pe=((A=G[0])==null?void 0:A.key.replace(/^(.*?)(\/.*)?$/,(be,Ie,Me)=>!Me||Me==="/"?"":Ie+"/"))||"";T(pe),Qn.current=!0,dn(),X({title:"Đã xóa tập tin",description:`Đã xóa thành công ${G.length} mục`}),Y(!1),x(new Set),await Qr("bulk-delete")}catch(O){console.error("Error deleting files:",O),X({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{q(!1)}},Qm=async(A,O)=>{if(!y.trim()){X({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}Ne(!0);try{const G=A.key;let pe;A.isFolder?pe=G.split("/").slice(0,-2).join("/")+"/":pe=G.substring(0,G.lastIndexOf("/")+1);const be=pe+O+(A.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:G,newPath:be}),Qn.current=!0,await dn(),X({title:"Đã đổi tên",description:`Đã đổi tên thành công "${A.name}" thành "${O}"`}),te(null),z(""),Pe(null),await Qr("rename")}catch(G){console.error("Error renaming item:",G),X({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Ne(!1)}},Xm=async A=>{Ve(O=>new Set([...O,...A]));try{const O=await Le.post(`${e}/api/download`,{paths:A},{responseType:"blob"}),G=window.URL.createObjectURL(O.data),pe=document.createElement("a");pe.href=G;const be=O.headers["Content-Disposition"]||O.headers["content-disposition"],Ie=be==null?void 0:be.match(/filename="(.+)"/),Me=Ie?decodeURIComponent(Ie[1]):"download.zip";pe.setAttribute("download",Me),document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),window.URL.revokeObjectURL(G),X({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${A.length} mục${A.length>1,""}`})}catch(O){console.error("Error downloading files:",O),X({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Ve(O=>{const G=new Set(O);return A.forEach(pe=>G.delete(pe)),G})}},Qu=y?y.replace(n,"").split("/").filter(Boolean):[],Xu=()=>{let A=Array.from(w).map(G=>({key:G}));A.length>1&&(A=A.filter(G=>G.key!==n));const O=G=>Md.findIndex(A,pe=>!pe.key.endsWith("/")&&pe.key.startsWith(G))!==-1;return A=A.filter(G=>G.key.endsWith("/")?!O(G.key):!0),A},ha=M.useMemo(()=>{const A=[...($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/")?[]:[{id:"select",header:()=>{const O=U3(Tn,y),G=O.length>0&&O.every(be=>w.has(be)),pe=O.some(be=>w.has(be));return d.jsx(oc,{checked:G?!0:pe?"indeterminate":!1,onCheckedChange:be=>{if(be){const Ie=Zt.reduce((Me,jt,Xr)=>(Me[Xr]=!0,Me),{});vs(Ie)}else{for(const Ie of Array.from(w))Ie.startsWith(y)&&(w.delete(Ie),zo.current[Ie]=!1);Md.forEach(zo.current,(Ie,Me)=>{Me.startsWith(y)&&(zo.current[Me]=!1)}),vs({})}},"aria-label":"Chọn tất cả"})},cell:({row:O})=>{const G=O.original;let be=G.isFolder?Ju(G.key):w.has(G.key)?"all":"none";if(be==="none"&&G.key.endsWith("/")){for(const Ie of Array.from(w))if(Ie.startsWith(G.key)){be="all";break}}return d.jsx("div",{className:"flex items-center",children:d.jsx(oc,{checked:be==="partial"?"indeterminate":be==="all",onCheckedChange:Ie=>{var jt,Xr;const Me={...fa};if(Ie?Me[O.index]=!0:delete Me[O.index],zo.current[((jt=O.original)==null?void 0:jt.key)||"_"]=!!Ie,(Xr=O.original)!=null&&Xr.key.endsWith("/"))for(const xr of Array.from(w))xr.startsWith(O.original.key)&&(zo.current[O.original.key]=!1,w.delete(xr));vs(Me)},"aria-label":"Chọn dòng"})})},enableSorting:!1}],{id:"fileName",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),children:["Tên tập tin",d.jsx(ag,{})]}),accessorKey:"name",cell:({row:O})=>{const G=O.original,pe=G.key.substring(0,G.key.lastIndexOf("/"))||"/",be=g.trim()!==""&&pe!==y,Ie=pe.split("/").filter(Boolean);return d.jsxs("div",{className:"flex flex-col group",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsxs("div",{className:`flex items-center gap-2 ${G.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{G.isFolder&&An(G.key)},children:[G.isFolder?d.jsx(Ks,{className:"h-5 w-5 text-blue-500"}):null,G.name]}),d.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Me=>{Me.stopPropagation(),navigator.clipboard.writeText(G.key),X({title:"Copied to clipboard",description:`Path: ${G.key}`,duration:2e3})},title:"Copy path to clipboard",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),d.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),be&&d.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[d.jsx(Ks,{className:"h-4 w-4 text-gray-500 my-auto"}),d.jsxs("span",{className:"flex items-center ml-1",children:[d.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{An("")},children:"/"}),Ie.map((Me,jt)=>d.jsxs("span",{className:"flex items-center",children:[d.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{An(Ie.slice(0,jt+1).join("/")+"/")},children:Me}),jt<Ie.length-1&&d.jsx("span",{children:"/"})]},jt))]})]})]})}}];return o||A.push({id:"size",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),children:["Kích thước",d.jsx(ag,{})]}),accessorKey:"size",cell:({getValue:O,row:G})=>{const pe=O();return d.jsx("span",{children:G.original.isFolder?"-":Xt(pe)})}},{id:"lastModified",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",d.jsx(ag,{})]}),accessorKey:"lastModified",cell:({row:O})=>{const G=O.original.lastModified;return d.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:d.jsx("span",{children:G&&Dx(G).isValid()?Dx(G).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>d.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:O})=>d.jsxs("div",{className:"flex items-center gap-2",children:[y===""&&r&&d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{ku(O.original.key),Nu(!0)},className:"h-8 w-8 p-0",children:ne.has(O.original.key)?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):d.jsx(vO,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Những Flow sử dụng Folder này làm Data"})]})}),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:!O.original.isFolder&&d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>Xm([O.original.key]),className:"h-8 w-8 p-0",disabled:!K3(O.original.permission)||ne.has(O.original.key),children:ne.has(O.original.key)?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):d.jsx(hO,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Tải xuống"})]})}),y.trim()!==""&&(Xi(O.original.permission)?d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{te(O.original),z(O.original.name)},className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(_O,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Đổi tên"})]})}):d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{console.log("call"),ke(O.original)},className:"h-8 w-8 p-0",disabled:O.original.isFolder,children:d.jsx(Hx,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Xem"})]})})),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{Ae(!0),se(O.original)},className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(KD,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Di chuyển"})]})}),!(($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/"))&&d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>W(O.original),className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(DC,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Xóa"})]})}),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>Ic(O.original),className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(RC,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Chia sẻ"})]})})]})}),A},[w,Zt,fa,ne,o]),_o=Gb({data:Zt,columns:ha,state:{rowSelection:fa,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:vs,getCoreRowModel:Kb(),getSortedRowModel:qM()}),Zu=async A=>{var O,G;bt(!0);try{if(Qi(A)){const pe=await Le.get(`${e}/api/read-text`,{params:{path:A.key}});Ct(pe.data.content)}try{const pe=await Le.get(`${e}/api/read-json`,{params:{path:A.key+".metadata.json"}}),be=((G=(O=pe==null?void 0:pe.data)==null?void 0:O.content)==null?void 0:G.metadataAttributes)||null;return Pe({fullPath:$==null?void 0:$.key,...be})}catch{return Pe("Lỗi phân tích siêu dữ liệu")}}catch(pe){console.error("Error loading file content:",pe),X({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{bt(!1)}},ef=async(A,O)=>{zt(!0);try{await Le.post(`${e}/api/modify-text`,{path:A.key,content:O}),X({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qn.current=!0,await dn(),te(null),Ct(""),Kt("rename"),await Qr("edit-content")}catch(G){console.error("Error saving file content:",G),X({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{zt(!1)}},tf=async A=>{zt(!0);try{await Le.post(`${e}/api/modify-json`,{path:A.key+".metadata.json",content:{metadataAttributes:xe}}),X({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qn.current=!0,await dn(),te(null),Ct(""),Kt("rename")}catch(O){console.error("Error saving file content:",O),X({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{zt(!1)}};M.useEffect(()=>{$&&($.isFolder||Zu($),Kt("rename"))},[$]),M.useEffect(()=>{_e&&!_e.isFolder&&Zu(_e)},[_e]);const ys=async(A,O)=>{var G;if(Je){X({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}Xe(!0);try{const{data:pe}=await Le.post(`${e}/api/crawl`,{url:A,limit:O,prefix:y});if(pe.id){_c({id:pe.id,url:A,limit:O,prefix:y,taskId:((G=pe.task)==null?void 0:G.id)||""});const be=localStorage.getItem(e0),Ie=be?JSON.parse(be):[];Ie.some(Me=>Me.id===pe.id)||(Ie.unshift({url:A,id:pe.id,limit:O,prefix:y,timestamp:Date.now()}),Ie.length>20&&(Ie.length=20),localStorage.setItem(e0,JSON.stringify(Ie))),X({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${A} với giới hạn ${O}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),J(!1),ae(""),he("1")}}catch(pe){console.error("Error crawling website:",pe),X({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{Xe(!1)}},Yc=async()=>{try{if(!(Je!=null&&Je.id))return;_c(null),localStorage.removeItem(ns),X({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${Je.url}`})}catch(A){console.error("Error stopping job:",A),X({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};M.useEffect(()=>{if(o)return;const A=(O=!0)=>{const pe=new URL(window.location.href).searchParams.get("prefix")||"";pe?An(pe,!1):(O&&!l&&x(new Set),T(n),b(n),Qn.current=!0,setTimeout(()=>{dn()},0))};return A(!1),window.addEventListener("popstate",()=>A(!0)),()=>{window.removeEventListener("popstate",()=>A(!0))}},[]);const Jc=async()=>{Mu(!0);try{await Le.post(`${e}/api/prediction-report`),X({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(A){console.error("Error exporting report:",A),X({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Mu(!1)}},Zm=async()=>{try{const A=Vi();A&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:y,user_id:A.id,userName:A.username})).status===200&&await ws()}catch(A){xt(!1),console.log(A)}},Qr=async A=>{try{ss&&y.includes(ss)&&(console.log(`Auto syncing knowledge base after ${A} operation`),await ws())}catch(O){console.log(`Error auto syncing after ${A}:`,O)}},br=M.useRef(),ws=async()=>{try{xt(!0);const A=await Le.post(`${e}/api/get-ingestion-job-status`,{prefix:y}),{status:O}=A==null?void 0:A.data;O==="FAILED"||O==="COMPLETE"||O==="STOPPED"||O==="STOPPING"||!O?(xt(!1),br.current&&(clearInterval(br.current),br.current=null),kc(A==null?void 0:A.data)):(br.current||(br.current=setInterval(()=>ws(),5e3)),kc(A==null?void 0:A.data))}catch(A){console.log(A)}},nf=()=>{const A=Array.from(w);let O;return y?O=A.filter(G=>G.startsWith(y)&&G!==y).length:O=new Set(A.filter(G=>G.split("/").shift())).size,`Đang chọn: ${O}`};return M.useEffect(()=>{const A=y==null?void 0:y.split("/")[0];return A!==ss&&(xt(!1),br.current&&(clearInterval(br.current),br.current=null),Lm(A||""),kc(null),A&&ws()),()=>{}},[ss,y]),M.useEffect(()=>{xo&&Hc.length===0&&(It(),Jr(null))},[xo]),M.useEffect(()=>{if(l)for(const A of Array.from(l))zo.current[A]=!0},[]),d.jsxs("div",{className:"space-y-4 s3-explr-container",children:[d.jsx(c_,{}),d.jsx(ar,{open:Iu,onOpenChange:A=>{ra(A),A||(os(""),ta(null),Qt(!1),oe(null))},children:d.jsxs(jn,{children:[d.jsxs(Wn,{children:[d.jsx(qn,{children:"Cảnh báo trùng lặp"}),d.jsxs(vi,{children:[na&&d.jsxs(d.Fragment,{children:["Folder $",na," đã có."]}),bo&&bo.length>0&&d.jsxs(d.Fragment,{children:["Những tệp sau bị lặp:",d.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(bo).map((A,O)=>d.jsx("li",{children:A.name},O))})]})]})]}),d.jsxs(Hr,{children:[d.jsx(He,{variant:"outline",onClick:()=>{ra(!1),os(""),ta(null),Qt(!1),oe(null)},children:"Bỏ qua"}),d.jsx(He,{variant:"destructive",onClick:()=>So(),children:"Ghi đè"})]})]})}),d.jsx(Ld,{className:"s3-explr-breadcrumb",children:d.jsxs(Fd,{className:"s3-explr-breadcrumb-list",children:[d.jsx(nc,{className:"s3-explr-breadcrumb-item",children:d.jsx(rc,{onClick:()=>An(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!u&&Qu.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[d.jsx($d,{className:"s3-explr-breadcrumb-separator"},`sep-${O}`),d.jsx(nc,{className:"s3-explr-breadcrumb-item",children:d.jsx(rc,{onClick:()=>An(n+Qu.slice(0,O+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:A})},`item-${A}`)]},O))]})}),d.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[d.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:d.jsx($H,{ref:Q,onChange:A=>C(A)})}),d.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{T(y),Qn.current=!0,dn()},disabled:Ko,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${Ko?"animate-spin":""}`}),"Làm mới"]}),y&&y!=="/"&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{Ko||ft||(xt(!0),Zm())},"aria-disabled":Ko||ft,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${Ko||ft?"animate-spin":""}`}),"Đồng bộ KB"]})}),Mt&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[d.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),d.jsx("div",{className:"space-y-1",children:d.jsxs("p",{className:"flex items-center gap-2",children:[d.jsx("span",{className:"font-medium",children:"Trạng thái:"}),d.jsxs("span",{className:`flex items-center gap-1 font-semibold ${Mt.status==="COMPLETE"?"text-green-600":Mt.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Mt.status==="COMPLETE"&&d.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:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Mt.status==="FAILED"&&d.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:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Mt.status!=="COMPLETE"&&Mt.status!=="FAILED"&&d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),lL(Mt.status)]})]})}),Mt.statistics&&d.jsxs("div",{className:"space-y-1 border-t pt-2",children:[d.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),d.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu quét:"}),d.jsx("span",{className:"font-medium",children:Mt.statistics.numberOfDocumentsScanned})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Metadata quét:"}),d.jsx("span",{className:"font-medium",children:Mt.statistics.numberOfMetadataDocumentsScanned})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu mới:"}),d.jsx("span",{className:"font-medium text-green-600",children:Mt.statistics.numberOfNewDocumentsIndexed})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu sửa:"}),d.jsx("span",{className:"font-medium text-blue-600",children:Mt.statistics.numberOfModifiedDocumentsIndexed})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Metadata sửa:"}),d.jsx("span",{className:"font-medium text-blue-600",children:Mt.statistics.numberOfMetadataDocumentsModified})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu xóa:"}),d.jsx("span",{className:"font-medium text-orange-600",children:Mt.statistics.numberOfDocumentsDeleted})]}),d.jsxs("div",{className:"flex justify-between col-span-2",children:[d.jsx("span",{children:"Tài liệu lỗi:"}),d.jsx("span",{className:"font-medium text-red-600",children:Mt.statistics.numberOfDocumentsFailed})]})]})]}),d.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[d.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",Mt.dataSourceId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",Mt.ingestionJobId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",Mt.knowledgeBaseId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",Mt.is_still_in_stock?"Còn":"Không"]})]}),Mt.errorMessage&&d.jsxs("div",{className:"border-t pt-2",children:[d.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),d.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:Mt.errorMessage})]}),Mt.failureReasons&&Mt.failureReasons.length>0&&d.jsx(UH,{failureReasons:Mt.failureReasons,onNavigateToFile:gs})]})})]})}),Xi(Tn==null?void 0:Tn.prefixPermission)&&d.jsxs("div",{className:"relative",ref:zc,children:[d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors aria-disabled:hidden",onClick:()=>Cr(A=>!A),"aria-disabled":($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/"),children:[d.jsx(TO,{className:"w-4 h-4"}),"Add file"]}),Bc&&d.jsxs("div",{className:"absolute z-50 mt-2 right-0 w-56 bg-white border rounded-lg shadow-lg py-2 flex flex-col",children:[d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1);const A=document.createElement("input");A.type="file",A.multiple=!0,A.onchange=O=>{const G=O.target.files;G&&kt(G,y,"files")},A.click()},children:[d.jsx(pp,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1);const A=document.createElement("input");A.type="file",A.multiple=!0,A.webkitdirectory=!0,A.onchange=O=>{const G=O.target.files;G&&kt(G,y,"folder")},A.click()},children:[d.jsx(Ks,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!s&&!y,onClick:()=>P(!0),children:[d.jsx(wO,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),J(!0)},children:[d.jsx(xO,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),ju()},children:[d.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[d.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"}),d.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"}),d.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"}),d.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"}),d.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"}),d.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"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),Go()},children:[d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[d.jsx("path",{fill:"#094ab2",d:"M47.3 28.2C45.3 18.6 37.1 12 28 12c-8.5 0-15.9 5.6-18.4 13.5C4.2 27.2 0 32.2 0 38c0 6.6 5.4 12 12 12h36c8.3 0 16-6.6 16-15.5 0-6.8-4.9-12.4-11.7-13.3z"}),d.jsx("path",{fill:"#0067c5",d:"M44.9 30.1c-.2 0-.4-.1-.6-.1H26c-3.3 0-6 2.7-6 6 0 .9.2 1.8.6 2.6-1.7-.7-3.5-1.1-5.5-1.1C7.6 37.5 4 41.5 4 46s3.6 8.5 8.1 8.5h34.3c6.8 0 12.6-5.4 12.6-12s-5.5-11.6-11.1-12.4z"})]})," ","Đồng bộ OneDrive"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),Gm()},children:[d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[d.jsx("path",{fill:"#036C70",d:"M19 14.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#17828F",d:"M16 17.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#4DB6AC",d:"M13 20.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),Xi((Tn==null?void 0:Tn.prefixPermission)&&w.size>0)&&d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors aria-disabled:hidden",onClick:()=>Ic({contentType:"application/x-directory",isFolder:!0,key:y||"/",lastModified:"-",name:"",size:0}),children:[d.jsx(RC,{className:"w-4 h-4"}),"Chia sẻ"]}),!o&&d.jsxs(d.Fragment,{children:[w.size>0&&d.jsx(d.Fragment,{children:d.jsxs(ar,{open:Z,onOpenChange:Y,children:[d.jsx(ic,{asChild:!0,children:d.jsxs(He,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[d.jsx(DC,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",w.size,")"]})}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),d.jsxs(vi,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",w.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>Y(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:qc,disabled:fe,className:"s3-explr-confirm-delete-btn",children:fe?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})}),!u&&d.jsxs(ar,{open:N,onOpenChange:P,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsx(Wn,{className:"s3-explr-dialog-header",children:d.jsx(qn,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),d.jsx(Yn,{disabled:H,id:"name",value:_,onChange:A=>D(A.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),d.jsxs(He,{onClick:()=>{_.trim()&&Wc(_,y)},disabled:H,className:"s3-explr-create-btn",children:[H&&d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),H?"Đang tạo...":"Tạo"]})]})]})]}),u&&!y?d.jsx(d.Fragment,{}):d.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[Je?d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[d.jsx(Pt,{className:"h-4 w-4 animate-spin s3-explr-loader"}),Je.status?d.jsxs(d.Fragment,{children:[Je.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",Je.status.completed,"/",Je.status.total,") -"," ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}):"Đang thu thập..."]}),d.jsxs(He,{variant:"destructive",size:"sm",onClick:()=>void Yc(),className:"flex items-center gap-2",children:[d.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),d.jsx(kO,{className:"h-4 w-4"})]})]})}),Je.status&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-1 p-2",children:[d.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",Je==null?void 0:Je.url]}),d.jsxs("p",{children:["Tiến độ: ",Je==null?void 0:Je.status.completed,"/",Je==null?void 0:Je.status.total," ","trang"]}),d.jsxs("p",{children:["Thời gian: ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}),d.jsxs("p",{children:["Trạng thái:"," ",(Je==null?void 0:Je.status.status)==="scraping"?"Đang thu thập":(Je==null?void 0:Je.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!u&&d.jsxs(ar,{open:L,onOpenChange:J,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Thêm website"}),d.jsx(vi,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),d.jsx(Yn,{id:"websiteUrl",value:U,onChange:A=>ae(A.target.value),placeholder:"https://example.com",type:"url",disabled:Ee,className:"s3-explr-input"})]}),d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),d.jsx(Yn,{id:"crawlLimit",value:ye,onChange:A=>{const O=A.target.value;/^\d*$/.test(O)&&he(O)},placeholder:"1",type:"text",disabled:Ee,className:"s3-explr-input"}),d.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)"})]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>{J(!1),ae(""),he("1")},disabled:Ee,className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{onClick:()=>{U.trim()&&ys(U.trim(),parseInt(ye)||1)},disabled:Ee||!U.trim(),className:"s3-explr-crawl-btn",children:Ee?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),y.startsWith("BKTTW/")&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!s&&!y,onClick:Jc,children:[oa&&d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${oa?"animate-spin":""}`}),"Xuất báo cáo"]})}),(Je==null?void 0:Je.status)&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-1 p-2",children:[d.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",Je.url]}),d.jsxs("p",{children:["Tiến độ: ",Je.status.completed,"/",Je.status.total," ","trang"]}),d.jsxs("p",{children:["Thời gian: ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}),d.jsxs("p",{children:["Trạng thái:"," ",Je.status.status==="scraping"?"Đang thu thập":Je.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),d.jsxs(ar,{open:L,onOpenChange:J,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Thêm website"}),d.jsx(vi,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),d.jsx(Yn,{id:"websiteUrl",value:U,onChange:A=>ae(A.target.value),placeholder:"https://example.com",type:"url",disabled:Ee,className:"s3-explr-input"})]}),d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),d.jsx(Yn,{id:"crawlLimit",value:ye,onChange:A=>{const O=A.target.value;/^\d*$/.test(O)&&he(O)},placeholder:"1",type:"text",disabled:Ee,className:"s3-explr-input"}),d.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)"})]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>{J(!1),ae(""),he("1")},disabled:Ee,className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{onClick:()=>{U.trim()&&ys(U.trim(),parseInt(ye)||1)},disabled:Ee||!U.trim(),className:"s3-explr-crawl-btn",children:Ee?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),y.startsWith("BKTTW/")&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!s&&!y,onClick:Jc,children:[oa&&d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${oa?"animate-spin":""}`}),"Xuất báo cáo"]})}),oa&&d.jsx(lr,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),d.jsxs("div",{className:"flex items-center gap-4",children:[ia&&d.jsxs(Gs,{open:ia,onOpenChange:cs,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Ip,{asChild:!0,children:d.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:jc,children:"✖"})}),d.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),d.jsx(Ld,{className:"onedrive-breadcrumb",children:d.jsx(Fd,{className:"onedrive-breadcrumb-list",children:aa.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[O>0&&d.jsx($d,{className:"onedrive-breadcrumb-separator"}),d.jsx(nc,{className:"onedrive-breadcrumb-item",children:d.jsx(rc,{onClick:()=>Ku(O),className:"cursor-pointer onedrive-breadcrumb-link",children:A.name})})]},O))})})]}),d.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Hm?d.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):d.jsx(d.Fragment,{children:[...Ru,...Oc].length>0?[...Ru,...Oc].map(A=>d.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${ds.some(O=>O.id===A.id)?"bg-blue-100":""}`,children:[d.jsx("input",{type:"checkbox",checked:ds.some(O=>O.id===A.id),onChange:O=>{O.stopPropagation(),zu(A)},className:"cursor-pointer"}),A.isFolder?d.jsx(Ks,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>yn(A.id,A.name)}):d.jsx(pp,{className:"text-gray-500 w-5 h-5"}),d.jsxs("div",{className:"flex-1",children:[d.jsx("div",{className:`font-medium ${A.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{A.isFolder?yn(A.id,A.name):zu(A)},children:A.name}),!A.isFolder&&d.jsxs("div",{className:"text-xs text-gray-500",children:[Xt(A.size)," •"," ",Kc(A.lastModified.toISOString())]})]})]},A.id)):d.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),d.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:d.jsx(He,{onClick:()=>{Gu(ds,y),jc()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:ds.length===0,children:"Đồng bộ"})}),d.jsx("button",{onClick:()=>da(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),d.jsx("polyline",{points:"16 17 21 12 16 7"}),d.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),d.jsxs(Gs,{open:Um,onOpenChange:da,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[d.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),d.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(He,{variant:"outline",onClick:()=>da(!1),children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>{Vu(),da(!1)},children:"Đăng xuất"})]})]})]}),xo&&d.jsxs(Gs,{open:xo,onOpenChange:ca,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Ip,{asChild:!0,children:d.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:Uu,children:"✖"})}),d.jsxs("div",{className:"flex items-center gap-2",children:[gt&&d.jsx("button",{onClick:()=>Jr(null),className:"text-gray-600 hover:text-gray-800",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:d.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),d.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&d.jsx(Ld,{className:"sharepoint-breadcrumb",children:d.jsx(Fd,{className:"sharepoint-breadcrumb-list",children:$c.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[O>0&&d.jsx($d,{className:"sharepoint-breadcrumb-separator"}),d.jsx(nc,{className:"sharepoint-breadcrumb-item",children:d.jsx(rc,{onClick:()=>Ym(O),className:"cursor-pointer sharepoint-breadcrumb-link",children:A.name})})]},O))})})]}),d.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Lu?d.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...Fc,...us].length===0?d.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...Fc,...us].map(A=>{const O=hs.some(G=>G.id===A.id);return d.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${O?"bg-blue-100":""}`,children:[d.jsx("input",{type:"checkbox",checked:O,onChange:G=>{G.stopPropagation(),qm(A)},className:"cursor-pointer"}),A.isFolder?d.jsx(Ks,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ps(A.id,A.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):d.jsx(pp,{className:"text-gray-500 w-5 h-5"}),d.jsxs("div",{className:"flex-1",children:[d.jsx("div",{className:`font-medium ${A.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{A.isFolder&&ps(A.id,A.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:A.name}),!A.isFolder&&d.jsxs("div",{className:"text-xs text-gray-500",children:[Xt(A.size)," •"," ",A.lastModified.toLocaleString()]})]})]},A.id)}):d.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:Hc.map(A=>d.jsxs("div",{className:"cursor-pointer bg-white shadow-md rounded-xl p-5 flex flex-col justify-center items-start transition-shadow duration-200 hover:shadow-lg border border-gray-100 min-h-[120px]",style:{overflow:"hidden",wordBreak:"break-word",textOverflow:"ellipsis",whiteSpace:"normal"},onClick:()=>Wm(A),children:[d.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:A.name,children:A.name}),d.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:A.description,children:A.description})]},A.id))})}),d.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&d.jsxs(d.Fragment,{children:[d.jsx(He,{onClick:()=>{Jm(hs,y),Uu()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:hs.length===0,children:"Đồng bộ"}),d.jsx(He,{onClick:()=>Jr(null),children:"Quay lại"})]})}),d.jsx("button",{onClick:()=>la(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),d.jsx("polyline",{points:"16 17 21 12 16 7"}),d.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),d.jsxs(Gs,{open:$u,onOpenChange:la,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[d.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),d.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(He,{variant:"outline",onClick:()=>la(!1),children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>{jm(),la(!1)},children:"Đăng xuất"})]})]})]})]}),d.jsx(ar,{open:!!Ec,onOpenChange:A=>{A||(Nu(!1),Ou([]),ku(""))},children:d.jsxs(jn,{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:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:d.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",d.jsx("span",{className:"font-bold",children:is}),"):"," "]})}),d.jsx(vi,{className:"s3-explr-dialog-description",children:Tc?d.jsxs("div",{className:"flex items-center justify-center py-4",children:[d.jsx(Pt,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):d.jsx("div",{children:as&&Array.isArray(as)&&as.length>0?d.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:d.jsxs("table",{className:"w-full border-collapse",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"bg-gray-100",children:[d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),d.jsx("tbody",{children:as.map((A,O)=>d.jsxs("tr",{className:O%2===0?"bg-white":"bg-gray-50",children:[d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.name}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.KnowledgeBaseId}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.createdDate?new Date(A.createdDate).toLocaleString("vi-VN"):"N/A"})]},O))})]})}):d.jsx("div",{className:"text-gray-500 italic py-2",children:"Không có flow nào sử dụng dữ liệu từ folder này"})})})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>ms(ee),disabled:vn,className:"s3-explr-confirm-delete-btn",children:vn?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),d.jsx(ar,{open:!!ee,onOpenChange:A=>!A&&W(null),children:d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),d.jsxs(vi,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",ee==null?void 0:ee.name,"? Hành động này không thể hoàn tác."]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>ms(ee),disabled:vn,className:"s3-explr-confirm-delete-btn",children:vn?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),d.jsx(ar,{open:!!$,onOpenChange:A=>{A||(te(null),Pe(null),z(""),Ct(""),Kt("rename"))},children:d.jsxs(jn,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[d.jsx(Wn,{className:"s3-explr-dialog-header",children:d.jsx(qn,{className:"s3-explr-dialog-title",children:$!=null&&$.isFolder?"Đổi tên thư mục":Qi($)?"Quản lý tập tin":"Đổi tên tập tin"})}),$&&d.jsxs(Sg,{value:$n,onValueChange:A=>Kt(A),children:[d.jsxs(Yd,{"aria-checked":!Qi($),"aria-disabled":$.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[d.jsx(Ki,{value:"rename",children:"Đổi tên"}),!$.isFolder&&d.jsxs(d.Fragment,{children:[Qi($)&&d.jsx(Ki,{value:"edit",children:"Sửa nội dung"}),d.jsx(Ki,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),d.jsx(Gi,{value:"rename",children:d.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:d.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),d.jsx(Yn,{id:"newName",value:Te,onChange:A=>z(A.target.value),placeholder:"Nhập tên mới",disabled:Ce,className:"s3-explr-input"})]})})}),!$.isFolder&&d.jsxs(d.Fragment,{children:[Qi($)&&d.jsx(Gi,{value:"edit",children:d.jsx("div",{className:"space-y-4 py-4",children:Jt?d.jsx("div",{className:"flex items-center justify-center py-10",children:d.jsx(Pt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.jsxs("div",{className:"max-h-[70dvh] overflow-auto rounded-md border px-4 py-3 bg-muted/30",children:[d.jsx(mr,{htmlFor:"content",className:"block text-sm font-medium mb-2 text-muted-foreground",children:"Nội dung tập tin"}),d.jsx(sc,{id:"content",value:Qe,onChange:A=>Ct(A.target.value),placeholder:"Nhập nội dung tập tin",className:"font-mono text-sm resize-none min-h-[200px] w-full",disabled:an,style:{height:"auto",maxHeight:"60vh"},rows:Math.max(10,Qe.split(`
227
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function KE(t,e){if(t){if(typeof t=="string")return um(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return um(t,e)}}function um(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function HU(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,i=!1,s,l;try{for(n=n.call(t);!(o=(s=n.next()).done)&&(r.push(s.value),!(e&&r.length===e));o=!0);}catch(u){i=!0,l=u}finally{try{!o&&n.return!=null&&n.return()}finally{if(i)throw l}}return r}}function UU(t){if(Array.isArray(t))return t}function GE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Bt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?GE(Object(n),!0).forEach(function(r){fm(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):GE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function fm(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function gu(t,e){if(t==null)return{};var n=BU(t,e),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function BU(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,i;for(i=0;i<r.length;i++)o=r[i],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var hm=M.forwardRef(function(t,e){var n=t.children,r=gu(t,NU),o=WE(r),i=o.open,s=gu(o,PU);return M.useImperativeHandle(e,function(){return{open:i}},[i]),M.createElement(M.Fragment,null,n(Bt(Bt({},s),{},{open:i})))});hm.displayName="Dropzone";var jE={disabled:!1,getFilesFromEvent:ZH,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};hm.defaultProps=jE,hm.propTypes={children:Ot.func,accept:Ot.objectOf(Ot.arrayOf(Ot.string)),multiple:Ot.bool,preventDropOnDocument:Ot.bool,noClick:Ot.bool,noKeyboard:Ot.bool,noDrag:Ot.bool,noDragEventsBubbling:Ot.bool,minSize:Ot.number,maxSize:Ot.number,maxFiles:Ot.number,disabled:Ot.bool,getFilesFromEvent:Ot.func,onFileDialogCancel:Ot.func,onFileDialogOpen:Ot.func,useFsAccessApi:Ot.bool,autoFocus:Ot.bool,onDragEnter:Ot.func,onDragLeave:Ot.func,onDragOver:Ot.func,onDrop:Ot.func,onDropAccepted:Ot.func,onDropRejected:Ot.func,onError:Ot.func,validator:Ot.func};var pm={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function WE(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Bt(Bt({},jE),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,i=e.maxSize,s=e.minSize,l=e.multiple,u=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,g=e.onDragOver,C=e.onDrop,w=e.onDropAccepted,x=e.onDropRejected,y=e.onFileDialogCancel,b=e.onFileDialogOpen,E=e.useFsAccessApi,T=e.autoFocus,N=e.preventDropOnDocument,P=e.noClick,_=e.noKeyboard,D=e.noDrag,H=e.noDragEventsBubbling,K=e.onError,ee=e.validator,W=M.useMemo(function(){return AU(n)},[n]),de=M.useMemo(function(){return TU(n)},[n]),se=M.useMemo(function(){return typeof b=="function"?b:qE},[b]),fe=M.useMemo(function(){return typeof y=="function"?y:qE},[y]),q=M.useRef(null),Z=M.useRef(null),Y=M.useReducer(zU,pm),oe=dm(Y,2),Q=oe[0],X=oe[1],$=Q.isFocused,te=Q.isFileDialogActive,_e=M.useRef(typeof window<"u"&&window.isSecureContext&&E&&EU()),ke=function(){!_e.current&&te&&setTimeout(function(){if(Z.current){var ae=Z.current.files;ae.length||(X({type:"closeDialog"}),fe())}},300)};M.useEffect(function(){return window.addEventListener("focus",ke,!1),function(){window.removeEventListener("focus",ke,!1)}},[Z,te,fe,_e]);var xe=M.useRef([]),Pe=function(ae){q.current&&q.current.contains(ae.target)||(ae.preventDefault(),xe.current=[])};M.useEffect(function(){return N&&(document.addEventListener("dragover",BE,!1),document.addEventListener("drop",Pe,!1)),function(){N&&(document.removeEventListener("dragover",BE),document.removeEventListener("drop",Pe))}},[q,N]),M.useEffect(function(){return!r&&T&&q.current&&q.current.focus(),function(){}},[q,T,r]);var Te=M.useCallback(function(U){K?K(U):console.error(U)},[K]),z=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U),xe.current=[].concat(RU(xe.current),[U.target]),pu(U)&&Promise.resolve(o(U)).then(function(ae){if(!(hu(U)&&!H)){var ye=ae.length,he=ye>0&&bU({files:ae,accept:W,minSize:s,maxSize:i,multiple:l,maxFiles:u,validator:ee}),Ee=ye>0&&!he;X({isDragAccept:he,isDragReject:Ee,isDragActive:!0,type:"setDraggedFiles"}),h&&h(U)}}).catch(function(ae){return Te(ae)})},[o,h,Te,H,W,s,i,l,u,ee]),ce=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U);var ae=pu(U);if(ae&&U.dataTransfer)try{U.dataTransfer.dropEffect="copy"}catch{}return ae&&g&&g(U),!1},[g,H]),Ae=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U);var ae=xe.current.filter(function(he){return q.current&&q.current.contains(he)}),ye=ae.indexOf(U.target);ye!==-1&&ae.splice(ye,1),xe.current=ae,!(ae.length>0)&&(X({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),pu(U)&&p&&p(U))},[q,p,H]),Ce=M.useCallback(function(U,ae){var ye=[],he=[];U.forEach(function(Ee){var Xe=HE(Ee,W),ft=dm(Xe,2),xt=ft[0],Co=ft[1],Qt=UE(Ee,s,i),vn=dm(Qt,2),qr=vn[0],Gt=vn[1],dr=ee?ee(Ee):null;if(xt&&qr&&!dr)ye.push(Ee);else{var Yr=[Co,Gt];dr&&(Yr=Yr.concat(dr)),he.push({file:Ee,errors:Yr.filter(function(ea){return ea})})}}),(!l&&ye.length>1||l&&u>=1&&ye.length>u)&&(ye.forEach(function(Ee){he.push({file:Ee,errors:[CU]})}),ye.splice(0)),X({acceptedFiles:ye,fileRejections:he,isDragReject:he.length>0,type:"setFiles"}),C&&C(ye,he,ae),he.length>0&&x&&x(he,ae),ye.length>0&&w&&w(ye,ae)},[X,l,W,s,i,u,C,w,x,ee]),Ne=M.useCallback(function(U){U.preventDefault(),U.persist(),$n(U),xe.current=[],pu(U)&&Promise.resolve(o(U)).then(function(ae){hu(U)&&!H||Ce(ae,U)}).catch(function(ae){return Te(ae)}),X({type:"reset"})},[o,Ce,Te,H]),ne=M.useCallback(function(){if(_e.current){X({type:"openDialog"}),se();var U={multiple:l,types:de};window.showOpenFilePicker(U).then(function(ae){return o(ae)}).then(function(ae){Ce(ae,null),X({type:"closeDialog"})}).catch(function(ae){IU(ae)?(fe(ae),X({type:"closeDialog"})):kU(ae)?(_e.current=!1,Z.current?(Z.current.value=null,Z.current.click()):Te(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."))):Te(ae)});return}Z.current&&(X({type:"openDialog"}),se(),Z.current.value=null,Z.current.click())},[X,se,fe,E,Ce,Te,de,l]),Ve=M.useCallback(function(U){!q.current||!q.current.isEqualNode(U.target)||(U.key===" "||U.key==="Enter"||U.keyCode===32||U.keyCode===13)&&(U.preventDefault(),ne())},[q,ne]),Qe=M.useCallback(function(){X({type:"focus"})},[]),Ct=M.useCallback(function(){X({type:"blur"})},[]),Jt=M.useCallback(function(){P||(_U()?setTimeout(ne,0):ne())},[P,ne]),bt=function(ae){return r?null:ae},an=function(ae){return _?null:bt(ae)},zt=function(ae){return D?null:bt(ae)},$n=function(ae){H&&ae.stopPropagation()},Kt=M.useMemo(function(){return function(){var U=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=U.refKey,ye=ae===void 0?"ref":ae,he=U.role,Ee=U.onKeyDown,Xe=U.onFocus,ft=U.onBlur,xt=U.onClick,Co=U.onDragEnter,Qt=U.onDragOver,vn=U.onDragLeave,qr=U.onDrop,Gt=gu(U,OU);return Bt(Bt(fm({onKeyDown:an(vo(Ee,Ve)),onFocus:an(vo(Xe,Qe)),onBlur:an(vo(ft,Ct)),onClick:bt(vo(xt,Jt)),onDragEnter:zt(vo(Co,z)),onDragOver:zt(vo(Qt,ce)),onDragLeave:zt(vo(vn,Ae)),onDrop:zt(vo(qr,Ne)),role:typeof he=="string"&&he!==""?he:"presentation"},ye,q),!r&&!_?{tabIndex:0}:{}),Gt)}},[q,Ve,Qe,Ct,Jt,z,ce,Ae,Ne,_,D,r]),L=M.useCallback(function(U){U.stopPropagation()},[]),J=M.useMemo(function(){return function(){var U=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=U.refKey,ye=ae===void 0?"ref":ae,he=U.onChange,Ee=U.onClick,Xe=gu(U,MU),ft=fm({accept:W,multiple:l,type:"file",style:{border:0,clip:"rect(0, 0, 0, 0)",clipPath:"inset(50%)",height:"1px",margin:"0 -1px -1px 0",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"},onChange:bt(vo(he,Ne)),onClick:bt(vo(Ee,L)),tabIndex:-1},ye,Z);return Bt(Bt({},ft),Xe)}},[Z,n,l,Ne,r]);return Bt(Bt({},Q),{},{isFocused:$&&!r,getRootProps:Kt,getInputProps:J,rootRef:q,inputRef:Z,open:bt(ne)})}function zU(t,e){switch(e.type){case"focus":return Bt(Bt({},t),{},{isFocused:!0});case"blur":return Bt(Bt({},t),{},{isFocused:!1});case"openDialog":return Bt(Bt({},pm),{},{isFileDialogActive:!0});case"closeDialog":return Bt(Bt({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Bt(Bt({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Bt(Bt({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Bt({},pm);default:return t}}function qE(){}const VU=({onFilesSelected:t,children:e})=>{const[n,r]=M.useState(!1),{getRootProps:o,getInputProps:i}=WE({noClick:!0,onDrop:s=>{if(s&&s.length>0)if(s[0].path.split("/").length>2){const u=s.map(h=>{const g=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:g,enumerable:!0,configurable:!0}),h});t(u,"folder")}else t(s,"files");r(!1)},onDragOver:s=>{s.preventDefault(),n||r(!0)},multiple:!0});return M.useEffect(()=>{const s=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",s),()=>{document.removeEventListener("dragleave",s)}},[]),d.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?d.jsx("div",{className:"flex flex-col items-center justify-center p-4 border-2 border-dashed border-gray-300 rounded-lg bg-gray-50 h-screen"}):e,d.jsx("input",{...i()})]})},KU=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:i,ignoreCache:s,autoSyncAfterFileOperation:l})=>{var N;const[u,h]=M.useState({}),[p,g]=M.useState(!1),[C,w]=M.useState(!1),[x,y]=M.useState(""),{toast:b}=dc();M.useEffect(()=>{t&&E(x)},[x,t]);const E=async P=>{try{w(!0);const _=await Le.get(`${n}/api/list-s3-folders?prefix=${P}`);h(_==null?void 0:_.data)}catch{b({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{w(!1)}},T=async()=>{g(!0);try{const P=o.key,_=P.endsWith("/")?P:`${P}/`,D=x.endsWith("/")?x:`${x}/`;if(_===D||P===x){b({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),g(!1);return}await Le.post(`${n}/api/move`,{oldPath:P,newPath:x}),s.current=!0,await i(),b({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${x}"`}),e(!1),r(null),y(""),l&&await l("move")}catch(P){console.error("Error renaming item:",P),b({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{g(!1)}};return d.jsx(ar,{open:t,onOpenChange:P=>{P||(e(!1),r(null),y(""))},children:d.jsxs(jn,{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:[d.jsxs(Wn,{className:"mb-4 w-full h-full",children:[d.jsx("nav",{className:"mb-4",children:d.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[d.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(""),children:"Root"}),x.split("/").map((P,_,D)=>d.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>y(P==="Root"?"":D.slice(0,_+1).join("/")+"/"),children:P},_))]})}),d.jsxs(qn,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",d.jsxs("span",{className:"text-sm text-gray-500",children:["( file hoặc folder sẽ được di chuyển đến thư mục"," ",x===""?"Root":x," )"]})]}),d.jsx(vi,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:C?d.jsx("div",{className:"flex justify-center items-center py-4",children:d.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):d.jsx("ul",{className:"space-y-2",children:(N=Object.keys(u))==null?void 0:N.map(P=>d.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>y(P),children:P},P))})})]}),d.jsxs(Hr,{className:"flex justify-end space-x-2",children:[d.jsx(He,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),d.jsx(He,{onClick:T,disabled:p,className:"s3-explr-crawl-btn",children:"Move"})]})]})})};function YE(t,[e,n]){return Math.min(n,Math.max(e,t))}function JE(t){const e=GU(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(WU);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function GU(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=YU(o),l=qU(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var jU=Symbol("radix.slottable");function WU(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===jU}function qU(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function YU(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}function JU(t){const e=t+"CollectionProvider",[n,r]=gr(e),[o,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),s=y=>{const{scope:b,children:E}=y,T=M.useRef(null),N=M.useRef(new Map).current;return d.jsx(o,{scope:b,itemMap:N,collectionRef:T,children:E})};s.displayName=e;const l=t+"CollectionSlot",u=JE(l),h=M.forwardRef((y,b)=>{const{scope:E,children:T}=y,N=i(l,E),P=rt(b,N.collectionRef);return d.jsx(u,{ref:P,children:T})});h.displayName=l;const p=t+"CollectionItemSlot",g="data-radix-collection-item",C=JE(p),w=M.forwardRef((y,b)=>{const{scope:E,children:T,...N}=y,P=M.useRef(null),_=rt(b,P),D=i(p,E);return M.useEffect(()=>(D.itemMap.set(P,{ref:P,...N}),()=>void D.itemMap.delete(P))),d.jsx(C,{[g]:"",ref:_,children:T})});w.displayName=p;function x(y){const b=i(t+"CollectionConsumer",y);return M.useCallback(()=>{const T=b.collectionRef.current;if(!T)return[];const N=Array.from(T.querySelectorAll(`[${g}]`));return Array.from(b.itemMap.values()).sort((D,H)=>N.indexOf(D.ref.current)-N.indexOf(H.ref.current))},[b.collectionRef,b.itemMap])}return[{Provider:s,Slot:h,ItemSlot:w},x,r]}function QE(t){const e=QU(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(ZU);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function QU(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=tB(o),l=eB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var XU=Symbol("radix.slottable");function ZU(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===XU}function eB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function tB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var nB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],mn=nB.reduce((t,e)=>{const n=QE(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function rB(t,e){t&&_a.flushSync(()=>t.dispatchEvent(e))}var oB="DismissableLayer",gm="dismissableLayer.update",iB="dismissableLayer.pointerDownOutside",aB="dismissableLayer.focusOutside",XE,ZE=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),eT=m.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:s,onDismiss:l,...u}=t,h=m.useContext(ZE),[p,g]=m.useState(null),C=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,w]=m.useState({}),x=rt(e,H=>g(H)),y=Array.from(h.layers),[b]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),E=y.indexOf(b),T=p?y.indexOf(p):-1,N=h.layersWithOutsidePointerEventsDisabled.size>0,P=T>=E,_=lB(H=>{const K=H.target,ee=[...h.branches].some(W=>W.contains(K));!P||ee||(o==null||o(H),s==null||s(H),H.defaultPrevented||l==null||l())},C),D=dB(H=>{const K=H.target;[...h.branches].some(W=>W.contains(K))||(i==null||i(H),s==null||s(H),H.defaultPrevented||l==null||l())},C);return $C(H=>{T===h.layers.size-1&&(r==null||r(H),!H.defaultPrevented&&l&&(H.preventDefault(),l()))},C),m.useEffect(()=>{if(p)return n&&(h.layersWithOutsidePointerEventsDisabled.size===0&&(XE=C.body.style.pointerEvents,C.body.style.pointerEvents="none"),h.layersWithOutsidePointerEventsDisabled.add(p)),h.layers.add(p),tT(),()=>{n&&h.layersWithOutsidePointerEventsDisabled.size===1&&(C.body.style.pointerEvents=XE)}},[p,C,n,h]),m.useEffect(()=>()=>{p&&(h.layers.delete(p),h.layersWithOutsidePointerEventsDisabled.delete(p),tT())},[p,h]),m.useEffect(()=>{const H=()=>w({});return document.addEventListener(gm,H),()=>document.removeEventListener(gm,H)},[]),d.jsx(mn.div,{...u,ref:x,style:{pointerEvents:N?P?"auto":"none":void 0,...t.style},onFocusCapture:Ue(t.onFocusCapture,D.onFocusCapture),onBlurCapture:Ue(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:Ue(t.onPointerDownCapture,_.onPointerDownCapture)})});eT.displayName=oB;var sB="DismissableLayerBranch",cB=m.forwardRef((t,e)=>{const n=m.useContext(ZE),r=m.useRef(null),o=rt(e,r);return m.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),d.jsx(mn.div,{...t,ref:o})});cB.displayName=sB;function lB(t,e=globalThis==null?void 0:globalThis.document){const n=gn(t),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const i=l=>{if(l.target&&!r.current){let u=function(){nT(iB,n,h,{discrete:!0})};const h={originalEvent:l};l.pointerType==="touch"?(e.removeEventListener("click",o.current),o.current=u,e.addEventListener("click",o.current,{once:!0})):u()}else e.removeEventListener("click",o.current);r.current=!1},s=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(s),e.removeEventListener("pointerdown",i),e.removeEventListener("click",o.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function dB(t,e=globalThis==null?void 0:globalThis.document){const n=gn(t),r=m.useRef(!1);return m.useEffect(()=>{const o=i=>{i.target&&!r.current&&nT(aB,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",o),()=>e.removeEventListener("focusin",o)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function tT(){const t=new CustomEvent(gm);document.dispatchEvent(t)}function nT(t,e,n,{discrete:r}){const o=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&o.addEventListener(t,e,{once:!0}),r?rB(o,i):o.dispatchEvent(i)}var mm="focusScope.autoFocusOnMount",vm="focusScope.autoFocusOnUnmount",rT={bubbles:!1,cancelable:!0},uB="FocusScope",oT=m.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:i,...s}=t,[l,u]=m.useState(null),h=gn(o),p=gn(i),g=m.useRef(null),C=rt(e,y=>u(y)),w=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let y=function(N){if(w.paused||!l)return;const P=N.target;l.contains(P)?g.current=P:Ci(g.current,{select:!0})},b=function(N){if(w.paused||!l)return;const P=N.relatedTarget;P!==null&&(l.contains(P)||Ci(g.current,{select:!0}))},E=function(N){if(document.activeElement===document.body)for(const _ of N)_.removedNodes.length>0&&Ci(l)};document.addEventListener("focusin",y),document.addEventListener("focusout",b);const T=new MutationObserver(E);return l&&T.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",b),T.disconnect()}}},[r,l,w.paused]),m.useEffect(()=>{if(l){sT.add(w);const y=document.activeElement;if(!l.contains(y)){const E=new CustomEvent(mm,rT);l.addEventListener(mm,h),l.dispatchEvent(E),E.defaultPrevented||(fB(vB(iT(l)),{select:!0}),document.activeElement===y&&Ci(l))}return()=>{l.removeEventListener(mm,h),setTimeout(()=>{const E=new CustomEvent(vm,rT);l.addEventListener(vm,p),l.dispatchEvent(E),E.defaultPrevented||Ci(y??document.body,{select:!0}),l.removeEventListener(vm,p),sT.remove(w)},0)}}},[l,h,p,w]);const x=m.useCallback(y=>{if(!n&&!r||w.paused)return;const b=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,E=document.activeElement;if(b&&E){const T=y.currentTarget,[N,P]=hB(T);N&&P?!y.shiftKey&&E===P?(y.preventDefault(),n&&Ci(N,{select:!0})):y.shiftKey&&E===N&&(y.preventDefault(),n&&Ci(P,{select:!0})):E===T&&y.preventDefault()}},[n,r,w.paused]);return d.jsx(mn.div,{tabIndex:-1,...s,ref:C,onKeyDown:x})});oT.displayName=uB;function fB(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Ci(r,{select:e}),document.activeElement!==n)return}function hB(t){const e=iT(t),n=aT(e,t),r=aT(e.reverse(),t);return[n,r]}function iT(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function aT(t,e){for(const n of t)if(!pB(n,{upTo:e}))return n}function pB(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function gB(t){return t instanceof HTMLInputElement&&"select"in t}function Ci(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&gB(t)&&e&&t.select()}}var sT=mB();function mB(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=cT(t,e),t.unshift(e)},remove(e){var n;t=cT(t,e),(n=t[0])==null||n.resume()}}}function cT(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function vB(t){return t.filter(e=>e.tagName!=="A")}function yB(t){const e=wB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(bB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function wB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=SB(o),l=xB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var CB=Symbol("radix.slottable");function bB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===CB}function xB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function SB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var _B=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],EB=_B.reduce((t,e)=>{const n=yB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),TB="Arrow",lT=m.forwardRef((t,e)=>{const{children:n,width:r=10,height:o=5,...i}=t;return d.jsx(EB.svg,{...i,ref:e,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});lT.displayName=TB;var AB=lT;function IB(t){const e=kB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(PB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function kB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=MB(o),l=OB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var NB=Symbol("radix.slottable");function PB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===NB}function OB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function MB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var RB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],dT=RB.reduce((t,e)=>{const n=IB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),ym="Popper",[uT,fT]=gr(ym),[DB,hT]=uT(ym),pT=t=>{const{__scopePopper:e,children:n}=t,[r,o]=m.useState(null);return d.jsx(DB,{scope:e,anchor:r,onAnchorChange:o,children:n})};pT.displayName=ym;var gT="PopperAnchor",mT=m.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,i=hT(gT,n),s=m.useRef(null),l=rt(e,s);return m.useEffect(()=>{i.onAnchorChange((r==null?void 0:r.current)||s.current)}),r?null:d.jsx(dT.div,{...o,ref:l})});mT.displayName=gT;var wm="PopperContent",[LB,FB]=uT(wm),vT=m.forwardRef((t,e)=>{var z,ce,Ae,Ce,Ne,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:i="center",alignOffset:s=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:p=0,sticky:g="partial",hideWhenDetached:C=!1,updatePositionStrategy:w="optimized",onPlaced:x,...y}=t,b=hT(wm,n),[E,T]=m.useState(null),N=rt(e,Ve=>T(Ve)),[P,_]=m.useState(null),D=mg(P),H=(D==null?void 0:D.width)??0,K=(D==null?void 0:D.height)??0,ee=r+(i!=="center"?"-"+i:""),W=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},de=Array.isArray(h)?h:[h],se=de.length>0,fe={padding:W,boundary:de.filter(HB),altBoundary:se},{refs:q,floatingStyles:Z,placement:Y,isPositioned:oe,middlewareData:Q}=I_({strategy:"fixed",placement:ee,whileElementsMounted:(...Ve)=>__(...Ve,{animationFrame:w==="always"}),elements:{reference:b.anchor},middleware:[k_({mainAxis:o+K,alignmentAxis:s}),u&&N_({mainAxis:!0,crossAxis:!1,limiter:g==="partial"?P_():void 0,...fe}),u&&O_({...fe}),M_({...fe,apply:({elements:Ve,rects:Qe,availableWidth:Ct,availableHeight:Jt})=>{const{width:bt,height:an}=Qe.reference,zt=Ve.floating.style;zt.setProperty("--radix-popper-available-width",`${Ct}px`),zt.setProperty("--radix-popper-available-height",`${Jt}px`),zt.setProperty("--radix-popper-anchor-width",`${bt}px`),zt.setProperty("--radix-popper-anchor-height",`${an}px`)}}),P&&D_({element:P,padding:l}),UB({arrowWidth:H,arrowHeight:K}),C&&R_({strategy:"referenceHidden",...fe})]}),[X,$]=CT(Y),te=gn(x);rn(()=>{oe&&(te==null||te())},[oe,te]);const _e=(z=Q.arrow)==null?void 0:z.x,ke=(ce=Q.arrow)==null?void 0:ce.y,xe=((Ae=Q.arrow)==null?void 0:Ae.centerOffset)!==0,[Pe,Te]=m.useState();return rn(()=>{E&&Te(window.getComputedStyle(E).zIndex)},[E]),d.jsx("div",{ref:q.setFloating,"data-radix-popper-content-wrapper":"",style:{...Z,transform:oe?Z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Pe,"--radix-popper-transform-origin":[(Ce=Q.transformOrigin)==null?void 0:Ce.x,(Ne=Q.transformOrigin)==null?void 0:Ne.y].join(" "),...((ne=Q.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(LB,{scope:n,placedSide:X,onArrowChange:_,arrowX:_e,arrowY:ke,shouldHideArrow:xe,children:d.jsx(dT.div,{"data-side":X,"data-align":$,...y,ref:N,style:{...y.style,animation:oe?void 0:"none"}})})})});vT.displayName=wm;var yT="PopperArrow",$B={top:"bottom",right:"left",bottom:"top",left:"right"},wT=m.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,i=FB(yT,r),s=$B[i.placedSide];return d.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:d.jsx(AB,{...o,ref:n,style:{...o.style,display:"block"}})})});wT.displayName=yT;function HB(t){return t!==null}var UB=t=>({name:"transformOrigin",options:t,fn(e){var b,E,T;const{placement:n,rects:r,middlewareData:o}=e,s=((b=o.arrow)==null?void 0:b.centerOffset)!==0,l=s?0:t.arrowWidth,u=s?0:t.arrowHeight,[h,p]=CT(n),g={start:"0%",center:"50%",end:"100%"}[p],C=(((E=o.arrow)==null?void 0:E.x)??0)+l/2,w=(((T=o.arrow)==null?void 0:T.y)??0)+u/2;let x="",y="";return h==="bottom"?(x=s?g:`${C}px`,y=`${-u}px`):h==="top"?(x=s?g:`${C}px`,y=`${r.floating.height+u}px`):h==="right"?(x=`${-u}px`,y=s?g:`${w}px`):h==="left"&&(x=`${r.floating.width+u}px`,y=s?g:`${w}px`),{data:{x,y}}}});function CT(t){const[e,n="center"]=t.split("-");return[e,n]}var BB=pT,zB=mT,VB=vT,KB=wT,GB="Portal",bT=m.forwardRef((t,e)=>{var l;const{container:n,...r}=t,[o,i]=m.useState(!1);rn(()=>i(!0),[]);const s=n||o&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return s?zf.createPortal(d.jsx(mn.div,{...r,ref:e}),s):null});bT.displayName=GB;function jB(t){const e=WB(t),n=m.forwardRef((r,o)=>{const{children:i,...s}=r,l=m.Children.toArray(i),u=l.find(YB);if(u){const h=u.props.children,p=l.map(g=>g===u?m.Children.count(h)>1?m.Children.only(null):m.isValidElement(h)?h.props.children:null:g);return d.jsx(e,{...s,ref:o,children:m.isValidElement(h)?m.cloneElement(h,void 0,p):null})}return d.jsx(e,{...s,ref:o,children:i})});return n.displayName=`${t}.Slot`,n}function WB(t){const e=m.forwardRef((n,r)=>{const{children:o,...i}=n;if(m.isValidElement(o)){const s=QB(o),l=JB(i,o.props);return o.type!==m.Fragment&&(l.ref=r?Fi(r,s):s),m.cloneElement(o,l)}return m.Children.count(o)>1?m.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var qB=Symbol("radix.slottable");function YB(t){return m.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qB}function JB(t,e){const n={...e};for(const r in e){const o=t[r],i=e[r];/^on[A-Z]/.test(r)?o&&i?n[r]=(...l)=>{const u=i(...l);return o(...l),u}:o&&(n[r]=o):r==="style"?n[r]={...o,...i}:r==="className"&&(n[r]=[o,i].filter(Boolean).join(" "))}return{...t,...n}}function QB(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var XB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ZB=XB.reduce((t,e)=>{const n=jB(`Primitive.${e}`),r=m.forwardRef((o,i)=>{const{asChild:s,...l}=o,u=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(u,{...l,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{}),xT=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),e3="VisuallyHidden",t3=m.forwardRef((t,e)=>d.jsx(ZB.span,{...t,ref:e,style:{...xT,...t.style}}));t3.displayName=e3;var n3=[" ","Enter","ArrowUp","ArrowDown"],r3=[" ","Enter"],qi="Select",[mu,vu,o3]=JU(qi),[ts,yW]=gr(qi,[o3,fT]),yu=fT(),[i3,bi]=ts(qi),[a3,s3]=ts(qi),ST=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:o,onOpenChange:i,value:s,defaultValue:l,onValueChange:u,dir:h,name:p,autoComplete:g,disabled:C,required:w,form:x}=t,y=yu(e),[b,E]=m.useState(null),[T,N]=m.useState(null),[P,_]=m.useState(!1),D=wg(h),[H,K]=li({prop:r,defaultProp:o??!1,onChange:i,caller:qi}),[ee,W]=li({prop:s,defaultProp:l,onChange:u,caller:qi}),de=m.useRef(null),se=b?x||!!b.closest("form"):!0,[fe,q]=m.useState(new Set),Z=Array.from(fe).map(Y=>Y.props.value).join(";");return d.jsx(BB,{...y,children:d.jsxs(i3,{required:w,scope:e,trigger:b,onTriggerChange:E,valueNode:T,onValueNodeChange:N,valueNodeHasChildren:P,onValueNodeHasChildrenChange:_,contentId:Oo(),value:ee,onValueChange:W,open:H,onOpenChange:K,dir:D,triggerPointerDownPosRef:de,disabled:C,children:[d.jsx(mu.Provider,{scope:e,children:d.jsx(a3,{scope:t.__scopeSelect,onNativeOptionAdd:m.useCallback(Y=>{q(oe=>new Set(oe).add(Y))},[]),onNativeOptionRemove:m.useCallback(Y=>{q(oe=>{const Q=new Set(oe);return Q.delete(Y),Q})},[]),children:n})}),se?d.jsxs(GT,{"aria-hidden":!0,required:w,tabIndex:-1,name:p,autoComplete:g,value:ee,onChange:Y=>W(Y.target.value),disabled:C,form:x,children:[ee===void 0?d.jsx("option",{value:""}):null,Array.from(fe)]},Z):null]})})};ST.displayName=qi;var _T="SelectTrigger",ET=m.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,i=yu(n),s=bi(_T,n),l=s.disabled||r,u=rt(e,s.onTriggerChange),h=vu(n),p=m.useRef("touch"),[g,C,w]=WT(y=>{const b=h().filter(N=>!N.disabled),E=b.find(N=>N.value===s.value),T=qT(b,y,E);T!==void 0&&s.onValueChange(T.value)}),x=y=>{l||(s.onOpenChange(!0),w()),y&&(s.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return d.jsx(zB,{asChild:!0,...i,children:d.jsx(mn.button,{type:"button",role:"combobox","aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":"none",dir:s.dir,"data-state":s.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":jT(s.value)?"":void 0,...o,ref:u,onClick:Ue(o.onClick,y=>{y.currentTarget.focus(),p.current!=="mouse"&&x(y)}),onPointerDown:Ue(o.onPointerDown,y=>{p.current=y.pointerType;const b=y.target;b.hasPointerCapture(y.pointerId)&&b.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(x(y),y.preventDefault())}),onKeyDown:Ue(o.onKeyDown,y=>{const b=g.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&C(y.key),!(b&&y.key===" ")&&n3.includes(y.key)&&(x(),y.preventDefault())})})})});ET.displayName=_T;var TT="SelectValue",AT=m.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:i,placeholder:s="",...l}=t,u=bi(TT,n),{onValueNodeHasChildrenChange:h}=u,p=i!==void 0,g=rt(e,u.onValueNodeChange);return rn(()=>{h(p)},[h,p]),d.jsx(mn.span,{...l,ref:g,style:{pointerEvents:"none"},children:jT(u.value)?d.jsx(d.Fragment,{children:s}):i})});AT.displayName=TT;var c3="SelectIcon",IT=m.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return d.jsx(mn.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});IT.displayName=c3;var l3="SelectPortal",kT=t=>d.jsx(bT,{asChild:!0,...t});kT.displayName=l3;var Yi="SelectContent",NT=m.forwardRef((t,e)=>{const n=bi(Yi,t.__scopeSelect),[r,o]=m.useState();if(rn(()=>{o(new DocumentFragment)},[]),!n.open){const i=r;return i?_a.createPortal(d.jsx(PT,{scope:t.__scopeSelect,children:d.jsx(mu.Slot,{scope:t.__scopeSelect,children:d.jsx("div",{children:t.children})})}),i):null}return d.jsx(OT,{...t,ref:e})});NT.displayName=Yi;var Gr=10,[PT,xi]=ts(Yi),d3="SelectContentImpl",u3=QE("SelectContent.RemoveScroll"),OT=m.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:i,onPointerDownOutside:s,side:l,sideOffset:u,align:h,alignOffset:p,arrowPadding:g,collisionBoundary:C,collisionPadding:w,sticky:x,hideWhenDetached:y,avoidCollisions:b,...E}=t,T=bi(Yi,n),[N,P]=m.useState(null),[_,D]=m.useState(null),H=rt(e,z=>P(z)),[K,ee]=m.useState(null),[W,de]=m.useState(null),se=vu(n),[fe,q]=m.useState(!1),Z=m.useRef(!1);m.useEffect(()=>{if(N)return hb(N)},[N]),JC();const Y=m.useCallback(z=>{const[ce,...Ae]=se().map(ne=>ne.ref.current),[Ce]=Ae.slice(-1),Ne=document.activeElement;for(const ne of z)if(ne===Ne||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===ce&&_&&(_.scrollTop=0),ne===Ce&&_&&(_.scrollTop=_.scrollHeight),ne==null||ne.focus(),document.activeElement!==Ne))return},[se,_]),oe=m.useCallback(()=>Y([K,N]),[Y,K,N]);m.useEffect(()=>{fe&&oe()},[fe,oe]);const{onOpenChange:Q,triggerPointerDownPosRef:X}=T;m.useEffect(()=>{if(N){let z={x:0,y:0};const ce=Ce=>{var Ne,ne;z={x:Math.abs(Math.round(Ce.pageX)-(((Ne=X.current)==null?void 0:Ne.x)??0)),y:Math.abs(Math.round(Ce.pageY)-(((ne=X.current)==null?void 0:ne.y)??0))}},Ae=Ce=>{z.x<=10&&z.y<=10?Ce.preventDefault():N.contains(Ce.target)||Q(!1),document.removeEventListener("pointermove",ce),X.current=null};return X.current!==null&&(document.addEventListener("pointermove",ce),document.addEventListener("pointerup",Ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ce),document.removeEventListener("pointerup",Ae,{capture:!0})}}},[N,Q,X]),m.useEffect(()=>{const z=()=>Q(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[Q]);const[$,te]=WT(z=>{const ce=se().filter(Ne=>!Ne.disabled),Ae=ce.find(Ne=>Ne.ref.current===document.activeElement),Ce=qT(ce,z,Ae);Ce&&setTimeout(()=>Ce.ref.current.focus())}),_e=m.useCallback((z,ce,Ae)=>{const Ce=!Z.current&&!Ae;(T.value!==void 0&&T.value===ce||Ce)&&(ee(z),Ce&&(Z.current=!0))},[T.value]),ke=m.useCallback(()=>N==null?void 0:N.focus(),[N]),xe=m.useCallback((z,ce,Ae)=>{const Ce=!Z.current&&!Ae;(T.value!==void 0&&T.value===ce||Ce)&&de(z)},[T.value]),Pe=r==="popper"?Cm:MT,Te=Pe===Cm?{side:l,sideOffset:u,align:h,alignOffset:p,arrowPadding:g,collisionBoundary:C,collisionPadding:w,sticky:x,hideWhenDetached:y,avoidCollisions:b}:{};return d.jsx(PT,{scope:n,content:N,viewport:_,onViewportChange:D,itemRefCallback:_e,selectedItem:K,onItemLeave:ke,itemTextRefCallback:xe,focusSelectedItem:oe,selectedItemText:W,position:r,isPositioned:fe,searchRef:$,children:d.jsx(Sp,{as:u3,allowPinchZoom:!0,children:d.jsx(oT,{asChild:!0,trapped:T.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:Ue(o,z=>{var ce;(ce=T.trigger)==null||ce.focus({preventScroll:!0}),z.preventDefault()}),children:d.jsx(eT,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:d.jsx(Pe,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:z=>z.preventDefault(),...E,...Te,onPlaced:()=>q(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:Ue(E.onKeyDown,z=>{const ce=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!ce&&z.key.length===1&&te(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let Ce=se().filter(Ne=>!Ne.disabled).map(Ne=>Ne.ref.current);if(["ArrowUp","End"].includes(z.key)&&(Ce=Ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const Ne=z.target,ne=Ce.indexOf(Ne);Ce=Ce.slice(ne+1)}setTimeout(()=>Y(Ce)),z.preventDefault()}})})})})})})});OT.displayName=d3;var f3="SelectItemAlignedPosition",MT=m.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,i=bi(Yi,n),s=xi(Yi,n),[l,u]=m.useState(null),[h,p]=m.useState(null),g=rt(e,H=>p(H)),C=vu(n),w=m.useRef(!1),x=m.useRef(!0),{viewport:y,selectedItem:b,selectedItemText:E,focusSelectedItem:T}=s,N=m.useCallback(()=>{if(i.trigger&&i.valueNode&&l&&h&&y&&b&&E){const H=i.trigger.getBoundingClientRect(),K=h.getBoundingClientRect(),ee=i.valueNode.getBoundingClientRect(),W=E.getBoundingClientRect();if(i.dir!=="rtl"){const Ne=W.left-K.left,ne=ee.left-Ne,Ve=H.left-ne,Qe=H.width+Ve,Ct=Math.max(Qe,K.width),Jt=window.innerWidth-Gr,bt=YE(ne,[Gr,Math.max(Gr,Jt-Ct)]);l.style.minWidth=Qe+"px",l.style.left=bt+"px"}else{const Ne=K.right-W.right,ne=window.innerWidth-ee.right-Ne,Ve=window.innerWidth-H.right-ne,Qe=H.width+Ve,Ct=Math.max(Qe,K.width),Jt=window.innerWidth-Gr,bt=YE(ne,[Gr,Math.max(Gr,Jt-Ct)]);l.style.minWidth=Qe+"px",l.style.right=bt+"px"}const de=C(),se=window.innerHeight-Gr*2,fe=y.scrollHeight,q=window.getComputedStyle(h),Z=parseInt(q.borderTopWidth,10),Y=parseInt(q.paddingTop,10),oe=parseInt(q.borderBottomWidth,10),Q=parseInt(q.paddingBottom,10),X=Z+Y+fe+Q+oe,$=Math.min(b.offsetHeight*5,X),te=window.getComputedStyle(y),_e=parseInt(te.paddingTop,10),ke=parseInt(te.paddingBottom,10),xe=H.top+H.height/2-Gr,Pe=se-xe,Te=b.offsetHeight/2,z=b.offsetTop+Te,ce=Z+Y+z,Ae=X-ce;if(ce<=xe){const Ne=de.length>0&&b===de[de.length-1].ref.current;l.style.bottom="0px";const ne=h.clientHeight-y.offsetTop-y.offsetHeight,Ve=Math.max(Pe,Te+(Ne?ke:0)+ne+oe),Qe=ce+Ve;l.style.height=Qe+"px"}else{const Ne=de.length>0&&b===de[0].ref.current;l.style.top="0px";const Ve=Math.max(xe,Z+y.offsetTop+(Ne?_e:0)+Te)+Ae;l.style.height=Ve+"px",y.scrollTop=ce-xe+y.offsetTop}l.style.margin=`${Gr}px 0`,l.style.minHeight=$+"px",l.style.maxHeight=se+"px",r==null||r(),requestAnimationFrame(()=>w.current=!0)}},[C,i.trigger,i.valueNode,l,h,y,b,E,i.dir,r]);rn(()=>N(),[N]);const[P,_]=m.useState();rn(()=>{h&&_(window.getComputedStyle(h).zIndex)},[h]);const D=m.useCallback(H=>{H&&x.current===!0&&(N(),T==null||T(),x.current=!1)},[N,T]);return d.jsx(p3,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:w,onScrollButtonChange:D,children:d.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:P},children:d.jsx(mn.div,{...o,ref:g,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});MT.displayName=f3;var h3="SelectPopperPosition",Cm=m.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Gr,...i}=t,s=yu(n);return d.jsx(VB,{...s,...i,ref:e,align:r,collisionPadding:o,style:{boxSizing:"border-box",...i.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Cm.displayName=h3;var[p3,bm]=ts(Yi,{}),xm="SelectViewport",RT=m.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,i=xi(xm,n),s=bm(xm,n),l=rt(e,i.onViewportChange),u=m.useRef(0);return d.jsxs(d.Fragment,{children:[d.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),d.jsx(mu.Slot,{scope:n,children:d.jsx(mn.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:Ue(o.onScroll,h=>{const p=h.currentTarget,{contentWrapper:g,shouldExpandOnScrollRef:C}=s;if(C!=null&&C.current&&g){const w=Math.abs(u.current-p.scrollTop);if(w>0){const x=window.innerHeight-Gr*2,y=parseFloat(g.style.minHeight),b=parseFloat(g.style.height),E=Math.max(y,b);if(E<x){const T=E+w,N=Math.min(x,T),P=T-N;g.style.height=N+"px",g.style.bottom==="0px"&&(p.scrollTop=P>0?P:0,g.style.justifyContent="flex-end")}}}u.current=p.scrollTop})})})]})});RT.displayName=xm;var DT="SelectGroup",[g3,m3]=ts(DT),v3=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Oo();return d.jsx(g3,{scope:n,id:o,children:d.jsx(mn.div,{role:"group","aria-labelledby":o,...r,ref:e})})});v3.displayName=DT;var LT="SelectLabel",FT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=m3(LT,n);return d.jsx(mn.div,{id:o.id,...r,ref:e})});FT.displayName=LT;var wu="SelectItem",[y3,$T]=ts(wu),HT=m.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:i,...s}=t,l=bi(wu,n),u=xi(wu,n),h=l.value===r,[p,g]=m.useState(i??""),[C,w]=m.useState(!1),x=rt(e,T=>{var N;return(N=u.itemRefCallback)==null?void 0:N.call(u,T,r,o)}),y=Oo(),b=m.useRef("touch"),E=()=>{o||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return d.jsx(y3,{scope:n,value:r,disabled:o,textId:y,isSelected:h,onItemTextChange:m.useCallback(T=>{g(N=>N||((T==null?void 0:T.textContent)??"").trim())},[]),children:d.jsx(mu.ItemSlot,{scope:n,value:r,disabled:o,textValue:p,children:d.jsx(mn.div,{role:"option","aria-labelledby":y,"data-highlighted":C?"":void 0,"aria-selected":h&&C,"data-state":h?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...s,ref:x,onFocus:Ue(s.onFocus,()=>w(!0)),onBlur:Ue(s.onBlur,()=>w(!1)),onClick:Ue(s.onClick,()=>{b.current!=="mouse"&&E()}),onPointerUp:Ue(s.onPointerUp,()=>{b.current==="mouse"&&E()}),onPointerDown:Ue(s.onPointerDown,T=>{b.current=T.pointerType}),onPointerMove:Ue(s.onPointerMove,T=>{var N;b.current=T.pointerType,o?(N=u.onItemLeave)==null||N.call(u):b.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Ue(s.onPointerLeave,T=>{var N;T.currentTarget===document.activeElement&&((N=u.onItemLeave)==null||N.call(u))}),onKeyDown:Ue(s.onKeyDown,T=>{var P;((P=u.searchRef)==null?void 0:P.current)!==""&&T.key===" "||(r3.includes(T.key)&&E(),T.key===" "&&T.preventDefault())})})})})});HT.displayName=wu;var yc="SelectItemText",UT=m.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...i}=t,s=bi(yc,n),l=xi(yc,n),u=$T(yc,n),h=s3(yc,n),[p,g]=m.useState(null),C=rt(e,E=>g(E),u.onItemTextChange,E=>{var T;return(T=l.itemTextRefCallback)==null?void 0:T.call(l,E,u.value,u.disabled)}),w=p==null?void 0:p.textContent,x=m.useMemo(()=>d.jsx("option",{value:u.value,disabled:u.disabled,children:w},u.value),[u.disabled,u.value,w]),{onNativeOptionAdd:y,onNativeOptionRemove:b}=h;return rn(()=>(y(x),()=>b(x)),[y,b,x]),d.jsxs(d.Fragment,{children:[d.jsx(mn.span,{id:u.textId,...i,ref:C}),u.isSelected&&s.valueNode&&!s.valueNodeHasChildren?_a.createPortal(i.children,s.valueNode):null]})});UT.displayName=yc;var BT="SelectItemIndicator",zT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return $T(BT,n).isSelected?d.jsx(mn.span,{"aria-hidden":!0,...r,ref:e}):null});zT.displayName=BT;var Sm="SelectScrollUpButton",w3=m.forwardRef((t,e)=>{const n=xi(Sm,t.__scopeSelect),r=bm(Sm,t.__scopeSelect),[o,i]=m.useState(!1),s=rt(e,r.onScrollButtonChange);return rn(()=>{if(n.viewport&&n.isPositioned){let l=function(){const h=u.scrollTop>0;i(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),o?d.jsx(VT,{...t,ref:s,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});w3.displayName=Sm;var _m="SelectScrollDownButton",C3=m.forwardRef((t,e)=>{const n=xi(_m,t.__scopeSelect),r=bm(_m,t.__scopeSelect),[o,i]=m.useState(!1),s=rt(e,r.onScrollButtonChange);return rn(()=>{if(n.viewport&&n.isPositioned){let l=function(){const h=u.scrollHeight-u.clientHeight,p=Math.ceil(u.scrollTop)<h;i(p)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),o?d.jsx(VT,{...t,ref:s,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});C3.displayName=_m;var VT=m.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=t,i=xi("SelectScrollButton",n),s=m.useRef(null),l=vu(n),u=m.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return m.useEffect(()=>()=>u(),[u]),rn(()=>{var p;const h=l().find(g=>g.ref.current===document.activeElement);(p=h==null?void 0:h.ref.current)==null||p.scrollIntoView({block:"nearest"})},[l]),d.jsx(mn.div,{"aria-hidden":!0,...o,ref:e,style:{flexShrink:0,...o.style},onPointerDown:Ue(o.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(r,50))}),onPointerMove:Ue(o.onPointerMove,()=>{var h;(h=i.onItemLeave)==null||h.call(i),s.current===null&&(s.current=window.setInterval(r,50))}),onPointerLeave:Ue(o.onPointerLeave,()=>{u()})})}),b3="SelectSeparator",KT=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return d.jsx(mn.div,{"aria-hidden":!0,...r,ref:e})});KT.displayName=b3;var Em="SelectArrow",x3=m.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=yu(n),i=bi(Em,n),s=xi(Em,n);return i.open&&s.position==="popper"?d.jsx(KB,{...o,...r,ref:e}):null});x3.displayName=Em;var S3="SelectBubbleInput",GT=m.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=m.useRef(null),i=rt(r,o),s=oS(e);return m.useEffect(()=>{const l=o.current;if(!l)return;const u=window.HTMLSelectElement.prototype,p=Object.getOwnPropertyDescriptor(u,"value").set;if(s!==e&&p){const g=new Event("change",{bubbles:!0});p.call(l,e),l.dispatchEvent(g)}},[s,e]),d.jsx(mn.select,{...n,style:{...xT,...n.style},ref:i,defaultValue:e})});GT.displayName=S3;function jT(t){return t===""||t===void 0}function WT(t){const e=gn(t),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(s=>{const l=n.current+s;e(l),function u(h){n.current=h,window.clearTimeout(r.current),h!==""&&(r.current=window.setTimeout(()=>u(""),1e3))}(l)},[e]),i=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,i]}function qT(t,e,n){const o=e.length>1&&Array.from(e).every(h=>h===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let s=_3(t,Math.max(i,0));o.length===1&&(s=s.filter(h=>h!==n));const u=s.find(h=>h.textValue.toLowerCase().startsWith(o.toLowerCase()));return u!==n?u:void 0}function _3(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var E3=ST,YT=ET,T3=AT,A3=IT,I3=kT,JT=NT,k3=RT,QT=FT,XT=HT,N3=UT,P3=zT,ZT=KT;const Tm=E3,Am=T3,Cu=m.forwardRef(({className:t,children:e,...n},r)=>d.jsxs(YT,{ref:r,className:ze("flex h-9 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50",t),...n,children:[e,d.jsx(A3,{asChild:!0,children:d.jsx(UD,{className:"h-4 w-4 opacity-50"})})]}));Cu.displayName=YT.displayName;const bu=m.forwardRef(({className:t,children:e,position:n="popper",...r},o)=>d.jsx(I3,{children:d.jsx(JT,{ref:o,className:ze("relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,...r,children:d.jsx(k3,{className:ze("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e})})}));bu.displayName=JT.displayName;const O3=m.forwardRef(({className:t,...e},n)=>d.jsx(QT,{ref:n,className:ze("px-2 py-1.5 text-sm font-semibold",t),...e}));O3.displayName=QT.displayName;const Ji=m.forwardRef(({className:t,children:e,...n},r)=>d.jsxs(XT,{ref:r,className:ze("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[d.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(P3,{children:d.jsx(Fx,{className:"h-4 w-4"})})}),d.jsx(N3,{children:e})]}));Ji.displayName=XT.displayName;const M3=m.forwardRef(({className:t,...e},n)=>d.jsx(ZT,{ref:n,className:ze("-mx-1 my-1 h-px bg-muted",t),...e}));M3.displayName=ZT.displayName;const Im=[{value:"VIEW_DOCUMENT",label:"Chỉ xem"},{value:"EDIT_DOCUMENT",label:"Chỉnh sửa"},{value:"DOWNLOAD_DOCUMENT",label:"Tải xuống"}];function R3({onClose:t,open:e,file:n,apiBaseUrl:r,rootUrlHostApi:o}){const[i,s]=M.useState("users"),[l,u]=M.useState(""),[h,p]=M.useState(""),[g,C]=M.useState(""),[w,x]=M.useState(""),[y,b]=M.useState(Kr.VIEW_DOCUMENT),[E,T]=M.useState([]),{users:N,groups:P,sharedUsers:_,sharedGroups:D,fetchData:H,loading:K,postGranted:ee,loadingGrandted:W,setSharedGroups:de,setSharedUsers:se}=HH(r,o),fe=Vi(),q=n?n.key:"",Z=N.filter(z=>{var ce;return(fe==null?void 0:fe.id)!==z.id&&(z.username.toLowerCase().includes(l.toLowerCase())||((ce=z.email)==null?void 0:ce.toLowerCase().includes(l.toLowerCase())))}),Y=P.filter(z=>z.groupname.toLowerCase().includes(h.toLowerCase())),oe=_.filter(z=>{var ce,Ae;return((ce=z.username)==null?void 0:ce.toLowerCase().includes(g.toLowerCase()))||((Ae=z.email)==null?void 0:Ae.toLowerCase().includes(g.toLowerCase()))}),Q=D.filter(z=>{var ce;return(ce=z.groupname)==null?void 0:ce.toLowerCase().includes(w.toLowerCase())}),X=z=>{b(z),T(ce=>ce.map(Ae=>({...Ae,permissions:z})))},$=()=>{i==="users"?(u(""),C("")):(p(""),x(""),s("users")),T([]),b(Kr.VIEW_DOCUMENT)};M.useEffect(()=>{e?H(q):$()},[e,q]);const te=z=>{z!==i&&(i==="users"?(u(""),C("")):(p(""),x(""))),s(z)},_e=z=>{n&&T(ce=>{if(ce.find(ne=>ne.userId===z))return ce.filter(ne=>ne.userId!==z);const Ne={path:n.key+n.name,permissions:y,userId:z,grandtedBy:fe==null?void 0:fe.id};return[...ce,Ne]})},ke=z=>{if(!n)return;const ce=z.groupname;T(Ae=>{if(Ae.find(Ve=>Ve.groupname===ce))return Ae.filter(Ve=>Ve.groupname!==ce);const ne={path:n.key+n.name,permissions:y,groupname:ce,groupId:z.id,grandtedBy:fe==null?void 0:fe.id,users:z.users};return[...Ae,ne]})},xe=async(z,ce,Ae)=>{const Ce={...z,permissions:ce};T(Ne=>{const ne=Ne.map(Qe=>Qe.id===Ce.id?Ce:Qe);return Ne.some(Qe=>Qe.id===Ce.id)||ne.push(Ce),ne}),Ae==="users"?se(Ne=>Ne.map(ne=>ne.id===z.id?Ce:ne)):de(Ne=>Ne.map(ne=>ne.id===z.id?Ce:ne))},Pe=async()=>{if(n){const z=(n==null?void 0:n.key)||""+(n==null?void 0:n.name),ce=await ee(z,fe==null?void 0:fe.id,E);(ce==null?void 0:ce.status)==200&&T([])}},Te="flex-1 min-h-0 overflow-y-auto border rounded-lg px-3 py-2 bg-background shadow-sm";return n?d.jsx(ar,{open:e,onOpenChange:t,children:d.jsxs(jn,{className:"max-w-5xl h-[80vh] flex flex-col overflow-hidden",children:[d.jsx(Wn,{children:d.jsxs(qn,{className:"text-lg font-semibold",children:["Chia sẻ tài liệu: ",n.name]})}),d.jsxs(Sg,{defaultValue:"users",className:"flex-1 flex flex-col overflow-hidden",children:[d.jsxs(Yd,{className:"grid grid-cols-2 w-1/2 mx-auto mb-4 bg-muted rounded-lg",children:[d.jsx(Ki,{value:"users",className:"py-2",onClick:()=>te("users"),children:"Người dùng"}),d.jsx(Ki,{value:"groups",className:"py-2",onClick:()=>te("groups"),children:"Nhóm"})]}),d.jsx(Gi,{value:"users",className:"flex-1 h-full min-h-0 overflow-hidden",children:d.jsxs("div",{className:"grid grid-cols-2 gap-6 h-full",children:[d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Chia sẻ với người dùng:"}),d.jsx(Yn,{placeholder:"Tìm người dùng...",className:"mb-3 border-input bg-background shadow-sm",value:l,onChange:z=>u(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Z.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Không tìm thấy người dùng."}):d.jsx("ul",{className:"space-y-2",children:Z.map(z=>d.jsx("li",{onClick:()=>_e(z.id),className:"flex flex-col space-y-1 cursor-pointer hover:bg-accent p-2 rounded-md transition-colors",children:d.jsxs("div",{className:"flex items-center space-x-3",children:[d.jsx(oc,{id:`user-${z.id}`,checked:!!E.find(ce=>ce.userId===z.id)}),d.jsxs(mr,{className:"flex-1",children:[d.jsx("p",{className:"font-medium",children:z.username}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.email}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.groupname})]})]})},z.id))})})]}),d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Đã chia sẻ với người dùng:"}),d.jsx(Yn,{placeholder:"Tìm người dùng đã chia sẻ...",className:"mb-3 border-input bg-background shadow-sm",value:g,onChange:z=>C(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):oe.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Chưa chia sẻ với người dùng nào."}):d.jsx("ul",{className:"space-y-2",children:oe.map(z=>d.jsxs("li",{className:"flex items-center justify-between gap-4 hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsxs("div",{className:"flex flex-col",children:[d.jsx("p",{className:"font-medium",children:z.username}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.email}),d.jsx("p",{className:"text-xs text-muted-foreground",children:z.groupname})]}),d.jsxs(Tm,{value:z.permissions,onValueChange:ce=>xe(z,ce,"users"),disabled:z.permissions===Kr.OWNER_DOCUMENT,children:[d.jsx(Cu,{className:"w-[120px]",children:d.jsx(Am,{placeholder:"Chọn quyền"})}),d.jsxs(bu,{children:[Im.map(ce=>d.jsx(Ji,{value:ce.value,children:ce.label},ce.value)),z.permissions===Kr.OWNER_DOCUMENT&&d.jsx(Ji,{value:Kr.OWNER_DOCUMENT,children:"Chủ sở hữu"},Kr.OWNER_DOCUMENT),d.jsx(Ji,{value:"None",children:"Thu hồi"},"None")]})]})]},z.id))})})]})]})}),d.jsx(Gi,{value:"groups",className:"flex-1 h-full min-h-0 overflow-hidden",children:d.jsxs("div",{className:"grid grid-cols-2 gap-6 h-full",children:[d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Chia sẻ với nhóm:"}),d.jsx(Yn,{placeholder:"Tìm nhóm...",className:"mb-3 border-input bg-background shadow-sm",value:h,onChange:z=>p(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Y.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Không tìm thấy nhóm."}):d.jsx("ul",{className:"space-y-2",children:Y.map(z=>d.jsxs("li",{onClick:()=>ke(z),className:"flex items-center space-x-3 cursor-pointer hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsx(oc,{id:`group-${z.groupname}`,checked:!!E.find(ce=>ce.groupname===z.groupname)}),d.jsxs(mr,{className:"font-medium",children:[d.jsx("p",{className:"font-medium",children:z.groupname}),d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Số lượng: ",z.users||0]})]})]},z.groupname))})})]}),d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx("p",{className:"text-sm font-semibold mb-2",children:"Đã chia sẻ với nhóm:"}),d.jsx(Yn,{placeholder:"Tìm nhóm đã chia sẻ...",className:"mb-3 border-input bg-background shadow-sm",value:w,onChange:z=>x(z.target.value)}),d.jsx("div",{className:Te,children:K?d.jsx("div",{className:"flex items-center justify-center h-full",children:d.jsx(Pt,{className:"h-10 w-10 animate-spin text-muted-foreground"})}):Q.length===0?d.jsx("p",{className:"text-muted-foreground italic text-center h-full flex items-center justify-center",children:"Chưa chia sẻ với nhóm nào."}):d.jsx("ul",{className:"space-y-2",children:Q.map(z=>d.jsxs("li",{className:"flex items-center justify-between gap-4 hover:bg-accent p-2 rounded-md transition-colors",children:[d.jsxs("div",{className:"flex flex-col",children:[d.jsx("p",{className:"font-medium",children:z.groupname}),d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Số lượng: ",z.users||0]})]}),d.jsxs(Tm,{value:z.permissions,onValueChange:ce=>xe(z,ce,"groups"),children:[d.jsx(Cu,{className:"w-[120px]",children:d.jsx(Am,{placeholder:"Chọn quyền"})}),d.jsxs(bu,{children:[Im.map(ce=>d.jsx(Ji,{value:ce.value,children:ce.label},ce.value)),d.jsx(Ji,{value:"None",children:"Thu hồi"},"None")]})]})]},z.groupname))})})]})]})})]}),d.jsxs("div",{className:"mt-4 bg-muted/50 p-4 rounded-lg",children:[d.jsx(mr,{className:"font-medium mb-2 block",children:"Phân quyền:"}),d.jsxs(Tm,{value:y,onValueChange:X,children:[d.jsx(Cu,{className:"w-1/2 border border-input bg-background shadow-sm hover:bg-accent",children:d.jsx(Am,{placeholder:"Chọn quyền truy cập"})}),d.jsx(bu,{children:Im.map(z=>d.jsx(Ji,{value:z.value,className:"flex items-center gap-2",children:z.label}))})]})]}),d.jsxs(Hr,{children:[d.jsx(He,{variant:"outline",onClick:t,children:"Huỷ"}),d.jsx(He,{variant:"default",onClick:Pe,disabled:E.length===0||W,className:"w-[120px] justify-center",children:W?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):"Lưu thay đổi"})]})]})}):null}const D3={},L3="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",F3="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",$3="https://www.googleapis.com/auth/drive";Do(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Do.isRetryableError(t)&&t.config.method==="get"});const Qn={current:!1},e0="crawl:jobs",ns="crawl:current_job",H3=t=>{const[e,n]=M.useState(null),[r,o]=M.useState(0);return M.useEffect(()=>{const i=localStorage.getItem(ns);if(i){const s=JSON.parse(i);n(s),s!=null&&s.startTime&&o(Math.floor((Date.now()-s.startTime)/1e3))}},[]),M.useEffect(()=>{if(!(e!=null&&e.startTime))return;const i=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(i)},[e==null?void 0:e.startTime]),M.useEffect(()=>{if(!(e!=null&&e.id))return;const i=async()=>{try{const u=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:u};return localStorage.setItem(ns,JSON.stringify(p)),(u.status==="completed"||u.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(ns)},100),p})}catch(l){console.error("Error polling job status:",l)}},s=setInterval(i,3e3);return i(),()=>clearInterval(s)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:i=>{i&&!i.startTime&&(i.startTime=Date.now()),n(i),i?localStorage.setItem(ns,JSON.stringify(i)):localStorage.removeItem(ns)}}},xu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(s=>{n.push(s.key),s.isFolder&&r(s.key)})};return r(e),n},U3=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...xu(t,o.key))}),n},B3=(t,e,n=[],r,o,i,s,l,u,h)=>{const[p,g]=M.useState({}),[C,w]=M.useState(!1),[x,y]=M.useState(null),[b,E]=M.useState(0),T=M.useRef(e);M.useEffect(()=>{T.current=e},[e]);const N=async()=>{var _;w(!0);try{const D=Vi(),H=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:T.current,userId:(D==null?void 0:D.id)||"",groupId:((_=D==null?void 0:D.group)==null?void 0:_.id)||"",groupname:(D==null?void 0:D.groupname)||""},timeout:3e5}),K=[];Md.forEach(H.data,(ee,W)=>{l!=null&&l.has(W)&&Md.forEach(ee,de=>{(u==null?void 0:u.current[de.key])!==!1&&K.push(de.key)})}),K.length&&(h==null||h(ee=>{const W=new Set(ee);return K.forEach(de=>W.add(de)),W})),g(H.data),y(null)}catch(D){y(D instanceof Error?D:new Error("Failed to fetch files"))}finally{w(!1),E(0),i("")}},P=async _=>{var D,H;try{if(!_)return;w(!0);const K=await Le.get(`${t}/api/search-db?query=${_}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return g({[e]:((D=K==null?void 0:K.data)==null?void 0:D.result)||[]}),E(((H=K==null?void 0:K.data)==null?void 0:H.estimatedTotalHits)||0),K}catch(K){y(K instanceof Error?K:new Error("Failed to fetch files"))}finally{w(!1)}};return M.useEffect(()=>{!r&&!C&&N(),r&&!C&&P(r)},[r,o]),{data:p,isLoading:C,error:x,estimatedTotalHits:b,refetch:N}},Qi=t=>{var r,o,i;const e=((i=(o=(r=t==null?void 0:t.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(e||"")},z3={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:D3.VITE_ONE_DRIVE_REDIRECT_URI||"https://s3-explorer.cmcts1.studio.ai.vn/sharepoint/redirect"}},V3=new hp(z3),km={[Kr.VIEW_DOCUMENT]:1,[Kr.DOWNLOAD_DOCUMENT]:2,[Kr.EDIT_DOCUMENT]:10,[Kr.OWNER_DOCUMENT]:100},Xi=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=10:!1},K3=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=2:!1},G3=t=>{const e=Vi();return`${e==null?void 0:e.groupname}`.toUpperCase()==="MASTER_ADMIN"?!0:t?km[t]>=1:!1},j3=M.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3000",rootPrefix:n="",rootUrlHostApi:r="http://localhost:3003/api/v1",asSelector:o=!1,onSelected:i=h=>console.log("Đã chọn:",h),displayPrefixes:s,preSelectedFiles:l,idCreator:u})=>{var In;const[h,p]=M.useState([]),[g,C]=M.useState(""),[w,x]=M.useState(new Set(l)),[y,b]=M.useState(n),[E,T]=M.useState(""),[N,P]=M.useState(!1),[_,D]=M.useState(""),[H,K]=M.useState(!1),[ee,W]=M.useState(null),[de,se]=M.useState(null),[fe,q]=M.useState(!1),[Z,Y]=M.useState(!1),[,oe]=M.useState(null),Q=M.useRef(null),{toast:X}=dc(),[$,te]=M.useState(null),[_e,ke]=M.useState(null),[xe,Pe]=M.useState(null),[Te,z]=M.useState(""),[ce,Ae]=M.useState(!1),[Ce,Ne]=M.useState(!1),[ne,Ve]=M.useState(new Set),[Qe,Ct]=M.useState(""),[Jt,bt]=M.useState(!1),[an,zt]=M.useState(!1),[$n,Kt]=M.useState("rename"),[L,J]=M.useState(!1),[U,ae]=M.useState(""),[ye,he]=M.useState("1"),[Ee,Xe]=M.useState(!1),[ft,xt]=M.useState(!1),[Co,Qt]=M.useState(!1),[vn,qr]=M.useState(!1),[Gt,dr]=M.useState(1),[Yr,ea]=M.useState(!1),{currentJob:Je,elapsedTime:Bo,setCurrentJob:_c}=H3(e),[bo,ta]=M.useState(null),[na,os]=M.useState(""),[Iu,ra]=M.useState(!1),[is,ku]=M.useState(""),[Ec,Nu]=M.useState(!1),[Tc,Pu]=M.useState(!1),[as,Ou]=M.useState([]),[oa,Mu]=M.useState(!1),[ss,Lm]=M.useState(""),zo=M.useRef({}),[Ac,Ic]=M.useState(null),Fm=async A=>{Pu(!0);try{const O=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${A}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});O.status===200&&Ou(O.data.knowledgeBase.chatflows.map(G=>({...G,KnowledgeBaseId:O.data.knowledgeBase.knowledge_base_id})))}catch{}finally{Pu(!1)}};M.useEffect(()=>{is&&r&&Fm(is)},[is]),M.useEffect(()=>{console.log("pre selected files",l)},[l]);const[Mt,kc]=M.useState(null),[S0,$m]=M.useState(!1),[Nc,Pc]=M.useState(!1),[ia,cs]=M.useState(!1),[Ru,Du]=M.useState([]),[Oc,Mc]=M.useState([]),[aa,Rc]=M.useState([{id:"root",name:"OneDrive"}]),[Hm,ls]=M.useState(!1),[ds,Dc]=M.useState([]),[Lu,Vo]=M.useState(!1),[us,Lc]=M.useState([]),[Fc,fs]=M.useState([]),[hs,Fu]=M.useState([]),[$c,sa]=M.useState([{id:"root",name:"SharePoint"}]),[xo,ca]=M.useState(!1),[Hc,Uc]=M.useState([]),[gt,Jr]=M.useState(null),[$u,la]=M.useState(!1),[Um,da]=M.useState(!1),Hu=new URL(window.location.href).searchParams.get("prefix")||""||E||n,[_0,Vm]=M.useState(null),{data:Tn,isLoading:Ko,error:Km,estimatedTotalHits:ua,refetch:dn}=B3(e,Hu,s,g,Gt,C,u,w,zo,x),[Bc,Cr]=M.useState(!1),zc=M.useRef(null),Vc=Vi(),$t=(()=>{const A=localStorage.getItem("dataLogin");try{if(A){const O=JSON.parse(A);return(O==null?void 0:O.user)??null}}catch{return null}return null})();M.useEffect(()=>{if(!Bc)return;function A(O){zc.current&&!zc.current.contains(O.target)&&Cr(!1)}return document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[Bc]);const Gm=async()=>{try{const A=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:O}=A.data,G=window.open(O,"SharePoint Login","width=600,height=600");if(!G)throw new Error("Không thể mở cửa sổ pop-up");G.focus();const pe=setInterval(()=>{try{if(G.closed){clearInterval(pe);return}const be=G.location.href;if(be.includes("code=")){const Ie=new URL(be).searchParams.get("code");Ie&&(At(Ie),G.close(),clearInterval(pe))}}catch(be){be instanceof Error&&!be.message.includes("cross-origin")&&console.error("SharePoint login error:",be)}},1e3)}catch(A){st.error("Lỗi khi đăng nhập SharePoint: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},jm=async()=>{try{Lc([]),sa([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),X({title:"Success",description:"Logged out from SharePoint"})}catch(A){console.error("Error logging out from SharePoint:",A),X({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},At=async A=>{try{const O=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:A,userId:"1"}),{accessToken:G}=O.data;localStorage.setItem("sharepoint_access_token",G),Pc(!0),ca(!0)}catch(O){console.error("❌ Error fetching SharePoint access token:",O),X({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},It=async()=>{try{Vo(!0);const O=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map(G=>{const pe=new URL(G.webUrl);return{id:G.id,name:G.name,description:G.description,hostname:G.hostname||pe.hostname,sitePath:G.sitePath||pe.pathname.replace(/^\/+/,"")}});console.log("data",O),Uc(O),Vo(!1)}catch(A){console.error("❌ Error fetching SharePoint sites:",A),X({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),Vo(!1)}},Wm=async A=>{Jr(A),console.log(A),await ps("root",A.name,A.hostname||"",A.sitePath||"")},ps=async(A,O,G,pe)=>{try{Vo(!0);const Ie=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:A,userId:"1",hostname:G,sitePath:pe})).data.files.map(Me=>({id:Me.id,name:Me.name,size:Me.size??0,lastModified:Me.lastModifiedDateTime?new Date(Me.lastModifiedDateTime):new Date,contentType:Me.mimeType??void 0,isFolder:Me.type==="folder",parentId:Me.parentId??""}));fs(Ie.filter(Me=>Me.isFolder)),Lc(Ie.filter(Me=>!Me.isFolder)),ca(!0),sa(Me=>Me.some(jt=>jt.id===A)?Me:[...Me,{id:A,name:O==="root"?"SharePoint":O}]),Vo(!1)}catch(be){console.error("❌ Error fetching SharePoint files:",be),X({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),Vo(!1)}},qm=A=>{Fu(O=>O.some(pe=>pe.id===A.id)?O.filter(pe=>pe.id!==A.id):[...O,{id:A.id,name:A.name,size:A.size,lastModified:A.lastModified,contentType:A.contentType,isFolder:A.isFolder,parentId:A.parentId}])},Ym=A=>{var G;sa(pe=>pe.slice(0,A+1));const O=(G=$c[A])==null?void 0:G.id;O&&ps(O,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},Jm=async(A,O)=>{const G=localStorage.getItem("sharepoint_access_token");if(!G){st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const pe=st.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};A.forEach(Me=>{Me.isFolder?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-sharepoint-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),ca(!1)}catch(be){console.error("Lỗi khi đồng bộ file từ SharePoint:",be),st.update(pe,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},Uu=()=>{ca(!1),Lc([]),Fu([]),sa([{id:"root",name:"SharePoint"}])};M.useEffect(()=>{if(xo){const O=new URLSearchParams(window.location.search).get("code");O&&(At(O),window.history.replaceState({},document.title,window.location.pathname))}},[xo]),M.useEffect(()=>{V3.initialize().then(()=>{$m(!0)}).catch(A=>console.error("❌ Lỗi khởi tạo MSAL:",A))},[]),M.useEffect(()=>{Bu()},[]);async function Bu(){localStorage.getItem("onedrive_access_token")&&Pc(!0)}const zu=A=>{Dc(O=>O.some(pe=>pe.id===A.id)?O.filter(pe=>pe.id!==A.id):[...O,{id:A.id,name:A.name,size:A.size,lastModified:A.lastModified,contentType:A.contentType,isFolder:A.isFolder,parentId:A.parentId}])};function Xt(A){if(A===0)return"0 B";const O=1024,G=["B","KB","MB","GB","TB"],pe=Math.floor(Math.log(A)/Math.log(O));return parseFloat((A/Math.pow(O,pe)).toFixed(1))+" "+G[pe]}function Kc(A){const O=new Date(A);return O.toLocaleDateString()+" "+O.toLocaleTimeString()}const Go=async()=>{try{const A=await Le.get(`${e}/api/login-one-drive`),{loginUrl:O}=A.data,G=window.open(O,"OneDrive Login","width=600,height=600");if(!G)throw new Error("Không thể mở cửa sổ pop-up");G.focus();const pe=setInterval(()=>{try{if(G.closed){clearInterval(pe);return}const be=G.location.href;if(be.includes("code=")){const Ie=new URL(be).searchParams.get("code");Ie&&(Gc(Ie),G.close(),clearInterval(pe))}}catch(be){be instanceof Error&&!be.message.includes("cross-origin")&&console.error("OneDrive login error:",be)}},1e3)}catch(A){st.error("Lỗi khi đăng nhập OneDrive: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},Vu=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),st.success("Đã đăng xuất khỏi OneDrive"),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin)}catch(A){st.error("Lỗi khi đăng xuất OneDrive: "+(A instanceof Error?A.message:"Lỗi không xác định"))}},Gc=async A=>{try{const G=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:A,userId:"1"}),{accessToken:pe}=G.data;localStorage.setItem("onedrive_access_token",pe),Pc(!0),cs(!0),await yn("root","One Drive")}catch(O){console.error("❌ Lỗi khi lấy Access Token:",O)}},yn=async(A,O)=>{try{ls(!0);const be=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:A,userId:"1"})).data.map(Ie=>({id:Ie.id,name:Ie.name,size:Ie.size??0,lastModified:Ie.lastModifiedDateTime?new Date(Ie.lastModifiedDateTime):new Date,contentType:Ie.mimeType??void 0,isFolder:Ie.type==="folder",parentId:Ie.parentId??""}));Du(be.filter(Ie=>Ie.isFolder)),Mc(be.filter(Ie=>!Ie.isFolder)),cs(!0),Rc(Ie=>Ie.some(Me=>Me.id===A)?Ie:[...Ie,{id:A,name:O==="root"?"OneDrive":O}]),ls(!1)}catch(G){console.error("Lỗi lấy danh sách file:",G),ls(!1)}},Ku=A=>{if(A===aa.length-1)return;const O=aa[A];O&&(Rc(aa.slice(0,A+1)),yn(O.id,O.name))},Gu=async(A,O)=>{const G=localStorage.getItem("onedrive_access_token");if(!G){st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const pe=st.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[]};A.forEach(Me=>{Me.isFolder?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-one-drive-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(be){console.error("Lỗi khi đồng bộ file từ OneDrive:",be),st.update(pe,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},jc=()=>{cs(!1),Rc([{id:"root",name:"OneDrive"}]),Du([]),Mc([]),Dc([]),ls(!1)},ju=pM({onSuccess:A=>{Vm(A.access_token),localStorage.setItem("google_access_token",A.access_token),Wu(A.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:$3}),Wu=A=>{const O=document.createElement("script");O.src="https://apis.google.com/js/api.js",O.onload=()=>{window.gapi.load("picker",()=>qu(A))},document.body.appendChild(O)},qu=A=>{const O=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),G=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(L3).setOAuthToken(A).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(O).addView(G).setCallback(async be=>{if(be.action===window.google.picker.Action.PICKED){const Ie=be.docs.map(Me=>({id:Me.id,name:Me.name,mimeType:Me.mimeType}));await Hn(Ie,y)}}).build().setVisible(!0)},Hn=async(A,O="")=>{const G=localStorage.getItem("google_access_token");if(!G){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),st.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const pe=st.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const be={prefix:O,folders:[],files:[]};A.forEach(Me=>{Me.mimeType==="application/vnd.google-apps.folder"?be.folders.push({id:Me.id,name:Me.name}):be.files.push({id:Me.id,name:Me.name})});const Ie=await Le.post(`${e}/api/sync-drive-to-s3`,be,{headers:{Authorization:`Bearer ${G}`}});Qn.current=!0,dn(),st.update(pe,{render:`Đồng bộ thành công! Đã tải lên ${Ie.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(be){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",be),st.update(pe,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};M.useEffect(()=>{const A=O=>{if(O.data.action==="logout"){const G=document.createElement("iframe");G.style.display="none",G.src="https://accounts.google.com/Logout",document.body.appendChild(G),setTimeout(()=>document.body.removeChild(G),2e3)}};return window.addEventListener("message",A),()=>window.removeEventListener("message",A)},[]),M.useEffect(()=>{const A=new Set(l);x(A)},[]),M.useEffect(()=>{Je!=null&&Je.status&&(Je.status.status==="completed"?(X({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${Je.url} với ${Je.status.completed} trang`}),Qn.current=!0,dn()):Je.status.status==="failed"&&X({title:"Thu thập website thất bại",description:`Không thể thu thập ${Je.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(In=Je==null?void 0:Je.status)==null?void 0:In.status]);const Yu=M.useMemo(()=>Tn[y]||[],[Tn,y]),Zt=M.useMemo(()=>Yu.filter(A=>G3(A.permission)),[Yu,y,Tn]),fa=M.useMemo(()=>{const A={};return Zt.forEach((O,G)=>{w.has(O.key)&&(A[G]=!0)}),A},[w,Zt]),Ju=A=>{const O=xu(Tn,A);if(O.length===0)return w.has(A)?"all":"none";const G=O.filter(pe=>w.has(pe)).length;return G===0?"none":G===O.length?"all":"partial"},An=(A,O=!0)=>{if(y!==A){if(u&&!y)ea(!0),T(A+u),b(A+u);else if(ea(!0),T(A),b(A),O&&!o){const G=window.location.pathname==="/"?"":window.location.pathname,pe=A?`${window.location.origin}${G}?prefix=${encodeURIComponent(A)}`:`${window.location.origin}${G}`;window.history.pushState({path:pe},"",pe)}}},gs=A=>{const O=A.lastIndexOf("/"),G=O>0?A.substring(0,O+1):"";G?(An(G),setTimeout(()=>{x(new Set([A]))},500)):x(new Set([A]))};M.useEffect(()=>{Yr&&(Qn.current=!0,dn().finally(()=>ea(!1)))},[Yr]);const Wc=async(A,O)=>{var G,pe;K(!0);try{if(Zt.some(jt=>jt.isFolder&&jt.name.toLowerCase()===A.toLowerCase())){X({title:"Lỗi",description:`Thư mục "${A}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),K(!1);return}const Ie=`${O}${A}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ie,userId:(Vc==null?void 0:Vc.id)||""})).status!==200){X({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Qn.current=!0,await dn(),X({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${A}"`}),D(""),P(!1)}catch(be){console.error("Error creating folder:",be);const Ie=((pe=(G=be==null?void 0:be.response)==null?void 0:G.data)==null?void 0:pe.error)||"Không thể tạo thư mục";X({title:"Lỗi",description:Ie,variant:"destructive"})}finally{K(!1)}},kt=async(A,O,G)=>{var pe,be,Ie,Me,jt,Xr,xr,rf,of;oe(G),Qt(!0);try{if(Array.from(A).reduce((Nn,ga)=>Nn+ga.size,0)>=100*1024*1024){X({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),oe(null),Qt(!1);return}const pa=Array.from(A).filter(Nn=>Nn.size===0);if(pa.length>0){const Nn=pa.map(ga=>ga.name).join(", ");X({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${Nn}`,variant:"destructive"}),Qt(!1),oe(null);return}const kn=new FormData;if($t!=null&&$t.id&&kn.append("metadata",JSON.stringify({creator:$t.username,creatorId:$t.id,DataSource:"Tệp tải lên"})),G==="folder"&&A[0]){const Nn=A[0].webkitRelativePath.split("/")[0];Nn&&kn.append("folderName",Nn)}kn.append("prefix",O),Array.from(A).forEach(Nn=>G==="folder"?kn.append("files",Nn,Nn.webkitRelativePath):kn.append("files",Nn)),Qn.current=!0;const Ut=await Le.post(`${e}/api/check-files-existed`,kn,{headers:{"Content-Type":"multipart/form-data"}});if(((pe=Ut==null?void 0:Ut.data)==null?void 0:pe.status)===200)await Le.post(`${e}/api/upload`,kn,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),C(""),T(O),setTimeout(async()=>{oe(null),await dn(),Qt(!1),await Qr("upload")},500);else{if(((Ie=(be=Ut==null?void 0:Ut.data)==null?void 0:be.names)==null?void 0:Ie.length)>0&&!((Me=Ut==null?void 0:Ut.data)!=null&&Me.isFolder)){const Nn=Array.from(A).filter(ga=>Ut.data.names.includes(ga.name));ta(Nn),ra(!0)}(jt=Ut==null?void 0:Ut.data)!=null&&jt.isFolder&&((Xr=Ut==null?void 0:Ut.data)!=null&&Xr.name)&&(os((xr=Ut==null?void 0:Ut.data)==null?void 0:xr.name),ta(A),ra(!0))}}catch(jo){console.error("Lỗi tải lên:",jo);const pa=((of=(rf=jo==null?void 0:jo.response)==null?void 0:rf.data)==null?void 0:of.error)||"Không thể tải lên tập tin";X({title:"Lỗi",description:pa,variant:"destructive"}),oe(null),Qt(!1)}},So=async()=>{var A,O;try{Qt(!0);const G=new FormData;if(bo){oe(na?"folder":"files"),ra(!1);let pe=localStorage.getItem("dataLogin"),be;try{pe&&(pe=JSON.parse(pe),be=pe.user)}catch{pe=null}if(na&&bo[0]){const Ie=bo[0].webkitRelativePath.split("/")[0];Ie&&G.append("folderName",Ie)}G.append("prefix",y),Array.from(bo).forEach(Ie=>na&&bo[0]?G.append("files",Ie,Ie.webkitRelativePath):G.append("files",Ie)),be!=null&&be.id&&G.append("metadata",JSON.stringify({creator:be.username,creatorId:be.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,G,{headers:{"Content-Type":"multipart/form-data"},timeout:0}),C(""),T(y),Qn.current=!0}}catch(G){console.error("Lỗi tải lên:",G);const pe=((O=(A=G==null?void 0:G.response)==null?void 0:A.data)==null?void 0:O.error)||"Không thể tải lên tập tin";X({title:"Lỗi",description:pe,variant:"destructive"})}finally{setTimeout(async()=>{oe(null),await dn(),Qt(!1),os(""),ta(null),await Qr("overwrite")},500)}},ms=async A=>{var O;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[A.key]}}),w.has(A.key)){const pe=new Set(w);pe.delete(A.key),x(pe)}const G=((O=A.key)==null?void 0:O.replace(/^(.*?)(\/.*)?$/,(pe,be,Ie)=>!Ie||Ie==="/"?"":be+"/"))||"";T(G),Qn.current=!0,X({title:"Đã xóa tập tin",description:`Đã xóa thành công "${A.name}"`}),W(null),await Qr("delete")}catch(G){console.error("Error deleting file:",G),X({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{qr(!1),await dn()}},vs=A=>{const O=new Set(w),G=typeof A=="function"?A(fa):A;new Set(Object.keys(fa).map(Number)).forEach(be=>{const Ie=Zt[be];Ie&&(G[be]||(O.delete(Ie.key),Ie.isFolder&&xu(Tn,Ie.key).forEach(Me=>O.delete(Me))))}),Object.entries(G).forEach(([be,Ie])=>{const Me=parseInt(be),jt=Zt[Me];jt&&Ie&&(O.add(jt.key),jt.isFolder&&xu(Tn,jt.key).forEach(Xr=>O.add(Xr)))}),x(O)},qc=async()=>{var A;q(!0);try{const O=Array.from(w),G=O.map(be=>Object.values(Tn).flat().find(Ie=>Ie.key===be)).filter(be=>be!==void 0);if(G.length===0){X({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:O}});const pe=((A=G[0])==null?void 0:A.key.replace(/^(.*?)(\/.*)?$/,(be,Ie,Me)=>!Me||Me==="/"?"":Ie+"/"))||"";T(pe),Qn.current=!0,dn(),X({title:"Đã xóa tập tin",description:`Đã xóa thành công ${G.length} mục`}),Y(!1),x(new Set),await Qr("bulk-delete")}catch(O){console.error("Error deleting files:",O),X({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{q(!1)}},Qm=async(A,O)=>{if(!y.trim()){X({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}Ne(!0);try{const G=A.key;let pe;A.isFolder?pe=G.split("/").slice(0,-2).join("/")+"/":pe=G.substring(0,G.lastIndexOf("/")+1);const be=pe+O+(A.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:G,newPath:be}),Qn.current=!0,await dn(),X({title:"Đã đổi tên",description:`Đã đổi tên thành công "${A.name}" thành "${O}"`}),te(null),z(""),Pe(null),await Qr("rename")}catch(G){console.error("Error renaming item:",G),X({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Ne(!1)}},Xm=async A=>{Ve(O=>new Set([...O,...A]));try{const O=await Le.post(`${e}/api/download`,{paths:A},{responseType:"blob"}),G=window.URL.createObjectURL(O.data),pe=document.createElement("a");pe.href=G;const be=O.headers["Content-Disposition"]||O.headers["content-disposition"],Ie=be==null?void 0:be.match(/filename="(.+)"/),Me=Ie?decodeURIComponent(Ie[1]):"download.zip";pe.setAttribute("download",Me),document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),window.URL.revokeObjectURL(G),X({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${A.length} mục${A.length>1,""}`})}catch(O){console.error("Error downloading files:",O),X({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Ve(O=>{const G=new Set(O);return A.forEach(pe=>G.delete(pe)),G})}},Qu=y?y.replace(n,"").split("/").filter(Boolean):[],Xu=()=>{let A=Array.from(w).map(G=>({key:G}));A.length>1&&(A=A.filter(G=>G.key!==n));const O=G=>Md.findIndex(A,pe=>!pe.key.endsWith("/")&&pe.key.startsWith(G))!==-1;return A=A.filter(G=>G.key.endsWith("/")?!O(G.key):!0),A},ha=M.useMemo(()=>{const A=[...($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/")?[]:[{id:"select",header:()=>{const O=U3(Tn,y),G=O.length>0&&O.every(be=>w.has(be)),pe=O.some(be=>w.has(be));return d.jsx(oc,{checked:G?!0:pe?"indeterminate":!1,onCheckedChange:be=>{if(be){const Ie=Zt.reduce((Me,jt,Xr)=>(Me[Xr]=!0,Me),{});vs(Ie)}else{for(const Ie of Array.from(w))Ie.startsWith(y)&&(w.delete(Ie),zo.current[Ie]=!1);Md.forEach(zo.current,(Ie,Me)=>{Me.startsWith(y)&&(zo.current[Me]=!1)}),vs({})}},"aria-label":"Chọn tất cả"})},cell:({row:O})=>{const G=O.original;let be=G.isFolder?Ju(G.key):w.has(G.key)?"all":"none";if(be==="none"&&G.key.endsWith("/")){for(const Ie of Array.from(w))if(Ie.startsWith(G.key)){be="all";break}}return d.jsx("div",{className:"flex items-center",children:d.jsx(oc,{checked:be==="partial"?"indeterminate":be==="all",onCheckedChange:Ie=>{var jt,Xr;const Me={...fa};if(Ie?Me[O.index]=!0:delete Me[O.index],zo.current[((jt=O.original)==null?void 0:jt.key)||"_"]=!!Ie,(Xr=O.original)!=null&&Xr.key.endsWith("/"))for(const xr of Array.from(w))xr.startsWith(O.original.key)&&(zo.current[O.original.key]=!1,w.delete(xr));vs(Me)},"aria-label":"Chọn dòng"})})},enableSorting:!1}],{id:"fileName",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),children:["Tên tập tin",d.jsx(ag,{})]}),accessorKey:"name",cell:({row:O})=>{const G=O.original,pe=G.key.substring(0,G.key.lastIndexOf("/"))||"/",be=g.trim()!==""&&pe!==y,Ie=pe.split("/").filter(Boolean);return d.jsxs("div",{className:"flex flex-col group",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsxs("div",{className:`flex items-center gap-2 ${G.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{G.isFolder&&An(G.key)},children:[G.isFolder?d.jsx(Ks,{className:"h-5 w-5 text-blue-500"}):null,G.name]}),d.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Me=>{Me.stopPropagation(),navigator.clipboard.writeText(G.key),X({title:"Copied to clipboard",description:`Path: ${G.key}`,duration:2e3})},title:"Copy path to clipboard",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),d.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),be&&d.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[d.jsx(Ks,{className:"h-4 w-4 text-gray-500 my-auto"}),d.jsxs("span",{className:"flex items-center ml-1",children:[d.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{An("")},children:"/"}),Ie.map((Me,jt)=>d.jsxs("span",{className:"flex items-center",children:[d.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{An(Ie.slice(0,jt+1).join("/")+"/")},children:Me}),jt<Ie.length-1&&d.jsx("span",{children:"/"})]},jt))]})]})]})}}];return o||A.push({id:"size",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),children:["Kích thước",d.jsx(ag,{})]}),accessorKey:"size",cell:({getValue:O,row:G})=>{const pe=O();return d.jsx("span",{children:G.original.isFolder?"-":Xt(pe)})}},{id:"lastModified",header:({column:O})=>d.jsxs(He,{variant:"ghost",onClick:()=>O.toggleSorting(O.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",d.jsx(ag,{})]}),accessorKey:"lastModified",cell:({row:O})=>{const G=O.original.lastModified;return d.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:d.jsx("span",{children:G&&Dx(G).isValid()?Dx(G).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>d.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:O})=>d.jsxs("div",{className:"flex items-center gap-2",children:[y===""&&r&&d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{ku(O.original.key),Nu(!0)},className:"h-8 w-8 p-0",children:ne.has(O.original.key)?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):d.jsx(vO,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Những Flow sử dụng Folder này làm Data"})]})}),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:!O.original.isFolder&&d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>Xm([O.original.key]),className:"h-8 w-8 p-0",disabled:!K3(O.original.permission)||ne.has(O.original.key),children:ne.has(O.original.key)?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):d.jsx(hO,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Tải xuống"})]})}),y.trim()!==""&&(Xi(O.original.permission)?d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{te(O.original),z(O.original.name)},className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(_O,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Đổi tên"})]})}):d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{console.log("call"),ke(O.original)},className:"h-8 w-8 p-0",disabled:O.original.isFolder,children:d.jsx(Hx,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Xem"})]})})),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>{Ae(!0),se(O.original)},className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(KD,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Di chuyển"})]})}),!(($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/"))&&d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>W(O.original),className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(DC,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Xóa"})]})}),d.jsx(vr,{children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsx(He,{variant:"ghost",size:"icon",onClick:()=>Ic(O.original),className:"h-8 w-8 p-0",disabled:!Xi(O.original.permission),children:d.jsx(RC,{className:"h-4 w-4"})})}),d.jsx(lr,{children:"Chia sẻ"})]})})]})}),A},[w,Zt,fa,ne,o]),_o=Gb({data:Zt,columns:ha,state:{rowSelection:fa,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:vs,getCoreRowModel:Kb(),getSortedRowModel:qM()}),Zu=async A=>{var O,G;bt(!0);try{if(Qi(A)){const pe=await Le.get(`${e}/api/read-text`,{params:{path:A.key}});Ct(pe.data.content)}try{const pe=await Le.get(`${e}/api/read-json`,{params:{path:A.key+".metadata.json"}}),be=((G=(O=pe==null?void 0:pe.data)==null?void 0:O.content)==null?void 0:G.metadataAttributes)||null;return Pe({fullPath:$==null?void 0:$.key,...be})}catch{return Pe("Lỗi phân tích siêu dữ liệu")}}catch(pe){console.error("Error loading file content:",pe),X({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{bt(!1)}},ef=async(A,O)=>{zt(!0);try{await Le.post(`${e}/api/modify-text`,{path:A.key,content:O}),X({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qn.current=!0,await dn(),te(null),Ct(""),Kt("rename"),await Qr("edit-content")}catch(G){console.error("Error saving file content:",G),X({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{zt(!1)}},tf=async A=>{zt(!0);try{await Le.post(`${e}/api/modify-json`,{path:A.key+".metadata.json",content:{metadataAttributes:xe}}),X({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Qn.current=!0,await dn(),te(null),Ct(""),Kt("rename")}catch(O){console.error("Error saving file content:",O),X({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{zt(!1)}};M.useEffect(()=>{$&&($.isFolder||Zu($),Kt("rename"))},[$]),M.useEffect(()=>{_e&&!_e.isFolder&&Zu(_e)},[_e]);const ys=async(A,O)=>{var G;if(Je){X({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}Xe(!0);try{const{data:pe}=await Le.post(`${e}/api/crawl`,{url:A,limit:O,prefix:y});if(pe.id){_c({id:pe.id,url:A,limit:O,prefix:y,taskId:((G=pe.task)==null?void 0:G.id)||""});const be=localStorage.getItem(e0),Ie=be?JSON.parse(be):[];Ie.some(Me=>Me.id===pe.id)||(Ie.unshift({url:A,id:pe.id,limit:O,prefix:y,timestamp:Date.now()}),Ie.length>20&&(Ie.length=20),localStorage.setItem(e0,JSON.stringify(Ie))),X({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${A} với giới hạn ${O}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),J(!1),ae(""),he("1")}}catch(pe){console.error("Error crawling website:",pe),X({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{Xe(!1)}},Yc=async()=>{try{if(!(Je!=null&&Je.id))return;_c(null),localStorage.removeItem(ns),X({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${Je.url}`})}catch(A){console.error("Error stopping job:",A),X({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};M.useEffect(()=>{if(o)return;const A=(O=!0)=>{const pe=new URL(window.location.href).searchParams.get("prefix")||"";pe?An(pe,!1):(O&&!l&&x(new Set),T(n),b(n),Qn.current=!0,setTimeout(()=>{dn()},0))};return A(!1),window.addEventListener("popstate",()=>A(!0)),()=>{window.removeEventListener("popstate",()=>A(!0))}},[]);const Jc=async()=>{Mu(!0);try{await Le.post(`${e}/api/prediction-report`),X({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(A){console.error("Error exporting report:",A),X({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{Mu(!1)}},Zm=async()=>{try{const A=Vi();A&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:y,user_id:A.id,userName:A.username})).status===200&&await ws()}catch(A){xt(!1),console.log(A)}},Qr=async A=>{try{ss&&y.includes(ss)&&(console.log(`Auto syncing knowledge base after ${A} operation`),await ws())}catch(O){console.log(`Error auto syncing after ${A}:`,O)}},br=M.useRef(),ws=async()=>{try{xt(!0);const A=await Le.post(`${e}/api/get-ingestion-job-status`,{prefix:y}),{status:O}=A==null?void 0:A.data;O==="FAILED"||O==="COMPLETE"||O==="STOPPED"||O==="STOPPING"||!O?(xt(!1),br.current&&(clearInterval(br.current),br.current=null),kc(A==null?void 0:A.data)):(br.current||(br.current=setInterval(()=>ws(),5e3)),kc(A==null?void 0:A.data))}catch(A){console.log(A)}},nf=()=>{const A=Array.from(w);let O;return y?O=A.filter(G=>G.startsWith(y)&&G!==y).length:O=new Set(A.filter(G=>G.split("/").shift())).size,`Đang chọn: ${O}`};return M.useEffect(()=>{const A=y==null?void 0:y.split("/")[0];return A!==ss&&(xt(!1),br.current&&(clearInterval(br.current),br.current=null),Lm(A||""),kc(null),A&&ws()),()=>{}},[ss,y]),M.useEffect(()=>{xo&&Hc.length===0&&(It(),Jr(null))},[xo]),M.useEffect(()=>{if(l)for(const A of Array.from(l))zo.current[A]=!0},[]),d.jsxs("div",{className:"space-y-4 s3-explr-container",children:[d.jsx(c_,{}),d.jsx(ar,{open:Iu,onOpenChange:A=>{ra(A),A||(os(""),ta(null),Qt(!1),oe(null))},children:d.jsxs(jn,{children:[d.jsxs(Wn,{children:[d.jsx(qn,{children:"Cảnh báo trùng lặp"}),d.jsxs(vi,{children:[na&&d.jsxs(d.Fragment,{children:["Folder $",na," đã có."]}),bo&&bo.length>0&&d.jsxs(d.Fragment,{children:["Những tệp sau bị lặp:",d.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(bo).map((A,O)=>d.jsx("li",{children:A.name},O))})]})]})]}),d.jsxs(Hr,{children:[d.jsx(He,{variant:"outline",onClick:()=>{ra(!1),os(""),ta(null),Qt(!1),oe(null)},children:"Bỏ qua"}),d.jsx(He,{variant:"destructive",onClick:()=>So(),children:"Ghi đè"})]})]})}),d.jsx(Ld,{className:"s3-explr-breadcrumb",children:d.jsxs(Fd,{className:"s3-explr-breadcrumb-list",children:[d.jsx(nc,{className:"s3-explr-breadcrumb-item",children:d.jsx(rc,{onClick:()=>An(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!u&&Qu.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[d.jsx($d,{className:"s3-explr-breadcrumb-separator"},`sep-${O}`),d.jsx(nc,{className:"s3-explr-breadcrumb-item",children:d.jsx(rc,{onClick:()=>An(n+Qu.slice(0,O+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:A})},`item-${A}`)]},O))]})}),d.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[d.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:d.jsx($H,{ref:Q,onChange:A=>C(A)})}),d.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{T(y),Qn.current=!0,dn()},disabled:Ko,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${Ko?"animate-spin":""}`}),"Làm mới"]}),y&&y!=="/"&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{Ko||ft||(xt(!0),Zm())},"aria-disabled":Ko||ft,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${Ko||ft?"animate-spin":""}`}),"Đồng bộ KB"]})}),Mt&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[d.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),d.jsx("div",{className:"space-y-1",children:d.jsxs("p",{className:"flex items-center gap-2",children:[d.jsx("span",{className:"font-medium",children:"Trạng thái:"}),d.jsxs("span",{className:`flex items-center gap-1 font-semibold ${Mt.status==="COMPLETE"?"text-green-600":Mt.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Mt.status==="COMPLETE"&&d.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:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Mt.status==="FAILED"&&d.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:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Mt.status!=="COMPLETE"&&Mt.status!=="FAILED"&&d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),lL(Mt.status)]})]})}),Mt.statistics&&d.jsxs("div",{className:"space-y-1 border-t pt-2",children:[d.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),d.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu quét:"}),d.jsx("span",{className:"font-medium",children:Mt.statistics.numberOfDocumentsScanned})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Metadata quét:"}),d.jsx("span",{className:"font-medium",children:Mt.statistics.numberOfMetadataDocumentsScanned})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu mới:"}),d.jsx("span",{className:"font-medium text-green-600",children:Mt.statistics.numberOfNewDocumentsIndexed})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu sửa:"}),d.jsx("span",{className:"font-medium text-blue-600",children:Mt.statistics.numberOfModifiedDocumentsIndexed})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Metadata sửa:"}),d.jsx("span",{className:"font-medium text-blue-600",children:Mt.statistics.numberOfMetadataDocumentsModified})]}),d.jsxs("div",{className:"flex justify-between",children:[d.jsx("span",{children:"Tài liệu xóa:"}),d.jsx("span",{className:"font-medium text-orange-600",children:Mt.statistics.numberOfDocumentsDeleted})]}),d.jsxs("div",{className:"flex justify-between col-span-2",children:[d.jsx("span",{children:"Tài liệu lỗi:"}),d.jsx("span",{className:"font-medium text-red-600",children:Mt.statistics.numberOfDocumentsFailed})]})]})]}),d.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[d.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",Mt.dataSourceId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",Mt.ingestionJobId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",Mt.knowledgeBaseId]}),d.jsxs("p",{children:[d.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",Mt.is_still_in_stock?"Còn":"Không"]})]}),Mt.errorMessage&&d.jsxs("div",{className:"border-t pt-2",children:[d.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),d.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:Mt.errorMessage})]}),Mt.failureReasons&&Mt.failureReasons.length>0&&d.jsx(UH,{failureReasons:Mt.failureReasons,onNavigateToFile:gs})]})})]})}),Xi(Tn==null?void 0:Tn.prefixPermission)&&d.jsxs("div",{className:"relative",ref:zc,children:[d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors aria-disabled:hidden",onClick:()=>Cr(A=>!A),"aria-disabled":($t==null?void 0:$t.role)!=="MASTER_ADMIN"&&($t==null?void 0:$t.role)!=="SITE_ADMIN"&&(y===""||y==="/"),children:[d.jsx(TO,{className:"w-4 h-4"}),"Add file"]}),Bc&&d.jsxs("div",{className:"absolute z-50 mt-2 right-0 w-56 bg-white border rounded-lg shadow-lg py-2 flex flex-col",children:[d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1);const A=document.createElement("input");A.type="file",A.multiple=!0,A.onchange=O=>{const G=O.target.files;G&&kt(G,y,"files")},A.click()},children:[d.jsx(pp,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1);const A=document.createElement("input");A.type="file",A.multiple=!0,A.webkitdirectory=!0,A.onchange=O=>{const G=O.target.files;G&&kt(G,y,"folder")},A.click()},children:[d.jsx(Ks,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!s&&!y,onClick:()=>P(!0),children:[d.jsx(wO,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),J(!0)},children:[d.jsx(xO,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),ju()},children:[d.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[d.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"}),d.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"}),d.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"}),d.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"}),d.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"}),d.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"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),Go()},children:[d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[d.jsx("path",{fill:"#094ab2",d:"M47.3 28.2C45.3 18.6 37.1 12 28 12c-8.5 0-15.9 5.6-18.4 13.5C4.2 27.2 0 32.2 0 38c0 6.6 5.4 12 12 12h36c8.3 0 16-6.6 16-15.5 0-6.8-4.9-12.4-11.7-13.3z"}),d.jsx("path",{fill:"#0067c5",d:"M44.9 30.1c-.2 0-.4-.1-.6-.1H26c-3.3 0-6 2.7-6 6 0 .9.2 1.8.6 2.6-1.7-.7-3.5-1.1-5.5-1.1C7.6 37.5 4 41.5 4 46s3.6 8.5 8.1 8.5h34.3c6.8 0 12.6-5.4 12.6-12s-5.5-11.6-11.1-12.4z"})]})," ","Đồng bộ OneDrive"]}),d.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{Cr(!1),Gm()},children:[d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[d.jsx("path",{fill:"#036C70",d:"M19 14.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#17828F",d:"M16 17.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#4DB6AC",d:"M13 20.5v-9c0-.28-.22-.5-.5-.5h-13c-.28 0-.5.22-.5.5v9c0 .28.22.5.5.5h13c.28 0 .5-.22.5-.5z"}),d.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),Xi((Tn==null?void 0:Tn.prefixPermission)&&w.size>0)&&d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors aria-disabled:hidden",onClick:()=>Ic({contentType:"application/x-directory",isFolder:!0,key:y||"/",lastModified:"-",name:"",size:0}),children:[d.jsx(RC,{className:"w-4 h-4"}),"Chia sẻ"]}),!o&&d.jsxs(d.Fragment,{children:[w.size>0&&d.jsx(d.Fragment,{children:d.jsxs(ar,{open:Z,onOpenChange:Y,children:[d.jsx(ic,{asChild:!0,children:d.jsxs(He,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[d.jsx(DC,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",w.size,")"]})}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),d.jsxs(vi,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",w.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>Y(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:qc,disabled:fe,className:"s3-explr-confirm-delete-btn",children:fe?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})}),!u&&d.jsxs(ar,{open:N,onOpenChange:P,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsx(Wn,{className:"s3-explr-dialog-header",children:d.jsx(qn,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),d.jsx(Yn,{disabled:H,id:"name",value:_,onChange:A=>D(A.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),d.jsxs(He,{onClick:()=>{_.trim()&&Wc(_,y)},disabled:H,className:"s3-explr-create-btn",children:[H&&d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),H?"Đang tạo...":"Tạo"]})]})]})]}),u&&!y?d.jsx(d.Fragment,{}):d.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[Je?d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[d.jsx(Pt,{className:"h-4 w-4 animate-spin s3-explr-loader"}),Je.status?d.jsxs(d.Fragment,{children:[Je.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",Je.status.completed,"/",Je.status.total,") -"," ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}):"Đang thu thập..."]}),d.jsxs(He,{variant:"destructive",size:"sm",onClick:()=>void Yc(),className:"flex items-center gap-2",children:[d.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),d.jsx(kO,{className:"h-4 w-4"})]})]})}),Je.status&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-1 p-2",children:[d.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",Je==null?void 0:Je.url]}),d.jsxs("p",{children:["Tiến độ: ",Je==null?void 0:Je.status.completed,"/",Je==null?void 0:Je.status.total," ","trang"]}),d.jsxs("p",{children:["Thời gian: ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}),d.jsxs("p",{children:["Trạng thái:"," ",(Je==null?void 0:Je.status.status)==="scraping"?"Đang thu thập":(Je==null?void 0:Je.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!u&&d.jsxs(ar,{open:L,onOpenChange:J,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Thêm website"}),d.jsx(vi,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),d.jsx(Yn,{id:"websiteUrl",value:U,onChange:A=>ae(A.target.value),placeholder:"https://example.com",type:"url",disabled:Ee,className:"s3-explr-input"})]}),d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),d.jsx(Yn,{id:"crawlLimit",value:ye,onChange:A=>{const O=A.target.value;/^\d*$/.test(O)&&he(O)},placeholder:"1",type:"text",disabled:Ee,className:"s3-explr-input"}),d.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)"})]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>{J(!1),ae(""),he("1")},disabled:Ee,className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{onClick:()=>{U.trim()&&ys(U.trim(),parseInt(ye)||1)},disabled:Ee||!U.trim(),className:"s3-explr-crawl-btn",children:Ee?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),y.startsWith("BKTTW/")&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!s&&!y,onClick:Jc,children:[oa&&d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${oa?"animate-spin":""}`}),"Xuất báo cáo"]})}),(Je==null?void 0:Je.status)&&d.jsx(lr,{side:"right",sideOffset:5,children:d.jsxs("div",{className:"space-y-1 p-2",children:[d.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",Je.url]}),d.jsxs("p",{children:["Tiến độ: ",Je.status.completed,"/",Je.status.total," ","trang"]}),d.jsxs("p",{children:["Thời gian: ",Math.floor(Bo/60),":",String(Bo%60).padStart(2,"0")]}),d.jsxs("p",{children:["Trạng thái:"," ",Je.status.status==="scraping"?"Đang thu thập":Je.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),d.jsxs(ar,{open:L,onOpenChange:J,children:[d.jsx(ic,{asChild:!0}),d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Thêm website"}),d.jsx(vi,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),d.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),d.jsx(Yn,{id:"websiteUrl",value:U,onChange:A=>ae(A.target.value),placeholder:"https://example.com",type:"url",disabled:Ee,className:"s3-explr-input"})]}),d.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),d.jsx(Yn,{id:"crawlLimit",value:ye,onChange:A=>{const O=A.target.value;/^\d*$/.test(O)&&he(O)},placeholder:"1",type:"text",disabled:Ee,className:"s3-explr-input"}),d.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)"})]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>{J(!1),ae(""),he("1")},disabled:Ee,className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{onClick:()=>{U.trim()&&ys(U.trim(),parseInt(ye)||1)},disabled:Ee||!U.trim(),className:"s3-explr-crawl-btn",children:Ee?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),y.startsWith("BKTTW/")&&d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{children:[d.jsx(wr,{asChild:!0,children:d.jsxs(He,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!s&&!y,onClick:Jc,children:[oa&&d.jsx(td,{className:`h-4 w-4 s3-explr-refresh-icon ${oa?"animate-spin":""}`}),"Xuất báo cáo"]})}),oa&&d.jsx(lr,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),d.jsxs("div",{className:"flex items-center gap-4",children:[ia&&d.jsxs(Gs,{open:ia,onOpenChange:cs,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Ip,{asChild:!0,children:d.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:jc,children:"✖"})}),d.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),d.jsx(Ld,{className:"onedrive-breadcrumb",children:d.jsx(Fd,{className:"onedrive-breadcrumb-list",children:aa.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[O>0&&d.jsx($d,{className:"onedrive-breadcrumb-separator"}),d.jsx(nc,{className:"onedrive-breadcrumb-item",children:d.jsx(rc,{onClick:()=>Ku(O),className:"cursor-pointer onedrive-breadcrumb-link",children:A.name})})]},O))})})]}),d.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Hm?d.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):d.jsx(d.Fragment,{children:[...Ru,...Oc].length>0?[...Ru,...Oc].map(A=>d.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${ds.some(O=>O.id===A.id)?"bg-blue-100":""}`,children:[d.jsx("input",{type:"checkbox",checked:ds.some(O=>O.id===A.id),onChange:O=>{O.stopPropagation(),zu(A)},className:"cursor-pointer"}),A.isFolder?d.jsx(Ks,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>yn(A.id,A.name)}):d.jsx(pp,{className:"text-gray-500 w-5 h-5"}),d.jsxs("div",{className:"flex-1",children:[d.jsx("div",{className:`font-medium ${A.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{A.isFolder?yn(A.id,A.name):zu(A)},children:A.name}),!A.isFolder&&d.jsxs("div",{className:"text-xs text-gray-500",children:[Xt(A.size)," •"," ",Kc(A.lastModified.toISOString())]})]})]},A.id)):d.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),d.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:d.jsx(He,{onClick:()=>{Gu(ds,y),jc()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:ds.length===0,children:"Đồng bộ"})}),d.jsx("button",{onClick:()=>da(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),d.jsx("polyline",{points:"16 17 21 12 16 7"}),d.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),d.jsxs(Gs,{open:Um,onOpenChange:da,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[d.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),d.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(He,{variant:"outline",onClick:()=>da(!1),children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>{Vu(),da(!1)},children:"Đăng xuất"})]})]})]}),xo&&d.jsxs(Gs,{open:xo,onOpenChange:ca,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[700px] max-w-[90vw] max-h-[80vh] z-50 flex flex-col",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Ip,{asChild:!0,children:d.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:Uu,children:"✖"})}),d.jsxs("div",{className:"flex items-center gap-2",children:[gt&&d.jsx("button",{onClick:()=>Jr(null),className:"text-gray-600 hover:text-gray-800",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:d.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),d.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&d.jsx(Ld,{className:"sharepoint-breadcrumb",children:d.jsx(Fd,{className:"sharepoint-breadcrumb-list",children:$c.map((A,O)=>d.jsxs("div",{className:"flex items-center",children:[O>0&&d.jsx($d,{className:"sharepoint-breadcrumb-separator"}),d.jsx(nc,{className:"sharepoint-breadcrumb-item",children:d.jsx(rc,{onClick:()=>Ym(O),className:"cursor-pointer sharepoint-breadcrumb-link",children:A.name})})]},O))})})]}),d.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Lu?d.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...Fc,...us].length===0?d.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...Fc,...us].map(A=>{const O=hs.some(G=>G.id===A.id);return d.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${O?"bg-blue-100":""}`,children:[d.jsx("input",{type:"checkbox",checked:O,onChange:G=>{G.stopPropagation(),qm(A)},className:"cursor-pointer"}),A.isFolder?d.jsx(Ks,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ps(A.id,A.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):d.jsx(pp,{className:"text-gray-500 w-5 h-5"}),d.jsxs("div",{className:"flex-1",children:[d.jsx("div",{className:`font-medium ${A.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{A.isFolder&&ps(A.id,A.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:A.name}),!A.isFolder&&d.jsxs("div",{className:"text-xs text-gray-500",children:[Xt(A.size)," •"," ",A.lastModified.toLocaleString()]})]})]},A.id)}):d.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:Hc.map(A=>d.jsxs("div",{className:"cursor-pointer bg-white shadow-md rounded-xl p-5 flex flex-col justify-center items-start transition-shadow duration-200 hover:shadow-lg border border-gray-100 min-h-[120px]",style:{overflow:"hidden",wordBreak:"break-word",textOverflow:"ellipsis",whiteSpace:"normal"},onClick:()=>Wm(A),children:[d.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:A.name,children:A.name}),d.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:A.description,children:A.description})]},A.id))})}),d.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&d.jsxs(d.Fragment,{children:[d.jsx(He,{onClick:()=>{Jm(hs,y),Uu()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:hs.length===0,children:"Đồng bộ"}),d.jsx(He,{onClick:()=>Jr(null),children:"Quay lại"})]})}),d.jsx("button",{onClick:()=>la(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:d.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),d.jsx("polyline",{points:"16 17 21 12 16 7"}),d.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),d.jsxs(Gs,{open:$u,onOpenChange:la,children:[d.jsx(za,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),d.jsxs(Va,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-lg w-[400px] max-w-[90vw] z-[60]",children:[d.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),d.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(He,{variant:"outline",onClick:()=>la(!1),children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>{jm(),la(!1)},children:"Đăng xuất"})]})]})]})]}),d.jsx(ar,{open:!!Ec,onOpenChange:A=>{A||(Nu(!1),Ou([]),ku(""))},children:d.jsxs(jn,{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:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:d.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",d.jsx("span",{className:"font-bold",children:is}),"):"," "]})}),d.jsx(vi,{className:"s3-explr-dialog-description",children:Tc?d.jsxs("div",{className:"flex items-center justify-center py-4",children:[d.jsx(Pt,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):d.jsx("div",{children:as&&Array.isArray(as)&&as.length>0?d.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:d.jsxs("table",{className:"w-full border-collapse",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"bg-gray-100",children:[d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),d.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),d.jsx("tbody",{children:as.map((A,O)=>d.jsxs("tr",{className:O%2===0?"bg-white":"bg-gray-50",children:[d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.name}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.KnowledgeBaseId}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),d.jsx("td",{className:"border border-gray-300 px-4 py-2",children:A.createdDate?new Date(A.createdDate).toLocaleString("vi-VN"):"N/A"})]},O))})]})}):d.jsx("div",{className:"text-gray-500 italic py-2",children:"Không có flow nào sử dụng dữ liệu từ folder này"})})})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>ms(ee),disabled:vn,className:"s3-explr-confirm-delete-btn",children:vn?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),d.jsx(ar,{open:!!ee,onOpenChange:A=>!A&&W(null),children:d.jsxs(jn,{className:"s3-explr-dialog-content",children:[d.jsxs(Wn,{className:"s3-explr-dialog-header",children:[d.jsx(qn,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),d.jsxs(vi,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",ee==null?void 0:ee.name,"? Hành động này không thể hoàn tác."]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),d.jsx(He,{variant:"destructive",onClick:()=>ms(ee),disabled:vn,className:"s3-explr-confirm-delete-btn",children:vn?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),d.jsx(ar,{open:!!$,onOpenChange:A=>{A||(te(null),Pe(null),z(""),Ct(""),Kt("rename"))},children:d.jsxs(jn,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[d.jsx(Wn,{className:"s3-explr-dialog-header",children:d.jsx(qn,{className:"s3-explr-dialog-title",children:$!=null&&$.isFolder?"Đổi tên thư mục":Qi($)?"Quản lý tập tin":"Đổi tên tập tin"})}),$&&d.jsxs(Sg,{value:$n,onValueChange:A=>Kt(A),children:[d.jsxs(Yd,{"aria-checked":!Qi($),"aria-disabled":$.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[d.jsx(Ki,{value:"rename",children:"Đổi tên"}),!$.isFolder&&d.jsxs(d.Fragment,{children:[Qi($)&&d.jsx(Ki,{value:"edit",children:"Sửa nội dung"}),d.jsx(Ki,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),d.jsx(Gi,{value:"rename",children:d.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:d.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[d.jsx(mr,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),d.jsx(Yn,{id:"newName",value:Te,onChange:A=>z(A.target.value),placeholder:"Nhập tên mới",disabled:Ce,className:"s3-explr-input"})]})})}),!$.isFolder&&d.jsxs(d.Fragment,{children:[Qi($)&&d.jsx(Gi,{value:"edit",children:d.jsx("div",{className:"space-y-4 py-4",children:Jt?d.jsx("div",{className:"flex items-center justify-center py-10",children:d.jsx(Pt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.jsxs("div",{className:"max-h-[70dvh] overflow-auto rounded-md border px-4 py-3 bg-muted/30",children:[d.jsx(mr,{htmlFor:"content",className:"block text-sm font-medium mb-2 text-muted-foreground",children:"Nội dung tập tin"}),d.jsx(sc,{id:"content",value:Qe,onChange:A=>Ct(A.target.value),placeholder:"Nhập nội dung tập tin",className:"font-mono text-sm resize-none min-h-[200px] w-full",disabled:an,style:{height:"auto",maxHeight:"60vh"},rows:Math.max(10,Qe.split(`
228
228
  `).length+1)})]})})}),d.jsx(Gi,{value:"edit-metadata",children:d.jsx("div",{className:"space-y-4 py-4",children:Jt?d.jsx("div",{className:"flex items-center justify-center py-4",children:d.jsx(Pt,{className:"h-6 w-6 animate-spin"})}):d.jsx("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:xe&&typeof xe=="object"&&Object.entries(xe).map(([A,O],G)=>d.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[d.jsxs(mr,{htmlFor:A,className:"s3-explr-label flex items-center gap-1",children:[aL[A]||A,ug(A)&&d.jsx(GD,{className:"h-[12px] w-[12px] text-red-500"})]}),sL(A)?d.jsx(sc,{id:A,value:typeof O=="string"?O:JSON.stringify(O),onChange:pe=>{const be={...xe,[A]:pe.target.value};Pe(be)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:an||ug(A)}):d.jsx(Yn,{id:A,value:typeof O=="string"?O:JSON.stringify(O),onChange:pe=>{const be={...xe,[A]:pe.target.value};Pe(be)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:an||ug(A)})]},G))})})})]})]}),d.jsxs(Hr,{className:"s3-explr-dialog-footer",children:[d.jsx(He,{variant:"outline",onClick:()=>{te(null),Pe(null),z(""),Ct("")},className:"s3-explr-cancel-btn",children:"Hủy"}),$n==="edit"?d.jsx(He,{onClick:()=>$&&ef($,Qe),disabled:an||Jt,className:"s3-explr-save-btn",children:an?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):$n==="edit-metadata"?d.jsx(He,{onClick:()=>xe&&typeof xe=="object"&&$&&tf($),disabled:an||Jt,className:"s3-explr-save-btn",children:an?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):d.jsx(He,{onClick:()=>{Te.trim()&&$&&Qm($,Te.trim())},disabled:Ce||!Te.trim()||Te.trim()===($==null?void 0:$.name),className:"s3-explr-rename-btn",children:Ce?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),d.jsx(ar,{open:!!_e,onOpenChange:A=>{A||(ke(null),Ct(""))},children:d.jsxs(jn,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[d.jsx(Wn,{className:"s3-explr-dialog-header",children:d.jsx(qn,{className:"s3-explr-dialog-title",children:"Xem tập tin"})}),_e&&d.jsxs(Sg,{value:"view",children:[d.jsx(Yd,{className:"grid w-full grid-cols-1 ",children:!_e.isFolder&&Qi(_e)&&d.jsx(Ki,{value:"view",children:"Nội dung"})}),!_e.isFolder&&Qi(_e)&&d.jsx(Gi,{value:"view",children:d.jsx("div",{className:"space-y-4 py-4",children:Jt?d.jsx("div",{className:"flex items-center justify-center py-4",children:d.jsx(Pt,{className:"h-6 w-6 animate-spin"})}):d.jsx("div",{className:"overflow-hidden overflow-y-auto pb-3 px-1",children:d.jsx("div",{className:"rounded-md bg-muted p-4 font-mono text-sm overflow-auto max-h-[60vh] border",children:d.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Qe})})})})})]}),d.jsx(Hr,{className:"s3-explr-dialog-footer",children:d.jsx(He,{variant:"outline",onClick:()=>{ke(null),Ct("")},className:"s3-explr-cancel-btn",children:"Đóng"})})]})}),de&&ce&&d.jsx(KU,{openDialogRename:ce,setOpenDialogRename:Ae,apiBaseUrl:e,setFileToMove:se,fileToMove:de,refreshFiles:dn,ignoreCache:Qn,autoSyncAfterFileOperation:Qr})]})]}),Km&&d.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"}),d.jsx(VU,{onFilesSelected:(A,O)=>kt(A,y,O),children:d.jsx("div",{className:"rounded-md border s3-explr-table-container",children:d.jsxs(Gd,{className:"s3-explr-table",children:[d.jsx(jd,{className:"s3-explr-table-header",children:_o.getHeaderGroups().map(A=>d.jsx(Br,{className:"hover:bg-transparent s3-explr-header-row",children:A.headers.map(O=>d.jsx(ho,{className:"s3-explr-header-cell",children:O.isPlaceholder?null:yd(O.column.columnDef.header,O.getContext())},O.id))},A.id))}),d.jsx(Wd,{className:"s3-explr-table-body",children:_o.getRowModel().rows.length===0?d.jsx(Br,{className:"s3-explr-empty-row",children:d.jsx(Jn,{colSpan:ha.length,className:"h-24 text-center s3-explr-empty-cell",children:g?d.jsxs("div",{className:"text-gray-500 s3-explr-no-results",children:['Không tìm thấy tập tin hoặc thư mục nào khớp với "',g,'"']}):d.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:Ko?"Đ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"})})}):_o.getRowModel().rows.map(A=>d.jsx(Br,{className:"h-12 s3-explr-row",children:A.getVisibleCells().map(O=>d.jsx(Jn,{className:"align-middle s3-explr-cell",children:yd(O.column.columnDef.cell,O.getContext())},O.id))},A.id))})]})})}),g&&ua!==0&&d.jsx(d.Fragment,{children:d.jsx(Ud,{children:d.jsxs(Bd,{children:[d.jsx(zd,{onClick:()=>dr(A=>Math.max(A-1,1)),"aria-disabled":Gt===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(ua/20)},(A,O)=>{const G=O+1,pe=Math.ceil(ua/20);return pe>7&&!(G===1||G===pe||G>=Gt-1&&G<=Gt+1)?G===Gt-2&&Gt>4||G===Gt+2&&Gt<pe-3?d.jsx(Kd,{className:"pointer-events-none",children:"..."},O):null:d.jsx(Ur,{className:"cursor-pointer",children:d.jsx(qa,{isActive:Gt===G,onClick:()=>dr(G),className:`${Gt===G?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:G})},O)}),d.jsx(Ur,{children:d.jsx(Vd,{onClick:()=>dr(A=>Math.min(A+1,Math.ceil(ua/20))),"aria-disabled":Gt===Math.ceil(ua/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),o&&i&&d.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[d.jsx("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:nf()}),d.jsx(He,{variant:"default",onClick:()=>i(Xu()),disabled:w.size===0,className:"s3-explr-ok-btn",children:"OK"})]}),d.jsx(R3,{open:!!Ac,onClose:()=>Ic(null),file:Ac,apiBaseUrl:e,rootUrlHostApi:r})]})}),W3=t=>d.jsx(fM,{clientId:F3,children:d.jsx(j3,{...t})});var wc=t=>t.type==="checkbox",Zi=t=>t instanceof Date,Ln=t=>t==null;const t0=t=>typeof t=="object";var Yt=t=>!Ln(t)&&!Array.isArray(t)&&t0(t)&&!Zi(t),q3=t=>Yt(t)&&t.target?wc(t.target)?t.target.checked:t.target.value:t,Y3=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,J3=(t,e)=>t.has(Y3(e)),Q3=t=>{const e=t.constructor&&t.constructor.prototype;return Yt(e)&&e.hasOwnProperty("isPrototypeOf")},Nm=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function En(t){let e;const n=Array.isArray(t),r=typeof FileList<"u"?t instanceof FileList:!1;if(t instanceof Date)e=new Date(t);else if(t instanceof Set)e=new Set(t);else if(!(Nm&&(t instanceof Blob||r))&&(n||Yt(t)))if(e=n?[]:{},!n&&!Q3(t))e=t;else for(const o in t)t.hasOwnProperty(o)&&(e[o]=En(t[o]));else return t;return e}var Su=t=>Array.isArray(t)?t.filter(Boolean):[],on=t=>t===void 0,Fe=(t,e,n)=>{if(!e||!Yt(t))return n;const r=Su(e.split(/[,[\].]+?/)).reduce((o,i)=>Ln(o)?o:o[i],t);return on(r)||r===t?on(t[e])?n:t[e]:r},yo=t=>typeof t=="boolean",Pm=t=>/^\w*$/.test(t),n0=t=>Su(t.replace(/["|']|\]/g,"").split(/\.|\[/)),Ft=(t,e,n)=>{let r=-1;const o=Pm(e)?[e]:n0(e),i=o.length,s=i-1;for(;++r<i;){const l=o[r];let u=n;if(r!==s){const h=t[l];u=Yt(h)||Array.isArray(h)?h:isNaN(+o[r+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;t[l]=u,t=t[l]}};const r0={BLUR:"blur",FOCUS_OUT:"focusout"},jr={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Uo={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};M.createContext(null);var X3=(t,e,n,r=!0)=>{const o={defaultValues:e._defaultValues};for(const i in t)Object.defineProperty(o,i,{get:()=>{const s=i;return e._proxyFormState[s]!==jr.all&&(e._proxyFormState[s]=!r||jr.all),t[s]}});return o};const Z3=typeof window<"u"?m.useLayoutEffect:m.useEffect;var wo=t=>typeof t=="string",e5=(t,e,n,r,o)=>wo(t)?(r&&e.watch.add(t),Fe(n,t,o)):Array.isArray(t)?t.map(i=>(r&&e.watch.add(i),Fe(n,i))):(r&&(e.watchAll=!0),n),t5=(t,e,n,r,o)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[r]:o||!0}}:{},Cc=t=>Array.isArray(t)?t:[t],o0=()=>{let t=[];return{get observers(){return t},next:o=>{for(const i of t)i.next&&i.next(o)},subscribe:o=>(t.push(o),{unsubscribe:()=>{t=t.filter(i=>i!==o)}}),unsubscribe:()=>{t=[]}}},Om=t=>Ln(t)||!t0(t);function Si(t,e){if(Om(t)||Om(e))return t===e;if(Zi(t)&&Zi(e))return t.getTime()===e.getTime();const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const o of n){const i=t[o];if(!r.includes(o))return!1;if(o!=="ref"){const s=e[o];if(Zi(i)&&Zi(s)||Yt(i)&&Yt(s)||Array.isArray(i)&&Array.isArray(s)?!Si(i,s):i!==s)return!1}}return!0}var Fn=t=>Yt(t)&&!Object.keys(t).length,Mm=t=>t.type==="file",Wr=t=>typeof t=="function",_u=t=>{if(!Nm)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},i0=t=>t.type==="select-multiple",Rm=t=>t.type==="radio",n5=t=>Rm(t)||wc(t),Dm=t=>_u(t)&&t.isConnected;function r5(t,e){const n=e.slice(0,-1).length;let r=0;for(;r<n;)t=on(t)?r++:t[e[r++]];return t}function o5(t){for(const e in t)if(t.hasOwnProperty(e)&&!on(t[e]))return!1;return!0}function sn(t,e){const n=Array.isArray(e)?e:Pm(e)?[e]:n0(e),r=n.length===1?t:r5(t,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(Yt(r)&&Fn(r)||Array.isArray(r)&&o5(r))&&sn(t,n.slice(0,-1)),t}var a0=t=>{for(const e in t)if(Wr(t[e]))return!0;return!1};function Eu(t,e={}){const n=Array.isArray(t);if(Yt(t)||n)for(const r in t)Array.isArray(t[r])||Yt(t[r])&&!a0(t[r])?(e[r]=Array.isArray(t[r])?[]:{},Eu(t[r],e[r])):Ln(t[r])||(e[r]=!0);return e}function s0(t,e,n){const r=Array.isArray(t);if(Yt(t)||r)for(const o in t)Array.isArray(t[o])||Yt(t[o])&&!a0(t[o])?on(e)||Om(n[o])?n[o]=Array.isArray(t[o])?Eu(t[o],[]):{...Eu(t[o])}:s0(t[o],Ln(e)?{}:e[o],n[o]):n[o]=!Si(t[o],e[o]);return n}var bc=(t,e)=>s0(t,e,Eu(e));const c0={value:!1,isValid:!1},l0={value:!0,isValid:!0};var d0=t=>{if(Array.isArray(t)){if(t.length>1){const e=t.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:e,isValid:!!e.length}}return t[0].checked&&!t[0].disabled?t[0].attributes&&!on(t[0].attributes.value)?on(t[0].value)||t[0].value===""?l0:{value:t[0].value,isValid:!0}:l0:c0}return c0},u0=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:r})=>on(t)?t:e?t===""?NaN:t&&+t:n&&wo(t)?new Date(t):r?r(t):t;const f0={isValid:!1,value:null};var h0=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,f0):f0;function p0(t){const e=t.ref;return Mm(e)?e.files:Rm(e)?h0(t.refs).value:i0(e)?[...e.selectedOptions].map(({value:n})=>n):wc(e)?d0(t.refs).value:u0(on(e.value)?t.ref.value:e.value,t)}var i5=(t,e,n,r)=>{const o={};for(const i of t){const s=Fe(e,i);s&&Ft(o,i,s._f)}return{criteriaMode:n,names:[...t],fields:o,shouldUseNativeValidation:r}},Tu=t=>t instanceof RegExp,xc=t=>on(t)?t:Tu(t)?t.source:Yt(t)?Tu(t.value)?t.value.source:t.value:t,g0=t=>({isOnSubmit:!t||t===jr.onSubmit,isOnBlur:t===jr.onBlur,isOnChange:t===jr.onChange,isOnAll:t===jr.all,isOnTouch:t===jr.onTouched});const m0="AsyncFunction";var a5=t=>!!t&&!!t.validate&&!!(Wr(t.validate)&&t.validate.constructor.name===m0||Yt(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===m0)),s5=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate),v0=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(r=>t.startsWith(r)&&/^\.\w+/.test(t.slice(r.length))));const Sc=(t,e,n,r)=>{for(const o of n||Object.keys(t)){const i=Fe(t,o);if(i){const{_f:s,...l}=i;if(s){if(s.refs&&s.refs[0]&&e(s.refs[0],o)&&!r)return!0;if(s.ref&&e(s.ref,s.name)&&!r)return!0;if(Sc(l,e))break}else if(Yt(l)&&Sc(l,e))break}}};function y0(t,e,n){const r=Fe(t,n);if(r||Pm(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),s=Fe(e,i),l=Fe(t,i);if(s&&!Array.isArray(s)&&n!==i)return{name:n};if(l&&l.type)return{name:i,error:l};o.pop()}return{name:n}}var c5=(t,e,n,r)=>{n(t);const{name:o,...i}=t;return Fn(i)||Object.keys(i).length>=Object.keys(e).length||Object.keys(i).find(s=>e[s]===(!r||jr.all))},l5=(t,e,n)=>!t||!e||t===e||Cc(t).some(r=>r&&(n?r===e:r.startsWith(e)||e.startsWith(r))),d5=(t,e,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(e||t):(n?r.isOnBlur:o.isOnBlur)?!t:(n?r.isOnChange:o.isOnChange)?t:!0,u5=(t,e)=>!Su(Fe(t,e)).length&&sn(t,e),f5=(t,e,n)=>{const r=Cc(Fe(t,n));return Ft(r,"root",e[n]),Ft(t,n,r),t},Au=t=>wo(t);function w0(t,e,n="validate"){if(Au(t)||Array.isArray(t)&&t.every(Au)||yo(t)&&!t)return{type:n,message:Au(t)?t:"",ref:e}}var rs=t=>Yt(t)&&!Tu(t)?t:{value:t,message:""},C0=async(t,e,n,r,o,i)=>{const{ref:s,refs:l,required:u,maxLength:h,minLength:p,min:g,max:C,pattern:w,validate:x,name:y,valueAsNumber:b,mount:E}=t._f,T=Fe(n,y);if(!E||e.has(y))return{};const N=l?l[0]:s,P=se=>{o&&N.reportValidity&&(N.setCustomValidity(yo(se)?"":se||""),N.reportValidity())},_={},D=Rm(s),H=wc(s),K=D||H,ee=(b||Mm(s))&&on(s.value)&&on(T)||_u(s)&&s.value===""||T===""||Array.isArray(T)&&!T.length,W=t5.bind(null,y,r,_),de=(se,fe,q,Z=Uo.maxLength,Y=Uo.minLength)=>{const oe=se?fe:q;_[y]={type:se?Z:Y,message:oe,ref:s,...W(se?Z:Y,oe)}};if(i?!Array.isArray(T)||!T.length:u&&(!K&&(ee||Ln(T))||yo(T)&&!T||H&&!d0(l).isValid||D&&!h0(l).isValid)){const{value:se,message:fe}=Au(u)?{value:!!u,message:u}:rs(u);if(se&&(_[y]={type:Uo.required,message:fe,ref:N,...W(Uo.required,fe)},!r))return P(fe),_}if(!ee&&(!Ln(g)||!Ln(C))){let se,fe;const q=rs(C),Z=rs(g);if(!Ln(T)&&!isNaN(T)){const Y=s.valueAsNumber||T&&+T;Ln(q.value)||(se=Y>q.value),Ln(Z.value)||(fe=Y<Z.value)}else{const Y=s.valueAsDate||new Date(T),oe=$=>new Date(new Date().toDateString()+" "+$),Q=s.type=="time",X=s.type=="week";wo(q.value)&&T&&(se=Q?oe(T)>oe(q.value):X?T>q.value:Y>new Date(q.value)),wo(Z.value)&&T&&(fe=Q?oe(T)<oe(Z.value):X?T<Z.value:Y<new Date(Z.value))}if((se||fe)&&(de(!!se,q.message,Z.message,Uo.max,Uo.min),!r))return P(_[y].message),_}if((h||p)&&!ee&&(wo(T)||i&&Array.isArray(T))){const se=rs(h),fe=rs(p),q=!Ln(se.value)&&T.length>+se.value,Z=!Ln(fe.value)&&T.length<+fe.value;if((q||Z)&&(de(q,se.message,fe.message),!r))return P(_[y].message),_}if(w&&!ee&&wo(T)){const{value:se,message:fe}=rs(w);if(Tu(se)&&!T.match(se)&&(_[y]={type:Uo.pattern,message:fe,ref:s,...W(Uo.pattern,fe)},!r))return P(fe),_}if(x){if(Wr(x)){const se=await x(T,n),fe=w0(se,N);if(fe&&(_[y]={...fe,...W(Uo.validate,fe.message)},!r))return P(fe.message),_}else if(Yt(x)){let se={};for(const fe in x){if(!Fn(se)&&!r)break;const q=w0(await x[fe](T,n),N,fe);q&&(se={...q,...W(fe,q.message)},P(q.message),r&&(_[y]=se))}if(!Fn(se)&&(_[y]={ref:N,...se},!r))return _}}return P(!0),_};const h5={mode:jr.onSubmit,reValidateMode:jr.onChange,shouldFocusError:!0};function p5(t={}){let e={...h5,...t},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:Wr(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1};const r={};let o=Yt(e.defaultValues)||Yt(e.values)?En(e.defaultValues||e.values)||{}:{},i=e.shouldUnregister?{}:En(o),s={action:!1,mount:!1,watch:!1},l={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},u,h=0;const p={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let g={...p};const C={array:o0(),state:o0()},w=g0(e.mode),x=g0(e.reValidateMode),y=e.criteriaMode===jr.all,b=L=>J=>{clearTimeout(h),h=setTimeout(L,J)},E=async L=>{if(!e.disabled&&(p.isValid||g.isValid||L)){const J=e.resolver?Fn((await ee()).errors):await de(r,!0);J!==n.isValid&&C.state.next({isValid:J})}},T=(L,J)=>{!e.disabled&&(p.isValidating||p.validatingFields||g.isValidating||g.validatingFields)&&((L||Array.from(l.mount)).forEach(U=>{U&&(J?Ft(n.validatingFields,U,J):sn(n.validatingFields,U))}),C.state.next({validatingFields:n.validatingFields,isValidating:!Fn(n.validatingFields)}))},N=(L,J=[],U,ae,ye=!0,he=!0)=>{if(ae&&U&&!e.disabled){if(s.action=!0,he&&Array.isArray(Fe(r,L))){const Ee=U(Fe(r,L),ae.argA,ae.argB);ye&&Ft(r,L,Ee)}if(he&&Array.isArray(Fe(n.errors,L))){const Ee=U(Fe(n.errors,L),ae.argA,ae.argB);ye&&Ft(n.errors,L,Ee),u5(n.errors,L)}if((p.touchedFields||g.touchedFields)&&he&&Array.isArray(Fe(n.touchedFields,L))){const Ee=U(Fe(n.touchedFields,L),ae.argA,ae.argB);ye&&Ft(n.touchedFields,L,Ee)}(p.dirtyFields||g.dirtyFields)&&(n.dirtyFields=bc(o,i)),C.state.next({name:L,isDirty:fe(L,J),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Ft(i,L,J)},P=(L,J)=>{Ft(n.errors,L,J),C.state.next({errors:n.errors})},_=L=>{n.errors=L,C.state.next({errors:n.errors,isValid:!1})},D=(L,J,U,ae)=>{const ye=Fe(r,L);if(ye){const he=Fe(i,L,on(U)?Fe(o,L):U);on(he)||ae&&ae.defaultChecked||J?Ft(i,L,J?he:p0(ye._f)):Y(L,he),s.mount&&E()}},H=(L,J,U,ae,ye)=>{let he=!1,Ee=!1;const Xe={name:L};if(!e.disabled){if(!U||ae){(p.isDirty||g.isDirty)&&(Ee=n.isDirty,n.isDirty=Xe.isDirty=fe(),he=Ee!==Xe.isDirty);const ft=Si(Fe(o,L),J);Ee=!!Fe(n.dirtyFields,L),ft?sn(n.dirtyFields,L):Ft(n.dirtyFields,L,!0),Xe.dirtyFields=n.dirtyFields,he=he||(p.dirtyFields||g.dirtyFields)&&Ee!==!ft}if(U){const ft=Fe(n.touchedFields,L);ft||(Ft(n.touchedFields,L,U),Xe.touchedFields=n.touchedFields,he=he||(p.touchedFields||g.touchedFields)&&ft!==U)}he&&ye&&C.state.next(Xe)}return he?Xe:{}},K=(L,J,U,ae)=>{const ye=Fe(n.errors,L),he=(p.isValid||g.isValid)&&yo(J)&&n.isValid!==J;if(e.delayError&&U?(u=b(()=>P(L,U)),u(e.delayError)):(clearTimeout(h),u=null,U?Ft(n.errors,L,U):sn(n.errors,L)),(U?!Si(ye,U):ye)||!Fn(ae)||he){const Ee={...ae,...he&&yo(J)?{isValid:J}:{},errors:n.errors,name:L};n={...n,...Ee},C.state.next(Ee)}},ee=async L=>{T(L,!0);const J=await e.resolver(i,e.context,i5(L||l.mount,r,e.criteriaMode,e.shouldUseNativeValidation));return T(L),J},W=async L=>{const{errors:J}=await ee(L);if(L)for(const U of L){const ae=Fe(J,U);ae?Ft(n.errors,U,ae):sn(n.errors,U)}else n.errors=J;return J},de=async(L,J,U={valid:!0})=>{for(const ae in L){const ye=L[ae];if(ye){const{_f:he,...Ee}=ye;if(he){const Xe=l.array.has(he.name),ft=ye._f&&a5(ye._f);ft&&p.validatingFields&&T([ae],!0);const xt=await C0(ye,l.disabled,i,y,e.shouldUseNativeValidation&&!J,Xe);if(ft&&p.validatingFields&&T([ae]),xt[he.name]&&(U.valid=!1,J))break;!J&&(Fe(xt,he.name)?Xe?f5(n.errors,xt,he.name):Ft(n.errors,he.name,xt[he.name]):sn(n.errors,he.name))}!Fn(Ee)&&await de(Ee,J,U)}}return U.valid},se=()=>{for(const L of l.unMount){const J=Fe(r,L);J&&(J._f.refs?J._f.refs.every(U=>!Dm(U)):!Dm(J._f.ref))&&Ae(L)}l.unMount=new Set},fe=(L,J)=>!e.disabled&&(L&&J&&Ft(i,L,J),!Si(_e(),o)),q=(L,J,U)=>e5(L,l,{...s.mount?i:on(J)?o:wo(L)?{[L]:J}:J},U,J),Z=L=>Su(Fe(s.mount?i:o,L,e.shouldUnregister?Fe(o,L,[]):[])),Y=(L,J,U={})=>{const ae=Fe(r,L);let ye=J;if(ae){const he=ae._f;he&&(!he.disabled&&Ft(i,L,u0(J,he)),ye=_u(he.ref)&&Ln(J)?"":J,i0(he.ref)?[...he.ref.options].forEach(Ee=>Ee.selected=ye.includes(Ee.value)):he.refs?wc(he.ref)?he.refs.length>1?he.refs.forEach(Ee=>(!Ee.defaultChecked||!Ee.disabled)&&(Ee.checked=Array.isArray(ye)?!!ye.find(Xe=>Xe===Ee.value):ye===Ee.value)):he.refs[0]&&(he.refs[0].checked=!!ye):he.refs.forEach(Ee=>Ee.checked=Ee.value===ye):Mm(he.ref)?he.ref.value="":(he.ref.value=ye,he.ref.type||C.state.next({name:L,values:En(i)})))}(U.shouldDirty||U.shouldTouch)&&H(L,ye,U.shouldTouch,U.shouldDirty,!0),U.shouldValidate&&te(L)},oe=(L,J,U)=>{for(const ae in J){const ye=J[ae],he=`${L}.${ae}`,Ee=Fe(r,he);(l.array.has(L)||Yt(ye)||Ee&&!Ee._f)&&!Zi(ye)?oe(he,ye,U):Y(he,ye,U)}},Q=(L,J,U={})=>{const ae=Fe(r,L),ye=l.array.has(L),he=En(J);Ft(i,L,he),ye?(C.array.next({name:L,values:En(i)}),(p.isDirty||p.dirtyFields||g.isDirty||g.dirtyFields)&&U.shouldDirty&&C.state.next({name:L,dirtyFields:bc(o,i),isDirty:fe(L,he)})):ae&&!ae._f&&!Ln(he)?oe(L,he,U):Y(L,he,U),v0(L,l)&&C.state.next({...n}),C.state.next({name:s.mount?L:void 0,values:En(i)})},X=async L=>{s.mount=!0;const J=L.target;let U=J.name,ae=!0;const ye=Fe(r,U),he=Ee=>{ae=Number.isNaN(Ee)||Zi(Ee)&&isNaN(Ee.getTime())||Si(Ee,Fe(i,U,Ee))};if(ye){let Ee,Xe;const ft=J.type?p0(ye._f):q3(L),xt=L.type===r0.BLUR||L.type===r0.FOCUS_OUT,Co=!s5(ye._f)&&!e.resolver&&!Fe(n.errors,U)&&!ye._f.deps||d5(xt,Fe(n.touchedFields,U),n.isSubmitted,x,w),Qt=v0(U,l,xt);Ft(i,U,ft),xt?(ye._f.onBlur&&ye._f.onBlur(L),u&&u(0)):ye._f.onChange&&ye._f.onChange(L);const vn=H(U,ft,xt),qr=!Fn(vn)||Qt;if(!xt&&C.state.next({name:U,type:L.type,values:En(i)}),Co)return(p.isValid||g.isValid)&&(e.mode==="onBlur"?xt&&E():xt||E()),qr&&C.state.next({name:U,...Qt?{}:vn});if(!xt&&Qt&&C.state.next({...n}),e.resolver){const{errors:Gt}=await ee([U]);if(he(ft),ae){const dr=y0(n.errors,r,U),Yr=y0(Gt,r,dr.name||U);Ee=Yr.error,U=Yr.name,Xe=Fn(Gt)}}else T([U],!0),Ee=(await C0(ye,l.disabled,i,y,e.shouldUseNativeValidation))[U],T([U]),he(ft),ae&&(Ee?Xe=!1:(p.isValid||g.isValid)&&(Xe=await de(r,!0)));ae&&(ye._f.deps&&te(ye._f.deps),K(U,Xe,Ee,vn))}},$=(L,J)=>{if(Fe(n.errors,J)&&L.focus)return L.focus(),1},te=async(L,J={})=>{let U,ae;const ye=Cc(L);if(e.resolver){const he=await W(on(L)?L:ye);U=Fn(he),ae=L?!ye.some(Ee=>Fe(he,Ee)):U}else L?(ae=(await Promise.all(ye.map(async he=>{const Ee=Fe(r,he);return await de(Ee&&Ee._f?{[he]:Ee}:Ee)}))).every(Boolean),!(!ae&&!n.isValid)&&E()):ae=U=await de(r);return C.state.next({...!wo(L)||(p.isValid||g.isValid)&&U!==n.isValid?{}:{name:L},...e.resolver||!L?{isValid:U}:{},errors:n.errors}),J.shouldFocus&&!ae&&Sc(r,$,L?ye:l.mount),ae},_e=L=>{const J={...s.mount?i:o};return on(L)?J:wo(L)?Fe(J,L):L.map(U=>Fe(J,U))},ke=(L,J)=>({invalid:!!Fe((J||n).errors,L),isDirty:!!Fe((J||n).dirtyFields,L),error:Fe((J||n).errors,L),isValidating:!!Fe(n.validatingFields,L),isTouched:!!Fe((J||n).touchedFields,L)}),xe=L=>{L&&Cc(L).forEach(J=>sn(n.errors,J)),C.state.next({errors:L?n.errors:{}})},Pe=(L,J,U)=>{const ae=(Fe(r,L,{_f:{}})._f||{}).ref,ye=Fe(n.errors,L)||{},{ref:he,message:Ee,type:Xe,...ft}=ye;Ft(n.errors,L,{...ft,...J,ref:ae}),C.state.next({name:L,errors:n.errors,isValid:!1}),U&&U.shouldFocus&&ae&&ae.focus&&ae.focus()},Te=(L,J)=>Wr(L)?C.state.subscribe({next:U=>L(q(void 0,J),U)}):q(L,J,!0),z=L=>C.state.subscribe({next:J=>{l5(L.name,J.name,L.exact)&&c5(J,L.formState||p,zt,L.reRenderRoot)&&L.callback({values:{...i},...n,...J})}}).unsubscribe,ce=L=>(s.mount=!0,g={...g,...L.formState},z({...L,formState:g})),Ae=(L,J={})=>{for(const U of L?Cc(L):l.mount)l.mount.delete(U),l.array.delete(U),J.keepValue||(sn(r,U),sn(i,U)),!J.keepError&&sn(n.errors,U),!J.keepDirty&&sn(n.dirtyFields,U),!J.keepTouched&&sn(n.touchedFields,U),!J.keepIsValidating&&sn(n.validatingFields,U),!e.shouldUnregister&&!J.keepDefaultValue&&sn(o,U);C.state.next({values:En(i)}),C.state.next({...n,...J.keepDirty?{isDirty:fe()}:{}}),!J.keepIsValid&&E()},Ce=({disabled:L,name:J})=>{(yo(L)&&s.mount||L||l.disabled.has(J))&&(L?l.disabled.add(J):l.disabled.delete(J))},Ne=(L,J={})=>{let U=Fe(r,L);const ae=yo(J.disabled)||yo(e.disabled);return Ft(r,L,{...U||{},_f:{...U&&U._f?U._f:{ref:{name:L}},name:L,mount:!0,...J}}),l.mount.add(L),U?Ce({disabled:yo(J.disabled)?J.disabled:e.disabled,name:L}):D(L,!0,J.value),{...ae?{disabled:J.disabled||e.disabled}:{},...e.progressive?{required:!!J.required,min:xc(J.min),max:xc(J.max),minLength:xc(J.minLength),maxLength:xc(J.maxLength),pattern:xc(J.pattern)}:{},name:L,onChange:X,onBlur:X,ref:ye=>{if(ye){Ne(L,J),U=Fe(r,L);const he=on(ye.value)&&ye.querySelectorAll&&ye.querySelectorAll("input,select,textarea")[0]||ye,Ee=n5(he),Xe=U._f.refs||[];if(Ee?Xe.find(ft=>ft===he):he===U._f.ref)return;Ft(r,L,{_f:{...U._f,...Ee?{refs:[...Xe.filter(Dm),he,...Array.isArray(Fe(o,L))?[{}]:[]],ref:{type:he.type,name:L}}:{ref:he}}}),D(L,!1,void 0,he)}else U=Fe(r,L,{}),U._f&&(U._f.mount=!1),(e.shouldUnregister||J.shouldUnregister)&&!(J3(l.array,L)&&s.action)&&l.unMount.add(L)}}},ne=()=>e.shouldFocusError&&Sc(r,$,l.mount),Ve=L=>{yo(L)&&(C.state.next({disabled:L}),Sc(r,(J,U)=>{const ae=Fe(r,U);ae&&(J.disabled=ae._f.disabled||L,Array.isArray(ae._f.refs)&&ae._f.refs.forEach(ye=>{ye.disabled=ae._f.disabled||L}))},0,!1))},Qe=(L,J)=>async U=>{let ae;U&&(U.preventDefault&&U.preventDefault(),U.persist&&U.persist());let ye=En(i);if(C.state.next({isSubmitting:!0}),e.resolver){const{errors:he,values:Ee}=await ee();n.errors=he,ye=Ee}else await de(r);if(l.disabled.size)for(const he of l.disabled)Ft(ye,he,void 0);if(sn(n.errors,"root"),Fn(n.errors)){C.state.next({errors:{}});try{await L(ye,U)}catch(he){ae=he}}else J&&await J({...n.errors},U),ne(),setTimeout(ne);if(C.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Fn(n.errors)&&!ae,submitCount:n.submitCount+1,errors:n.errors}),ae)throw ae},Ct=(L,J={})=>{Fe(r,L)&&(on(J.defaultValue)?Q(L,En(Fe(o,L))):(Q(L,J.defaultValue),Ft(o,L,En(J.defaultValue))),J.keepTouched||sn(n.touchedFields,L),J.keepDirty||(sn(n.dirtyFields,L),n.isDirty=J.defaultValue?fe(L,En(Fe(o,L))):fe()),J.keepError||(sn(n.errors,L),p.isValid&&E()),C.state.next({...n}))},Jt=(L,J={})=>{const U=L?En(L):o,ae=En(U),ye=Fn(L),he=ye?o:ae;if(J.keepDefaultValues||(o=U),!J.keepValues){if(J.keepDirtyValues){const Ee=new Set([...l.mount,...Object.keys(bc(o,i))]);for(const Xe of Array.from(Ee))Fe(n.dirtyFields,Xe)?Ft(he,Xe,Fe(i,Xe)):Q(Xe,Fe(he,Xe))}else{if(Nm&&on(L))for(const Ee of l.mount){const Xe=Fe(r,Ee);if(Xe&&Xe._f){const ft=Array.isArray(Xe._f.refs)?Xe._f.refs[0]:Xe._f.ref;if(_u(ft)){const xt=ft.closest("form");if(xt){xt.reset();break}}}}for(const Ee of l.mount)Q(Ee,Fe(he,Ee))}i=En(he),C.array.next({values:{...he}}),C.state.next({values:{...he}})}l={mount:J.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},s.mount=!p.isValid||!!J.keepIsValid||!!J.keepDirtyValues,s.watch=!!e.shouldUnregister,C.state.next({submitCount:J.keepSubmitCount?n.submitCount:0,isDirty:ye?!1:J.keepDirty?n.isDirty:!!(J.keepDefaultValues&&!Si(L,o)),isSubmitted:J.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ye?{}:J.keepDirtyValues?J.keepDefaultValues&&i?bc(o,i):n.dirtyFields:J.keepDefaultValues&&L?bc(o,L):J.keepDirty?n.dirtyFields:{},touchedFields:J.keepTouched?n.touchedFields:{},errors:J.keepErrors?n.errors:{},isSubmitSuccessful:J.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},bt=(L,J)=>Jt(Wr(L)?L(i):L,J),an=(L,J={})=>{const U=Fe(r,L),ae=U&&U._f;if(ae){const ye=ae.refs?ae.refs[0]:ae.ref;ye.focus&&(ye.focus(),J.shouldSelect&&Wr(ye.select)&&ye.select())}},zt=L=>{n={...n,...L}},Kt={control:{register:Ne,unregister:Ae,getFieldState:ke,handleSubmit:Qe,setError:Pe,_subscribe:z,_runSchema:ee,_getWatch:q,_getDirty:fe,_setValid:E,_setFieldArray:N,_setDisabledField:Ce,_setErrors:_,_getFieldArray:Z,_reset:Jt,_resetDefaultValues:()=>Wr(e.defaultValues)&&e.defaultValues().then(L=>{bt(L,e.resetOptions),C.state.next({isLoading:!1})}),_removeUnmounted:se,_disableForm:Ve,_subjects:C,_proxyFormState:p,get _fields(){return r},get _formValues(){return i},get _state(){return s},set _state(L){s=L},get _defaultValues(){return o},get _names(){return l},set _names(L){l=L},get _formState(){return n},get _options(){return e},set _options(L){e={...e,...L}}},subscribe:ce,trigger:te,register:Ne,handleSubmit:Qe,watch:Te,setValue:Q,getValues:_e,reset:bt,resetField:Ct,clearErrors:xe,unregister:Ae,setError:Pe,setFocus:an,getFieldState:ke};return{...Kt,formControl:Kt}}function g5(t={}){const e=M.useRef(void 0),n=M.useRef(void 0),[r,o]=M.useState({isDirty:!1,isValidating:!1,isLoading:Wr(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1,isReady:!1,defaultValues:Wr(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...t.formControl?t.formControl:p5(t),formState:r},t.formControl&&t.defaultValues&&!Wr(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions));const i=e.current.control;return i._options=t,Z3(()=>{const s=i._subscribe({formState:i._proxyFormState,callback:()=>o({...i._formState}),reRenderRoot:!0});return o(l=>({...l,isReady:!0})),i._formState.isReady=!0,s},[i]),M.useEffect(()=>i._disableForm(t.disabled),[i,t.disabled]),M.useEffect(()=>{t.mode&&(i._options.mode=t.mode),t.reValidateMode&&(i._options.reValidateMode=t.reValidateMode),t.errors&&!Fn(t.errors)&&i._setErrors(t.errors)},[i,t.errors,t.mode,t.reValidateMode]),M.useEffect(()=>{t.shouldUnregister&&i._subjects.state.next({values:i._getWatch()})},[i,t.shouldUnregister]),M.useEffect(()=>{if(i._proxyFormState.isDirty){const s=i._getDirty();s!==r.isDirty&&i._subjects.state.next({isDirty:s})}},[i,r.isDirty]),M.useEffect(()=>{t.values&&!Si(t.values,n.current)?(i._reset(t.values,i._options.resetOptions),n.current=t.values,o(s=>({...s}))):i._resetDefaultValues()},[i,t.values]),M.useEffect(()=>{i._state.mount||(i._setValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),e.current.formState=X3(r,i),e.current}const b0=({className:t,children:e,content:n,side:r})=>{const[o,i]=M.useState(!1);return d.jsx(vr,{delayDuration:0,children:d.jsxs(yr,{open:o,children:[d.jsx(wr,{asChild:!0,children:d.jsx("button",{type:"button",className:ze("cursor-pointer",t),onClick:()=>i(!o),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onTouchStart:()=>i(!o),onKeyDown:s=>{s.preventDefault(),s.key==="Enter"&&i(!o)},children:e})}),d.jsx(lr,{side:r,className:n?"":"hidden",children:d.jsx("span",{className:"inline-block",children:n})})]})})},m5=(t,e)=>{const[n,r]=M.useState(t);return M.useEffect(()=>{const o=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(o)}},[t,e]),n},v5=({apiBaseUrl:t="http://localhost:3000"})=>{var D,H;const[e,n]=M.useState([]),[r,o]=M.useState(!1),[i,s]=M.useState([]),[l,u]=M.useState(1),[h,p]=M.useState(1),[g,C]=M.useState(null),[w,x]=M.useState(""),y=m5(w,500),b=K=>{const ee=K.match(/\d{6}/);if(!ee)return{month:"",year:""};const W=ee[0],de=W.substring(0,2),se=W.substring(2);return{month:de,year:se}},E=K=>K.map(W=>{let de=(W==null?void 0:W.month)||"",se=(W==null?void 0:W.year)||"";if((!de||!se)&&(W!=null&&W.file_name)){const fe=b(W.file_name);de=de||fe.month,se=se||fe.year}return{id:W==null?void 0:W.id,prefix:(W==null?void 0:W.prefix)||"",model:(W==null?void 0:W.model)||"",fileName:(W==null?void 0:W.file_name)||"",code:(W==null?void 0:W.stock_id)||"",month:de,year:se,content:(W==null?void 0:W.text_summary)||"",status:(W==null?void 0:W.status)||"",note:(W==null?void 0:W.note)||"",lastUpdate:W==null?void 0:W.updated_at,stock_id:W==null?void 0:W.stock_id}}),T=K=>{if(!(K!=null&&K.data))return[];const ee=E(K==null?void 0:K.data);n(ee),p(K.pagination.totalPages)},N=async(K=1,ee=15)=>{C(K),o(!0);try{const W=await Le.get(`${t}/api/latest-summaries`,{params:{page:K,limit:ee,search:w}});(W==null?void 0:W.status)===200?T(W.data):console.error(W)}catch(W){console.error("Error fetching data:",W)}finally{C(null),o(!1)}};M.useEffect(()=>{y&&u(1),N(l)},[l,y]);const P=M.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:ee})=>d.jsx("span",{className:"flex flex-col",children:ee.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:ee})=>{const W=ee.original.month,de=ee.original.year;return d.jsx("span",{className:"flex flex-col",children:`${W.toString().padStart(2,"0")}/${de}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:ee})=>{const W=ee.getValue("content");return d.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[30dvw]",children:W})}},{id:"status",header:"Trạng thái",accessorKey:"status",cell:({row:ee})=>{const de=ee.original.status!=="unpublish";return d.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${de?"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:de?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:ee})=>d.jsx(b0,{content:d.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:ee.original.note}),children:d.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:ee.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:ee})=>{const W=new Date(ee.original.lastUpdate),de=W.getDate(),se=W.getMonth()+1,fe=`ngày ${de} tháng ${se}`;return d.jsx("span",{className:"flex flex-col",children:fe})}},{accessorKey:"actions",header:()=>d.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:ee})=>{const[W,de]=M.useState(!1),[se,fe]=M.useState(!1),[q,Z]=M.useState(!1),{handleSubmit:Y,register:oe,reset:Q}=g5(),X=ee.original.id,$=ee.getValue("status"),te=ee.getValue("content"),[_e,ke]=M.useState(!1),xe=async()=>{try{ke(!0);const Te=$==="unpublish"?"published":"unpublish",z=await Le.patch(`${t}/api/toggle-publish/${X}`,{id:X,typeAction:"update",status:$,idInput:X,stock_id:ee.original.stock_id,prefix:ee.original.prefix,model:ee.original.model,summary_result:ee.original.content,note:ee.original.note});z.status===200?n(ce=>ce.map(Ae=>Ae.id===X?{...Ae,status:Te}:Ae)):console.error("Failed to toggle publish status:",z)}catch(Te){console.error("Error toggling publish status:",Te)}finally{ke(!1)}},Pe=async Te=>{de(!0);try{const z=await Le.patch(`${t}/api/update-summary`,{note:Te.note,text_summary:Te.content,id:X});z.status===200?(await N(l),fe(!1)):console.error("Failed to update summary:",z)}catch(z){console.error("Error updating summary:",z)}return de(!1)};return d.jsxs("div",{className:"flex items-center justify-end gap-2",children:[d.jsx(He,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"px-2 py-0.5 h-7",children:d.jsx(Hx,{className:"h-4 w-4"})}),d.jsx(ar,{open:q,onOpenChange:Z,children:d.jsxs(jn,{className:"max-w-3xl max-h-[80vh]",children:[d.jsx(Wn,{children:d.jsx(qn,{children:"Nội dung chi tiết"})}),d.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:d.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:te})})]})}),d.jsxs(ar,{open:se,onOpenChange:Te=>{fe(Te),Te?Q({content:ee.original.content,note:ee.original.note}):Q()},children:[d.jsx(ic,{asChild:!0,children:d.jsx(He,{variant:"outline",size:"sm",onClick:()=>fe(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),d.jsx(jn,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:d.jsxs(Wn,{className:"flex flex-col gap-3",children:[d.jsx(qn,{className:"max-sm:hidden text-center",children:"Sửa summary"}),d.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:Y(Pe),children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex flex-col items-start",children:[d.jsx("span",{children:"Nội dung:"}),d.jsx(sc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ee.original.answer||"",rows:10,...oe("content")})]}),d.jsxs("div",{className:"flex flex-col items-start",children:[d.jsx("span",{children:"Ghi chú:"}),d.jsx(sc,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ee.original.note||"",rows:1,...oe("note")})]})]}),d.jsx("div",{className:"flex justify-end",children:d.jsx(He,{disabled:W,type:"submit",variant:"default",children:W?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),d.jsx(He,{variant:"outline",size:"sm",onClick:xe,disabled:_e,className:"w-[70px] px-2 py-0.5 h-7",children:_e?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):$==="unpublish"?"Publish":"Unpublish"})]})}}],[]),_=Gb({data:e,columns:P,state:{columnFilters:i},enableRowSelection:!0,onColumnFiltersChange:s,getFilteredRowModel:WM(),getCoreRowModel:Kb()});return d.jsxs("div",{className:"space-y-4 s3-explr-container",children:[d.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:d.jsxs("div",{className:"relative max-w-sm",children:[d.jsx(Yn,{placeholder:"Tìm kiếm theo mã...",value:w,onChange:K=>x(K.target.value),className:"pr-8"}),w&&d.jsx(He,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>x(""),children:d.jsx(cg,{className:"h-4 w-4"})})]})}),d.jsx("div",{className:"rounded-md border s3-explr-table-container",children:d.jsxs(Gd,{className:"s3-explr-table",children:[d.jsx(jd,{className:"s3-explr-table-header",children:_.getHeaderGroups().map(K=>d.jsx(Br,{className:"hover:bg-transparent s3-explr-header-row",children:K.headers.map(ee=>d.jsx(ho,{className:"s3-explr-header-cell",children:ee.isPlaceholder?null:yd(ee.column.columnDef.header,ee.getContext())},ee.id))},K.id))}),d.jsx(Wd,{className:"s3-explr-table-body",children:r?d.jsx(Br,{children:d.jsx(Jn,{colSpan:P.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(D=_.getRowModel().rows)!=null&&D.length?(H=_.getRowModel().rows)==null?void 0:H.map(K=>d.jsx(Br,{className:"h-12 s3-explr-row",children:K.getVisibleCells().map(ee=>d.jsx(Jn,{className:"align-middle s3-explr-cell",children:yd(ee.column.columnDef.cell,ee.getContext())},ee.id))},K.id)):d.jsx(Br,{children:d.jsx(Jn,{colSpan:P.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),d.jsx("div",{className:"mt-4",children:d.jsx(Ud,{children:d.jsxs(Bd,{children:[d.jsx(Ur,{children:d.jsx(zd,{onClick:()=>u(K=>Math.max(1,K-1)),className:l===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:h},(K,ee)=>ee+1).filter(K=>K===1||K===h||Math.abs(K-l)<=1).map((K,ee,W)=>d.jsxs(d.Fragment,{children:[ee>0&&W[ee-1]!==K-1&&d.jsx(Ur,{children:d.jsx(Kd,{})},K+"..."),d.jsx(Ur,{children:d.jsx(qa,{onClick:()=>u(K),isActive:l===K,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:g===K?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):K})},K)]})),d.jsx(Ur,{children:d.jsx(Vd,{onClick:()=>u(K=>Math.min(h,K+1)),className:l===h||g!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},x0=10,y5=M.memo(({apiBaseUrl:t="http://localhost:3000"})=>{const[e,n]=M.useState(1),[r,o]=M.useState([]),[i,s]=M.useState({total:0,page:1,limit:x0,totalPages:1}),[l,u]=M.useState(!0),[h,p]=M.useState(null),[g,C]=M.useState(new Set),{toast:w}=dc(),[x,y]=M.useState(!1),b=async _=>{try{p(_);const D=await Le.get(`${t}/api/jobs`,{params:{page:_.toString(),limit:x0.toString()}});o(D.data.data),s(D.data.pagination)}catch{w({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{p(null),u(!1)}};M.useEffect(()=>{b(e)},[e,t]);const E=async _=>{C(D=>new Set(D).add(_.toString()));try{await Le.post(`${t}/api/retry-job`,{jobId:_}),w({title:"Job Restarted",description:`Job ${_} has been successfully restarted.`}),b(e)}catch{w({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${_}. Please try again.`})}finally{C(D=>{const H=new Set(D);return H.delete(_.toString()),H})}},T=async()=>{y(!0),n(1),await b(1),y(!1)},N=_=>new Date(_).toLocaleString(),P=_=>{if(_=parseFloat(_),_<60)return`${_.toFixed(2)}s`;const D=Math.floor(_/60),H=(_%60).toFixed(0);return`${D}m ${H}s`};return d.jsxs("div",{children:[d.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[d.jsx(HD,{className:"w-8 h-8 text-primary"}),d.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),d.jsx(He,{variant:"outline",size:"icon",onClick:T,disabled:x||l,className:"ml-2",children:d.jsx(jD,{className:`h-4 w-4 ${x?"animate-spin":""}`})})]}),d.jsx("div",{className:"rounded-md border",children:d.jsxs(Gd,{children:[d.jsx(jd,{children:d.jsxs(Br,{children:[d.jsx(ho,{children:"ID"}),d.jsx(ho,{children:"Tên Công Việc"}),d.jsx(ho,{children:"Thời Gian Bắt Đầu"}),d.jsx(ho,{children:"Thời Gian Cập Nhật"}),d.jsx(ho,{children:"Thời Gian Thực Thi"}),d.jsx(ho,{children:"Trạng Thái"}),d.jsx(ho,{children:"Thao Tác"})]})}),d.jsx(Wd,{children:l&&r.length===0?d.jsx(Br,{children:d.jsx(Jn,{colSpan:7,className:"text-center py-4",children:d.jsx(Pt,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(_=>{var D,H;return d.jsxs(Br,{children:[d.jsx(Jn,{className:"!w-[100px]",children:_.id}),d.jsx(Jn,{className:"font-medium",children:(D=_.job_name)==null?void 0:D.replace("Upload file","Summary")}),d.jsx(Jn,{className:"!w-[200px]",children:N(_.created_at)}),d.jsx(Jn,{className:"!w-[200px]",children:N(_.updated_at)}),d.jsx(Jn,{className:"!w-[150px]",children:P(_.execution_time_seconds)}),d.jsx(Jn,{className:"!w-[200px]",children:d.jsx(b0,{content:_.status==="fail"&&_.error?d.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:_.error}):null,children:d.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]
229
229
  ${_.status==="done"?"bg-green-100 text-green-800":_.status==="fail"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:_.status==="fail"?"FAILED":(H=_.status)==null?void 0:H.toUpperCase()})})}),d.jsx(Jn,{className:"!w-[200px]",children:_.status==="fail"?d.jsx(He,{variant:"outline",size:"sm",onClick:()=>E(_.id),disabled:g.has(_.id.toString()),className:"h-[32px]",children:g.has(_.id.toString())?d.jsxs(d.Fragment,{children:[d.jsx(Pt,{className:"mr-2 h-4 w-4 animate-spin"}),"Đang thử lại..."]}):"Thử Lại"}):d.jsx("div",{className:"h-[32px]"})})]},_.id)})})]})}),d.jsx("div",{className:"mt-4",children:d.jsx(Ud,{children:d.jsxs(Bd,{children:[d.jsx(Ur,{children:d.jsx(zd,{onClick:()=>n(_=>Math.max(1,_-1)),className:e===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:i.totalPages},(_,D)=>D+1).filter(_=>_===1||_===i.totalPages||Math.abs(_-e)<=1).map((_,D,H)=>d.jsxs(d.Fragment,{children:[D>0&&H[D-1]!==_-1&&d.jsx(Ur,{children:d.jsx(Kd,{})},_+"..."),d.jsx(Ur,{children:d.jsx(qa,{onClick:()=>n(_),isActive:e===_,className:`cursor-pointer ${h!==null?"pointer-events-none":""}`,children:h===_?d.jsx(Pt,{className:"h-4 w-4 animate-spin"}):_})},_)]})),d.jsx(Ur,{children:d.jsx(Vd,{onClick:()=>n(_=>Math.min(i.totalPages,_+1)),className:e===i.totalPages||h!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),d.jsx(c_,{})]})});kr.Job=y5,kr.S3Explorer=W3,kr.Summary=v5,Object.defineProperty(kr,Symbol.toStringTag,{value:"Module"})});
230
230
  //# sourceMappingURL=s3-explorer.umd.cjs.map