dccxx-s3-explorer 1.0.2-vib → 1.0.6-vib

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -204,6 +204,6 @@ Valid keys: `+JSON.stringify(Object.keys(F),null," "));var ye=Je(Pe,Oe,Te,Ie,Ee
204
204
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function z2(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function K2(t){if(Array.isArray(t))return Ag(t)}function NT(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 PT(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?NT(Object(n),!0).forEach(function(r){RT(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):NT(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function RT(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function nc(t,e){return j2(t)||G2(t,e)||MT(t,e)||V2()}function V2(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
205
205
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function MT(t,e){if(t){if(typeof t=="string")return Ag(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 Ag(t,e)}}function Ag(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 G2(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(d){a=!0,l=d}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function j2(t){if(Array.isArray(t))return t}var q2=typeof Eg=="function"?Eg:Eg.default,W2="file-invalid-type",Y2="file-too-large",J2="file-too-small",Q2="too-many-files",X2=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:W2,message:"File type must be ".concat(r)}},DT=function(e){return{code:Y2,message:"File is larger than ".concat(e," ").concat(e===1?"byte":"bytes")}},LT=function(e){return{code:J2,message:"File is smaller than ".concat(e," ").concat(e===1?"byte":"bytes")}},Z2={code:Q2,message:"Too many files"};function FT(t,e){var n=t.type==="application/x-moz-file"||q2(t,e);return[n,n?null:X2(e)]}function HT(t,e,n){if($i(t.size))if($i(e)&&$i(n)){if(t.size>n)return[!1,DT(n)];if(t.size<e)return[!1,LT(e)]}else{if($i(e)&&t.size<e)return[!1,LT(e)];if($i(n)&&t.size>n)return[!1,DT(n)]}return[!0,null]}function $i(t){return t!=null}function eH(t){var e=t.files,n=t.accept,r=t.minSize,o=t.maxSize,a=t.multiple,c=t.maxFiles,l=t.validator;return!a&&e.length>1||a&&c>=1&&e.length>c?!1:e.every(function(d){var h=FT(d,n),p=nc(h,1),m=p[0],y=HT(d,r,o),v=nc(y,1),b=v[0],w=l?l(d):null;return m&&b&&!w})}function Vu(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function Gu(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 UT(t){t.preventDefault()}function tH(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function nH(t){return t.indexOf("Edge/")!==-1}function rH(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return tH(t)||nH(t)}function io(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return function(r){for(var o=arguments.length,a=new Array(o>1?o-1:0),c=1;c<o;c++)a[c-1]=arguments[c];return e.some(function(l){return!Vu(r)&&l&&l.apply(void 0,[r].concat(a)),Vu(r)})}}function oH(){return"showOpenFilePicker"in window}function iH(t){if($i(t)){var e=Object.entries(t).filter(function(n){var r=nc(n,2),o=r[0],a=r[1],c=!0;return $T(o)||(console.warn('Skipped "'.concat(o,'" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.')),c=!1),(!Array.isArray(a)||!a.every(BT))&&(console.warn('Skipped "'.concat(o,'" because an invalid file extension was provided.')),c=!1),c}).reduce(function(n,r){var o=nc(r,2),a=o[0],c=o[1];return PT(PT({},n),{},RT({},a,c))},{});return[{description:"Files",accept:e}]}return t}function aH(t){if($i(t))return Object.entries(t).reduce(function(e,n){var r=nc(n,2),o=r[0],a=r[1];return[].concat(OT(e),[o],OT(a))},[]).filter(function(e){return $T(e)||BT(e)}).join(",")}function sH(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function cH(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function $T(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function BT(t){return/^.*\.[\w]+$/.test(t)}var lH=["children"],uH=["open"],dH=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],fH=["refKey","onChange","onClick"];function hH(t){return mH(t)||gH(t)||zT(t)||pH()}function pH(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
206
206
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function gH(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function mH(t){if(Array.isArray(t))return kg(t)}function Ig(t,e){return wH(t)||yH(t,e)||zT(t,e)||vH()}function vH(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
207
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zT(t,e){if(t){if(typeof t=="string")return kg(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 kg(t,e)}}function kg(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 yH(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(d){a=!0,l=d}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function wH(t){if(Array.isArray(t))return t}function KT(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Ut(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?KT(Object(n),!0).forEach(function(r){Og(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):KT(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Og(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ju(t,e){if(t==null)return{};var n=CH(t,e),r,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(o=0;o<a.length;o++)r=a[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function CH(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,a;for(a=0;a<r.length;a++)o=r[a],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var Ng=M.forwardRef(function(t,e){var n=t.children,r=ju(t,lH),o=GT(r),a=o.open,c=ju(o,uH);return M.useImperativeHandle(e,function(){return{open:a}},[a]),M.createElement(M.Fragment,null,n(Ut(Ut({},c),{},{open:a})))});Ng.displayName="Dropzone";var VT={disabled:!1,getFilesFromEvent:P2,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};Ng.defaultProps=VT,Ng.propTypes={children:At.func,accept:At.objectOf(At.arrayOf(At.string)),multiple:At.bool,preventDropOnDocument:At.bool,noClick:At.bool,noKeyboard:At.bool,noDrag:At.bool,noDragEventsBubbling:At.bool,minSize:At.number,maxSize:At.number,maxFiles:At.number,disabled:At.bool,getFilesFromEvent:At.func,onFileDialogCancel:At.func,onFileDialogOpen:At.func,useFsAccessApi:At.bool,autoFocus:At.bool,onDragEnter:At.func,onDragLeave:At.func,onDragOver:At.func,onDrop:At.func,onDropAccepted:At.func,onDropRejected:At.func,onError:At.func,validator:At.func};var Pg={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function GT(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Ut(Ut({},VT),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,a=e.maxSize,c=e.minSize,l=e.multiple,d=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,m=e.onDragOver,y=e.onDrop,v=e.onDropAccepted,b=e.onDropRejected,w=e.onFileDialogCancel,x=e.onFileDialogOpen,I=e.useFsAccessApi,k=e.autoFocus,O=e.preventDropOnDocument,D=e.noClick,E=e.noKeyboard,B=e.noDrag,j=e.noDragEventsBubbling,q=e.onError,ne=e.validator,W=M.useMemo(function(){return aH(n)},[n]),me=M.useMemo(function(){return iH(n)},[n]),fe=M.useMemo(function(){return typeof x=="function"?x:jT},[x]),we=M.useMemo(function(){return typeof w=="function"?w:jT},[w]),G=M.useRef(null),X=M.useRef(null),Y=M.useReducer(bH,Pg),ie=Ig(Y,2),Z=ie[0],J=ie[1],F=Z.isFocused,te=Z.isFileDialogActive,xe=M.useRef(typeof window<"u"&&window.isSecureContext&&I&&oH()),_e=function(){!xe.current&&te&&setTimeout(function(){if(X.current){var re=X.current.files;re.length||(J({type:"closeDialog"}),we())}},300)};M.useEffect(function(){return window.addEventListener("focus",_e,!1),function(){window.removeEventListener("focus",_e,!1)}},[X,te,we,xe]);var Te=M.useRef([]),Ie=function(re){G.current&&G.current.contains(re.target)||(re.preventDefault(),Te.current=[])};M.useEffect(function(){return O&&(document.addEventListener("dragover",UT,!1),document.addEventListener("drop",Ie,!1)),function(){O&&(document.removeEventListener("dragover",UT),document.removeEventListener("drop",Ie))}},[G,O]),M.useEffect(function(){return!r&&k&&G.current&&G.current.focus(),function(){}},[G,k,r]);var Ee=M.useCallback(function(H){q?q(H):console.error(H)},[q]),Pe=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H),Te.current=[].concat(hH(Te.current),[H.target]),Gu(H)&&Promise.resolve(o(H)).then(function(re){if(!(Vu(H)&&!j)){var he=re.length,ue=he>0&&eH({files:re,accept:W,minSize:c,maxSize:a,multiple:l,maxFiles:d,validator:ne}),be=he>0&&!ue;J({isDragAccept:ue,isDragReject:be,isDragActive:!0,type:"setDraggedFiles"}),h&&h(H)}}).catch(function(re){return Ee(re)})},[o,h,Ee,j,W,c,a,l,d,ne]),Fe=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H);var re=Gu(H);if(re&&H.dataTransfer)try{H.dataTransfer.dropEffect="copy"}catch{}return re&&m&&m(H),!1},[m,j]),Me=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H);var re=Te.current.filter(function(ue){return G.current&&G.current.contains(ue)}),he=re.indexOf(H.target);he!==-1&&re.splice(he,1),Te.current=re,!(re.length>0)&&(J({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Gu(H)&&p&&p(H))},[G,p,j]),Oe=M.useCallback(function(H,re){var he=[],ue=[];H.forEach(function(be){var qe=FT(be,W),pt=Ig(qe,2),ft=pt[0],Dn=pt[1],Wn=HT(be,c,a),Ft=Ig(Wn,2),Yn=Ft[0],Jn=Ft[1],Qn=ne?ne(be):null;if(ft&&Yn&&!Qn)he.push(be);else{var He=[Dn,Jn];Qn&&(He=He.concat(Qn)),ue.push({file:be,errors:He.filter(function(co){return co})})}}),(!l&&he.length>1||l&&d>=1&&he.length>d)&&(he.forEach(function(be){ue.push({file:be,errors:[Z2]})}),he.splice(0)),J({acceptedFiles:he,fileRejections:ue,isDragReject:ue.length>0,type:"setFiles"}),y&&y(he,ue,re),ue.length>0&&b&&b(ue,re),he.length>0&&v&&v(he,re)},[J,l,W,c,a,d,y,v,b,ne]),Je=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H),Te.current=[],Gu(H)&&Promise.resolve(o(H)).then(function(re){Vu(H)&&!j||Oe(re,H)}).catch(function(re){return Ee(re)}),J({type:"reset"})},[o,Oe,Ee,j]),ye=M.useCallback(function(){if(xe.current){J({type:"openDialog"}),fe();var H={multiple:l,types:me};window.showOpenFilePicker(H).then(function(re){return o(re)}).then(function(re){Oe(re,null),J({type:"closeDialog"})}).catch(function(re){sH(re)?(we(re),J({type:"closeDialog"})):cH(re)?(xe.current=!1,X.current?(X.current.value=null,X.current.click()):Ee(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."))):Ee(re)});return}X.current&&(J({type:"openDialog"}),fe(),X.current.value=null,X.current.click())},[J,fe,we,I,Oe,Ee,me,l]),st=M.useCallback(function(H){!G.current||!G.current.isEqualNode(H.target)||(H.key===" "||H.key==="Enter"||H.keyCode===32||H.keyCode===13)&&(H.preventDefault(),ye())},[G,ye]),Ct=M.useCallback(function(){J({type:"focus"})},[]),nn=M.useCallback(function(){J({type:"blur"})},[]),ln=M.useCallback(function(){D||(rH()?setTimeout(ye,0):ye())},[D,ye]),Pt=function(re){return r?null:re},Rn=function(re){return E?null:Pt(re)},Xt=function(re){return B?null:Pt(re)},Mn=function(re){j&&re.stopPropagation()},$t=M.useMemo(function(){return function(){var H=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},re=H.refKey,he=re===void 0?"ref":re,ue=H.role,be=H.onKeyDown,qe=H.onFocus,pt=H.onBlur,ft=H.onClick,Dn=H.onDragEnter,Wn=H.onDragOver,Ft=H.onDragLeave,Yn=H.onDrop,Jn=ju(H,dH);return Ut(Ut(Og({onKeyDown:Rn(io(be,st)),onFocus:Rn(io(qe,Ct)),onBlur:Rn(io(pt,nn)),onClick:Pt(io(ft,ln)),onDragEnter:Xt(io(Dn,Pe)),onDragOver:Xt(io(Wn,Fe)),onDragLeave:Xt(io(Ft,Me)),onDrop:Xt(io(Yn,Je)),role:typeof ue=="string"&&ue!==""?ue:"presentation"},he,G),!r&&!E?{tabIndex:0}:{}),Jn)}},[G,st,Ct,nn,ln,Pe,Fe,Me,Je,E,B,r]),R=M.useCallback(function(H){H.stopPropagation()},[]),V=M.useMemo(function(){return function(){var H=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},re=H.refKey,he=re===void 0?"ref":re,ue=H.onChange,be=H.onClick,qe=ju(H,fH),pt=Og({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:Pt(io(ue,Je)),onClick:Pt(io(be,R)),tabIndex:-1},he,X);return Ut(Ut({},pt),qe)}},[X,n,l,Je,r]);return Ut(Ut({},Z),{},{isFocused:F&&!r,getRootProps:$t,getInputProps:V,rootRef:G,inputRef:X,open:Pt(ye)})}function bH(t,e){switch(e.type){case"focus":return Ut(Ut({},t),{},{isFocused:!0});case"blur":return Ut(Ut({},t),{},{isFocused:!1});case"openDialog":return Ut(Ut({},Pg),{},{isFileDialogActive:!0});case"closeDialog":return Ut(Ut({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ut(Ut({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Ut(Ut({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Ut({},Pg);default:return t}}function jT(){}const xH=({onFilesSelected:t,children:e})=>{const[n,r]=M.useState(!1),{getRootProps:o,getInputProps:a}=GT({noClick:!0,onDrop:c=>{if(c&&c.length>0)if(c[0].path.split("/").length>2){const d=c.map(h=>{const m=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:m,enumerable:!0,configurable:!0}),h});t(d,"folder")}else t(c,"files");r(!1)},onDragOver:c=>{c.preventDefault(),n||r(!0)},multiple:!0});return M.useEffect(()=>{const c=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",c),()=>{document.removeEventListener("dragleave",c)}},[]),f.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?f.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,f.jsx("input",{...a()})]})},_H=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:a,ignoreCache:c})=>{var k;const[l,d]=M.useState({}),[h,p]=M.useState(!1),[m,y]=M.useState(!1),[v,b]=M.useState(""),{toast:w}=Ou();M.useEffect(()=>{t&&x(v)},[v,t]);const x=async O=>{try{y(!0);const D=await Le.get(`${n}/api/list-s3-folders?prefix=${O}`);d(D==null?void 0:D.data)}catch{w({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{y(!1)}},I=async()=>{p(!0);try{const O=o.key,D=O.endsWith("/")?O:`${O}/`,E=v.endsWith("/")?v:`${v}/`;if(D===E||O===v){w({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),p(!1);return}await Le.post(`${n}/api/move`,{oldPath:O,newPath:v}),c.current=!0,await a(),w({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${v}"`}),e(!1),r(null),b("")}catch(O){console.error("Error renaming item:",O),w({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{p(!1)}};return f.jsx(Tr,{open:t,onOpenChange:O=>{O||(e(!1),r(null),b(""))},children:f.jsxs(or,{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:[f.jsxs(ir,{className:"mb-4 w-full h-full",children:[f.jsx("nav",{className:"mb-4",children:f.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[f.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>b(""),children:"Root"}),v.split("/").map((O,D,E)=>f.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>b(O==="Root"?"":E.slice(0,D+1).join("/")+"/"),children:O},D))]})}),f.jsxs(ar,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",f.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",v===""?"Root":v," )"]})]}),f.jsx(ci,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:m?f.jsx("div",{className:"flex justify-center items-center py-4",children:f.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):f.jsx("ul",{className:"space-y-2",children:(k=Object.keys(l))==null?void 0:k.map(O=>f.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>b(O),children:O},O))})})]}),f.jsxs(Io,{className:"flex justify-end space-x-2",children:[f.jsx($e,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),f.jsx($e,{onClick:I,disabled:h,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},TH="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",SH="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",EH="https://www.googleapis.com/auth/drive";Eo(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Eo.isRetryableError(t)&&t.config.method==="get"});const Pn={current:!1},qT="crawl:jobs",Va="crawl:current_job",AH=t=>{const[e,n]=M.useState(null),[r,o]=M.useState(0);return M.useEffect(()=>{const a=localStorage.getItem(Va);if(a){const c=JSON.parse(a);n(c),c!=null&&c.startTime&&o(Math.floor((Date.now()-c.startTime)/1e3))}},[]),M.useEffect(()=>{if(!(e!=null&&e.startTime))return;const a=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(a)},[e==null?void 0:e.startTime]),M.useEffect(()=>{if(!(e!=null&&e.id))return;const a=async()=>{try{const d=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:d};return localStorage.setItem(Va,JSON.stringify(p)),(d.status==="completed"||d.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Va)},100),p})}catch(l){console.error("Error polling job status:",l)}},c=setInterval(a,3e3);return a(),()=>clearInterval(c)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:a=>{a&&!a.startTime&&(a.startTime=Date.now()),n(a),a?localStorage.setItem(Va,JSON.stringify(a)):localStorage.removeItem(Va)}}},qu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(c=>{n.push(c.key),c.isFolder&&r(c.key)})};return r(e),n},IH=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...qu(t,o.key))}),n},kH=(t,e,n=[],r,o,a,c,l,d,h)=>{const[p,m]=M.useState({}),[y,v]=M.useState(!1),[b,w]=M.useState(null),[x,I]=M.useState(0),k=M.useRef(e);M.useEffect(()=>{k.current=e},[e]);const O=async()=>{v(!0);try{const E=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:k.current,excludePrivateFiles:c?"false":"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5}),B=[];cu.forEach(E.data,(j,q)=>{l!=null&&l.has(q)&&cu.forEach(j,ne=>{(d==null?void 0:d.current[ne.key])!==!1&&B.push(ne.key)})}),B.length&&(h==null||h(j=>{const q=new Set(j);return B.forEach(ne=>q.add(ne)),q})),m(E.data),w(null)}catch(E){w(E instanceof Error?E:new Error("Failed to fetch files"))}finally{v(!1),I(0),a("")}},D=async E=>{var B,j;try{if(!E)return;v(!0);const q=await Le.get(`${t}/api/search-db?query=${E}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return m({[e]:((B=q==null?void 0:q.data)==null?void 0:B.result)||[]}),I(((j=q==null?void 0:q.data)==null?void 0:j.estimatedTotalHits)||0),q}catch(q){w(q instanceof Error?q:new Error("Failed to fetch files"))}finally{v(!1)}};return M.useEffect(()=>{!r&&!y&&O(),r&&!y&&D(r)},[r,o]),{data:p,isLoading:y,error:b,estimatedTotalHits:x,refetch:O}},rc=t=>{var r,o,a;const e=((a=(o=(r=t==null?void 0:t.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:a.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(e||"")},OH={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:"http://localhost:5173/"}},NH=new Dh(OH),PH=M.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3002",rootPrefix:n="",rootUrlHostApi:r,asSelector:o=!1,onSelected:a=h=>console.log("Đã chọn:",h),displayPrefixes:c,preSelectedFiles:l,idCreator:d})=>{var is;const[h,p]=M.useState([]),[m,y]=M.useState(""),[v,b]=M.useState(new Set(l)),[w,x]=M.useState(n),[I,k]=M.useState(""),[O,D]=M.useState(!1),[E,B]=M.useState(""),[j,q]=M.useState(!1),[ne,W]=M.useState(null),[me,fe]=M.useState(null),[we,G]=M.useState(!1),[X,Y]=M.useState(!1),[,ie]=M.useState(null),Z=M.useRef(null),{toast:J}=Ou(),[F,te]=M.useState(null),[xe,_e]=M.useState(null),[Te,Ie]=M.useState(""),[Ee,Pe]=M.useState(!1),[Fe,Me]=M.useState(!1),[Oe,Je]=M.useState(new Set),[ye,st]=M.useState(""),[Ct,nn]=M.useState(!1),[ln,Pt]=M.useState(!1),[Rn,Xt]=M.useState("rename"),[Mn,$t]=M.useState(!1),[R,V]=M.useState(""),[H,re]=M.useState("1"),[he,ue]=M.useState(!1),[be,qe]=M.useState(!1),[pt,ft]=M.useState(!1),[Dn,Wn]=M.useState(!1),[Ft,Yn]=M.useState(1),[Jn,Qn]=M.useState(!1),{currentJob:He,elapsedTime:co,setCurrentJob:Zu}=AH(e),[Pr,fi]=M.useState(null),[zi,ja]=M.useState(""),[Ug,Ki]=M.useState(!1),[Vi,ed]=M.useState(""),[$g,td]=M.useState(!1),[lc,nd]=M.useState(!1),[hi,rd]=M.useState([]),[Gi,od]=M.useState(!1),[id,Bg]=M.useState(""),Mo=M.useRef({}),zg=async S=>{nd(!0);try{const P=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${S}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});P.status===200&&rd(P.data.knowledgeBase.chatflows.map(z=>({...z,KnowledgeBaseId:P.data.knowledgeBase.knowledge_base_id})))}catch{}finally{nd(!1)}};M.useEffect(()=>{Vi&&r&&zg(Vi)},[Vi]),M.useEffect(()=>{console.log("pre selected files",l)},[l]);const[Ht,qa]=M.useState(null),[mS,Kg]=M.useState(!1),[vS,uc]=M.useState(!1),[ad,Wa]=M.useState(!1),[ji,sd]=M.useState([]),[qi,cd]=M.useState([]),[Ya,dc]=M.useState([{id:"root",name:"OneDrive"}]),[ld,Wi]=M.useState(!1),[Yi,ud]=M.useState([]),[Vg,pi]=M.useState(!1),[dd,Ja]=M.useState([]),[fc,fd]=M.useState([]),[Ji,hd]=M.useState([]),[hc,Do]=M.useState([{id:"root",name:"SharePoint"}]),[Lo,Qi]=M.useState(!1),[pc,pd]=M.useState([]),[gt,Qa]=M.useState(null),[gd,gi]=M.useState(!1),[gc,Rr]=M.useState(!1),qg=new URL(window.location.href).searchParams.get("prefix")||""||I||n,[Wg,md]=M.useState(null),{data:Mr,isLoading:Fo,error:Yg,estimatedTotalHits:Xi,refetch:rn}=kH(e,qg,c,m,Ft,y,d,v,Mo,b),[Xa,lo]=M.useState(!1),mc=M.useRef(null);M.useEffect(()=>{if(!Xa)return;function S(P){mc.current&&!mc.current.contains(P.target)&&lo(!1)}return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[Xa]);const Jg=async()=>{try{const S=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:P}=S.data,z=window.open(P,"SharePoint Login","width=600,height=600");if(!z)throw new Error("Không thể mở cửa sổ pop-up");z.focus();const se=setInterval(()=>{try{if(z.closed){clearInterval(se);return}const pe=z.location.href;if(pe.includes("code=")){const Ce=new URL(pe).searchParams.get("code");Ce&&(Za(Ce),z.close(),clearInterval(se))}}catch(pe){pe instanceof Error&&!pe.message.includes("cross-origin")&&console.error("SharePoint login error:",pe)}},1e3)}catch(S){rt.error("Lỗi khi đăng nhập SharePoint: "+(S instanceof Error?S.message:"Unknown error"))}},Qg=async()=>{try{Ja([]),Do([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),J({title:"Success",description:"Logged out from SharePoint"})}catch(S){console.error("Error logging out from SharePoint:",S),J({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},Za=async S=>{try{const P=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:S,userId:"1"}),{accessToken:z}=P.data;localStorage.setItem("sharepoint_access_token",z),uc(!0),Qi(!0)}catch(P){console.error("❌ Error fetching SharePoint access token:",P),J({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},Xg=async()=>{try{pi(!0);const P=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map(z=>{const se=new URL(z.webUrl);return{id:z.id,name:z.name,description:z.description,hostname:z.hostname||se.hostname,sitePath:z.sitePath||se.pathname.replace(/^\/+/,"")}});pd(P),pi(!1)}catch(S){console.error("❌ Error fetching SharePoint sites:",S),J({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),pi(!1)}},Zg=async S=>{Qa(S),await es("root",S.name,S.hostname||"",S.sitePath||"")},es=async(S,P,z,se)=>{try{pi(!0);const Ce=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:S,userId:"1",hostname:z,sitePath:se})).data.files.map(Ae=>({id:Ae.id,name:Ae.name,size:Ae.size??0,lastModified:Ae.lastModifiedDateTime?new Date(Ae.lastModifiedDateTime):new Date,contentType:Ae.mimeType??void 0,isFolder:Ae.type==="folder",parentId:Ae.parentId??""}));fd(Ce.filter(Ae=>Ae.isFolder)),Ja(Ce.filter(Ae=>!Ae.isFolder)),Qi(!0),Do(Ae=>Ae.some(ht=>ht.id===S)?Ae:[...Ae,{id:S,name:P==="root"?"SharePoint":P}]),pi(!1)}catch(pe){console.error("❌ Error fetching SharePoint files:",pe),J({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),pi(!1)}},em=S=>{hd(P=>P.some(se=>se.id===S.id)?P.filter(se=>se.id!==S.id):[...P,{id:S.id,name:S.name,size:S.size,lastModified:S.lastModified,contentType:S.contentType,isFolder:S.isFolder,parentId:S.parentId}])},tm=S=>{var z;Do(se=>se.slice(0,S+1));const P=(z=hc[S])==null?void 0:z.id;P&&es(P,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},It=async(S,P)=>{const z=localStorage.getItem("sharepoint_access_token");if(!z){rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const se=rt.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};S.forEach(Ae=>{Ae.isFolder?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-sharepoint-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),Qi(!1)}catch(pe){console.error("Lỗi khi đồng bộ file từ SharePoint:",pe),rt.update(se,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},_t=()=>{Qi(!1),Ja([]),hd([]),Do([{id:"root",name:"SharePoint"}])};M.useEffect(()=>{if(Lo){const P=new URLSearchParams(window.location.search).get("code");P&&(Za(P),window.history.replaceState({},document.title,window.location.pathname))}},[Lo]),M.useEffect(()=>{NH.initialize().then(()=>{Kg(!0)}).catch(S=>console.error("❌ Lỗi khởi tạo MSAL:",S))},[]),M.useEffect(()=>{nm()},[]);async function nm(){localStorage.getItem("onedrive_access_token")&&uc(!0)}const vd=S=>{ud(P=>P.some(se=>se.id===S.id)?P.filter(se=>se.id!==S.id):[...P,{id:S.id,name:S.name,size:S.size,lastModified:S.lastModified,contentType:S.contentType,isFolder:S.isFolder,parentId:S.parentId}])};function vc(S){if(S===0)return"0 B";const P=1024,z=["B","KB","MB","GB","TB"],se=Math.floor(Math.log(S)/Math.log(P));return parseFloat((S/Math.pow(P,se)).toFixed(1))+" "+z[se]}function rm(S){const P=new Date(S);return P.toLocaleDateString()+" "+P.toLocaleTimeString()}const om=async()=>{try{const S=await Le.get(`${e}/api/login-one-drive`),{loginUrl:P}=S.data,z=window.open(P,"OneDrive Login","width=600,height=600");if(!z)throw new Error("Không thể mở cửa sổ pop-up");z.focus();const se=setInterval(()=>{try{if(z.closed){clearInterval(se);return}const pe=z.location.href;if(pe.includes("code=")){const Ce=new URL(pe).searchParams.get("code");Ce&&(yd(Ce),z.close(),clearInterval(se))}}catch(pe){pe instanceof Error&&!pe.message.includes("cross-origin")&&console.error("OneDrive login error:",pe)}},1e3)}catch(S){rt.error("Lỗi khi đăng nhập OneDrive: "+(S instanceof Error?S.message:"Unknown error"))}},im=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),rt.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(S){rt.error("Lỗi khi đăng xuất OneDrive: "+(S instanceof Error?S.message:"Unknown error"))}},yd=async S=>{try{const z=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:S,userId:"1"}),{accessToken:se}=z.data;localStorage.setItem("onedrive_access_token",se),uc(!0),Wa(!0),await ts("root","One Drive")}catch(P){console.error("❌ Lỗi khi lấy Access Token:",P)}},ts=async(S,P)=>{try{Wi(!0);const pe=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:S,userId:"1"})).data.map(Ce=>({id:Ce.id,name:Ce.name,size:Ce.size??0,lastModified:Ce.lastModifiedDateTime?new Date(Ce.lastModifiedDateTime):new Date,contentType:Ce.mimeType??void 0,isFolder:Ce.type==="folder",parentId:Ce.parentId??""}));sd(pe.filter(Ce=>Ce.isFolder)),cd(pe.filter(Ce=>!Ce.isFolder)),Wa(!0),dc(Ce=>Ce.some(Ae=>Ae.id===S)?Ce:[...Ce,{id:S,name:P==="root"?"OneDrive":P}]),Wi(!1)}catch(z){console.error("Lỗi lấy danh sách file:",z),Wi(!1)}},Zt=S=>{if(S===Ya.length-1)return;const P=Ya[S];P&&(dc(Ya.slice(0,S+1)),ts(P.id,P.name))},yc=async(S,P)=>{const z=localStorage.getItem("onedrive_access_token");if(!z){rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const se=rt.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[]};S.forEach(Ae=>{Ae.isFolder?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-one-drive-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(pe){console.error("Lỗi khi đồng bộ file từ OneDrive:",pe),rt.update(se,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},uo=()=>{Wa(!1),dc([{id:"root",name:"OneDrive"}]),sd([]),cd([]),ud([]),Wi(!1)},wd=rP({onSuccess:S=>{md(S.access_token),localStorage.setItem("google_access_token",S.access_token),wc(S.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:EH}),wc=S=>{const P=document.createElement("script");P.src="https://apis.google.com/js/api.js",P.onload=()=>{window.gapi.load("picker",()=>Ln(S))},document.body.appendChild(P)},Ln=S=>{const P=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),z=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(TH).setOAuthToken(S).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(P).addView(z).setCallback(async pe=>{if(pe.action===window.google.picker.Action.PICKED){const Ce=pe.docs.map(Ae=>({id:Ae.id,name:Ae.name,mimeType:Ae.mimeType}));await Cd(Ce,w)}}).build().setVisible(!0)},Cd=async(S,P="")=>{const z=localStorage.getItem("google_access_token");if(!z){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const se=rt.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[]};S.forEach(Ae=>{Ae.mimeType==="application/vnd.google-apps.folder"?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-drive-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});Pn.current=!0,rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(pe){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",pe),rt.update(se,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};M.useEffect(()=>{const S=P=>{if(P.data.action==="logout"){const z=document.createElement("iframe");z.style.display="none",z.src="https://accounts.google.com/Logout",document.body.appendChild(z),setTimeout(()=>document.body.removeChild(z),2e3)}};return window.addEventListener("message",S),()=>window.removeEventListener("message",S)},[]),M.useEffect(()=>{const S=new Set(l);b(S)},[]),M.useEffect(()=>{He!=null&&He.status&&(He.status.status==="completed"?(J({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${He.url} với ${He.status.completed} trang`}),Pn.current=!0,rn()):He.status.status==="failed"&&J({title:"Thu thập website thất bại",description:`Không thể thu thập ${He.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(is=He==null?void 0:He.status)==null?void 0:is.status]);const Cc=M.useMemo(()=>Mr[w]||[],[Mr,w]),Dr=M.useMemo(()=>Cc,[Cc,w,Mr]),mi=M.useMemo(()=>{const S={};return Dr.forEach((P,z)=>{v.has(P.key)&&(S[z]=!0)}),S},[v,Dr]),bd=S=>{const P=qu(Mr,S);if(P.length===0)return v.has(S)?"all":"none";const z=P.filter(se=>v.has(se)).length;return z===0?"none":z===P.length?"all":"partial"},Ho=(S,P=!0)=>{if(w!==S){if(d&&!w)Qn(!0),k(S+d),x(S+d);else if(Qn(!0),k(S),x(S),P&&!o){const z=window.location.pathname==="/"?"":window.location.pathname,se=S?`${window.location.origin}${z}?prefix=${encodeURIComponent(S)}`:`${window.location.origin}${z}`;window.history.pushState({path:se},"",se)}}};M.useEffect(()=>{Jn&&(Pn.current=!0,rn().finally(()=>Qn(!1)))},[Jn]);const Tn=async(S,P)=>{var z,se;q(!0);try{if(Dr.some(ht=>ht.isFolder&&ht.name.toLowerCase()===S.toLowerCase())){J({title:"Lỗi",description:`Thư mục "${S}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),q(!1);return}const Ce=`${P}${S}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ce})).status!==200){J({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Pn.current=!0,await rn(),J({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${S}"`}),B(""),D(!1)}catch(pe){console.error("Error creating folder:",pe);const Ce=((se=(z=pe==null?void 0:pe.response)==null?void 0:z.data)==null?void 0:se.error)||"Không thể tạo thư mục";J({title:"Lỗi",description:Ce,variant:"destructive"})}finally{q(!1)}},bc=async(S,P,z)=>{var se,pe,Ce,Ae,ht,Xn,Fr,Tc,Sc;ie(z),ft(!0);try{if(Array.from(S).reduce((un,ra)=>un+ra.size,0)>=100*1024*1024){J({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),ie(null),ft(!1);return}const as=Array.from(S).filter(un=>un.size===0);if(as.length>0){const un=as.map(ra=>ra.name).join(", ");J({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${un}`,variant:"destructive"}),ft(!1),ie(null);return}let na=localStorage.getItem("dataLogin"),yi;try{na&&(na=JSON.parse(na),yi=na.user)}catch{na=null}const Uo=new FormData;if(yi!=null&&yi.id&&Uo.append("metadata",JSON.stringify({creator:yi.username,creatorId:yi.id,DataSource:"Tệp tải lên"})),z==="folder"&&S[0]){const un=S[0].webkitRelativePath.split("/")[0];un&&Uo.append("folderName",un)}Uo.append("prefix",P),Array.from(S).forEach(un=>z==="folder"?Uo.append("files",un,un.webkitRelativePath):Uo.append("files",un)),Pn.current=!0;const Rt=await Le.post(`${e}/api/check-files-existed`,Uo,{headers:{"Content-Type":"multipart/form-data"}});if(((se=Rt==null?void 0:Rt.data)==null?void 0:se.status)===200)await Le.post(`${e}/api/upload`,Uo,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),y(""),k(P),setTimeout(async()=>{ie(null),await rn(),ft(!1),await Lr()},500);else{if(((Ce=(pe=Rt==null?void 0:Rt.data)==null?void 0:pe.names)==null?void 0:Ce.length)>0&&!((Ae=Rt==null?void 0:Rt.data)!=null&&Ae.isFolder)){const un=Array.from(S).filter(ra=>Rt.data.names.includes(ra.name));fi(un),Ki(!0)}(ht=Rt==null?void 0:Rt.data)!=null&&ht.isFolder&&((Xn=Rt==null?void 0:Rt.data)!=null&&Xn.name)&&(ja((Fr=Rt==null?void 0:Rt.data)==null?void 0:Fr.name),fi(S),Ki(!0))}}catch(ta){console.error("Lỗi tải lên:",ta);const as=((Sc=(Tc=ta==null?void 0:ta.response)==null?void 0:Tc.data)==null?void 0:Sc.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:as,variant:"destructive"}),ie(null),ft(!1)}},Fn=async()=>{var S,P;try{ft(!0);const z=new FormData;if(Pr){ie(zi?"folder":"files"),Ki(!1);let se=localStorage.getItem("dataLogin"),pe;try{se&&(se=JSON.parse(se),pe=se.user)}catch{se=null}if(pe!=null&&pe.id&&z.append("metadata",JSON.stringify({creator:pe.username,creatorId:pe.id,DataSource:"Tệp tải lên"})),zi&&Pr[0]){const Ce=Pr[0].webkitRelativePath.split("/")[0];Ce&&z.append("folderName",Ce)}z.append("prefix",w),Array.from(Pr).forEach(Ce=>zi&&Pr[0]?z.append("files",Ce,Ce.webkitRelativePath):z.append("files",Ce)),pe!=null&&pe.id&&z.append("metadata",JSON.stringify({creator:pe.username,creatorId:pe.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,z,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),y(""),k(w),Pn.current=!0}}catch(z){console.error("Lỗi tải lên:",z);const se=((P=(S=z==null?void 0:z.response)==null?void 0:S.data)==null?void 0:P.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:se,variant:"destructive"})}finally{setTimeout(async()=>{ie(null),await rn(),ft(!1),ja(""),fi(null),await Lr()},500)}},xd=async S=>{var P;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[S.key]},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v.has(S.key)){const se=new Set(v);se.delete(S.key),b(se)}const z=((P=S.key)==null?void 0:P.replace(/^(.*?)(\/.*)?$/,(se,pe,Ce)=>!Ce||Ce==="/"?"":pe+"/"))||"";k(z),Pn.current=!0,J({title:"Đã xóa tập tin",description:`Đã xóa thành công "${S.name}"`}),W(null),await Lr()}catch(z){console.error("Error deleting file:",z),J({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{Wn(!1),await rn()}},Zi=S=>{const P=new Set(v),z=typeof S=="function"?S(mi):S;new Set(Object.keys(mi).map(Number)).forEach(pe=>{const Ce=Dr[pe];Ce&&(z[pe]||(P.delete(Ce.key),Ce.isFolder&&qu(Mr,Ce.key).forEach(Ae=>P.delete(Ae))))}),Object.entries(z).forEach(([pe,Ce])=>{const Ae=parseInt(pe),ht=Dr[Ae];ht&&Ce&&(P.add(ht.key),ht.isFolder&&qu(Mr,ht.key).forEach(Xn=>P.add(Xn)))}),b(P)},fo=async()=>{var S;G(!0);try{const P=Array.from(v),z=P.map(pe=>Object.values(Mr).flat().find(Ce=>Ce.key===pe)).filter(pe=>pe!==void 0);if(z.length===0){J({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:P},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});const se=((S=z[0])==null?void 0:S.key.replace(/^(.*?)(\/.*)?$/,(pe,Ce,Ae)=>!Ae||Ae==="/"?"":Ce+"/"))||"";k(se),Pn.current=!0,rn(),J({title:"Đã xóa tập tin",description:`Đã xóa thành công ${z.length} mục`}),Y(!1),b(new Set),await Lr()}catch(P){console.error("Error deleting files:",P),J({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{G(!1)}},ns=async(S,P)=>{if(!w.trim()){J({title:"Lỗi",description:"Không thể đổi tên tập tin hoặc thư mục ở thư mục gốc. Chỉ có thể xóa.",variant:"destructive"});return}Me(!0);try{const z=S.key;let se;S.isFolder?se=z.split("/").slice(0,-2).join("/")+"/":se=z.substring(0,z.lastIndexOf("/")+1);const pe=se+P+(S.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:z,newPath:pe}),Pn.current=!0,await rn(),J({title:"Đã đổi tên",description:`Đã đổi tên thành công "${S.name}" thành "${P}"`}),te(null),Ie(""),_e(null)}catch(z){console.error("Error renaming item:",z),J({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Me(!1)}},rs=async S=>{Je(P=>new Set([...P,...S]));try{const P=await Le.post(`${e}/api/download`,{paths:S},{responseType:"blob",headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),z=window.URL.createObjectURL(P.data),se=document.createElement("a");se.href=z;const pe=P.headers["Content-Disposition"]||P.headers["content-disposition"],Ce=pe==null?void 0:pe.match(/filename="(.+)"/),Ae=Ce?decodeURIComponent(Ce[1]):"download.zip";se.setAttribute("download",Ae),document.body.appendChild(se),se.click(),document.body.removeChild(se),window.URL.revokeObjectURL(z),J({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${S.length} mục${S.length>1,""}`})}catch(P){console.error("Error downloading files:",P),J({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Je(P=>{const z=new Set(P);return S.forEach(se=>z.delete(se)),z})}},kt=w?w.replace(n,"").split("/").filter(Boolean):[],ho=()=>{let S=Array.from(v).map(z=>({key:z}));S.length>1&&(S=S.filter(z=>z.key!==n));const P=z=>cu.findIndex(S,se=>!se.key.endsWith("/")&&se.key.startsWith(z))!==-1;return S=S.filter(z=>z.key.endsWith("/")?!P(z.key):!0),S},os=M.useMemo(()=>{const S=[{id:"select",header:()=>{const P=IH(Mr,w),z=P.length>0&&P.every(pe=>v.has(pe)),se=P.some(pe=>v.has(pe));return f.jsx(Hp,{checked:z?!0:se?"indeterminate":!1,onCheckedChange:pe=>{if(pe){const Ce=Dr.reduce((Ae,ht,Xn)=>(Ae[Xn]=!0,Ae),{});Zi(Ce)}else{for(const Ce of Array.from(v))Ce.startsWith(w)&&(v.delete(Ce),Mo.current[Ce]=!1);cu.forEach(Mo.current,(Ce,Ae)=>{Ae.startsWith(w)&&(Mo.current[Ae]=!1)}),Zi({})}},"aria-label":"Chọn tất cả"})},cell:({row:P})=>{const z=P.original;let pe=z.isFolder?bd(z.key):v.has(z.key)?"all":"none";if(pe==="none"&&z.key.endsWith("/")){for(const Ce of Array.from(v))if(Ce.startsWith(z.key)){pe="all";break}}return f.jsx("div",{className:"flex items-center",children:f.jsx(Hp,{checked:pe==="partial"?"indeterminate":pe==="all",onCheckedChange:Ce=>{var ht,Xn;const Ae={...mi};if(Ce?Ae[P.index]=!0:delete Ae[P.index],Mo.current[((ht=P.original)==null?void 0:ht.key)||"_"]=!!Ce,(Xn=P.original)!=null&&Xn.key.endsWith("/"))for(const Fr of Array.from(v))Fr.startsWith(P.original.key)&&(Mo.current[P.original.key]=!1,v.delete(Fr));Zi(Ae)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),children:["Tên tập tin",f.jsx(Ap,{})]}),accessorKey:"name",cell:({row:P})=>{const z=P.original,se=z.key.substring(0,z.key.lastIndexOf("/"))||"/",pe=m.trim()!==""&&se!==w,Ce=se.split("/").filter(Boolean);return f.jsxs("div",{className:"flex flex-col group",children:[f.jsxs("div",{className:"flex items-center",children:[f.jsxs("div",{className:`flex items-center gap-2 ${z.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{z.isFolder&&Ho(z.key)},children:[z.isFolder?f.jsx(Ns,{className:"h-5 w-5 text-blue-500"}):null,z.name]}),f.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),navigator.clipboard.writeText(z.key),J({title:"Copied to clipboard",description:`Path: ${z.key}`,duration:2e3})},title:"Copy path to clipboard",children:f.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:[f.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),f.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),pe&&f.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[f.jsx(Ns,{className:"h-4 w-4 text-gray-500 my-auto"}),f.jsxs("span",{className:"flex items-center ml-1",children:[f.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Ho("")},children:"/"}),Ce.map((Ae,ht)=>f.jsxs("span",{className:"flex items-center",children:[f.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Ho(Ce.slice(0,ht+1).join("/")+"/")},children:Ae}),ht<Ce.length-1&&f.jsx("span",{children:"/"})]},ht))]})]})]})}}];return o||S.push({id:"size",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),children:["Kích thước",f.jsx(Ap,{})]}),accessorKey:"size",cell:({getValue:P,row:z})=>{const se=P();return f.jsx("span",{children:z.original.isFolder?"-":vc(se)})}},{id:"lastModified",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",f.jsx(Ap,{})]}),accessorKey:"lastModified",cell:({row:P})=>{const z=P.original.lastModified;return f.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:f.jsx("span",{children:z&&Gb(z).isValid()?Gb(z).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>f.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:P})=>f.jsxs("div",{className:"flex items-center gap-2",children:[w===""&&r&&f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{ed(P.original.key),td(!0)},className:"h-8 w-8 p-0",children:Oe.has(P.original.key)?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):f.jsx(uO,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Những Flow sử dụng Folder này làm Data"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>rs([P.original.key]),className:"h-8 w-8 p-0",disabled:Oe.has(P.original.key),children:Oe.has(P.original.key)?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):f.jsx(Vw,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Tải xuống"})]})}),w.trim()!==""&&f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{te(P.original),Ie(P.original.name)},className:"h-8 w-8 p-0",children:f.jsx(vO,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Đổi tên"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Pe(!0),fe(P.original)},className:"h-8 w-8 p-0",children:f.jsx(RR,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Di chuyển"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>W(P.original),className:"h-8 w-8 p-0",children:f.jsx(Gw,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Xóa"})]})})]})}),S},[v,Dr,mi,Oe,o]),xc=tb({data:Dr,columns:os,state:{rowSelection:mi,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:Zi,getCoreRowModel:eb(),getSortedRowModel:FP()}),_c=async S=>{var P,z;nn(!0);try{if(rc(S)){const se=await Le.get(`${e}/api/read-text`,{params:{path:S.key}});st(se.data.content)}try{const se=await Le.get(`${e}/api/read-json`,{params:{path:S.key+".metadata.json"}}),pe=((z=(P=se==null?void 0:se.data)==null?void 0:P.content)==null?void 0:z.metadataAttributes)||null;return _e({fullPath:F==null?void 0:F.key,...pe})}catch{return _e("Lỗi phân tích siêu dữ liệu")}}catch(se){console.error("Error loading file content:",se),J({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{nn(!1)}},am=async(S,P)=>{Pt(!0);try{await Le.post(`${e}/api/modify-text`,{path:S.key,content:P}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Pn.current=!0,await rn(),te(null),st(""),Xt("rename"),await Lr()}catch(z){console.error("Error saving file content:",z),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Pt(!1)}},sm=async S=>{Pt(!0);try{await Le.post(`${e}/api/modify-json`,{path:S.key+".metadata.json",content:{metadataAttributes:xe}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Pn.current=!0,await rn(),te(null),st(""),Xt("rename")}catch(P){console.error("Error saving file content:",P),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Pt(!1)}};M.useEffect(()=>{F&&(F.isFolder||_c(F),Xt("rename"))},[F]);const _d=async(S,P)=>{var z;if(He){J({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}ue(!0);try{const{data:se}=await Le.post(`${e}/api/crawl`,{url:S,limit:P,prefix:w});if(se.id){Zu({id:se.id,url:S,limit:P,prefix:w,taskId:((z=se.task)==null?void 0:z.id)||""});const pe=localStorage.getItem(qT),Ce=pe?JSON.parse(pe):[];Ce.some(Ae=>Ae.id===se.id)||(Ce.unshift({url:S,id:se.id,limit:P,prefix:w,timestamp:Date.now()}),Ce.length>20&&(Ce.length=20),localStorage.setItem(qT,JSON.stringify(Ce))),J({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${S} với giới hạn ${P}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),$t(!1),V(""),re("1")}}catch(se){console.error("Error crawling website:",se),J({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{ue(!1)}},Td=async()=>{try{if(!(He!=null&&He.id))return;Zu(null),localStorage.removeItem(Va),J({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${He.url}`})}catch(S){console.error("Error stopping job:",S),J({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};M.useEffect(()=>{if(o)return;const S=(P=!0)=>{const se=new URL(window.location.href).searchParams.get("prefix")||"";se?Ho(se,!1):(P&&!l&&b(new Set),k(n),x(n),Pn.current=!0,setTimeout(()=>{rn()},0))};return S(!1),window.addEventListener("popstate",()=>S(!0)),()=>{window.removeEventListener("popstate",()=>S(!0))}},[]);const ea=async()=>{od(!0);try{await Le.post(`${e}/api/prediction-report`),J({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(S){console.error("Error exporting report:",S),J({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{od(!1)}},vi=async()=>{try{const S=IM();S&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:w,user_id:S.id,userName:S.username})).status===200&&await Lr()}catch(S){qe(!1),console.log(S)}},po=M.useRef(),Lr=async()=>{try{qe(!0);const S=await Le.post(`${e}/api/ingestion-job-status`,{prefix:w}),{status:P}=S==null?void 0:S.data;P==="FAILED"||P==="COMPLETE"||P==="STOPPED"||P==="STOPPING"||!P?(qe(!1),po.current&&(clearInterval(po.current),po.current=null),qa(S==null?void 0:S.data)):(po.current||(po.current=setInterval(()=>Lr(),5e3)),qa(S==null?void 0:S.data))}catch(S){console.log(S)}},Sd=()=>{const S=Array.from(v);let P;return w?P=S.filter(z=>z.startsWith(w)&&z!==w).length:P=new Set(S.filter(z=>z.split("/").shift())).size,`Đang chọn: ${P}`};return M.useEffect(()=>{const S=w==null?void 0:w.split("/")[0];return S!==id&&(qe(!1),po.current&&(clearInterval(po.current),po.current=null),Bg(S||""),qa(null),S&&Lr()),()=>{}},[id,w]),M.useEffect(()=>{Lo&&pc.length===0&&(Xg(),Qa(null))},[Lo]),M.useEffect(()=>{if(l)for(const S of Array.from(l))Mo.current[S]=!0},[]),f.jsxs("div",{className:"space-y-4 s3-explr-container",children:[f.jsx(g_,{}),f.jsx(Tr,{open:Ug,onOpenChange:S=>{Ki(S),S||(ja(""),fi(null),ft(!1),ie(null))},children:f.jsxs(or,{children:[f.jsxs(ir,{children:[f.jsx(ar,{children:"Cảnh báo trùng lặp"}),f.jsxs(ci,{children:[zi&&f.jsxs(f.Fragment,{children:["Folder $",zi," đã có."]}),Pr&&Pr.length>0&&f.jsxs(f.Fragment,{children:["Những tệp sau bị lặp:",f.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(Pr).map((S,P)=>f.jsx("li",{children:S.name},P))})]})]})]}),f.jsxs(Io,{children:[f.jsx($e,{variant:"outline",onClick:()=>{Ki(!1),ja(""),fi(null),ft(!1),ie(null)},children:"Bỏ qua"}),f.jsx($e,{variant:"destructive",onClick:()=>Fn(),children:"Ghi đè"})]})]})}),f.jsx(du,{className:"s3-explr-breadcrumb",children:f.jsxs(fu,{className:"s3-explr-breadcrumb-list",children:[f.jsx(Ks,{className:"s3-explr-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Ho(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!d&&kt.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[f.jsx(hu,{className:"s3-explr-breadcrumb-separator"},`sep-${P}`),f.jsx(Ks,{className:"s3-explr-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Ho(n+kt.slice(0,P+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:S})},`item-${S}`)]},P))]})}),f.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[f.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:f.jsx(w2,{ref:Z,onChange:S=>y(S)})}),f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{k(w),Pn.current=!0,rn()},disabled:Fo,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Fo?"animate-spin":""}`}),"Làm mới"]}),w&&w!=="/"&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{Fo||be||(qe(!0),vi())},"aria-disabled":Fo||be,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Fo||be?"animate-spin":""}`}),"Đồng bộ KB"]})}),Ht&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[f.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),f.jsx("div",{className:"space-y-1",children:f.jsxs("p",{className:"flex items-center gap-2",children:[f.jsx("span",{className:"font-medium",children:"Trạng thái:"}),f.jsxs("span",{className:`flex items-center gap-1 font-semibold ${Ht.status==="COMPLETE"?"text-green-600":Ht.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Ht.status==="COMPLETE"&&f.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:f.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Ht.status==="FAILED"&&f.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:f.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Ht.status!=="COMPLETE"&&Ht.status!=="FAILED"&&f.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:f.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"})}),Ht.status]})]})}),Ht.statistics&&f.jsxs("div",{className:"space-y-1 border-t pt-2",children:[f.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),f.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu quét:"}),f.jsx("span",{className:"font-medium",children:Ht.statistics.numberOfDocumentsScanned})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Metadata quét:"}),f.jsx("span",{className:"font-medium",children:Ht.statistics.numberOfMetadataDocumentsScanned})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu mới:"}),f.jsx("span",{className:"font-medium text-green-600",children:Ht.statistics.numberOfNewDocumentsIndexed})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu sửa:"}),f.jsx("span",{className:"font-medium text-blue-600",children:Ht.statistics.numberOfModifiedDocumentsIndexed})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Metadata sửa:"}),f.jsx("span",{className:"font-medium text-blue-600",children:Ht.statistics.numberOfMetadataDocumentsModified})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu xóa:"}),f.jsx("span",{className:"font-medium text-orange-600",children:Ht.statistics.numberOfDocumentsDeleted})]}),f.jsxs("div",{className:"flex justify-between col-span-2",children:[f.jsx("span",{children:"Tài liệu lỗi:"}),f.jsx("span",{className:"font-medium text-red-600",children:Ht.statistics.numberOfDocumentsFailed})]})]})]}),f.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[f.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",Ht.dataSourceId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",Ht.ingestionJobId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",Ht.knowledgeBaseId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",Ht.is_still_in_stock?"Còn":"Không"]})]}),Ht.errorMessage&&f.jsxs("div",{className:"border-t pt-2",children:[f.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),f.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:Ht.errorMessage})]})]})})]})}),f.jsxs("div",{className:"relative",ref:mc,children:[f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",onClick:()=>lo(S=>!S),children:[f.jsx(wO,{className:"w-4 h-4"}),"Add file"]}),Xa&&f.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:[f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{lo(!1);const S=document.createElement("input");S.type="file",S.multiple=!0,S.onchange=P=>{const z=P.target.files;z&&bc(z,w,"files")},S.click()},children:[f.jsx(Lh,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{lo(!1);const S=document.createElement("input");S.type="file",S.multiple=!0,S.webkitdirectory=!0,S.onchange=P=>{const z=P.target.files;z&&bc(z,w,"folder")},S.click()},children:[f.jsx(Ns,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!c&&!w,onClick:()=>D(!0),children:[f.jsx(fO,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),$t(!0)},children:[f.jsx(gO,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),wd()},children:[f.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"}),f.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"}),f.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"}),f.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"}),f.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"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),om()},children:[f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),Jg()},children:[f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"}),f.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"}),f.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),!o&&f.jsxs(f.Fragment,{children:[v.size>0&&f.jsxs(f.Fragment,{children:[f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>rs(Array.from(v)),disabled:Array.from(v).some(S=>Oe.has(S)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(v).some(S=>Oe.has(S))?f.jsx(zt,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):f.jsx(Vw,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",v.size,")"]}),f.jsxs(Tr,{open:X,onOpenChange:Y,children:[f.jsx(Gs,{asChild:!0,children:f.jsxs($e,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[f.jsx(Gw,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",v.size,")"]})}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),f.jsxs(ci,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",v.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>Y(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:fo,disabled:we,className:"s3-explr-confirm-delete-btn",children:we?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),!d&&f.jsxs(Tr,{open:O,onOpenChange:D,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsx(ir,{className:"s3-explr-dialog-header",children:f.jsx(ar,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),f.jsx(Qr,{disabled:j,id:"name",value:E,onChange:S=>B(S.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),f.jsxs($e,{onClick:()=>{E.trim()&&Tn(E,w)},disabled:j,className:"s3-explr-create-btn",children:[j&&f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),j?"Đang tạo...":"Tạo"]})]})]})]}),d&&!w?f.jsx(f.Fragment,{}):f.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[He?f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[f.jsx(zt,{className:"h-4 w-4 animate-spin s3-explr-loader"}),He.status?f.jsxs(f.Fragment,{children:[He.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",He.status.completed,"/",He.status.total,") -"," ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}):"Đang thu thập..."]}),f.jsxs($e,{variant:"destructive",size:"sm",onClick:()=>void Td(),className:"flex items-center gap-2",children:[f.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),f.jsx(bO,{className:"h-4 w-4"})]})]})}),He.status&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-1 p-2",children:[f.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",He==null?void 0:He.url]}),f.jsxs("p",{children:["Tiến độ: ",He==null?void 0:He.status.completed,"/",He==null?void 0:He.status.total," ","trang"]}),f.jsxs("p",{children:["Thời gian: ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}),f.jsxs("p",{children:["Trạng thái:"," ",(He==null?void 0:He.status.status)==="scraping"?"Đang thu thập":(He==null?void 0:He.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!d&&f.jsxs(Tr,{open:Mn,onOpenChange:$t,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Thêm website"}),f.jsx(ci,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),f.jsx(Qr,{id:"websiteUrl",value:R,onChange:S=>V(S.target.value),placeholder:"https://example.com",type:"url",disabled:he,className:"s3-explr-input"})]}),f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),f.jsx(Qr,{id:"crawlLimit",value:H,onChange:S=>{const P=S.target.value;/^\d*$/.test(P)&&re(P)},placeholder:"1",type:"text",disabled:he,className:"s3-explr-input"}),f.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)"})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{$t(!1),V(""),re("1")},disabled:he,className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{onClick:()=>{R.trim()&&_d(R.trim(),parseInt(H)||1)},disabled:he||!R.trim(),className:"s3-explr-crawl-btn",children:he?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),w.startsWith("BKTTW/")&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!w,onClick:ea,children:[Gi&&f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Gi?"animate-spin":""}`}),"Xuất báo cáo"]})}),(He==null?void 0:He.status)&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-1 p-2",children:[f.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",He.url]}),f.jsxs("p",{children:["Tiến độ: ",He.status.completed,"/",He.status.total," ","trang"]}),f.jsxs("p",{children:["Thời gian: ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}),f.jsxs("p",{children:["Trạng thái:"," ",He.status.status==="scraping"?"Đang thu thập":He.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),f.jsxs(Tr,{open:Mn,onOpenChange:$t,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Thêm website"}),f.jsx(ci,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),f.jsx(Qr,{id:"websiteUrl",value:R,onChange:S=>V(S.target.value),placeholder:"https://example.com",type:"url",disabled:he,className:"s3-explr-input"})]}),f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),f.jsx(Qr,{id:"crawlLimit",value:H,onChange:S=>{const P=S.target.value;/^\d*$/.test(P)&&re(P)},placeholder:"1",type:"text",disabled:he,className:"s3-explr-input"}),f.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)"})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{$t(!1),V(""),re("1")},disabled:he,className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{onClick:()=>{R.trim()&&_d(R.trim(),parseInt(H)||1)},disabled:he||!R.trim(),className:"s3-explr-crawl-btn",children:he?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),w.startsWith("BKTTW/")&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!w,onClick:ea,children:[Gi&&f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Gi?"animate-spin":""}`}),"Xuất báo cáo"]})}),Gi&&f.jsx(kr,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),f.jsxs("div",{className:"flex items-center gap-4",children:[ad&&f.jsxs(Ps,{open:ad,onOpenChange:Wa,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),f.jsxs(Pa,{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:[f.jsxs("div",{className:"relative",children:[f.jsx(Yh,{asChild:!0,children:f.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:uo,children:"✖"})}),f.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),f.jsx(du,{className:"onedrive-breadcrumb",children:f.jsx(fu,{className:"onedrive-breadcrumb-list",children:Ya.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[P>0&&f.jsx(hu,{className:"onedrive-breadcrumb-separator"}),f.jsx(Ks,{className:"onedrive-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Zt(P),className:"cursor-pointer onedrive-breadcrumb-link",children:S.name})})]},P))})})]}),f.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:ld?f.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):f.jsx(f.Fragment,{children:[...ji,...qi].length>0?[...ji,...qi].map(S=>f.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${Yi.some(P=>P.id===S.id)?"bg-blue-100":""}`,children:[f.jsx("input",{type:"checkbox",checked:Yi.some(P=>P.id===S.id),onChange:P=>{P.stopPropagation(),vd(S)},className:"cursor-pointer"}),S.isFolder?f.jsx(Ns,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ts(S.id,S.name)}):f.jsx(Lh,{className:"text-gray-500 w-5 h-5"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("div",{className:`font-medium ${S.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{S.isFolder?ts(S.id,S.name):vd(S)},children:S.name}),!S.isFolder&&f.jsxs("div",{className:"text-xs text-gray-500",children:[vc(S.size)," •"," ",rm(S.lastModified.toISOString())]})]})]},S.id)):f.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),f.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:f.jsx($e,{onClick:()=>{yc(Yi,w),uo()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:Yi.length===0,children:"Đồng bộ"})}),f.jsx("button",{onClick:()=>Rr(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:f.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:[f.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),f.jsx("polyline",{points:"16 17 21 12 16 7"}),f.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),f.jsxs(Ps,{open:gc,onOpenChange:Rr,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),f.jsxs(Pa,{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:[f.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),f.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx($e,{variant:"outline",onClick:()=>Rr(!1),children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>{im(),Rr(!1)},children:"Đăng xuất"})]})]})]}),Lo&&f.jsxs(Ps,{open:Lo,onOpenChange:Qi,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),f.jsxs(Pa,{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:[f.jsxs("div",{className:"relative",children:[f.jsx(Yh,{asChild:!0,children:f.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:_t,children:"✖"})}),f.jsxs("div",{className:"flex items-center gap-2",children:[gt&&f.jsx("button",{onClick:()=>Qa(null),className:"text-gray-600 hover:text-gray-800",children:f.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:f.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),f.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&f.jsx(du,{className:"sharepoint-breadcrumb",children:f.jsx(fu,{className:"sharepoint-breadcrumb-list",children:hc.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[P>0&&f.jsx(hu,{className:"sharepoint-breadcrumb-separator"}),f.jsx(Ks,{className:"sharepoint-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>tm(P),className:"cursor-pointer sharepoint-breadcrumb-link",children:S.name})})]},P))})})]}),f.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Vg?f.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...fc,...dd].length===0?f.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...fc,...dd].map(S=>{const P=Ji.some(z=>z.id===S.id);return f.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${P?"bg-blue-100":""}`,children:[f.jsx("input",{type:"checkbox",checked:P,onChange:z=>{z.stopPropagation(),em(S)},className:"cursor-pointer"}),S.isFolder?f.jsx(Ns,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>es(S.id,S.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):f.jsx(Lh,{className:"text-gray-500 w-5 h-5"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("div",{className:`font-medium ${S.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{S.isFolder&&es(S.id,S.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:S.name}),!S.isFolder&&f.jsxs("div",{className:"text-xs text-gray-500",children:[vc(S.size)," •"," ",S.lastModified.toLocaleString()]})]})]},S.id)}):f.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:pc.map(S=>f.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:()=>Zg(S),children:[f.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:S.name,children:S.name}),f.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:S.description,children:S.description})]},S.id))})}),f.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&f.jsxs(f.Fragment,{children:[f.jsx($e,{onClick:()=>{It(Ji,w),_t()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:Ji.length===0,children:"Đồng bộ"}),f.jsx($e,{onClick:()=>Qa(null),children:"Quay lại"})]})}),f.jsx("button",{onClick:()=>gi(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:f.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:[f.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),f.jsx("polyline",{points:"16 17 21 12 16 7"}),f.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),f.jsxs(Ps,{open:gd,onOpenChange:gi,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),f.jsxs(Pa,{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:[f.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),f.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx($e,{variant:"outline",onClick:()=>gi(!1),children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>{Qg(),gi(!1)},children:"Đăng xuất"})]})]})]})]}),f.jsx(Tr,{open:!!$g,onOpenChange:S=>{S||(td(!1),rd([]),ed(""))},children:f.jsxs(or,{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:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:f.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",f.jsx("span",{className:"font-bold",children:Vi}),"):"," "]})}),f.jsx(ci,{className:"s3-explr-dialog-description",children:lc?f.jsxs("div",{className:"flex items-center justify-center py-4",children:[f.jsx(zt,{className:"h-6 w-6 animate-spin"}),f.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):f.jsx("div",{children:hi&&Array.isArray(hi)&&hi.length>0?f.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:f.jsxs("table",{className:"w-full border-collapse",children:[f.jsx("thead",{children:f.jsxs("tr",{className:"bg-gray-100",children:[f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),f.jsx("tbody",{children:hi.map((S,P)=>f.jsxs("tr",{className:P%2===0?"bg-white":"bg-gray-50",children:[f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.name}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.KnowledgeBaseId}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.createdDate?new Date(S.createdDate).toLocaleString("vi-VN"):"N/A"})]},P))})]})}):f.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"})})})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>xd(ne),disabled:Dn,className:"s3-explr-confirm-delete-btn",children:Dn?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),f.jsx(Tr,{open:!!ne,onOpenChange:S=>!S&&W(null),children:f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),f.jsxs(ci,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",ne==null?void 0:ne.name,"? Hành động này không thể hoàn tác."]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>xd(ne),disabled:Dn,className:"s3-explr-confirm-delete-btn",children:Dn?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),f.jsx(Tr,{open:!!F,onOpenChange:S=>{S||(te(null),_e(null),Ie(""),st(""),Xt("rename"))},children:f.jsxs(or,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[f.jsx(ir,{className:"s3-explr-dialog-header",children:f.jsx(ar,{className:"s3-explr-dialog-title",children:F!=null&&F.isFolder?"Đổi tên thư mục":rc(F)?"Quản lý tập tin":"Đổi tên tập tin"})}),F&&f.jsxs(rD,{value:Rn,onValueChange:S=>Xt(S),children:[f.jsxs(zx,{"aria-checked":!rc(F),"aria-disabled":F.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[f.jsx(Tu,{value:"rename",children:"Đổi tên"}),!F.isFolder&&f.jsxs(f.Fragment,{children:[rc(F)&&f.jsx(Tu,{value:"edit",children:"Sửa nội dung"}),f.jsx(Tu,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),f.jsx(Su,{value:"rename",children:f.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:f.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),f.jsx(Qr,{id:"newName",value:Te,onChange:S=>Ie(S.target.value),placeholder:"Nhập tên mới",disabled:Fe,className:"s3-explr-input"})]})})}),!F.isFolder&&f.jsxs(f.Fragment,{children:[rc(F)&&f.jsx(Su,{value:"edit",children:f.jsx("div",{className:"space-y-4 py-4",children:Ct?f.jsx("div",{className:"flex items-center justify-center py-4",children:f.jsx(zt,{className:"h-6 w-6 animate-spin"})}):f.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[f.jsx(ko,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),f.jsx(qs,{id:"content",value:ye,onChange:S=>st(S.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:ln})]})})}),f.jsx(Su,{value:"edit-metadata",children:f.jsx("div",{className:"space-y-4 py-4",children:Ct?f.jsx("div",{className:"flex items-center justify-center py-4",children:f.jsx(zt,{className:"h-6 w-6 animate-spin"})}):f.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(([S,P],z)=>f.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[f.jsxs(ko,{htmlFor:S,className:"s3-explr-label flex items-center gap-1",children:[YR[S]||S,Np(S)&&f.jsx(MR,{className:"h-[12px] w-[12px] text-red-500"})]}),JR(S)?f.jsx(qs,{id:S,value:typeof P=="string"?P:JSON.stringify(P),onChange:se=>{const pe={...xe,[S]:se.target.value};_e(pe)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:ln||Np(S)}):f.jsx(Qr,{id:S,value:typeof P=="string"?P:JSON.stringify(P),onChange:se=>{const pe={...xe,[S]:se.target.value};_e(pe)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:ln||Np(S)})]},z))})})})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{te(null),_e(null),Ie(""),st("")},className:"s3-explr-cancel-btn",children:"Hủy"}),Rn==="edit"?f.jsx($e,{onClick:()=>F&&am(F,ye),disabled:ln||Ct,className:"s3-explr-save-btn",children:ln?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):Rn==="edit-metadata"?f.jsx($e,{onClick:()=>xe&&typeof xe=="object"&&F&&sm(F),disabled:ln||Ct,className:"s3-explr-save-btn",children:ln?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):f.jsx($e,{onClick:()=>{Te.trim()&&F&&ns(F,Te.trim())},disabled:Fe||!Te.trim()||Te.trim()===(F==null?void 0:F.name),className:"s3-explr-rename-btn",children:Fe?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),me&&Ee&&f.jsx(_H,{openDialogRename:Ee,setOpenDialogRename:Pe,apiBaseUrl:e,setFileToMove:fe,fileToMove:me,refreshFiles:rn,ignoreCache:Pn})]})]}),Yg&&f.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"}),f.jsx(xH,{onFilesSelected:(S,P)=>bc(S,w,P),children:f.jsx("div",{className:"rounded-md border s3-explr-table-container",children:f.jsxs(Cu,{className:"s3-explr-table",children:[f.jsx(bu,{className:"s3-explr-table-header",children:xc.getHeaderGroups().map(S=>f.jsx(Er,{className:"hover:bg-transparent s3-explr-header-row",children:S.headers.map(P=>f.jsx(Xr,{className:"s3-explr-header-cell",children:P.isPlaceholder?null:ql(P.column.columnDef.header,P.getContext())},P.id))},S.id))}),f.jsx(xu,{className:"s3-explr-table-body",children:xc.getRowModel().rows.length===0?f.jsx(Er,{className:"s3-explr-empty-row",children:f.jsx(Nn,{colSpan:os.length,className:"h-24 text-center s3-explr-empty-cell",children:m?f.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 "',m,'"']}):f.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:Fo?"Đ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"})})}):xc.getRowModel().rows.map(S=>f.jsx(Er,{className:"h-12 s3-explr-row",children:S.getVisibleCells().map(P=>f.jsx(Nn,{className:"align-middle s3-explr-cell",children:ql(P.column.columnDef.cell,P.getContext())},P.id))},S.id))})]})})}),m&&Xi!==0&&f.jsx(f.Fragment,{children:f.jsx(gu,{children:f.jsxs(mu,{children:[f.jsx(vu,{onClick:()=>Yn(S=>Math.max(S-1,1)),"aria-disabled":Ft===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Xi/20)},(S,P)=>{const z=P+1,se=Math.ceil(Xi/20);return se>7&&!(z===1||z===se||z>=Ft-1&&z<=Ft+1)?z===Ft-2&&Ft>4||z===Ft+2&&Ft<se-3?f.jsx(wu,{className:"pointer-events-none",children:"..."},P):null:f.jsx(Sr,{className:"cursor-pointer",children:f.jsx(Fa,{isActive:Ft===z,onClick:()=>Yn(z),className:`${Ft===z?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:z})},P)}),f.jsx(Sr,{children:f.jsx(yu,{onClick:()=>Yn(S=>Math.min(S+1,Math.ceil(Xi/20))),"aria-disabled":Ft===Math.ceil(Xi/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),o&&a&&f.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[f.jsx("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:Sd()}),f.jsx($e,{variant:"default",onClick:()=>a(ho()),disabled:v.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),RH=t=>f.jsx(tP,{clientId:SH,children:f.jsx(PH,{...t})});var oc=t=>t.type==="checkbox",Bi=t=>t instanceof Date,xn=t=>t==null;const WT=t=>typeof t=="object";var jt=t=>!xn(t)&&!Array.isArray(t)&&WT(t)&&!Bi(t),MH=t=>jt(t)&&t.target?oc(t.target)?t.target.checked:t.target.value:t,DH=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,LH=(t,e)=>t.has(DH(e)),FH=t=>{const e=t.constructor&&t.constructor.prototype;return jt(e)&&e.hasOwnProperty("isPrototypeOf")},Rg=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mn(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(!(Rg&&(t instanceof Blob||r))&&(n||jt(t)))if(e=n?[]:{},!n&&!FH(t))e=t;else for(const o in t)t.hasOwnProperty(o)&&(e[o]=mn(t[o]));else return t;return e}var Wu=t=>Array.isArray(t)?t.filter(Boolean):[],Jt=t=>t===void 0,Re=(t,e,n)=>{if(!e||!jt(t))return n;const r=Wu(e.split(/[,[\].]+?/)).reduce((o,a)=>xn(o)?o:o[a],t);return Jt(r)||r===t?Jt(t[e])?n:t[e]:r},ao=t=>typeof t=="boolean",Mg=t=>/^\w*$/.test(t),YT=t=>Wu(t.replace(/["|']|\]/g,"").split(/\.|\[/)),Dt=(t,e,n)=>{let r=-1;const o=Mg(e)?[e]:YT(e),a=o.length,c=a-1;for(;++r<a;){const l=o[r];let d=n;if(r!==c){const h=t[l];d=jt(h)||Array.isArray(h)?h:isNaN(+o[r+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;t[l]=d,t=t[l]}};const JT={BLUR:"blur",FOCUS_OUT:"focusout"},Or={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Ro={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};M.createContext(null);var HH=(t,e,n,r=!0)=>{const o={defaultValues:e._defaultValues};for(const a in t)Object.defineProperty(o,a,{get:()=>{const c=a;return e._proxyFormState[c]!==Or.all&&(e._proxyFormState[c]=!r||Or.all),t[c]}});return o};const UH=typeof window<"u"?_.useLayoutEffect:_.useEffect;var so=t=>typeof t=="string",$H=(t,e,n,r,o)=>so(t)?(r&&e.watch.add(t),Re(n,t,o)):Array.isArray(t)?t.map(a=>(r&&e.watch.add(a),Re(n,a))):(r&&(e.watchAll=!0),n),BH=(t,e,n,r,o)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[r]:o||!0}}:{},ic=t=>Array.isArray(t)?t:[t],QT=()=>{let t=[];return{get observers(){return t},next:o=>{for(const a of t)a.next&&a.next(o)},subscribe:o=>(t.push(o),{unsubscribe:()=>{t=t.filter(a=>a!==o)}}),unsubscribe:()=>{t=[]}}},Dg=t=>xn(t)||!WT(t);function di(t,e){if(Dg(t)||Dg(e))return t===e;if(Bi(t)&&Bi(e))return t.getTime()===e.getTime();const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const o of n){const a=t[o];if(!r.includes(o))return!1;if(o!=="ref"){const c=e[o];if(Bi(a)&&Bi(c)||jt(a)&&jt(c)||Array.isArray(a)&&Array.isArray(c)?!di(a,c):a!==c)return!1}}return!0}var _n=t=>jt(t)&&!Object.keys(t).length,Lg=t=>t.type==="file",Nr=t=>typeof t=="function",Yu=t=>{if(!Rg)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},XT=t=>t.type==="select-multiple",Fg=t=>t.type==="radio",zH=t=>Fg(t)||oc(t),Hg=t=>Yu(t)&&t.isConnected;function KH(t,e){const n=e.slice(0,-1).length;let r=0;for(;r<n;)t=Jt(t)?r++:t[e[r++]];return t}function VH(t){for(const e in t)if(t.hasOwnProperty(e)&&!Jt(t[e]))return!1;return!0}function Qt(t,e){const n=Array.isArray(e)?e:Mg(e)?[e]:YT(e),r=n.length===1?t:KH(t,n),o=n.length-1,a=n[o];return r&&delete r[a],o!==0&&(jt(r)&&_n(r)||Array.isArray(r)&&VH(r))&&Qt(t,n.slice(0,-1)),t}var ZT=t=>{for(const e in t)if(Nr(t[e]))return!0;return!1};function Ju(t,e={}){const n=Array.isArray(t);if(jt(t)||n)for(const r in t)Array.isArray(t[r])||jt(t[r])&&!ZT(t[r])?(e[r]=Array.isArray(t[r])?[]:{},Ju(t[r],e[r])):xn(t[r])||(e[r]=!0);return e}function eS(t,e,n){const r=Array.isArray(t);if(jt(t)||r)for(const o in t)Array.isArray(t[o])||jt(t[o])&&!ZT(t[o])?Jt(e)||Dg(n[o])?n[o]=Array.isArray(t[o])?Ju(t[o],[]):{...Ju(t[o])}:eS(t[o],xn(e)?{}:e[o],n[o]):n[o]=!di(t[o],e[o]);return n}var ac=(t,e)=>eS(t,e,Ju(e));const tS={value:!1,isValid:!1},nS={value:!0,isValid:!0};var rS=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&&!Jt(t[0].attributes.value)?Jt(t[0].value)||t[0].value===""?nS:{value:t[0].value,isValid:!0}:nS:tS}return tS},oS=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:r})=>Jt(t)?t:e?t===""?NaN:t&&+t:n&&so(t)?new Date(t):r?r(t):t;const iS={isValid:!1,value:null};var aS=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,iS):iS;function sS(t){const e=t.ref;return Lg(e)?e.files:Fg(e)?aS(t.refs).value:XT(e)?[...e.selectedOptions].map(({value:n})=>n):oc(e)?rS(t.refs).value:oS(Jt(e.value)?t.ref.value:e.value,t)}var GH=(t,e,n,r)=>{const o={};for(const a of t){const c=Re(e,a);c&&Dt(o,a,c._f)}return{criteriaMode:n,names:[...t],fields:o,shouldUseNativeValidation:r}},Qu=t=>t instanceof RegExp,sc=t=>Jt(t)?t:Qu(t)?t.source:jt(t)?Qu(t.value)?t.value.source:t.value:t,cS=t=>({isOnSubmit:!t||t===Or.onSubmit,isOnBlur:t===Or.onBlur,isOnChange:t===Or.onChange,isOnAll:t===Or.all,isOnTouch:t===Or.onTouched});const lS="AsyncFunction";var jH=t=>!!t&&!!t.validate&&!!(Nr(t.validate)&&t.validate.constructor.name===lS||jt(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===lS)),qH=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate),uS=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(r=>t.startsWith(r)&&/^\.\w+/.test(t.slice(r.length))));const cc=(t,e,n,r)=>{for(const o of n||Object.keys(t)){const a=Re(t,o);if(a){const{_f:c,...l}=a;if(c){if(c.refs&&c.refs[0]&&e(c.refs[0],o)&&!r)return!0;if(c.ref&&e(c.ref,c.name)&&!r)return!0;if(cc(l,e))break}else if(jt(l)&&cc(l,e))break}}};function dS(t,e,n){const r=Re(t,n);if(r||Mg(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const a=o.join("."),c=Re(e,a),l=Re(t,a);if(c&&!Array.isArray(c)&&n!==a)return{name:n};if(l&&l.type)return{name:a,error:l};o.pop()}return{name:n}}var WH=(t,e,n,r)=>{n(t);const{name:o,...a}=t;return _n(a)||Object.keys(a).length>=Object.keys(e).length||Object.keys(a).find(c=>e[c]===(!r||Or.all))},YH=(t,e,n)=>!t||!e||t===e||ic(t).some(r=>r&&(n?r===e:r.startsWith(e)||e.startsWith(r))),JH=(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,QH=(t,e)=>!Wu(Re(t,e)).length&&Qt(t,e),XH=(t,e,n)=>{const r=ic(Re(t,n));return Dt(r,"root",e[n]),Dt(t,n,r),t},Xu=t=>so(t);function fS(t,e,n="validate"){if(Xu(t)||Array.isArray(t)&&t.every(Xu)||ao(t)&&!t)return{type:n,message:Xu(t)?t:"",ref:e}}var Ga=t=>jt(t)&&!Qu(t)?t:{value:t,message:""},hS=async(t,e,n,r,o,a)=>{const{ref:c,refs:l,required:d,maxLength:h,minLength:p,min:m,max:y,pattern:v,validate:b,name:w,valueAsNumber:x,mount:I}=t._f,k=Re(n,w);if(!I||e.has(w))return{};const O=l?l[0]:c,D=fe=>{o&&O.reportValidity&&(O.setCustomValidity(ao(fe)?"":fe||""),O.reportValidity())},E={},B=Fg(c),j=oc(c),q=B||j,ne=(x||Lg(c))&&Jt(c.value)&&Jt(k)||Yu(c)&&c.value===""||k===""||Array.isArray(k)&&!k.length,W=BH.bind(null,w,r,E),me=(fe,we,G,X=Ro.maxLength,Y=Ro.minLength)=>{const ie=fe?we:G;E[w]={type:fe?X:Y,message:ie,ref:c,...W(fe?X:Y,ie)}};if(a?!Array.isArray(k)||!k.length:d&&(!q&&(ne||xn(k))||ao(k)&&!k||j&&!rS(l).isValid||B&&!aS(l).isValid)){const{value:fe,message:we}=Xu(d)?{value:!!d,message:d}:Ga(d);if(fe&&(E[w]={type:Ro.required,message:we,ref:O,...W(Ro.required,we)},!r))return D(we),E}if(!ne&&(!xn(m)||!xn(y))){let fe,we;const G=Ga(y),X=Ga(m);if(!xn(k)&&!isNaN(k)){const Y=c.valueAsNumber||k&&+k;xn(G.value)||(fe=Y>G.value),xn(X.value)||(we=Y<X.value)}else{const Y=c.valueAsDate||new Date(k),ie=F=>new Date(new Date().toDateString()+" "+F),Z=c.type=="time",J=c.type=="week";so(G.value)&&k&&(fe=Z?ie(k)>ie(G.value):J?k>G.value:Y>new Date(G.value)),so(X.value)&&k&&(we=Z?ie(k)<ie(X.value):J?k<X.value:Y<new Date(X.value))}if((fe||we)&&(me(!!fe,G.message,X.message,Ro.max,Ro.min),!r))return D(E[w].message),E}if((h||p)&&!ne&&(so(k)||a&&Array.isArray(k))){const fe=Ga(h),we=Ga(p),G=!xn(fe.value)&&k.length>+fe.value,X=!xn(we.value)&&k.length<+we.value;if((G||X)&&(me(G,fe.message,we.message),!r))return D(E[w].message),E}if(v&&!ne&&so(k)){const{value:fe,message:we}=Ga(v);if(Qu(fe)&&!k.match(fe)&&(E[w]={type:Ro.pattern,message:we,ref:c,...W(Ro.pattern,we)},!r))return D(we),E}if(b){if(Nr(b)){const fe=await b(k,n),we=fS(fe,O);if(we&&(E[w]={...we,...W(Ro.validate,we.message)},!r))return D(we.message),E}else if(jt(b)){let fe={};for(const we in b){if(!_n(fe)&&!r)break;const G=fS(await b[we](k,n),O,we);G&&(fe={...G,...W(we,G.message)},D(G.message),r&&(E[w]=fe))}if(!_n(fe)&&(E[w]={ref:O,...fe},!r))return E}}return D(!0),E};const ZH={mode:Or.onSubmit,reValidateMode:Or.onChange,shouldFocusError:!0};function eU(t={}){let e={...ZH,...t},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:Nr(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=jt(e.defaultValues)||jt(e.values)?mn(e.defaultValues||e.values)||{}:{},a=e.shouldUnregister?{}:mn(o),c={action:!1,mount:!1,watch:!1},l={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},d,h=0;const p={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let m={...p};const y={array:QT(),state:QT()},v=cS(e.mode),b=cS(e.reValidateMode),w=e.criteriaMode===Or.all,x=R=>V=>{clearTimeout(h),h=setTimeout(R,V)},I=async R=>{if(!e.disabled&&(p.isValid||m.isValid||R)){const V=e.resolver?_n((await ne()).errors):await me(r,!0);V!==n.isValid&&y.state.next({isValid:V})}},k=(R,V)=>{!e.disabled&&(p.isValidating||p.validatingFields||m.isValidating||m.validatingFields)&&((R||Array.from(l.mount)).forEach(H=>{H&&(V?Dt(n.validatingFields,H,V):Qt(n.validatingFields,H))}),y.state.next({validatingFields:n.validatingFields,isValidating:!_n(n.validatingFields)}))},O=(R,V=[],H,re,he=!0,ue=!0)=>{if(re&&H&&!e.disabled){if(c.action=!0,ue&&Array.isArray(Re(r,R))){const be=H(Re(r,R),re.argA,re.argB);he&&Dt(r,R,be)}if(ue&&Array.isArray(Re(n.errors,R))){const be=H(Re(n.errors,R),re.argA,re.argB);he&&Dt(n.errors,R,be),QH(n.errors,R)}if((p.touchedFields||m.touchedFields)&&ue&&Array.isArray(Re(n.touchedFields,R))){const be=H(Re(n.touchedFields,R),re.argA,re.argB);he&&Dt(n.touchedFields,R,be)}(p.dirtyFields||m.dirtyFields)&&(n.dirtyFields=ac(o,a)),y.state.next({name:R,isDirty:we(R,V),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Dt(a,R,V)},D=(R,V)=>{Dt(n.errors,R,V),y.state.next({errors:n.errors})},E=R=>{n.errors=R,y.state.next({errors:n.errors,isValid:!1})},B=(R,V,H,re)=>{const he=Re(r,R);if(he){const ue=Re(a,R,Jt(H)?Re(o,R):H);Jt(ue)||re&&re.defaultChecked||V?Dt(a,R,V?ue:sS(he._f)):Y(R,ue),c.mount&&I()}},j=(R,V,H,re,he)=>{let ue=!1,be=!1;const qe={name:R};if(!e.disabled){if(!H||re){(p.isDirty||m.isDirty)&&(be=n.isDirty,n.isDirty=qe.isDirty=we(),ue=be!==qe.isDirty);const pt=di(Re(o,R),V);be=!!Re(n.dirtyFields,R),pt?Qt(n.dirtyFields,R):Dt(n.dirtyFields,R,!0),qe.dirtyFields=n.dirtyFields,ue=ue||(p.dirtyFields||m.dirtyFields)&&be!==!pt}if(H){const pt=Re(n.touchedFields,R);pt||(Dt(n.touchedFields,R,H),qe.touchedFields=n.touchedFields,ue=ue||(p.touchedFields||m.touchedFields)&&pt!==H)}ue&&he&&y.state.next(qe)}return ue?qe:{}},q=(R,V,H,re)=>{const he=Re(n.errors,R),ue=(p.isValid||m.isValid)&&ao(V)&&n.isValid!==V;if(e.delayError&&H?(d=x(()=>D(R,H)),d(e.delayError)):(clearTimeout(h),d=null,H?Dt(n.errors,R,H):Qt(n.errors,R)),(H?!di(he,H):he)||!_n(re)||ue){const be={...re,...ue&&ao(V)?{isValid:V}:{},errors:n.errors,name:R};n={...n,...be},y.state.next(be)}},ne=async R=>{k(R,!0);const V=await e.resolver(a,e.context,GH(R||l.mount,r,e.criteriaMode,e.shouldUseNativeValidation));return k(R),V},W=async R=>{const{errors:V}=await ne(R);if(R)for(const H of R){const re=Re(V,H);re?Dt(n.errors,H,re):Qt(n.errors,H)}else n.errors=V;return V},me=async(R,V,H={valid:!0})=>{for(const re in R){const he=R[re];if(he){const{_f:ue,...be}=he;if(ue){const qe=l.array.has(ue.name),pt=he._f&&jH(he._f);pt&&p.validatingFields&&k([re],!0);const ft=await hS(he,l.disabled,a,w,e.shouldUseNativeValidation&&!V,qe);if(pt&&p.validatingFields&&k([re]),ft[ue.name]&&(H.valid=!1,V))break;!V&&(Re(ft,ue.name)?qe?XH(n.errors,ft,ue.name):Dt(n.errors,ue.name,ft[ue.name]):Qt(n.errors,ue.name))}!_n(be)&&await me(be,V,H)}}return H.valid},fe=()=>{for(const R of l.unMount){const V=Re(r,R);V&&(V._f.refs?V._f.refs.every(H=>!Hg(H)):!Hg(V._f.ref))&&Me(R)}l.unMount=new Set},we=(R,V)=>!e.disabled&&(R&&V&&Dt(a,R,V),!di(xe(),o)),G=(R,V,H)=>$H(R,l,{...c.mount?a:Jt(V)?o:so(R)?{[R]:V}:V},H,V),X=R=>Wu(Re(c.mount?a:o,R,e.shouldUnregister?Re(o,R,[]):[])),Y=(R,V,H={})=>{const re=Re(r,R);let he=V;if(re){const ue=re._f;ue&&(!ue.disabled&&Dt(a,R,oS(V,ue)),he=Yu(ue.ref)&&xn(V)?"":V,XT(ue.ref)?[...ue.ref.options].forEach(be=>be.selected=he.includes(be.value)):ue.refs?oc(ue.ref)?ue.refs.length>1?ue.refs.forEach(be=>(!be.defaultChecked||!be.disabled)&&(be.checked=Array.isArray(he)?!!he.find(qe=>qe===be.value):he===be.value)):ue.refs[0]&&(ue.refs[0].checked=!!he):ue.refs.forEach(be=>be.checked=be.value===he):Lg(ue.ref)?ue.ref.value="":(ue.ref.value=he,ue.ref.type||y.state.next({name:R,values:mn(a)})))}(H.shouldDirty||H.shouldTouch)&&j(R,he,H.shouldTouch,H.shouldDirty,!0),H.shouldValidate&&te(R)},ie=(R,V,H)=>{for(const re in V){const he=V[re],ue=`${R}.${re}`,be=Re(r,ue);(l.array.has(R)||jt(he)||be&&!be._f)&&!Bi(he)?ie(ue,he,H):Y(ue,he,H)}},Z=(R,V,H={})=>{const re=Re(r,R),he=l.array.has(R),ue=mn(V);Dt(a,R,ue),he?(y.array.next({name:R,values:mn(a)}),(p.isDirty||p.dirtyFields||m.isDirty||m.dirtyFields)&&H.shouldDirty&&y.state.next({name:R,dirtyFields:ac(o,a),isDirty:we(R,ue)})):re&&!re._f&&!xn(ue)?ie(R,ue,H):Y(R,ue,H),uS(R,l)&&y.state.next({...n}),y.state.next({name:c.mount?R:void 0,values:mn(a)})},J=async R=>{c.mount=!0;const V=R.target;let H=V.name,re=!0;const he=Re(r,H),ue=be=>{re=Number.isNaN(be)||Bi(be)&&isNaN(be.getTime())||di(be,Re(a,H,be))};if(he){let be,qe;const pt=V.type?sS(he._f):MH(R),ft=R.type===JT.BLUR||R.type===JT.FOCUS_OUT,Dn=!qH(he._f)&&!e.resolver&&!Re(n.errors,H)&&!he._f.deps||JH(ft,Re(n.touchedFields,H),n.isSubmitted,b,v),Wn=uS(H,l,ft);Dt(a,H,pt),ft?(he._f.onBlur&&he._f.onBlur(R),d&&d(0)):he._f.onChange&&he._f.onChange(R);const Ft=j(H,pt,ft),Yn=!_n(Ft)||Wn;if(!ft&&y.state.next({name:H,type:R.type,values:mn(a)}),Dn)return(p.isValid||m.isValid)&&(e.mode==="onBlur"?ft&&I():ft||I()),Yn&&y.state.next({name:H,...Wn?{}:Ft});if(!ft&&Wn&&y.state.next({...n}),e.resolver){const{errors:Jn}=await ne([H]);if(ue(pt),re){const Qn=dS(n.errors,r,H),He=dS(Jn,r,Qn.name||H);be=He.error,H=He.name,qe=_n(Jn)}}else k([H],!0),be=(await hS(he,l.disabled,a,w,e.shouldUseNativeValidation))[H],k([H]),ue(pt),re&&(be?qe=!1:(p.isValid||m.isValid)&&(qe=await me(r,!0)));re&&(he._f.deps&&te(he._f.deps),q(H,qe,be,Ft))}},F=(R,V)=>{if(Re(n.errors,V)&&R.focus)return R.focus(),1},te=async(R,V={})=>{let H,re;const he=ic(R);if(e.resolver){const ue=await W(Jt(R)?R:he);H=_n(ue),re=R?!he.some(be=>Re(ue,be)):H}else R?(re=(await Promise.all(he.map(async ue=>{const be=Re(r,ue);return await me(be&&be._f?{[ue]:be}:be)}))).every(Boolean),!(!re&&!n.isValid)&&I()):re=H=await me(r);return y.state.next({...!so(R)||(p.isValid||m.isValid)&&H!==n.isValid?{}:{name:R},...e.resolver||!R?{isValid:H}:{},errors:n.errors}),V.shouldFocus&&!re&&cc(r,F,R?he:l.mount),re},xe=R=>{const V={...c.mount?a:o};return Jt(R)?V:so(R)?Re(V,R):R.map(H=>Re(V,H))},_e=(R,V)=>({invalid:!!Re((V||n).errors,R),isDirty:!!Re((V||n).dirtyFields,R),error:Re((V||n).errors,R),isValidating:!!Re(n.validatingFields,R),isTouched:!!Re((V||n).touchedFields,R)}),Te=R=>{R&&ic(R).forEach(V=>Qt(n.errors,V)),y.state.next({errors:R?n.errors:{}})},Ie=(R,V,H)=>{const re=(Re(r,R,{_f:{}})._f||{}).ref,he=Re(n.errors,R)||{},{ref:ue,message:be,type:qe,...pt}=he;Dt(n.errors,R,{...pt,...V,ref:re}),y.state.next({name:R,errors:n.errors,isValid:!1}),H&&H.shouldFocus&&re&&re.focus&&re.focus()},Ee=(R,V)=>Nr(R)?y.state.subscribe({next:H=>R(G(void 0,V),H)}):G(R,V,!0),Pe=R=>y.state.subscribe({next:V=>{YH(R.name,V.name,R.exact)&&WH(V,R.formState||p,Xt,R.reRenderRoot)&&R.callback({values:{...a},...n,...V})}}).unsubscribe,Fe=R=>(c.mount=!0,m={...m,...R.formState},Pe({...R,formState:m})),Me=(R,V={})=>{for(const H of R?ic(R):l.mount)l.mount.delete(H),l.array.delete(H),V.keepValue||(Qt(r,H),Qt(a,H)),!V.keepError&&Qt(n.errors,H),!V.keepDirty&&Qt(n.dirtyFields,H),!V.keepTouched&&Qt(n.touchedFields,H),!V.keepIsValidating&&Qt(n.validatingFields,H),!e.shouldUnregister&&!V.keepDefaultValue&&Qt(o,H);y.state.next({values:mn(a)}),y.state.next({...n,...V.keepDirty?{isDirty:we()}:{}}),!V.keepIsValid&&I()},Oe=({disabled:R,name:V})=>{(ao(R)&&c.mount||R||l.disabled.has(V))&&(R?l.disabled.add(V):l.disabled.delete(V))},Je=(R,V={})=>{let H=Re(r,R);const re=ao(V.disabled)||ao(e.disabled);return Dt(r,R,{...H||{},_f:{...H&&H._f?H._f:{ref:{name:R}},name:R,mount:!0,...V}}),l.mount.add(R),H?Oe({disabled:ao(V.disabled)?V.disabled:e.disabled,name:R}):B(R,!0,V.value),{...re?{disabled:V.disabled||e.disabled}:{},...e.progressive?{required:!!V.required,min:sc(V.min),max:sc(V.max),minLength:sc(V.minLength),maxLength:sc(V.maxLength),pattern:sc(V.pattern)}:{},name:R,onChange:J,onBlur:J,ref:he=>{if(he){Je(R,V),H=Re(r,R);const ue=Jt(he.value)&&he.querySelectorAll&&he.querySelectorAll("input,select,textarea")[0]||he,be=zH(ue),qe=H._f.refs||[];if(be?qe.find(pt=>pt===ue):ue===H._f.ref)return;Dt(r,R,{_f:{...H._f,...be?{refs:[...qe.filter(Hg),ue,...Array.isArray(Re(o,R))?[{}]:[]],ref:{type:ue.type,name:R}}:{ref:ue}}}),B(R,!1,void 0,ue)}else H=Re(r,R,{}),H._f&&(H._f.mount=!1),(e.shouldUnregister||V.shouldUnregister)&&!(LH(l.array,R)&&c.action)&&l.unMount.add(R)}}},ye=()=>e.shouldFocusError&&cc(r,F,l.mount),st=R=>{ao(R)&&(y.state.next({disabled:R}),cc(r,(V,H)=>{const re=Re(r,H);re&&(V.disabled=re._f.disabled||R,Array.isArray(re._f.refs)&&re._f.refs.forEach(he=>{he.disabled=re._f.disabled||R}))},0,!1))},Ct=(R,V)=>async H=>{let re;H&&(H.preventDefault&&H.preventDefault(),H.persist&&H.persist());let he=mn(a);if(y.state.next({isSubmitting:!0}),e.resolver){const{errors:ue,values:be}=await ne();n.errors=ue,he=be}else await me(r);if(l.disabled.size)for(const ue of l.disabled)Dt(he,ue,void 0);if(Qt(n.errors,"root"),_n(n.errors)){y.state.next({errors:{}});try{await R(he,H)}catch(ue){re=ue}}else V&&await V({...n.errors},H),ye(),setTimeout(ye);if(y.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:_n(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},nn=(R,V={})=>{Re(r,R)&&(Jt(V.defaultValue)?Z(R,mn(Re(o,R))):(Z(R,V.defaultValue),Dt(o,R,mn(V.defaultValue))),V.keepTouched||Qt(n.touchedFields,R),V.keepDirty||(Qt(n.dirtyFields,R),n.isDirty=V.defaultValue?we(R,mn(Re(o,R))):we()),V.keepError||(Qt(n.errors,R),p.isValid&&I()),y.state.next({...n}))},ln=(R,V={})=>{const H=R?mn(R):o,re=mn(H),he=_n(R),ue=he?o:re;if(V.keepDefaultValues||(o=H),!V.keepValues){if(V.keepDirtyValues){const be=new Set([...l.mount,...Object.keys(ac(o,a))]);for(const qe of Array.from(be))Re(n.dirtyFields,qe)?Dt(ue,qe,Re(a,qe)):Z(qe,Re(ue,qe))}else{if(Rg&&Jt(R))for(const be of l.mount){const qe=Re(r,be);if(qe&&qe._f){const pt=Array.isArray(qe._f.refs)?qe._f.refs[0]:qe._f.ref;if(Yu(pt)){const ft=pt.closest("form");if(ft){ft.reset();break}}}}for(const be of l.mount)Z(be,Re(ue,be))}a=mn(ue),y.array.next({values:{...ue}}),y.state.next({values:{...ue}})}l={mount:V.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},c.mount=!p.isValid||!!V.keepIsValid||!!V.keepDirtyValues,c.watch=!!e.shouldUnregister,y.state.next({submitCount:V.keepSubmitCount?n.submitCount:0,isDirty:he?!1:V.keepDirty?n.isDirty:!!(V.keepDefaultValues&&!di(R,o)),isSubmitted:V.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:he?{}:V.keepDirtyValues?V.keepDefaultValues&&a?ac(o,a):n.dirtyFields:V.keepDefaultValues&&R?ac(o,R):V.keepDirty?n.dirtyFields:{},touchedFields:V.keepTouched?n.touchedFields:{},errors:V.keepErrors?n.errors:{},isSubmitSuccessful:V.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Pt=(R,V)=>ln(Nr(R)?R(a):R,V),Rn=(R,V={})=>{const H=Re(r,R),re=H&&H._f;if(re){const he=re.refs?re.refs[0]:re.ref;he.focus&&(he.focus(),V.shouldSelect&&Nr(he.select)&&he.select())}},Xt=R=>{n={...n,...R}},$t={control:{register:Je,unregister:Me,getFieldState:_e,handleSubmit:Ct,setError:Ie,_subscribe:Pe,_runSchema:ne,_getWatch:G,_getDirty:we,_setValid:I,_setFieldArray:O,_setDisabledField:Oe,_setErrors:E,_getFieldArray:X,_reset:ln,_resetDefaultValues:()=>Nr(e.defaultValues)&&e.defaultValues().then(R=>{Pt(R,e.resetOptions),y.state.next({isLoading:!1})}),_removeUnmounted:fe,_disableForm:st,_subjects:y,_proxyFormState:p,get _fields(){return r},get _formValues(){return a},get _state(){return c},set _state(R){c=R},get _defaultValues(){return o},get _names(){return l},set _names(R){l=R},get _formState(){return n},get _options(){return e},set _options(R){e={...e,...R}}},subscribe:Fe,trigger:te,register:Je,handleSubmit:Ct,watch:Ee,setValue:Z,getValues:xe,reset:Pt,resetField:nn,clearErrors:Te,unregister:Me,setError:Ie,setFocus:Rn,getFieldState:_e};return{...$t,formControl:$t}}function tU(t={}){const e=M.useRef(void 0),n=M.useRef(void 0),[r,o]=M.useState({isDirty:!1,isValidating:!1,isLoading:Nr(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:Nr(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...t.formControl?t.formControl:eU(t),formState:r},t.formControl&&t.defaultValues&&!Nr(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions));const a=e.current.control;return a._options=t,UH(()=>{const c=a._subscribe({formState:a._proxyFormState,callback:()=>o({...a._formState}),reRenderRoot:!0});return o(l=>({...l,isReady:!0})),a._formState.isReady=!0,c},[a]),M.useEffect(()=>a._disableForm(t.disabled),[a,t.disabled]),M.useEffect(()=>{t.mode&&(a._options.mode=t.mode),t.reValidateMode&&(a._options.reValidateMode=t.reValidateMode),t.errors&&!_n(t.errors)&&a._setErrors(t.errors)},[a,t.errors,t.mode,t.reValidateMode]),M.useEffect(()=>{t.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,t.shouldUnregister]),M.useEffect(()=>{if(a._proxyFormState.isDirty){const c=a._getDirty();c!==r.isDirty&&a._subjects.state.next({isDirty:c})}},[a,r.isDirty]),M.useEffect(()=>{t.values&&!di(t.values,n.current)?(a._reset(t.values,a._options.resetOptions),n.current=t.values,o(c=>({...c}))):a._resetDefaultValues()},[a,t.values]),M.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),e.current.formState=HH(r,a),e.current}const pS=({className:t,children:e,content:n,side:r})=>{const[o,a]=M.useState(!1);return f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{open:o,children:[f.jsx(oo,{asChild:!0,children:f.jsx("button",{type:"button",className:We("cursor-pointer",t),onClick:()=>a(!o),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onTouchStart:()=>a(!o),onKeyDown:c=>{c.preventDefault(),c.key==="Enter"&&a(!o)},children:e})}),f.jsx(kr,{side:r,className:n?"":"hidden",children:f.jsx("span",{className:"inline-block",children:n})})]})})},nU=(t,e)=>{const[n,r]=M.useState(t);return M.useEffect(()=>{const o=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(o)}},[t,e]),n},rU=({apiBaseUrl:t="http://localhost:3002"})=>{var B,j;const[e,n]=M.useState([]),[r,o]=M.useState(!1),[a,c]=M.useState([]),[l,d]=M.useState(1),[h,p]=M.useState(1),[m,y]=M.useState(null),[v,b]=M.useState(""),w=nU(v,500),x=q=>{const ne=q.match(/\d{6}/);if(!ne)return{month:"",year:""};const W=ne[0],me=W.substring(0,2),fe=W.substring(2);return{month:me,year:fe}},I=q=>q.map(W=>{let me=(W==null?void 0:W.month)||"",fe=(W==null?void 0:W.year)||"";if((!me||!fe)&&(W!=null&&W.file_name)){const we=x(W.file_name);me=me||we.month,fe=fe||we.year}return{id:W==null?void 0:W.id,prefix:(W==null?void 0:W.prefix)||"",model:(W==null?void 0:W.model)||"",fileName:(W==null?void 0:W.file_name)||"",code:(W==null?void 0:W.stock_id)||"",month:me,year:fe,content:(W==null?void 0:W.text_summary)||"",status:(W==null?void 0:W.status)||"",note:(W==null?void 0:W.note)||"",lastUpdate:W==null?void 0:W.updated_at,stock_id:W==null?void 0:W.stock_id}}),k=q=>{if(!(q!=null&&q.data))return[];const ne=I(q==null?void 0:q.data);n(ne),p(q.pagination.totalPages)},O=async(q=1,ne=15)=>{y(q),o(!0);try{const W=await Le.get(`${t}/api/latest-summaries`,{params:{page:q,limit:ne,search:v}});(W==null?void 0:W.status)===200?k(W.data):console.error(W)}catch(W){console.error("Error fetching data:",W)}finally{y(null),o(!1)}};M.useEffect(()=>{w&&d(1),O(l)},[l,w]);const D=M.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:ne})=>f.jsx("span",{className:"flex flex-col",children:ne.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:ne})=>{const W=ne.original.month,me=ne.original.year;return f.jsx("span",{className:"flex flex-col",children:`${W.toString().padStart(2,"0")}/${me}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:ne})=>{const W=ne.getValue("content");return f.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:ne})=>{const me=ne.original.status!=="unpublish";return f.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${me?"bg-green-50 text-green-700 ring-1 ring-inset ring-green-600/20":"bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/20"}`,children:me?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:ne})=>f.jsx(pS,{content:f.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:ne.original.note}),children:f.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:ne.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:ne})=>{const W=new Date(ne.original.lastUpdate),me=W.getDate(),fe=W.getMonth()+1,we=`ngày ${me} tháng ${fe}`;return f.jsx("span",{className:"flex flex-col",children:we})}},{accessorKey:"actions",header:()=>f.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:ne})=>{const[W,me]=M.useState(!1),[fe,we]=M.useState(!1),[G,X]=M.useState(!1),{handleSubmit:Y,register:ie,reset:Z}=tU(),J=ne.original.id,F=ne.getValue("status"),te=ne.getValue("content"),[xe,_e]=M.useState(!1),Te=async()=>{try{_e(!0);const Ee=F==="unpublish"?"published":"unpublish",Pe=await Le.patch(`${t}/api/toggle-publish/${J}`,{id:J,typeAction:"update",status:F,idInput:J,stock_id:ne.original.stock_id,prefix:ne.original.prefix,model:ne.original.model,summary_result:ne.original.content,note:ne.original.note});Pe.status===200?n(Fe=>Fe.map(Me=>Me.id===J?{...Me,status:Ee}:Me)):console.error("Failed to toggle publish status:",Pe)}catch(Ee){console.error("Error toggling publish status:",Ee)}finally{_e(!1)}},Ie=async Ee=>{me(!0);try{const Pe=await Le.patch(`${t}/api/update-summary`,{note:Ee.note,text_summary:Ee.content,id:J});Pe.status===200?(await O(l),we(!1)):console.error("Failed to update summary:",Pe)}catch(Pe){console.error("Error updating summary:",Pe)}return me(!1)};return f.jsxs("div",{className:"flex items-center justify-end gap-2",children:[f.jsx($e,{variant:"outline",size:"sm",onClick:()=>X(!0),className:"px-2 py-0.5 h-7",children:f.jsx(PR,{className:"h-4 w-4"})}),f.jsx(Tr,{open:G,onOpenChange:X,children:f.jsxs(or,{className:"max-w-3xl max-h-[80vh]",children:[f.jsx(ir,{children:f.jsx(ar,{children:"Nội dung chi tiết"})}),f.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:f.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:te})})]})}),f.jsxs(Tr,{open:fe,onOpenChange:Ee=>{we(Ee),Ee?Z({content:ne.original.content,note:ne.original.note}):Z()},children:[f.jsx(Gs,{asChild:!0,children:f.jsx($e,{variant:"outline",size:"sm",onClick:()=>we(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),f.jsx(or,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:f.jsxs(ir,{className:"flex flex-col gap-3",children:[f.jsx(ar,{className:"max-sm:hidden text-center",children:"Sửa summary"}),f.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:Y(Ie),children:[f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsxs("div",{className:"flex flex-col items-start",children:[f.jsx("span",{children:"Nội dung:"}),f.jsx(qs,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ne.original.answer||"",rows:10,...ie("content")})]}),f.jsxs("div",{className:"flex flex-col items-start",children:[f.jsx("span",{children:"Ghi chú:"}),f.jsx(qs,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ne.original.note||"",rows:1,...ie("note")})]})]}),f.jsx("div",{className:"flex justify-end",children:f.jsx($e,{disabled:W,type:"submit",variant:"default",children:W?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),f.jsx($e,{variant:"outline",size:"sm",onClick:Te,disabled:xe,className:"w-[70px] px-2 py-0.5 h-7",children:xe?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):F==="unpublish"?"Publish":"Unpublish"})]})}}],[]),E=tb({data:e,columns:D,state:{columnFilters:a},enableRowSelection:!0,onColumnFiltersChange:c,getFilteredRowModel:LP(),getCoreRowModel:eb()});return f.jsxs("div",{className:"space-y-4 s3-explr-container",children:[f.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:f.jsxs("div",{className:"relative max-w-sm",children:[f.jsx(Qr,{placeholder:"Tìm kiếm theo mã...",value:v,onChange:q=>b(q.target.value),className:"pr-8"}),v&&f.jsx($e,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>b(""),children:f.jsx(Ip,{className:"h-4 w-4"})})]})}),f.jsx("div",{className:"rounded-md border s3-explr-table-container",children:f.jsxs(Cu,{className:"s3-explr-table",children:[f.jsx(bu,{className:"s3-explr-table-header",children:E.getHeaderGroups().map(q=>f.jsx(Er,{className:"hover:bg-transparent s3-explr-header-row",children:q.headers.map(ne=>f.jsx(Xr,{className:"s3-explr-header-cell",children:ne.isPlaceholder?null:ql(ne.column.columnDef.header,ne.getContext())},ne.id))},q.id))}),f.jsx(xu,{className:"s3-explr-table-body",children:r?f.jsx(Er,{children:f.jsx(Nn,{colSpan:D.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(B=E.getRowModel().rows)!=null&&B.length?(j=E.getRowModel().rows)==null?void 0:j.map(q=>f.jsx(Er,{className:"h-12 s3-explr-row",children:q.getVisibleCells().map(ne=>f.jsx(Nn,{className:"align-middle s3-explr-cell",children:ql(ne.column.columnDef.cell,ne.getContext())},ne.id))},q.id)):f.jsx(Er,{children:f.jsx(Nn,{colSpan:D.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),f.jsx("div",{className:"mt-4",children:f.jsx(gu,{children:f.jsxs(mu,{children:[f.jsx(Sr,{children:f.jsx(vu,{onClick:()=>d(q=>Math.max(1,q-1)),className:l===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:h},(q,ne)=>ne+1).filter(q=>q===1||q===h||Math.abs(q-l)<=1).map((q,ne,W)=>f.jsxs(f.Fragment,{children:[ne>0&&W[ne-1]!==q-1&&f.jsx(Sr,{children:f.jsx(wu,{})},q+"..."),f.jsx(Sr,{children:f.jsx(Fa,{onClick:()=>d(q),isActive:l===q,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:m===q?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):q})},q)]})),f.jsx(Sr,{children:f.jsx(yu,{onClick:()=>d(q=>Math.min(h,q+1)),className:l===h||m!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},gS=10,oU=M.memo(({apiBaseUrl:t="http://localhost:3002"})=>{const[e,n]=M.useState(1),[r,o]=M.useState([]),[a,c]=M.useState({total:0,page:1,limit:gS,totalPages:1}),[l,d]=M.useState(!0),[h,p]=M.useState(null),[m,y]=M.useState(new Set),{toast:v}=Ou(),[b,w]=M.useState(!1),x=async E=>{try{p(E);const B=await Le.get(`${t}/api/jobs`,{params:{page:E.toString(),limit:gS.toString()}});o(B.data.data),c(B.data.pagination)}catch{v({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{p(null),d(!1)}};M.useEffect(()=>{x(e)},[e,t]);const I=async E=>{y(B=>new Set(B).add(E.toString()));try{await Le.post(`${t}/api/retry-job`,{jobId:E}),v({title:"Job Restarted",description:`Job ${E} has been successfully restarted.`}),x(e)}catch{v({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${E}. Please try again.`})}finally{y(B=>{const j=new Set(B);return j.delete(E.toString()),j})}},k=async()=>{w(!0),n(1),await x(1),w(!1)},O=E=>new Date(E).toLocaleString(),D=E=>{if(E=parseFloat(E),E<60)return`${E.toFixed(2)}s`;const B=Math.floor(E/60),j=(E%60).toFixed(0);return`${B}m ${j}s`};return f.jsxs("div",{children:[f.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[f.jsx(IR,{className:"w-8 h-8 text-primary"}),f.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),f.jsx($e,{variant:"outline",size:"icon",onClick:k,disabled:b||l,className:"ml-2",children:f.jsx(DR,{className:`h-4 w-4 ${b?"animate-spin":""}`})})]}),f.jsx("div",{className:"rounded-md border",children:f.jsxs(Cu,{children:[f.jsx(bu,{children:f.jsxs(Er,{children:[f.jsx(Xr,{children:"ID"}),f.jsx(Xr,{children:"Tên Công Việc"}),f.jsx(Xr,{children:"Thời Gian Bắt Đầu"}),f.jsx(Xr,{children:"Thời Gian Cập Nhật"}),f.jsx(Xr,{children:"Thời Gian Thực Thi"}),f.jsx(Xr,{children:"Trạng Thái"}),f.jsx(Xr,{children:"Thao Tác"})]})}),f.jsx(xu,{children:l&&r.length===0?f.jsx(Er,{children:f.jsx(Nn,{colSpan:7,className:"text-center py-4",children:f.jsx(zt,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(E=>{var B,j;return f.jsxs(Er,{children:[f.jsx(Nn,{className:"!w-[100px]",children:E.id}),f.jsx(Nn,{className:"font-medium",children:(B=E.job_name)==null?void 0:B.replace("Upload file","Summary")}),f.jsx(Nn,{className:"!w-[200px]",children:O(E.created_at)}),f.jsx(Nn,{className:"!w-[200px]",children:O(E.updated_at)}),f.jsx(Nn,{className:"!w-[150px]",children:D(E.execution_time_seconds)}),f.jsx(Nn,{className:"!w-[200px]",children:f.jsx(pS,{content:E.status==="fail"&&E.error?f.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:E.error}):null,children:f.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]
207
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zT(t,e){if(t){if(typeof t=="string")return kg(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 kg(t,e)}}function kg(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 yH(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],o=!0,a=!1,c,l;try{for(n=n.call(t);!(o=(c=n.next()).done)&&(r.push(c.value),!(e&&r.length===e));o=!0);}catch(d){a=!0,l=d}finally{try{!o&&n.return!=null&&n.return()}finally{if(a)throw l}}return r}}function wH(t){if(Array.isArray(t))return t}function KT(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Ut(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?KT(Object(n),!0).forEach(function(r){Og(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):KT(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Og(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ju(t,e){if(t==null)return{};var n=CH(t,e),r,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(o=0;o<a.length;o++)r=a[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function CH(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,a;for(a=0;a<r.length;a++)o=r[a],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}var Ng=M.forwardRef(function(t,e){var n=t.children,r=ju(t,lH),o=GT(r),a=o.open,c=ju(o,uH);return M.useImperativeHandle(e,function(){return{open:a}},[a]),M.createElement(M.Fragment,null,n(Ut(Ut({},c),{},{open:a})))});Ng.displayName="Dropzone";var VT={disabled:!1,getFilesFromEvent:P2,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};Ng.defaultProps=VT,Ng.propTypes={children:At.func,accept:At.objectOf(At.arrayOf(At.string)),multiple:At.bool,preventDropOnDocument:At.bool,noClick:At.bool,noKeyboard:At.bool,noDrag:At.bool,noDragEventsBubbling:At.bool,minSize:At.number,maxSize:At.number,maxFiles:At.number,disabled:At.bool,getFilesFromEvent:At.func,onFileDialogCancel:At.func,onFileDialogOpen:At.func,useFsAccessApi:At.bool,autoFocus:At.bool,onDragEnter:At.func,onDragLeave:At.func,onDragOver:At.func,onDrop:At.func,onDropAccepted:At.func,onDropRejected:At.func,onError:At.func,validator:At.func};var Pg={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function GT(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=Ut(Ut({},VT),t),n=e.accept,r=e.disabled,o=e.getFilesFromEvent,a=e.maxSize,c=e.minSize,l=e.multiple,d=e.maxFiles,h=e.onDragEnter,p=e.onDragLeave,m=e.onDragOver,y=e.onDrop,v=e.onDropAccepted,b=e.onDropRejected,w=e.onFileDialogCancel,x=e.onFileDialogOpen,I=e.useFsAccessApi,k=e.autoFocus,O=e.preventDropOnDocument,D=e.noClick,E=e.noKeyboard,B=e.noDrag,j=e.noDragEventsBubbling,q=e.onError,ne=e.validator,W=M.useMemo(function(){return aH(n)},[n]),me=M.useMemo(function(){return iH(n)},[n]),fe=M.useMemo(function(){return typeof x=="function"?x:jT},[x]),we=M.useMemo(function(){return typeof w=="function"?w:jT},[w]),G=M.useRef(null),X=M.useRef(null),Y=M.useReducer(bH,Pg),ie=Ig(Y,2),Z=ie[0],J=ie[1],F=Z.isFocused,te=Z.isFileDialogActive,xe=M.useRef(typeof window<"u"&&window.isSecureContext&&I&&oH()),_e=function(){!xe.current&&te&&setTimeout(function(){if(X.current){var re=X.current.files;re.length||(J({type:"closeDialog"}),we())}},300)};M.useEffect(function(){return window.addEventListener("focus",_e,!1),function(){window.removeEventListener("focus",_e,!1)}},[X,te,we,xe]);var Te=M.useRef([]),Ie=function(re){G.current&&G.current.contains(re.target)||(re.preventDefault(),Te.current=[])};M.useEffect(function(){return O&&(document.addEventListener("dragover",UT,!1),document.addEventListener("drop",Ie,!1)),function(){O&&(document.removeEventListener("dragover",UT),document.removeEventListener("drop",Ie))}},[G,O]),M.useEffect(function(){return!r&&k&&G.current&&G.current.focus(),function(){}},[G,k,r]);var Ee=M.useCallback(function(H){q?q(H):console.error(H)},[q]),Pe=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H),Te.current=[].concat(hH(Te.current),[H.target]),Gu(H)&&Promise.resolve(o(H)).then(function(re){if(!(Vu(H)&&!j)){var he=re.length,ue=he>0&&eH({files:re,accept:W,minSize:c,maxSize:a,multiple:l,maxFiles:d,validator:ne}),be=he>0&&!ue;J({isDragAccept:ue,isDragReject:be,isDragActive:!0,type:"setDraggedFiles"}),h&&h(H)}}).catch(function(re){return Ee(re)})},[o,h,Ee,j,W,c,a,l,d,ne]),Fe=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H);var re=Gu(H);if(re&&H.dataTransfer)try{H.dataTransfer.dropEffect="copy"}catch{}return re&&m&&m(H),!1},[m,j]),Me=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H);var re=Te.current.filter(function(ue){return G.current&&G.current.contains(ue)}),he=re.indexOf(H.target);he!==-1&&re.splice(he,1),Te.current=re,!(re.length>0)&&(J({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Gu(H)&&p&&p(H))},[G,p,j]),Oe=M.useCallback(function(H,re){var he=[],ue=[];H.forEach(function(be){var qe=FT(be,W),pt=Ig(qe,2),ft=pt[0],Dn=pt[1],Wn=HT(be,c,a),Ft=Ig(Wn,2),Yn=Ft[0],Jn=Ft[1],Qn=ne?ne(be):null;if(ft&&Yn&&!Qn)he.push(be);else{var He=[Dn,Jn];Qn&&(He=He.concat(Qn)),ue.push({file:be,errors:He.filter(function(co){return co})})}}),(!l&&he.length>1||l&&d>=1&&he.length>d)&&(he.forEach(function(be){ue.push({file:be,errors:[Z2]})}),he.splice(0)),J({acceptedFiles:he,fileRejections:ue,isDragReject:ue.length>0,type:"setFiles"}),y&&y(he,ue,re),ue.length>0&&b&&b(ue,re),he.length>0&&v&&v(he,re)},[J,l,W,c,a,d,y,v,b,ne]),Je=M.useCallback(function(H){H.preventDefault(),H.persist(),Mn(H),Te.current=[],Gu(H)&&Promise.resolve(o(H)).then(function(re){Vu(H)&&!j||Oe(re,H)}).catch(function(re){return Ee(re)}),J({type:"reset"})},[o,Oe,Ee,j]),ye=M.useCallback(function(){if(xe.current){J({type:"openDialog"}),fe();var H={multiple:l,types:me};window.showOpenFilePicker(H).then(function(re){return o(re)}).then(function(re){Oe(re,null),J({type:"closeDialog"})}).catch(function(re){sH(re)?(we(re),J({type:"closeDialog"})):cH(re)?(xe.current=!1,X.current?(X.current.value=null,X.current.click()):Ee(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."))):Ee(re)});return}X.current&&(J({type:"openDialog"}),fe(),X.current.value=null,X.current.click())},[J,fe,we,I,Oe,Ee,me,l]),st=M.useCallback(function(H){!G.current||!G.current.isEqualNode(H.target)||(H.key===" "||H.key==="Enter"||H.keyCode===32||H.keyCode===13)&&(H.preventDefault(),ye())},[G,ye]),Ct=M.useCallback(function(){J({type:"focus"})},[]),nn=M.useCallback(function(){J({type:"blur"})},[]),ln=M.useCallback(function(){D||(rH()?setTimeout(ye,0):ye())},[D,ye]),Pt=function(re){return r?null:re},Rn=function(re){return E?null:Pt(re)},Xt=function(re){return B?null:Pt(re)},Mn=function(re){j&&re.stopPropagation()},$t=M.useMemo(function(){return function(){var H=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},re=H.refKey,he=re===void 0?"ref":re,ue=H.role,be=H.onKeyDown,qe=H.onFocus,pt=H.onBlur,ft=H.onClick,Dn=H.onDragEnter,Wn=H.onDragOver,Ft=H.onDragLeave,Yn=H.onDrop,Jn=ju(H,dH);return Ut(Ut(Og({onKeyDown:Rn(io(be,st)),onFocus:Rn(io(qe,Ct)),onBlur:Rn(io(pt,nn)),onClick:Pt(io(ft,ln)),onDragEnter:Xt(io(Dn,Pe)),onDragOver:Xt(io(Wn,Fe)),onDragLeave:Xt(io(Ft,Me)),onDrop:Xt(io(Yn,Je)),role:typeof ue=="string"&&ue!==""?ue:"presentation"},he,G),!r&&!E?{tabIndex:0}:{}),Jn)}},[G,st,Ct,nn,ln,Pe,Fe,Me,Je,E,B,r]),R=M.useCallback(function(H){H.stopPropagation()},[]),V=M.useMemo(function(){return function(){var H=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},re=H.refKey,he=re===void 0?"ref":re,ue=H.onChange,be=H.onClick,qe=ju(H,fH),pt=Og({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:Pt(io(ue,Je)),onClick:Pt(io(be,R)),tabIndex:-1},he,X);return Ut(Ut({},pt),qe)}},[X,n,l,Je,r]);return Ut(Ut({},Z),{},{isFocused:F&&!r,getRootProps:$t,getInputProps:V,rootRef:G,inputRef:X,open:Pt(ye)})}function bH(t,e){switch(e.type){case"focus":return Ut(Ut({},t),{},{isFocused:!0});case"blur":return Ut(Ut({},t),{},{isFocused:!1});case"openDialog":return Ut(Ut({},Pg),{},{isFileDialogActive:!0});case"closeDialog":return Ut(Ut({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ut(Ut({},t),{},{isDragActive:e.isDragActive,isDragAccept:e.isDragAccept,isDragReject:e.isDragReject});case"setFiles":return Ut(Ut({},t),{},{acceptedFiles:e.acceptedFiles,fileRejections:e.fileRejections,isDragReject:e.isDragReject});case"reset":return Ut({},Pg);default:return t}}function jT(){}const xH=({onFilesSelected:t,children:e})=>{const[n,r]=M.useState(!1),{getRootProps:o,getInputProps:a}=GT({noClick:!0,onDrop:c=>{if(c&&c.length>0)if(c[0].path.split("/").length>2){const d=c.map(h=>{const m=(h.path||h.relativePath||"").split("/").slice(1).join("/");return(!h.webkitRelativePath||h.webkitRelativePath==="")&&Object.defineProperty(h,"webkitRelativePath",{writable:!0,value:m,enumerable:!0,configurable:!0}),h});t(d,"folder")}else t(c,"files");r(!1)},onDragOver:c=>{c.preventDefault(),n||r(!0)},multiple:!0});return M.useEffect(()=>{const c=l=>{l.clientX===0&&l.clientY===0&&r(!1)};return document.addEventListener("dragleave",c),()=>{document.removeEventListener("dragleave",c)}},[]),f.jsxs("div",{...o(),className:"transition-opacity min-h-[600px]",children:[n?f.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,f.jsx("input",{...a()})]})},_H=({openDialogRename:t,setOpenDialogRename:e,apiBaseUrl:n,setFileToMove:r,fileToMove:o,refreshFiles:a,ignoreCache:c})=>{var k;const[l,d]=M.useState({}),[h,p]=M.useState(!1),[m,y]=M.useState(!1),[v,b]=M.useState(""),{toast:w}=Ou();M.useEffect(()=>{t&&x(v)},[v,t]);const x=async O=>{try{y(!0);const D=await Le.get(`${n}/api/list-s3-folders?prefix=${O}`);d(D==null?void 0:D.data)}catch{w({title:"Error",description:"Unable to load S3 folder list",variant:"destructive"})}finally{y(!1)}},I=async()=>{p(!0);try{const O=o.key,D=O.endsWith("/")?O:`${O}/`,E=v.endsWith("/")?v:`${v}/`;if(D===E||O===v){w({title:"Lỗi",description:"Không thể di chuyển file đến cùng vị trí",variant:"destructive"}),p(!1);return}await Le.post(`${n}/api/move`,{oldPath:O,newPath:v}),c.current=!0,await a(),w({title:"Đã di chuyển",description:`Đã di chuyển thành công "${o.name}" đến "${v}"`}),e(!1),r(null),b("")}catch(O){console.error("Error renaming item:",O),w({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{p(!1)}};return f.jsx(Tr,{open:t,onOpenChange:O=>{O||(e(!1),r(null),b(""))},children:f.jsxs(or,{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:[f.jsxs(ir,{className:"mb-4 w-full h-full",children:[f.jsx("nav",{className:"mb-4",children:f.jsxs("ul",{className:"flex items-center space-x-2 text-sm text-gray-600",children:[f.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>b(""),children:"Root"}),v.split("/").map((O,D,E)=>f.jsx("li",{className:"cursor-pointer hover:text-blue-600 transition-colors",onClick:()=>b(O==="Root"?"":E.slice(0,D+1).join("/")+"/"),children:O},D))]})}),f.jsxs(ar,{className:"text-xl font-semibold text-gray-800",children:["Di chuyển"," ",f.jsxs("span",{className:"text-sm text-gray-500",children:["( file Hoặc folder sẽ được di chuyển đến thư mục"," ",v===""?"Root":v," )"]})]}),f.jsx(ci,{className:"text-gray-600 w-full h-[50dvh] max-h-[500px] overflow-hidden overflow-y-auto",children:m?f.jsx("div",{className:"flex justify-center items-center py-4",children:f.jsx("div",{className:"loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"})}):f.jsx("ul",{className:"space-y-2",children:(k=Object.keys(l))==null?void 0:k.map(O=>f.jsx("li",{className:"cursor-pointer hover:bg-gray-100 p-2 rounded transition-colors",onClick:()=>b(O),children:O},O))})})]}),f.jsxs(Io,{className:"flex justify-end space-x-2",children:[f.jsx($e,{variant:"outline",onClick:()=>e(!1),className:"px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"Cancel"}),f.jsx($e,{onClick:I,disabled:h,className:"s3-explr-crawl-btn",children:"Move"})]})]})})},TH="AIzaSyBI8KiTWudkw8iR5cjH7ZsA4JBN1NqJw8A",SH="726815747852-5deq413t8kd8j3mgj48d46eatjauapq5.apps.googleusercontent.com",EH="https://www.googleapis.com/auth/drive";Eo(Le,{retries:3,shouldResetTimeout:!0,retryCondition:t=>Eo.isRetryableError(t)&&t.config.method==="get"});const Pn={current:!1},qT="crawl:jobs",Va="crawl:current_job",AH=t=>{const[e,n]=M.useState(null),[r,o]=M.useState(0);return M.useEffect(()=>{const a=localStorage.getItem(Va);if(a){const c=JSON.parse(a);n(c),c!=null&&c.startTime&&o(Math.floor((Date.now()-c.startTime)/1e3))}},[]),M.useEffect(()=>{if(!(e!=null&&e.startTime))return;const a=setInterval(()=>{o(Math.floor((Date.now()-e.startTime)/1e3))},1e3);return()=>clearInterval(a)},[e==null?void 0:e.startTime]),M.useEffect(()=>{if(!(e!=null&&e.id))return;const a=async()=>{try{const d=(await Le.get(`${t}/api/crawl/${e.id}?taskId=${e.taskId}`)).data;n(h=>{if(!h)return null;const p={...h,status:d};return localStorage.setItem(Va,JSON.stringify(p)),(d.status==="completed"||d.status==="failed")&&setTimeout(()=>{n(null),localStorage.removeItem(Va)},100),p})}catch(l){console.error("Error polling job status:",l)}},c=setInterval(a,3e3);return a(),()=>clearInterval(c)},[e==null?void 0:e.id,t]),{currentJob:e,elapsedTime:r,setCurrentJob:a=>{a&&!a.startTime&&(a.startTime=Date.now()),n(a),a?localStorage.setItem(Va,JSON.stringify(a)):localStorage.removeItem(Va)}}},qu=(t,e)=>{const n=[],r=o=>{(t[o]||[]).forEach(c=>{n.push(c.key),c.isFolder&&r(c.key)})};return r(e),n},IH=(t,e)=>{const n=[];return(t[e]||[]).forEach(o=>{n.push(o.key),o.isFolder&&n.push(...qu(t,o.key))}),n},kH=(t,e,n=[],r,o,a,c,l,d,h)=>{const[p,m]=M.useState({}),[y,v]=M.useState(!1),[b,w]=M.useState(null),[x,I]=M.useState(0),k=M.useRef(e);M.useEffect(()=>{k.current=e},[e]);const O=async()=>{v(!0);try{const E=await Le.get(`${t}/api/files`,{params:{cache:!1,displayPrefixes:JSON.stringify(n),prefix:k.current,excludePrivateFiles:c?"false":"true"},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:3e5}),B=[];cu.forEach(E.data,(j,q)=>{l!=null&&l.has(q)&&cu.forEach(j,ne=>{(d==null?void 0:d.current[ne.key])!==!1&&B.push(ne.key)})}),B.length&&(h==null||h(j=>{const q=new Set(j);return B.forEach(ne=>q.add(ne)),q})),m(E.data),w(null)}catch(E){w(E instanceof Error?E:new Error("Failed to fetch files"))}finally{v(!1),I(0),a("")}},D=async E=>{var B,j;try{if(!E)return;v(!0);const q=await Le.get(`${t}/api/search-db?query=${E}&rootPrefix=${e}&offset=${(o-1)*20}&limit=20`,{timeout:3e5});return m({[e]:((B=q==null?void 0:q.data)==null?void 0:B.result)||[]}),I(((j=q==null?void 0:q.data)==null?void 0:j.estimatedTotalHits)||0),q}catch(q){w(q instanceof Error?q:new Error("Failed to fetch files"))}finally{v(!1)}};return M.useEffect(()=>{!r&&!y&&O(),r&&!y&&D(r)},[r,o]),{data:p,isLoading:y,error:b,estimatedTotalHits:x,refetch:O}},rc=t=>{var r,o,a;const e=((a=(o=(r=t==null?void 0:t.name)==null?void 0:r.split("."))==null?void 0:o.pop())==null?void 0:a.toLowerCase())??"";return["txt","md","json","js","ts","jsx","tsx","css","html","xml","yaml","yml"].includes(e||"")},OH={auth:{clientId:"584d5fa9-5123-4602-a1a5-a3746a83745f",authority:"https://login.microsoftonline.com/consumers",redirectUri:"http://localhost:5173/"}},NH=new Dh(OH),PH=M.memo(({homeLabel:t="Kho tài liệu",apiBaseUrl:e="http://localhost:3002",rootPrefix:n="",rootUrlHostApi:r,asSelector:o=!1,onSelected:a=h=>console.log("Đã chọn:",h),displayPrefixes:c,preSelectedFiles:l,idCreator:d})=>{var is;const[h,p]=M.useState([]),[m,y]=M.useState(""),[v,b]=M.useState(new Set(l)),[w,x]=M.useState(n),[I,k]=M.useState(""),[O,D]=M.useState(!1),[E,B]=M.useState(""),[j,q]=M.useState(!1),[ne,W]=M.useState(null),[me,fe]=M.useState(null),[we,G]=M.useState(!1),[X,Y]=M.useState(!1),[,ie]=M.useState(null),Z=M.useRef(null),{toast:J}=Ou(),[F,te]=M.useState(null),[xe,_e]=M.useState(null),[Te,Ie]=M.useState(""),[Ee,Pe]=M.useState(!1),[Fe,Me]=M.useState(!1),[Oe,Je]=M.useState(new Set),[ye,st]=M.useState(""),[Ct,nn]=M.useState(!1),[ln,Pt]=M.useState(!1),[Rn,Xt]=M.useState("rename"),[Mn,$t]=M.useState(!1),[R,V]=M.useState(""),[H,re]=M.useState("1"),[he,ue]=M.useState(!1),[be,qe]=M.useState(!1),[pt,ft]=M.useState(!1),[Dn,Wn]=M.useState(!1),[Ft,Yn]=M.useState(1),[Jn,Qn]=M.useState(!1),{currentJob:He,elapsedTime:co,setCurrentJob:Zu}=AH(e),[Pr,fi]=M.useState(null),[zi,ja]=M.useState(""),[Ug,Ki]=M.useState(!1),[Vi,ed]=M.useState(""),[$g,td]=M.useState(!1),[lc,nd]=M.useState(!1),[hi,rd]=M.useState([]),[Gi,od]=M.useState(!1),[id,Bg]=M.useState(""),Mo=M.useRef({}),zg=async S=>{nd(!0);try{const P=await Le.get(`${r}get-knowledge-base/knowledge-base-name/${S}`,{headers:{Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAyOTliMmIwLTk4MGEtNGQ1Yy04NjkyLWJjNjllM2I1NzZlMiIsInVzZXJuYW1lIjoiY21jX3RzX2FkbWluIiwiaWF0IjoxNzQ3MTk0MTg3fQ.7LB2rgd0fQnhZP_cFgTTCPMSYl0_apwffcNEd7oqjeM"}});P.status===200&&rd(P.data.knowledgeBase.chatflows.map(z=>({...z,KnowledgeBaseId:P.data.knowledgeBase.knowledge_base_id})))}catch{}finally{nd(!1)}};M.useEffect(()=>{Vi&&r&&zg(Vi)},[Vi]),M.useEffect(()=>{console.log("pre selected files",l)},[l]);const[Ht,qa]=M.useState(null),[mS,Kg]=M.useState(!1),[vS,uc]=M.useState(!1),[ad,Wa]=M.useState(!1),[ji,sd]=M.useState([]),[qi,cd]=M.useState([]),[Ya,dc]=M.useState([{id:"root",name:"OneDrive"}]),[ld,Wi]=M.useState(!1),[Yi,ud]=M.useState([]),[Vg,pi]=M.useState(!1),[dd,Ja]=M.useState([]),[fc,fd]=M.useState([]),[Ji,hd]=M.useState([]),[hc,Do]=M.useState([{id:"root",name:"SharePoint"}]),[Lo,Qi]=M.useState(!1),[pc,pd]=M.useState([]),[gt,Qa]=M.useState(null),[gd,gi]=M.useState(!1),[gc,Rr]=M.useState(!1),qg=new URL(window.location.href).searchParams.get("prefix")||""||I||n,[Wg,md]=M.useState(null),{data:Mr,isLoading:Fo,error:Yg,estimatedTotalHits:Xi,refetch:rn}=kH(e,qg,c,m,Ft,y,d,v,Mo,b),[Xa,lo]=M.useState(!1),mc=M.useRef(null);M.useEffect(()=>{if(!Xa)return;function S(P){mc.current&&!mc.current.contains(P.target)&&lo(!1)}return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[Xa]);const Jg=async()=>{try{const S=await Le.get(`${e}/api/login-sharepoint`),{loginUrl:P}=S.data,z=window.open(P,"SharePoint Login","width=600,height=600");if(!z)throw new Error("Không thể mở cửa sổ pop-up");z.focus();const se=setInterval(()=>{try{if(z.closed){clearInterval(se);return}const pe=z.location.href;if(pe.includes("code=")){const Ce=new URL(pe).searchParams.get("code");Ce&&(Za(Ce),z.close(),clearInterval(se))}}catch(pe){pe instanceof Error&&!pe.message.includes("cross-origin")&&console.error("SharePoint login error:",pe)}},1e3)}catch(S){rt.error("Lỗi khi đăng nhập SharePoint: "+(S instanceof Error?S.message:"Unknown error"))}},Qg=async()=>{try{Ja([]),Do([{id:"root",name:"SharePoint"}]),window.location.href="https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri="+encodeURIComponent(window.location.origin),J({title:"Success",description:"Logged out from SharePoint"})}catch(S){console.error("Error logging out from SharePoint:",S),J({title:"Error",description:"Failed to logout from SharePoint",variant:"destructive"})}},Za=async S=>{try{const P=await Le.post(`${e}/api/get-sharepoint-access-token`,{code:S,userId:"1"}),{accessToken:z}=P.data;localStorage.setItem("sharepoint_access_token",z),uc(!0),Qi(!0)}catch(P){console.error("❌ Error fetching SharePoint access token:",P),J({title:"Error",description:"Failed to connect to SharePoint",variant:"destructive"})}},Xg=async()=>{try{pi(!0);const P=(await Le.post(`${e}/api/list-site-sharepoint`,{userId:"1"})).data.sites.map(z=>{const se=new URL(z.webUrl);return{id:z.id,name:z.name,description:z.description,hostname:z.hostname||se.hostname,sitePath:z.sitePath||se.pathname.replace(/^\/+/,"")}});pd(P),pi(!1)}catch(S){console.error("❌ Error fetching SharePoint sites:",S),J({title:"Error",description:"Failed to fetch SharePoint sites",variant:"destructive"}),pi(!1)}},Zg=async S=>{Qa(S),await es("root",S.name,S.hostname||"",S.sitePath||"")},es=async(S,P,z,se)=>{try{pi(!0);const Ce=(await Le.post(`${e}/api/list-file-sharepoint`,{folderId:S,userId:"1",hostname:z,sitePath:se})).data.files.map(Ae=>({id:Ae.id,name:Ae.name,size:Ae.size??0,lastModified:Ae.lastModifiedDateTime?new Date(Ae.lastModifiedDateTime):new Date,contentType:Ae.mimeType??void 0,isFolder:Ae.type==="folder",parentId:Ae.parentId??""}));fd(Ce.filter(Ae=>Ae.isFolder)),Ja(Ce.filter(Ae=>!Ae.isFolder)),Qi(!0),Do(Ae=>Ae.some(ht=>ht.id===S)?Ae:[...Ae,{id:S,name:P==="root"?"SharePoint":P}]),pi(!1)}catch(pe){console.error("❌ Error fetching SharePoint files:",pe),J({title:"Error",description:"Failed to fetch SharePoint files",variant:"destructive"}),pi(!1)}},em=S=>{hd(P=>P.some(se=>se.id===S.id)?P.filter(se=>se.id!==S.id):[...P,{id:S.id,name:S.name,size:S.size,lastModified:S.lastModified,contentType:S.contentType,isFolder:S.isFolder,parentId:S.parentId}])},tm=S=>{var z;Do(se=>se.slice(0,S+1));const P=(z=hc[S])==null?void 0:z.id;P&&es(P,"SharePoint",(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},It=async(S,P)=>{const z=localStorage.getItem("sharepoint_access_token");if(!z){rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const se=rt.loading("Đang đồng bộ SharePoint...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[],hostname:(gt==null?void 0:gt.hostname)||"",sitePath:(gt==null?void 0:gt.sitePath)||""};S.forEach(Ae=>{Ae.isFolder?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-sharepoint-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"}),Qi(!1)}catch(pe){console.error("Lỗi khi đồng bộ file từ SharePoint:",pe),rt.update(se,{render:"Không thể đồng bộ file từ SharePoint.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},_t=()=>{Qi(!1),Ja([]),hd([]),Do([{id:"root",name:"SharePoint"}])};M.useEffect(()=>{if(Lo){const P=new URLSearchParams(window.location.search).get("code");P&&(Za(P),window.history.replaceState({},document.title,window.location.pathname))}},[Lo]),M.useEffect(()=>{NH.initialize().then(()=>{Kg(!0)}).catch(S=>console.error("❌ Lỗi khởi tạo MSAL:",S))},[]),M.useEffect(()=>{nm()},[]);async function nm(){localStorage.getItem("onedrive_access_token")&&uc(!0)}const vd=S=>{ud(P=>P.some(se=>se.id===S.id)?P.filter(se=>se.id!==S.id):[...P,{id:S.id,name:S.name,size:S.size,lastModified:S.lastModified,contentType:S.contentType,isFolder:S.isFolder,parentId:S.parentId}])};function vc(S){if(S===0)return"0 B";const P=1024,z=["B","KB","MB","GB","TB"],se=Math.floor(Math.log(S)/Math.log(P));return parseFloat((S/Math.pow(P,se)).toFixed(1))+" "+z[se]}function rm(S){const P=new Date(S);return P.toLocaleDateString()+" "+P.toLocaleTimeString()}const om=async()=>{try{const S=await Le.get(`${e}/api/login-one-drive`),{loginUrl:P}=S.data,z=window.open(P,"OneDrive Login","width=600,height=600");if(!z)throw new Error("Không thể mở cửa sổ pop-up");z.focus();const se=setInterval(()=>{try{if(z.closed){clearInterval(se);return}const pe=z.location.href;if(pe.includes("code=")){const Ce=new URL(pe).searchParams.get("code");Ce&&(yd(Ce),z.close(),clearInterval(se))}}catch(pe){pe instanceof Error&&!pe.message.includes("cross-origin")&&console.error("OneDrive login error:",pe)}},1e3)}catch(S){rt.error("Lỗi khi đăng nhập OneDrive: "+(S instanceof Error?S.message:"Unknown error"))}},im=async()=>{try{await Le.post(`${e}/api/logout-one-drive`),localStorage.removeItem("onedrive_access_token"),rt.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(S){rt.error("Lỗi khi đăng xuất OneDrive: "+(S instanceof Error?S.message:"Unknown error"))}},yd=async S=>{try{const z=await Le.post(`${e}/api/get-one-drive-access-token`,{authorizationCode:S,userId:"1"}),{accessToken:se}=z.data;localStorage.setItem("onedrive_access_token",se),uc(!0),Wa(!0),await ts("root","One Drive")}catch(P){console.error("❌ Lỗi khi lấy Access Token:",P)}},ts=async(S,P)=>{try{Wi(!0);const pe=(await Le.post(`${e}/api/list-file-one-drive`,{folderId:S,userId:"1"})).data.map(Ce=>({id:Ce.id,name:Ce.name,size:Ce.size??0,lastModified:Ce.lastModifiedDateTime?new Date(Ce.lastModifiedDateTime):new Date,contentType:Ce.mimeType??void 0,isFolder:Ce.type==="folder",parentId:Ce.parentId??""}));sd(pe.filter(Ce=>Ce.isFolder)),cd(pe.filter(Ce=>!Ce.isFolder)),Wa(!0),dc(Ce=>Ce.some(Ae=>Ae.id===S)?Ce:[...Ce,{id:S,name:P==="root"?"OneDrive":P}]),Wi(!1)}catch(z){console.error("Lỗi lấy danh sách file:",z),Wi(!1)}},Zt=S=>{if(S===Ya.length-1)return;const P=Ya[S];P&&(dc(Ya.slice(0,S+1)),ts(P.id,P.name))},yc=async(S,P)=>{const z=localStorage.getItem("onedrive_access_token");if(!z){rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.");return}const se=rt.loading("Đang đồng bộ OneDrive...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[]};S.forEach(Ae=>{Ae.isFolder?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-one-drive-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(pe){console.error("Lỗi khi đồng bộ file từ OneDrive:",pe),rt.update(se,{render:"Không thể đồng bộ file từ OneDrive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}},uo=()=>{Wa(!1),dc([{id:"root",name:"OneDrive"}]),sd([]),cd([]),ud([]),Wi(!1)},wd=rP({onSuccess:S=>{md(S.access_token),localStorage.setItem("google_access_token",S.access_token),wc(S.access_token)},onError:()=>{console.log("Đăng nhập thất bại!")},scope:EH}),wc=S=>{const P=document.createElement("script");P.src="https://apis.google.com/js/api.js",P.onload=()=>{window.gapi.load("picker",()=>Ln(S))},document.body.appendChild(P)},Ln=S=>{const P=new window.google.picker.DocsView(window.google.picker.ViewId.DOCS).setIncludeFolders(!0).setSelectFolderEnabled(!0).setOwnedByMe(!1),z=new window.google.picker.DocsView(window.google.picker.ViewId.DRIVE).setIncludeFolders(!0).setSelectFolderEnabled(!0);new window.google.picker.PickerBuilder().setDeveloperKey(TH).setOAuthToken(S).enableFeature(window.google.picker.Feature.MULTISELECT_ENABLED).setLocale("vi").addView(P).addView(z).setCallback(async pe=>{if(pe.action===window.google.picker.Action.PICKED){const Ce=pe.docs.map(Ae=>({id:Ae.id,name:Ae.name,mimeType:Ae.mimeType}));await Cd(Ce,w)}}).build().setVisible(!0)},Cd=async(S,P="")=>{const z=localStorage.getItem("google_access_token");if(!z){console.error("❌ Không tìm thấy access token. Vui lòng đăng nhập lại."),rt.error("Không tìm thấy access token. Vui lòng đăng nhập lại.",{position:"bottom-right"});return}const se=rt.loading("Đang đồng bộ...",{position:"bottom-right",autoClose:!1});try{const pe={prefix:P,folders:[],files:[]};S.forEach(Ae=>{Ae.mimeType==="application/vnd.google-apps.folder"?pe.folders.push({id:Ae.id,name:Ae.name}):pe.files.push({id:Ae.id,name:Ae.name})});const Ce=await Le.post(`${e}/api/sync-drive-to-s3`,pe,{headers:{Authorization:`Bearer ${z}`}});Pn.current=!0,rn(),rt.update(se,{render:`Đồng bộ thành công! Đã tải lên ${Ce.data.uploadedKeys.length} file.`,type:"success",isLoading:!1,autoClose:3e3,position:"bottom-right"})}catch(pe){console.error("❌ Lỗi khi đồng bộ file từ Google Drive:",pe),rt.update(se,{render:"Không thể đồng bộ file từ Google Drive.",type:"error",isLoading:!1,autoClose:3e3,position:"bottom-right"})}};M.useEffect(()=>{const S=P=>{if(P.data.action==="logout"){const z=document.createElement("iframe");z.style.display="none",z.src="https://accounts.google.com/Logout",document.body.appendChild(z),setTimeout(()=>document.body.removeChild(z),2e3)}};return window.addEventListener("message",S),()=>window.removeEventListener("message",S)},[]),M.useEffect(()=>{const S=new Set(l);b(S)},[]),M.useEffect(()=>{He!=null&&He.status&&(He.status.status==="completed"?(J({title:"Thu thập website hoàn tất",description:`Đã thu thập thành công ${He.url} với ${He.status.completed} trang`}),Pn.current=!0,rn()):He.status.status==="failed"&&J({title:"Thu thập website thất bại",description:`Không thể thu thập ${He.url}. Vui lòng thử lại.`,variant:"destructive"}))},[(is=He==null?void 0:He.status)==null?void 0:is.status]);const Cc=M.useMemo(()=>Mr[w]||[],[Mr,w]),Dr=M.useMemo(()=>Cc,[Cc,w,Mr]),mi=M.useMemo(()=>{const S={};return Dr.forEach((P,z)=>{v.has(P.key)&&(S[z]=!0)}),S},[v,Dr]),bd=S=>{const P=qu(Mr,S);if(P.length===0)return v.has(S)?"all":"none";const z=P.filter(se=>v.has(se)).length;return z===0?"none":z===P.length?"all":"partial"},Ho=(S,P=!0)=>{if(w!==S){if(d&&!w)Qn(!0),k(S+d),x(S+d);else if(Qn(!0),k(S),x(S),P&&!o){const z=window.location.pathname==="/"?"":window.location.pathname,se=S?`${window.location.origin}${z}?prefix=${encodeURIComponent(S)}`:`${window.location.origin}${z}`;window.history.pushState({path:se},"",se)}}};M.useEffect(()=>{Jn&&(Pn.current=!0,rn().finally(()=>Qn(!1)))},[Jn]);const Tn=async(S,P)=>{var z,se;q(!0);try{if(Dr.some(ht=>ht.isFolder&&ht.name.toLowerCase()===S.toLowerCase())){J({title:"Lỗi",description:`Thư mục "${S}" đã tồn tại trong thư mục hiện tại.`,variant:"destructive"}),q(!1);return}const Ce=`${P}${S}/`;if((await Le.post(`${e}/api/create-folder`,{prefix:Ce})).status!==200){J({title:"Lỗi",description:"Không thể tạo thư mục",variant:"destructive"});return}Pn.current=!0,await rn(),J({title:"Đã tạo thư mục",description:`Đã tạo thành công thư mục "${S}"`}),B(""),D(!1)}catch(pe){console.error("Error creating folder:",pe);const Ce=((se=(z=pe==null?void 0:pe.response)==null?void 0:z.data)==null?void 0:se.error)||"Không thể tạo thư mục";J({title:"Lỗi",description:Ce,variant:"destructive"})}finally{q(!1)}},bc=async(S,P,z)=>{var se,pe,Ce,Ae,ht,Xn,Fr,Tc,Sc;ie(z),ft(!0);try{if(Array.from(S).reduce((un,ra)=>un+ra.size,0)>=100*1024*1024){J({title:"Lỗi",description:"Tổng kích thước các tập tin vượt quá 100 MB",variant:"destructive"}),ie(null),ft(!1);return}const as=Array.from(S).filter(un=>un.size===0);if(as.length>0){const un=as.map(ra=>ra.name).join(", ");J({title:"Lỗi tải lên",description:`Không thể tải lên tập tin rỗng: ${un}`,variant:"destructive"}),ft(!1),ie(null);return}let na=localStorage.getItem("dataLogin"),yi;try{na&&(na=JSON.parse(na),yi=na.user)}catch{na=null}const Uo=new FormData;if(yi!=null&&yi.id&&Uo.append("metadata",JSON.stringify({creator:yi.username,creatorId:yi.id,DataSource:"Tệp tải lên"})),z==="folder"&&S[0]){const un=S[0].webkitRelativePath.split("/")[0];un&&Uo.append("folderName",un)}Uo.append("prefix",P),Array.from(S).forEach(un=>z==="folder"?Uo.append("files",un,un.webkitRelativePath):Uo.append("files",un)),Pn.current=!0;const Rt=await Le.post(`${e}/api/check-files-existed`,Uo,{headers:{"Content-Type":"multipart/form-data"}});if(((se=Rt==null?void 0:Rt.data)==null?void 0:se.status)===200)await Le.post(`${e}/api/upload`,Uo,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),y(""),k(P),setTimeout(async()=>{ie(null),await rn(),ft(!1),P.includes("/Uploads")||await Lr()},500);else{if(((Ce=(pe=Rt==null?void 0:Rt.data)==null?void 0:pe.names)==null?void 0:Ce.length)>0&&!((Ae=Rt==null?void 0:Rt.data)!=null&&Ae.isFolder)){const un=Array.from(S).filter(ra=>Rt.data.names.includes(ra.name));fi(un),Ki(!0)}(ht=Rt==null?void 0:Rt.data)!=null&&ht.isFolder&&((Xn=Rt==null?void 0:Rt.data)!=null&&Xn.name)&&(ja((Fr=Rt==null?void 0:Rt.data)==null?void 0:Fr.name),fi(S),Ki(!0))}}catch(ta){console.error("Lỗi tải lên:",ta);const as=((Sc=(Tc=ta==null?void 0:ta.response)==null?void 0:Tc.data)==null?void 0:Sc.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:as,variant:"destructive"}),ie(null),ft(!1)}},Fn=async()=>{var S,P;try{ft(!0);const z=new FormData;if(Pr){ie(zi?"folder":"files"),Ki(!1);let se=localStorage.getItem("dataLogin"),pe;try{se&&(se=JSON.parse(se),pe=se.user)}catch{se=null}if(pe!=null&&pe.id&&z.append("metadata",JSON.stringify({creator:pe.username,creatorId:pe.id,DataSource:"Tệp tải lên"})),zi&&Pr[0]){const Ce=Pr[0].webkitRelativePath.split("/")[0];Ce&&z.append("folderName",Ce)}z.append("prefix",w),Array.from(Pr).forEach(Ce=>zi&&Pr[0]?z.append("files",Ce,Ce.webkitRelativePath):z.append("files",Ce)),pe!=null&&pe.id&&z.append("metadata",JSON.stringify({creator:pe.username,creatorId:pe.id,DataSource:"Tệp tải lên"})),await Le.post(`${e}/api/upload`,z,{headers:{"Content-Type":"multipart/form-data",Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="},timeout:0}),y(""),k(w),Pn.current=!0}}catch(z){console.error("Lỗi tải lên:",z);const se=((P=(S=z==null?void 0:z.response)==null?void 0:S.data)==null?void 0:P.error)||"Không thể tải lên tập tin";J({title:"Lỗi",description:se,variant:"destructive"})}finally{setTimeout(async()=>{ie(null),await rn(),ft(!1),ja(""),fi(null),await Lr()},500)}},xd=async S=>{var P;try{if(await Le.delete(`${e}/api/files`,{data:{paths:[S.key]},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),v.has(S.key)){const se=new Set(v);se.delete(S.key),b(se)}const z=((P=S.key)==null?void 0:P.replace(/^(.*?)(\/.*)?$/,(se,pe,Ce)=>!Ce||Ce==="/"?"":pe+"/"))||"";k(z),Pn.current=!0,J({title:"Đã xóa tập tin",description:`Đã xóa thành công "${S.name}"`}),W(null),await Lr()}catch(z){console.error("Error deleting file:",z),J({title:"Lỗi",description:"Không thể xóa tập tin",variant:"destructive"})}finally{Wn(!1),await rn()}},Zi=S=>{const P=new Set(v),z=typeof S=="function"?S(mi):S;new Set(Object.keys(mi).map(Number)).forEach(pe=>{const Ce=Dr[pe];Ce&&(z[pe]||(P.delete(Ce.key),Ce.isFolder&&qu(Mr,Ce.key).forEach(Ae=>P.delete(Ae))))}),Object.entries(z).forEach(([pe,Ce])=>{const Ae=parseInt(pe),ht=Dr[Ae];ht&&Ce&&(P.add(ht.key),ht.isFolder&&qu(Mr,ht.key).forEach(Xn=>P.add(Xn)))}),b(P)},fo=async()=>{var S;G(!0);try{const P=Array.from(v),z=P.map(pe=>Object.values(Mr).flat().find(Ce=>Ce.key===pe)).filter(pe=>pe!==void 0);if(z.length===0){J({title:"Lỗi",description:"Không có tập tin nào được chọn để xóa",variant:"destructive"});return}await Le.delete(`${e}/api/files`,{data:{paths:P},headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}});const se=((S=z[0])==null?void 0:S.key.replace(/^(.*?)(\/.*)?$/,(pe,Ce,Ae)=>!Ae||Ae==="/"?"":Ce+"/"))||"";k(se),Pn.current=!0,rn(),J({title:"Đã xóa tập tin",description:`Đã xóa thành công ${z.length} mục`}),Y(!1),b(new Set),await Lr()}catch(P){console.error("Error deleting files:",P),J({title:"Lỗi",description:"Không thể xóa các tập tin đã chọn",variant:"destructive"})}finally{G(!1)}},ns=async(S,P)=>{if(!w.trim()){J({title:"Lỗi",description:"Không thể đổi tên tập tin hoặc thư mục ở thư mục gốc. Chỉ có thể xóa.",variant:"destructive"});return}Me(!0);try{const z=S.key;let se;S.isFolder?se=z.split("/").slice(0,-2).join("/")+"/":se=z.substring(0,z.lastIndexOf("/")+1);const pe=se+P+(S.isFolder?"/":"");await Le.post(`${e}/api/rename`,{oldPath:z,newPath:pe}),Pn.current=!0,await rn(),J({title:"Đã đổi tên",description:`Đã đổi tên thành công "${S.name}" thành "${P}"`}),te(null),Ie(""),_e(null)}catch(z){console.error("Error renaming item:",z),J({title:"Lỗi",description:"Không thể đổi tên",variant:"destructive"})}finally{Me(!1)}},rs=async S=>{Je(P=>new Set([...P,...S]));try{const P=await Le.post(`${e}/api/download`,{paths:S},{responseType:"blob",headers:{Authorization:"Basic am9obkBleGFtcGxlLmNvbTphYmMxMjM="}}),z=window.URL.createObjectURL(P.data),se=document.createElement("a");se.href=z;const pe=P.headers["Content-Disposition"]||P.headers["content-disposition"],Ce=pe==null?void 0:pe.match(/filename="(.+)"/),Ae=Ce?decodeURIComponent(Ce[1]):"download.zip";se.setAttribute("download",Ae),document.body.appendChild(se),se.click(),document.body.removeChild(se),window.URL.revokeObjectURL(z),J({title:"Bắt đầu tải xuống",description:`Đã bắt đầu tải xuống ${S.length} mục${S.length>1,""}`})}catch(P){console.error("Error downloading files:",P),J({title:"Lỗi",description:"Không thể tải xuống tập tin",variant:"destructive"})}finally{Je(P=>{const z=new Set(P);return S.forEach(se=>z.delete(se)),z})}},kt=w?w.replace(n,"").split("/").filter(Boolean):[],ho=()=>{let S=Array.from(v).map(z=>({key:z}));S.length>1&&(S=S.filter(z=>z.key!==n));const P=z=>cu.findIndex(S,se=>!se.key.endsWith("/")&&se.key.startsWith(z))!==-1;return S=S.filter(z=>z.key.endsWith("/")?!P(z.key):!0),S},os=M.useMemo(()=>{const S=[{id:"select",header:()=>{const P=IH(Mr,w),z=P.length>0&&P.every(pe=>v.has(pe)),se=P.some(pe=>v.has(pe));return f.jsx(Hp,{checked:z?!0:se?"indeterminate":!1,onCheckedChange:pe=>{if(pe){const Ce=Dr.reduce((Ae,ht,Xn)=>(Ae[Xn]=!0,Ae),{});Zi(Ce)}else{for(const Ce of Array.from(v))Ce.startsWith(w)&&(v.delete(Ce),Mo.current[Ce]=!1);cu.forEach(Mo.current,(Ce,Ae)=>{Ae.startsWith(w)&&(Mo.current[Ae]=!1)}),Zi({})}},"aria-label":"Chọn tất cả"})},cell:({row:P})=>{const z=P.original;let pe=z.isFolder?bd(z.key):v.has(z.key)?"all":"none";if(pe==="none"&&z.key.endsWith("/")){for(const Ce of Array.from(v))if(Ce.startsWith(z.key)){pe="all";break}}return f.jsx("div",{className:"flex items-center",children:f.jsx(Hp,{checked:pe==="partial"?"indeterminate":pe==="all",onCheckedChange:Ce=>{var ht,Xn;const Ae={...mi};if(Ce?Ae[P.index]=!0:delete Ae[P.index],Mo.current[((ht=P.original)==null?void 0:ht.key)||"_"]=!!Ce,(Xn=P.original)!=null&&Xn.key.endsWith("/"))for(const Fr of Array.from(v))Fr.startsWith(P.original.key)&&(Mo.current[P.original.key]=!1,v.delete(Fr));Zi(Ae)},"aria-label":"Chọn dòng"})})},enableSorting:!1},{id:"fileName",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),children:["Tên tập tin",f.jsx(Ap,{})]}),accessorKey:"name",cell:({row:P})=>{const z=P.original,se=z.key.substring(0,z.key.lastIndexOf("/"))||"/",pe=m.trim()!==""&&se!==w,Ce=se.split("/").filter(Boolean);return f.jsxs("div",{className:"flex flex-col group",children:[f.jsxs("div",{className:"flex items-center",children:[f.jsxs("div",{className:`flex items-center gap-2 ${z.isFolder?"cursor-pointer hover:text-blue-600":""}`,onClick:()=>{z.isFolder&&Ho(z.key)},children:[z.isFolder?f.jsx(Ns,{className:"h-5 w-5 text-blue-500"}):null,z.name]}),f.jsx("button",{className:"ml-2 opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),navigator.clipboard.writeText(z.key),J({title:"Copied to clipboard",description:`Path: ${z.key}`,duration:2e3})},title:"Copy path to clipboard",children:f.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:[f.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),f.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),pe&&f.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[f.jsx(Ns,{className:"h-4 w-4 text-gray-500 my-auto"}),f.jsxs("span",{className:"flex items-center ml-1",children:[f.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Ho("")},children:"/"}),Ce.map((Ae,ht)=>f.jsxs("span",{className:"flex items-center",children:[f.jsx("span",{className:"cursor-pointer hover:text-blue-600",onClick:()=>{Ho(Ce.slice(0,ht+1).join("/")+"/")},children:Ae}),ht<Ce.length-1&&f.jsx("span",{children:"/"})]},ht))]})]})]})}}];return o||S.push({id:"size",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),children:["Kích thước",f.jsx(Ap,{})]}),accessorKey:"size",cell:({getValue:P,row:z})=>{const se=P();return f.jsx("span",{children:z.original.isFolder?"-":vc(se)})}},{id:"lastModified",header:({column:P})=>f.jsxs($e,{variant:"ghost",onClick:()=>P.toggleSorting(P.getIsSorted()==="asc"),className:"px-0 w-full flex-row justify-end",children:["Sửa đổi lần cuối",f.jsx(Ap,{})]}),accessorKey:"lastModified",cell:({row:P})=>{const z=P.original.lastModified;return f.jsx("div",{className:"w-full flex-row justify-end items-center text-right",children:f.jsx("span",{children:z&&Gb(z).isValid()?Gb(z).format("DD/MM/YYYY HH:mm"):"-"})})},size:200},{id:"actions",header:()=>f.jsx("span",{children:"Hành động"}),accessorKey:"key",cell:({row:P})=>f.jsxs("div",{className:"flex items-center gap-2",children:[w===""&&r&&f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{ed(P.original.key),td(!0)},className:"h-8 w-8 p-0",children:Oe.has(P.original.key)?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):f.jsx(uO,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Những Flow sử dụng Folder này làm Data"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>rs([P.original.key]),className:"h-8 w-8 p-0",disabled:Oe.has(P.original.key),children:Oe.has(P.original.key)?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):f.jsx(Vw,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Tải xuống"})]})}),w.trim()!==""&&f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{te(P.original),Ie(P.original.name)},className:"h-8 w-8 p-0",children:f.jsx(vO,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Đổi tên"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{Pe(!0),fe(P.original)},className:"h-8 w-8 p-0",children:f.jsx(RR,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Di chuyển"})]})}),f.jsx(no,{children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsx($e,{variant:"ghost",size:"icon",onClick:()=>W(P.original),className:"h-8 w-8 p-0",children:f.jsx(Gw,{className:"h-4 w-4"})})}),f.jsx(kr,{children:"Xóa"})]})})]})}),S},[v,Dr,mi,Oe,o]),xc=tb({data:Dr,columns:os,state:{rowSelection:mi,sorting:h},onSortingChange:p,enableRowSelection:!0,onRowSelectionChange:Zi,getCoreRowModel:eb(),getSortedRowModel:FP()}),_c=async S=>{var P,z;nn(!0);try{if(rc(S)){const se=await Le.get(`${e}/api/read-text`,{params:{path:S.key}});st(se.data.content)}try{const se=await Le.get(`${e}/api/read-json`,{params:{path:S.key+".metadata.json"}}),pe=((z=(P=se==null?void 0:se.data)==null?void 0:P.content)==null?void 0:z.metadataAttributes)||null;return _e({fullPath:F==null?void 0:F.key,...pe})}catch{return _e("Lỗi phân tích siêu dữ liệu")}}catch(se){console.error("Error loading file content:",se),J({title:"Lỗi",description:"Không thể tải nội dung tập tin",variant:"destructive"})}finally{nn(!1)}},am=async(S,P)=>{Pt(!0);try{await Le.post(`${e}/api/modify-text`,{path:S.key,content:P}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Pn.current=!0,await rn(),te(null),st(""),Xt("rename"),await Lr()}catch(z){console.error("Error saving file content:",z),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Pt(!1)}},sm=async S=>{Pt(!0);try{await Le.post(`${e}/api/modify-json`,{path:S.key+".metadata.json",content:{metadataAttributes:xe}}),J({title:"Đã lưu tập tin",description:"Nội dung tập tin đã được cập nhật thành công"}),Pn.current=!0,await rn(),te(null),st(""),Xt("rename")}catch(P){console.error("Error saving file content:",P),J({title:"Lỗi",description:"Không thể lưu nội dung tập tin",variant:"destructive"})}finally{Pt(!1)}};M.useEffect(()=>{F&&(F.isFolder||_c(F),Xt("rename"))},[F]);const _d=async(S,P)=>{var z;if(He){J({title:"Đang thu thập website",description:"Vui lòng đợi cho công việc thu thập hiện tại hoàn thành.",variant:"destructive"});return}ue(!0);try{const{data:se}=await Le.post(`${e}/api/crawl`,{url:S,limit:P,prefix:w});if(se.id){Zu({id:se.id,url:S,limit:P,prefix:w,taskId:((z=se.task)==null?void 0:z.id)||""});const pe=localStorage.getItem(qT),Ce=pe?JSON.parse(pe):[];Ce.some(Ae=>Ae.id===se.id)||(Ce.unshift({url:S,id:se.id,limit:P,prefix:w,timestamp:Date.now()}),Ce.length>20&&(Ce.length=20),localStorage.setItem(qT,JSON.stringify(Ce))),J({title:"Bắt đầu thu thập website",description:`Đã thêm nhiệm vụ thu thập ${S} với giới hạn ${P}. Dữ liệu sẽ có sẵn sau khi thu thập hoàn tất.`}),$t(!1),V(""),re("1")}}catch(se){console.error("Error crawling website:",se),J({title:"Lỗi",description:"Không thể bắt đầu thu thập website",variant:"destructive"})}finally{ue(!1)}},Td=async()=>{try{if(!(He!=null&&He.id))return;Zu(null),localStorage.removeItem(Va),J({title:"Đã dừng thu thập",description:`Đã dừng thu thập website ${He.url}`})}catch(S){console.error("Error stopping job:",S),J({title:"Lỗi",description:"Không thể dừng thu thập website",variant:"destructive"})}};M.useEffect(()=>{if(o)return;const S=(P=!0)=>{const se=new URL(window.location.href).searchParams.get("prefix")||"";se?Ho(se,!1):(P&&!l&&b(new Set),k(n),x(n),Pn.current=!0,setTimeout(()=>{rn()},0))};return S(!1),window.addEventListener("popstate",()=>S(!0)),()=>{window.removeEventListener("popstate",()=>S(!0))}},[]);const ea=async()=>{od(!0);try{await Le.post(`${e}/api/prediction-report`),J({title:"Xuất báo cáo thành công",description:"Báo cáo dự đoán đã được xuất"})}catch(S){console.error("Error exporting report:",S),J({title:"Lỗi",description:"Không thể xuất báo cáo dự đoán",variant:"destructive"})}finally{od(!1)}},vi=async()=>{try{const S=IM();S&&(await Le.post(`${e}/api/start-ingestion-job`,{prefix:w,user_id:S.id,userName:S.username})).status===200&&await Lr()}catch(S){qe(!1),console.log(S)}},po=M.useRef(),Lr=async()=>{try{qe(!0);const S=await Le.post(`${e}/api/ingestion-job-status`,{prefix:w}),{status:P}=S==null?void 0:S.data;P==="FAILED"||P==="COMPLETE"||P==="STOPPED"||P==="STOPPING"||!P?(qe(!1),po.current&&(clearInterval(po.current),po.current=null),qa(S==null?void 0:S.data)):(po.current||(po.current=setInterval(()=>Lr(),5e3)),qa(S==null?void 0:S.data))}catch(S){console.log(S)}},Sd=()=>{const S=Array.from(v);let P;return w?P=S.filter(z=>z.startsWith(w)&&z!==w).length:P=new Set(S.filter(z=>z.split("/").shift())).size,`Đang chọn: ${P}`};return M.useEffect(()=>{const S=w==null?void 0:w.split("/")[0];return S!==id&&(qe(!1),po.current&&(clearInterval(po.current),po.current=null),Bg(S||""),qa(null),S&&Lr()),()=>{}},[id,w]),M.useEffect(()=>{Lo&&pc.length===0&&(Xg(),Qa(null))},[Lo]),M.useEffect(()=>{if(l)for(const S of Array.from(l))Mo.current[S]=!0},[]),f.jsxs("div",{className:"space-y-4 s3-explr-container",children:[f.jsx(g_,{}),f.jsx(Tr,{open:Ug,onOpenChange:S=>{Ki(S),S||(ja(""),fi(null),ft(!1),ie(null))},children:f.jsxs(or,{children:[f.jsxs(ir,{children:[f.jsx(ar,{children:"Cảnh báo trùng lặp"}),f.jsxs(ci,{children:[zi&&f.jsxs(f.Fragment,{children:["Folder $",zi," đã có."]}),Pr&&Pr.length>0&&f.jsxs(f.Fragment,{children:["Những tệp sau bị lặp:",f.jsx("ul",{className:"mt-2 list-disc pl-5 text-sm text-red-600",children:Array.from(Pr).map((S,P)=>f.jsx("li",{children:S.name},P))})]})]})]}),f.jsxs(Io,{children:[f.jsx($e,{variant:"outline",onClick:()=>{Ki(!1),ja(""),fi(null),ft(!1),ie(null)},children:"Bỏ qua"}),f.jsx($e,{variant:"destructive",onClick:()=>Fn(),children:"Ghi đè"})]})]})}),f.jsx(du,{className:"s3-explr-breadcrumb",children:f.jsxs(fu,{className:"s3-explr-breadcrumb-list",children:[f.jsx(Ks,{className:"s3-explr-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Ho(n),className:"flex items-center gap-1 cursor-pointer s3-explr-breadcrumb-home",children:t})}),!d&&kt.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[f.jsx(hu,{className:"s3-explr-breadcrumb-separator"},`sep-${P}`),f.jsx(Ks,{className:"s3-explr-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Ho(n+kt.slice(0,P+1).join("/")+"/"),className:"cursor-pointer s3-explr-breadcrumb-link",children:S})},`item-${S}`)]},P))]})}),f.jsxs("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:[f.jsx("div",{className:"relative max-w-sm w-full s3-explr-search-container",children:f.jsx(w2,{ref:Z,onChange:S=>y(S)})}),f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{k(w),Pn.current=!0,rn()},disabled:Fo,className:"flex items-center gap-2 s3-explr-refresh-btn",children:[f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Fo?"animate-spin":""}`}),"Làm mới"]}),w&&w!=="/"&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>{Fo||be||(qe(!0),vi())},"aria-disabled":Fo||be,className:"flex items-center gap-2 s3-explr-refresh-btn aria-disabled:opacity-50",children:[f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Fo||be?"animate-spin":""}`}),"Đồng bộ KB"]})}),Ht&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-2 p-3 max-w-md",children:[f.jsx("p",{className:"font-semibold text-lg border-b pb-1",children:"Thông tin đồng bộ"}),f.jsx("div",{className:"space-y-1",children:f.jsxs("p",{className:"flex items-center gap-2",children:[f.jsx("span",{className:"font-medium",children:"Trạng thái:"}),f.jsxs("span",{className:`flex items-center gap-1 font-semibold ${Ht.status==="COMPLETE"?"text-green-600":Ht.status==="FAILED"?"text-red-600":"text-yellow-600"}`,children:[Ht.status==="COMPLETE"&&f.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:f.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),Ht.status==="FAILED"&&f.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:f.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Ht.status!=="COMPLETE"&&Ht.status!=="FAILED"&&f.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:f.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"})}),Ht.status]})]})}),Ht.statistics&&f.jsxs("div",{className:"space-y-1 border-t pt-2",children:[f.jsx("p",{className:"font-medium text-gray-50",children:"Thống kê xử lý:"}),f.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:[f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu quét:"}),f.jsx("span",{className:"font-medium",children:Ht.statistics.numberOfDocumentsScanned})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Metadata quét:"}),f.jsx("span",{className:"font-medium",children:Ht.statistics.numberOfMetadataDocumentsScanned})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu mới:"}),f.jsx("span",{className:"font-medium text-green-600",children:Ht.statistics.numberOfNewDocumentsIndexed})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu sửa:"}),f.jsx("span",{className:"font-medium text-blue-600",children:Ht.statistics.numberOfModifiedDocumentsIndexed})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Metadata sửa:"}),f.jsx("span",{className:"font-medium text-blue-600",children:Ht.statistics.numberOfMetadataDocumentsModified})]}),f.jsxs("div",{className:"flex justify-between",children:[f.jsx("span",{children:"Tài liệu xóa:"}),f.jsx("span",{className:"font-medium text-orange-600",children:Ht.statistics.numberOfDocumentsDeleted})]}),f.jsxs("div",{className:"flex justify-between col-span-2",children:[f.jsx("span",{children:"Tài liệu lỗi:"}),f.jsx("span",{className:"font-medium text-red-600",children:Ht.statistics.numberOfDocumentsFailed})]})]})]}),f.jsxs("div",{className:"space-y-1 border-t pt-2 text-sm text-gray-200",children:[f.jsx("p",{className:"font-medium text-gray-50",children:"Chi tiết Job:"}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"DataSource ID:"})," ",Ht.dataSourceId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Ingestion Job ID:"})," ",Ht.ingestionJobId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Knowledge Base ID:"})," ",Ht.knowledgeBaseId]}),f.jsxs("p",{children:[f.jsx("span",{className:"font-medium",children:"Job trong queue:"})," ",Ht.is_still_in_stock?"Còn":"Không"]})]}),Ht.errorMessage&&f.jsxs("div",{className:"border-t pt-2",children:[f.jsx("p",{className:"text-red-600 font-medium",children:"Lỗi:"}),f.jsx("p",{className:"text-red-600 text-sm bg-red-50 p-2 rounded",children:Ht.errorMessage})]})]})})]})}),f.jsxs("div",{className:"relative",ref:mc,children:[f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-file-btn bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",onClick:()=>lo(S=>!S),children:[f.jsx(wO,{className:"w-4 h-4"}),"Add file"]}),Xa&&f.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:[f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{lo(!1);const S=document.createElement("input");S.type="file",S.multiple=!0,S.onchange=P=>{const z=P.target.files;z&&bc(z,w,"files")},S.click()},children:[f.jsx(Lh,{className:"h-4 w-4 mr-2"})," Tải tệp tin"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",onClick:()=>{lo(!1);const S=document.createElement("input");S.type="file",S.multiple=!0,S.webkitdirectory=!0,S.onchange=P=>{const z=P.target.files;z&&bc(z,w,"folder")},S.click()},children:[f.jsx(Ns,{className:"h-4 w-4 mr-2"})," Tải lên thư mục"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left",disabled:!!c&&!w,onClick:()=>D(!0),children:[f.jsx(fO,{className:"h-4 w-4 mr-2 s3-explr-folder-plus-icon"}),"Thư mục mới"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),$t(!0)},children:[f.jsx(gO,{className:"h-4 w-4 mr-2"})," Thêm Website"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),wd()},children:[f.jsxs("svg",{viewBox:"0 0 87.3 78",xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"}),f.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"}),f.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"}),f.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"}),f.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"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),om()},children:[f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 64 64",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"]}),f.jsxs("button",{className:"flex items-center px-4 py-2 text-sm hover:bg-gray-100 text-left hidden",onClick:()=>{lo(!1),Jg()},children:[f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",className:"h-4 w-4 mr-2",children:[f.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"}),f.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"}),f.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"}),f.jsx("path",{fill:"#fff",d:"M4.5 15.5v-3c0-.28.22-.5.5-.5h3c.28 0 .5.22.5.5v3c0 .28-.22.5-.5.5H5c-.28 0-.5-.22-.5-.5z"})]})," ","Đồng bộ SharePoint"]})]})]}),!o&&f.jsxs(f.Fragment,{children:[v.size>0&&f.jsxs(f.Fragment,{children:[f.jsxs($e,{variant:"outline",size:"sm",onClick:()=>rs(Array.from(v)),disabled:Array.from(v).some(S=>Oe.has(S)),className:"flex items-center gap-2 s3-explr-download-selected-btn",children:[Array.from(v).some(S=>Oe.has(S))?f.jsx(zt,{className:"h-4 w-4 animate-spin mr-2 s3-explr-loader"}):f.jsx(Vw,{className:"h-4 w-4 s3-explr-download-icon"}),"Tải xuống đã chọn (",v.size,")"]}),f.jsxs(Tr,{open:X,onOpenChange:Y,children:[f.jsx(Gs,{asChild:!0,children:f.jsxs($e,{variant:"destructive",size:"sm",className:"flex items-center gap-2 s3-explr-bulk-delete-btn",children:[f.jsx(Gw,{className:"h-4 w-4 s3-explr-trash-icon"}),"Xóa đã chọn (",v.size,")"]})}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Xác nhận xóa hàng loạt"}),f.jsxs(ci,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",v.size," mục đã chọn? Hành động này không thể hoàn tác."]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>Y(!1),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:fo,disabled:we,className:"s3-explr-confirm-delete-btn",children:we?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa đã chọn"})]})]})]})]}),!d&&f.jsxs(Tr,{open:O,onOpenChange:D,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsx(ir,{className:"s3-explr-dialog-header",children:f.jsx(ar,{className:"s3-explr-dialog-title",children:"Tạo thư mục mới"})}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"name",className:"s3-explr-label",children:"Tên thư mục"}),f.jsx(Qr,{disabled:j,id:"name",value:E,onChange:S=>B(S.target.value),placeholder:"Nhập tên thư mục",className:"s3-explr-input"})]}),f.jsxs($e,{onClick:()=>{E.trim()&&Tn(E,w)},disabled:j,className:"s3-explr-create-btn",children:[j&&f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),j?"Đang tạo...":"Tạo"]})]})]})]}),d&&!w?f.jsx(f.Fragment,{}):f.jsxs("div",{className:"flex items-center gap-2 s3-explr-upload-group",children:[He?f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!0,children:[f.jsx(zt,{className:"h-4 w-4 animate-spin s3-explr-loader"}),He.status?f.jsxs(f.Fragment,{children:[He.status.isProcessing?"Đang thu thập ":"Đang quét sitemap ","(",He.status.completed,"/",He.status.total,") -"," ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}):"Đang thu thập..."]}),f.jsxs($e,{variant:"destructive",size:"sm",onClick:()=>void Td(),className:"flex items-center gap-2",children:[f.jsx("span",{className:"sr-only",children:"Dừng thu thập"}),f.jsx(bO,{className:"h-4 w-4"})]})]})}),He.status&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-1 p-2",children:[f.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",He==null?void 0:He.url]}),f.jsxs("p",{children:["Tiến độ: ",He==null?void 0:He.status.completed,"/",He==null?void 0:He.status.total," ","trang"]}),f.jsxs("p",{children:["Thời gian: ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}),f.jsxs("p",{children:["Trạng thái:"," ",(He==null?void 0:He.status.status)==="scraping"?"Đang thu thập":(He==null?void 0:He.status.status)==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}):!d&&f.jsxs(Tr,{open:Mn,onOpenChange:$t,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Thêm website"}),f.jsx(ci,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),f.jsx(Qr,{id:"websiteUrl",value:R,onChange:S=>V(S.target.value),placeholder:"https://example.com",type:"url",disabled:he,className:"s3-explr-input"})]}),f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),f.jsx(Qr,{id:"crawlLimit",value:H,onChange:S=>{const P=S.target.value;/^\d*$/.test(P)&&re(P)},placeholder:"1",type:"text",disabled:he,className:"s3-explr-input"}),f.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)"})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{$t(!1),V(""),re("1")},disabled:he,className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{onClick:()=>{R.trim()&&_d(R.trim(),parseInt(H)||1)},disabled:he||!R.trim(),className:"s3-explr-crawl-btn",children:he?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]}),w.startsWith("BKTTW/")&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!w,onClick:ea,children:[Gi&&f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Gi?"animate-spin":""}`}),"Xuất báo cáo"]})}),(He==null?void 0:He.status)&&f.jsx(kr,{side:"right",sideOffset:5,children:f.jsxs("div",{className:"space-y-1 p-2",children:[f.jsxs("p",{className:"font-semibold",children:["Đang thu thập ",He.url]}),f.jsxs("p",{children:["Tiến độ: ",He.status.completed,"/",He.status.total," ","trang"]}),f.jsxs("p",{children:["Thời gian: ",Math.floor(co/60),":",String(co%60).padStart(2,"0")]}),f.jsxs("p",{children:["Trạng thái:"," ",He.status.status==="scraping"?"Đang thu thập":He.status.status==="completed"?"Hoàn thành":"Thất bại"]})]})})]})}),f.jsxs(Tr,{open:Mn,onOpenChange:$t,children:[f.jsx(Gs,{asChild:!0}),f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Thêm website"}),f.jsx(ci,{className:"s3-explr-dialog-description",children:"Nhập URL website để thu thập và thêm vào S3."})]}),f.jsxs("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:[f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"websiteUrl",className:"s3-explr-label",children:"URL Website"}),f.jsx(Qr,{id:"websiteUrl",value:R,onChange:S=>V(S.target.value),placeholder:"https://example.com",type:"url",disabled:he,className:"s3-explr-input"})]}),f.jsxs("div",{className:"space-y-2 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"crawlLimit",className:"s3-explr-label",children:"Giới hạn thu thập"}),f.jsx(Qr,{id:"crawlLimit",value:H,onChange:S=>{const P=S.target.value;/^\d*$/.test(P)&&re(P)},placeholder:"1",type:"text",disabled:he,className:"s3-explr-input"}),f.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)"})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{$t(!1),V(""),re("1")},disabled:he,className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{onClick:()=>{R.trim()&&_d(R.trim(),parseInt(H)||1)},disabled:he||!R.trim(),className:"s3-explr-crawl-btn",children:he?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang thu thập..."]}):"Bắt đầu thu thập"})]})]})]})]}),w.startsWith("BKTTW/")&&f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{children:[f.jsx(oo,{asChild:!0,children:f.jsxs($e,{variant:"outline",size:"sm",className:"flex items-center gap-2 s3-explr-add-website-btn",disabled:!!c&&!w,onClick:ea,children:[Gi&&f.jsx(Ol,{className:`h-4 w-4 s3-explr-refresh-icon ${Gi?"animate-spin":""}`}),"Xuất báo cáo"]})}),Gi&&f.jsx(kr,{sideOffset:5,children:"Đang xuất báo cáo"})]})}),f.jsxs("div",{className:"flex items-center gap-4",children:[ad&&f.jsxs(Ps,{open:ad,onOpenChange:Wa,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),f.jsxs(Pa,{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:[f.jsxs("div",{className:"relative",children:[f.jsx(Yh,{asChild:!0,children:f.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:uo,children:"✖"})}),f.jsx("h2",{className:"text-lg font-semibold",children:"My OneDrive"}),f.jsx(du,{className:"onedrive-breadcrumb",children:f.jsx(fu,{className:"onedrive-breadcrumb-list",children:Ya.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[P>0&&f.jsx(hu,{className:"onedrive-breadcrumb-separator"}),f.jsx(Ks,{className:"onedrive-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>Zt(P),className:"cursor-pointer onedrive-breadcrumb-link",children:S.name})})]},P))})})]}),f.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:ld?f.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):f.jsx(f.Fragment,{children:[...ji,...qi].length>0?[...ji,...qi].map(S=>f.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${Yi.some(P=>P.id===S.id)?"bg-blue-100":""}`,children:[f.jsx("input",{type:"checkbox",checked:Yi.some(P=>P.id===S.id),onChange:P=>{P.stopPropagation(),vd(S)},className:"cursor-pointer"}),S.isFolder?f.jsx(Ns,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>ts(S.id,S.name)}):f.jsx(Lh,{className:"text-gray-500 w-5 h-5"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("div",{className:`font-medium ${S.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{S.isFolder?ts(S.id,S.name):vd(S)},children:S.name}),!S.isFolder&&f.jsxs("div",{className:"text-xs text-gray-500",children:[vc(S.size)," •"," ",rm(S.lastModified.toISOString())]})]})]},S.id)):f.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."})})}),f.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:f.jsx($e,{onClick:()=>{yc(Yi,w),uo()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:Yi.length===0,children:"Đồng bộ"})}),f.jsx("button",{onClick:()=>Rr(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất OneDrive",children:f.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:[f.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),f.jsx("polyline",{points:"16 17 21 12 16 7"}),f.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),f.jsxs(Ps,{open:gc,onOpenChange:Rr,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),f.jsxs(Pa,{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:[f.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),f.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi OneDrive?"}),f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx($e,{variant:"outline",onClick:()=>Rr(!1),children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>{im(),Rr(!1)},children:"Đăng xuất"})]})]})]}),Lo&&f.jsxs(Ps,{open:Lo,onOpenChange:Qi,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-50"}),f.jsxs(Pa,{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:[f.jsxs("div",{className:"relative",children:[f.jsx(Yh,{asChild:!0,children:f.jsx("button",{className:"absolute top-2 right-2 text-gray-600",onClick:_t,children:"✖"})}),f.jsxs("div",{className:"flex items-center gap-2",children:[gt&&f.jsx("button",{onClick:()=>Qa(null),className:"text-gray-600 hover:text-gray-800",children:f.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:f.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),f.jsx("h2",{className:"text-lg font-semibold",children:"My SharePoint"})]}),gt&&f.jsx(du,{className:"sharepoint-breadcrumb",children:f.jsx(fu,{className:"sharepoint-breadcrumb-list",children:hc.map((S,P)=>f.jsxs("div",{className:"flex items-center",children:[P>0&&f.jsx(hu,{className:"sharepoint-breadcrumb-separator"}),f.jsx(Ks,{className:"sharepoint-breadcrumb-item",children:f.jsx(Vs,{onClick:()=>tm(P),className:"cursor-pointer sharepoint-breadcrumb-link",children:S.name})})]},P))})})]}),f.jsx("div",{className:"space-y-2 mt-4 flex-1 overflow-y-auto",children:Vg?f.jsx("div",{className:"text-sm text-gray-500",children:"Đang tải nội dung thư mục... Vui lòng đợi."}):gt?[...fc,...dd].length===0?f.jsx("div",{className:"text-sm text-gray-500",children:"Không có thư mục hoặc tệp nào."}):[...fc,...dd].map(S=>{const P=Ji.some(z=>z.id===S.id);return f.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-gray-100 ${P?"bg-blue-100":""}`,children:[f.jsx("input",{type:"checkbox",checked:P,onChange:z=>{z.stopPropagation(),em(S)},className:"cursor-pointer"}),S.isFolder?f.jsx(Ns,{className:"text-blue-500 w-5 h-5 cursor-pointer",onClick:()=>es(S.id,S.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")}):f.jsx(Lh,{className:"text-gray-500 w-5 h-5"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("div",{className:`font-medium ${S.isFolder?"cursor-pointer text-blue-600":""}`,onClick:()=>{S.isFolder&&es(S.id,S.name,(gt==null?void 0:gt.hostname)||"",(gt==null?void 0:gt.sitePath)||"")},children:S.name}),!S.isFolder&&f.jsxs("div",{className:"text-xs text-gray-500",children:[vc(S.size)," •"," ",S.lastModified.toLocaleString()]})]})]},S.id)}):f.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:pc.map(S=>f.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:()=>Zg(S),children:[f.jsx("div",{className:"font-bold text-lg mb-1 truncate w-full",title:S.name,children:S.name}),f.jsx("div",{className:"text-sm text-gray-500 truncate w-full",title:S.description,children:S.description})]},S.id))})}),f.jsx("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:gt&&f.jsxs(f.Fragment,{children:[f.jsx($e,{onClick:()=>{It(Ji,w),_t()},className:"bg-[#1682fe] hover:bg-[#0f6cd4] text-white rounded-md px-4 py-2 transition-colors",disabled:Ji.length===0,children:"Đồng bộ"}),f.jsx($e,{onClick:()=>Qa(null),children:"Quay lại"})]})}),f.jsx("button",{onClick:()=>gi(!0),className:"absolute bottom-4 left-4 text-gray-600 hover:text-gray-800",title:"Đăng xuất SharePoint",children:f.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:[f.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),f.jsx("polyline",{points:"16 17 21 12 16 7"}),f.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})]}),f.jsxs(Ps,{open:gd,onOpenChange:gi,children:[f.jsx(Na,{className:"fixed inset-0 bg-black bg-opacity-50 z-[60]"}),f.jsxs(Pa,{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:[f.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Xác nhận đăng xuất"}),f.jsx("p",{className:"text-gray-600 mb-6",children:"Bạn có chắc chắn muốn đăng xuất khỏi SharePoint?"}),f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx($e,{variant:"outline",onClick:()=>gi(!1),children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>{Qg(),gi(!1)},children:"Đăng xuất"})]})]})]})]}),f.jsx(Tr,{open:!!$g,onOpenChange:S=>{S||(td(!1),rd([]),ed(""))},children:f.jsxs(or,{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:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:f.jsxs("h3",{className:"font-medium mb-2",children:["Danh sách flows đang sử dụng dữ liệu từ folder(",f.jsx("span",{className:"font-bold",children:Vi}),"):"," "]})}),f.jsx(ci,{className:"s3-explr-dialog-description",children:lc?f.jsxs("div",{className:"flex items-center justify-center py-4",children:[f.jsx(zt,{className:"h-6 w-6 animate-spin"}),f.jsx("span",{className:"ml-2",children:"Đang tải thông tin flows..."})]}):f.jsx("div",{children:hi&&Array.isArray(hi)&&hi.length>0?f.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:f.jsxs("table",{className:"w-full border-collapse",children:[f.jsx("thead",{children:f.jsxs("tr",{className:"bg-gray-100",children:[f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Tên Flow"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"KnowledgeBase Id"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Loại"}),f.jsx("th",{className:"border border-gray-300 px-4 py-2 text-left",children:"Ngày tạo"})]})}),f.jsx("tbody",{children:hi.map((S,P)=>f.jsxs("tr",{className:P%2===0?"bg-white":"bg-gray-50",children:[f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.name}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.KnowledgeBaseId}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.type==="MULTIAGENT"?"Agent Flow":"Chat Flow"}),f.jsx("td",{className:"border border-gray-300 px-4 py-2",children:S.createdDate?new Date(S.createdDate).toLocaleString("vi-VN"):"N/A"})]},P))})]})}):f.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"})})})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>xd(ne),disabled:Dn,className:"s3-explr-confirm-delete-btn",children:Dn?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),f.jsx(Tr,{open:!!ne,onOpenChange:S=>!S&&W(null),children:f.jsxs(or,{className:"s3-explr-dialog-content",children:[f.jsxs(ir,{className:"s3-explr-dialog-header",children:[f.jsx(ar,{className:"s3-explr-dialog-title",children:"Xác nhận xóa"}),f.jsxs(ci,{className:"s3-explr-dialog-description",children:["Bạn có chắc chắn muốn xóa ",ne==null?void 0:ne.name,"? Hành động này không thể hoàn tác."]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>W(null),className:"s3-explr-cancel-btn",children:"Hủy"}),f.jsx($e,{variant:"destructive",onClick:()=>xd(ne),disabled:Dn,className:"s3-explr-confirm-delete-btn",children:Dn?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang xóa..."]}):"Xóa"})]})]})}),f.jsx(Tr,{open:!!F,onOpenChange:S=>{S||(te(null),_e(null),Ie(""),st(""),Xt("rename"))},children:f.jsxs(or,{className:"s3-explr-dialog-content max-w-5xl w-[90%]",children:[f.jsx(ir,{className:"s3-explr-dialog-header",children:f.jsx(ar,{className:"s3-explr-dialog-title",children:F!=null&&F.isFolder?"Đổi tên thư mục":rc(F)?"Quản lý tập tin":"Đổi tên tập tin"})}),F&&f.jsxs(rD,{value:Rn,onValueChange:S=>Xt(S),children:[f.jsxs(zx,{"aria-checked":!rc(F),"aria-disabled":F.isFolder,className:"grid w-full grid-cols-3 aria-checked:grid-cols-2 aria-disabled:grid-cols-1",children:[f.jsx(Tu,{value:"rename",children:"Đổi tên"}),!F.isFolder&&f.jsxs(f.Fragment,{children:[rc(F)&&f.jsx(Tu,{value:"edit",children:"Sửa nội dung"}),f.jsx(Tu,{value:"edit-metadata",children:"Sửa metadata file"})]})]}),f.jsx(Su,{value:"rename",children:f.jsx("div",{className:"space-y-4 py-4 s3-explr-dialog-body",children:f.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1 s3-explr-input-group",children:[f.jsx(ko,{htmlFor:"newName",className:"s3-explr-label",children:"Tên mới"}),f.jsx(Qr,{id:"newName",value:Te,onChange:S=>Ie(S.target.value),placeholder:"Nhập tên mới",disabled:Fe,className:"s3-explr-input"})]})})}),!F.isFolder&&f.jsxs(f.Fragment,{children:[rc(F)&&f.jsx(Su,{value:"edit",children:f.jsx("div",{className:"space-y-4 py-4",children:Ct?f.jsx("div",{className:"flex items-center justify-center py-4",children:f.jsx(zt,{className:"h-6 w-6 animate-spin"})}):f.jsxs("div",{className:"h-[70dvh] min-h-[500px] overflow-hidden overflow-y-auto pb-3 px-1",children:[f.jsx(ko,{htmlFor:"content",className:"s3-explr-label",children:"Nội dung tập tin"}),f.jsx(qs,{id:"content",value:ye,onChange:S=>st(S.target.value),placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:ln})]})})}),f.jsx(Su,{value:"edit-metadata",children:f.jsx("div",{className:"space-y-4 py-4",children:Ct?f.jsx("div",{className:"flex items-center justify-center py-4",children:f.jsx(zt,{className:"h-6 w-6 animate-spin"})}):f.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(([S,P],z)=>f.jsxs("div",{className:"pb-3 flex flex-col gap-2",children:[f.jsxs(ko,{htmlFor:S,className:"s3-explr-label flex items-center gap-1",children:[YR[S]||S,Np(S)&&f.jsx(MR,{className:"h-[12px] w-[12px] text-red-500"})]}),JR(S)?f.jsx(qs,{id:S,value:typeof P=="string"?P:JSON.stringify(P),onChange:se=>{const pe={...xe,[S]:se.target.value};_e(pe)},placeholder:"Nhập nội dung tập tin",className:"min-h-[200px] font-mono",disabled:ln||Np(S)}):f.jsx(Qr,{id:S,value:typeof P=="string"?P:JSON.stringify(P),onChange:se=>{const pe={...xe,[S]:se.target.value};_e(pe)},placeholder:"Nhập nội dung",className:"s3-explr-input",disabled:ln||Np(S)})]},z))})})})]})]}),f.jsxs(Io,{className:"s3-explr-dialog-footer",children:[f.jsx($e,{variant:"outline",onClick:()=>{te(null),_e(null),Ie(""),st("")},className:"s3-explr-cancel-btn",children:"Hủy"}),Rn==="edit"?f.jsx($e,{onClick:()=>F&&am(F,ye),disabled:ln||Ct,className:"s3-explr-save-btn",children:ln?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):Rn==="edit-metadata"?f.jsx($e,{onClick:()=>xe&&typeof xe=="object"&&F&&sm(F),disabled:ln||Ct,className:"s3-explr-save-btn",children:ln?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang lưu..."]}):"Lưu thay đổi"}):f.jsx($e,{onClick:()=>{Te.trim()&&F&&ns(F,Te.trim())},disabled:Fe||!Te.trim()||Te.trim()===(F==null?void 0:F.name),className:"s3-explr-rename-btn",children:Fe?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin s3-explr-loader"}),"Đang đổi tên..."]}):"Đổi tên"})]})]})}),me&&Ee&&f.jsx(_H,{openDialogRename:Ee,setOpenDialogRename:Pe,apiBaseUrl:e,setFileToMove:fe,fileToMove:me,refreshFiles:rn,ignoreCache:Pn})]})]}),Yg&&f.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"}),f.jsx(xH,{onFilesSelected:(S,P)=>bc(S,w,P),children:f.jsx("div",{className:"rounded-md border s3-explr-table-container",children:f.jsxs(Cu,{className:"s3-explr-table",children:[f.jsx(bu,{className:"s3-explr-table-header",children:xc.getHeaderGroups().map(S=>f.jsx(Er,{className:"hover:bg-transparent s3-explr-header-row",children:S.headers.map(P=>f.jsx(Xr,{className:"s3-explr-header-cell",children:P.isPlaceholder?null:ql(P.column.columnDef.header,P.getContext())},P.id))},S.id))}),f.jsx(xu,{className:"s3-explr-table-body",children:xc.getRowModel().rows.length===0?f.jsx(Er,{className:"s3-explr-empty-row",children:f.jsx(Nn,{colSpan:os.length,className:"h-24 text-center s3-explr-empty-cell",children:m?f.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 "',m,'"']}):f.jsx("div",{className:"text-gray-500 s3-explr-empty-message",children:Fo?"Đ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"})})}):xc.getRowModel().rows.map(S=>f.jsx(Er,{className:"h-12 s3-explr-row",children:S.getVisibleCells().map(P=>f.jsx(Nn,{className:"align-middle s3-explr-cell",children:ql(P.column.columnDef.cell,P.getContext())},P.id))},S.id))})]})})}),m&&Xi!==0&&f.jsx(f.Fragment,{children:f.jsx(gu,{children:f.jsxs(mu,{children:[f.jsx(vu,{onClick:()=>Yn(S=>Math.max(S-1,1)),"aria-disabled":Ft===1,className:"cursor-pointer aria-disabled:pointer-events-none"}),Array.from({length:Math.ceil(Xi/20)},(S,P)=>{const z=P+1,se=Math.ceil(Xi/20);return se>7&&!(z===1||z===se||z>=Ft-1&&z<=Ft+1)?z===Ft-2&&Ft>4||z===Ft+2&&Ft<se-3?f.jsx(wu,{className:"pointer-events-none",children:"..."},P):null:f.jsx(Sr,{className:"cursor-pointer",children:f.jsx(Fa,{isActive:Ft===z,onClick:()=>Yn(z),className:`${Ft===z?"bg-blue-500 text-white":"bg-white text-black"} hover:bg-blue-100`,children:z})},P)}),f.jsx(Sr,{children:f.jsx(yu,{onClick:()=>Yn(S=>Math.min(S+1,Math.ceil(Xi/20))),"aria-disabled":Ft===Math.ceil(Xi/20),className:"cursor-pointer aria-disabled:pointer-events-none"})})]})})}),o&&a&&f.jsxs("div",{className:"flex justify-between items-center mt-4 s3-explr-selector-footer",children:[f.jsx("div",{className:"text-sm text-gray-500 s3-explr-selection-count",children:Sd()}),f.jsx($e,{variant:"default",onClick:()=>a(ho()),disabled:v.size===0,className:"s3-explr-ok-btn",children:"OK"})]})]})}),RH=t=>f.jsx(tP,{clientId:SH,children:f.jsx(PH,{...t})});var oc=t=>t.type==="checkbox",Bi=t=>t instanceof Date,xn=t=>t==null;const WT=t=>typeof t=="object";var jt=t=>!xn(t)&&!Array.isArray(t)&&WT(t)&&!Bi(t),MH=t=>jt(t)&&t.target?oc(t.target)?t.target.checked:t.target.value:t,DH=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,LH=(t,e)=>t.has(DH(e)),FH=t=>{const e=t.constructor&&t.constructor.prototype;return jt(e)&&e.hasOwnProperty("isPrototypeOf")},Rg=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mn(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(!(Rg&&(t instanceof Blob||r))&&(n||jt(t)))if(e=n?[]:{},!n&&!FH(t))e=t;else for(const o in t)t.hasOwnProperty(o)&&(e[o]=mn(t[o]));else return t;return e}var Wu=t=>Array.isArray(t)?t.filter(Boolean):[],Jt=t=>t===void 0,Re=(t,e,n)=>{if(!e||!jt(t))return n;const r=Wu(e.split(/[,[\].]+?/)).reduce((o,a)=>xn(o)?o:o[a],t);return Jt(r)||r===t?Jt(t[e])?n:t[e]:r},ao=t=>typeof t=="boolean",Mg=t=>/^\w*$/.test(t),YT=t=>Wu(t.replace(/["|']|\]/g,"").split(/\.|\[/)),Dt=(t,e,n)=>{let r=-1;const o=Mg(e)?[e]:YT(e),a=o.length,c=a-1;for(;++r<a;){const l=o[r];let d=n;if(r!==c){const h=t[l];d=jt(h)||Array.isArray(h)?h:isNaN(+o[r+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;t[l]=d,t=t[l]}};const JT={BLUR:"blur",FOCUS_OUT:"focusout"},Or={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Ro={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};M.createContext(null);var HH=(t,e,n,r=!0)=>{const o={defaultValues:e._defaultValues};for(const a in t)Object.defineProperty(o,a,{get:()=>{const c=a;return e._proxyFormState[c]!==Or.all&&(e._proxyFormState[c]=!r||Or.all),t[c]}});return o};const UH=typeof window<"u"?_.useLayoutEffect:_.useEffect;var so=t=>typeof t=="string",$H=(t,e,n,r,o)=>so(t)?(r&&e.watch.add(t),Re(n,t,o)):Array.isArray(t)?t.map(a=>(r&&e.watch.add(a),Re(n,a))):(r&&(e.watchAll=!0),n),BH=(t,e,n,r,o)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[r]:o||!0}}:{},ic=t=>Array.isArray(t)?t:[t],QT=()=>{let t=[];return{get observers(){return t},next:o=>{for(const a of t)a.next&&a.next(o)},subscribe:o=>(t.push(o),{unsubscribe:()=>{t=t.filter(a=>a!==o)}}),unsubscribe:()=>{t=[]}}},Dg=t=>xn(t)||!WT(t);function di(t,e){if(Dg(t)||Dg(e))return t===e;if(Bi(t)&&Bi(e))return t.getTime()===e.getTime();const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const o of n){const a=t[o];if(!r.includes(o))return!1;if(o!=="ref"){const c=e[o];if(Bi(a)&&Bi(c)||jt(a)&&jt(c)||Array.isArray(a)&&Array.isArray(c)?!di(a,c):a!==c)return!1}}return!0}var _n=t=>jt(t)&&!Object.keys(t).length,Lg=t=>t.type==="file",Nr=t=>typeof t=="function",Yu=t=>{if(!Rg)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},XT=t=>t.type==="select-multiple",Fg=t=>t.type==="radio",zH=t=>Fg(t)||oc(t),Hg=t=>Yu(t)&&t.isConnected;function KH(t,e){const n=e.slice(0,-1).length;let r=0;for(;r<n;)t=Jt(t)?r++:t[e[r++]];return t}function VH(t){for(const e in t)if(t.hasOwnProperty(e)&&!Jt(t[e]))return!1;return!0}function Qt(t,e){const n=Array.isArray(e)?e:Mg(e)?[e]:YT(e),r=n.length===1?t:KH(t,n),o=n.length-1,a=n[o];return r&&delete r[a],o!==0&&(jt(r)&&_n(r)||Array.isArray(r)&&VH(r))&&Qt(t,n.slice(0,-1)),t}var ZT=t=>{for(const e in t)if(Nr(t[e]))return!0;return!1};function Ju(t,e={}){const n=Array.isArray(t);if(jt(t)||n)for(const r in t)Array.isArray(t[r])||jt(t[r])&&!ZT(t[r])?(e[r]=Array.isArray(t[r])?[]:{},Ju(t[r],e[r])):xn(t[r])||(e[r]=!0);return e}function eS(t,e,n){const r=Array.isArray(t);if(jt(t)||r)for(const o in t)Array.isArray(t[o])||jt(t[o])&&!ZT(t[o])?Jt(e)||Dg(n[o])?n[o]=Array.isArray(t[o])?Ju(t[o],[]):{...Ju(t[o])}:eS(t[o],xn(e)?{}:e[o],n[o]):n[o]=!di(t[o],e[o]);return n}var ac=(t,e)=>eS(t,e,Ju(e));const tS={value:!1,isValid:!1},nS={value:!0,isValid:!0};var rS=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&&!Jt(t[0].attributes.value)?Jt(t[0].value)||t[0].value===""?nS:{value:t[0].value,isValid:!0}:nS:tS}return tS},oS=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:r})=>Jt(t)?t:e?t===""?NaN:t&&+t:n&&so(t)?new Date(t):r?r(t):t;const iS={isValid:!1,value:null};var aS=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,iS):iS;function sS(t){const e=t.ref;return Lg(e)?e.files:Fg(e)?aS(t.refs).value:XT(e)?[...e.selectedOptions].map(({value:n})=>n):oc(e)?rS(t.refs).value:oS(Jt(e.value)?t.ref.value:e.value,t)}var GH=(t,e,n,r)=>{const o={};for(const a of t){const c=Re(e,a);c&&Dt(o,a,c._f)}return{criteriaMode:n,names:[...t],fields:o,shouldUseNativeValidation:r}},Qu=t=>t instanceof RegExp,sc=t=>Jt(t)?t:Qu(t)?t.source:jt(t)?Qu(t.value)?t.value.source:t.value:t,cS=t=>({isOnSubmit:!t||t===Or.onSubmit,isOnBlur:t===Or.onBlur,isOnChange:t===Or.onChange,isOnAll:t===Or.all,isOnTouch:t===Or.onTouched});const lS="AsyncFunction";var jH=t=>!!t&&!!t.validate&&!!(Nr(t.validate)&&t.validate.constructor.name===lS||jt(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===lS)),qH=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate),uS=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(r=>t.startsWith(r)&&/^\.\w+/.test(t.slice(r.length))));const cc=(t,e,n,r)=>{for(const o of n||Object.keys(t)){const a=Re(t,o);if(a){const{_f:c,...l}=a;if(c){if(c.refs&&c.refs[0]&&e(c.refs[0],o)&&!r)return!0;if(c.ref&&e(c.ref,c.name)&&!r)return!0;if(cc(l,e))break}else if(jt(l)&&cc(l,e))break}}};function dS(t,e,n){const r=Re(t,n);if(r||Mg(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const a=o.join("."),c=Re(e,a),l=Re(t,a);if(c&&!Array.isArray(c)&&n!==a)return{name:n};if(l&&l.type)return{name:a,error:l};o.pop()}return{name:n}}var WH=(t,e,n,r)=>{n(t);const{name:o,...a}=t;return _n(a)||Object.keys(a).length>=Object.keys(e).length||Object.keys(a).find(c=>e[c]===(!r||Or.all))},YH=(t,e,n)=>!t||!e||t===e||ic(t).some(r=>r&&(n?r===e:r.startsWith(e)||e.startsWith(r))),JH=(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,QH=(t,e)=>!Wu(Re(t,e)).length&&Qt(t,e),XH=(t,e,n)=>{const r=ic(Re(t,n));return Dt(r,"root",e[n]),Dt(t,n,r),t},Xu=t=>so(t);function fS(t,e,n="validate"){if(Xu(t)||Array.isArray(t)&&t.every(Xu)||ao(t)&&!t)return{type:n,message:Xu(t)?t:"",ref:e}}var Ga=t=>jt(t)&&!Qu(t)?t:{value:t,message:""},hS=async(t,e,n,r,o,a)=>{const{ref:c,refs:l,required:d,maxLength:h,minLength:p,min:m,max:y,pattern:v,validate:b,name:w,valueAsNumber:x,mount:I}=t._f,k=Re(n,w);if(!I||e.has(w))return{};const O=l?l[0]:c,D=fe=>{o&&O.reportValidity&&(O.setCustomValidity(ao(fe)?"":fe||""),O.reportValidity())},E={},B=Fg(c),j=oc(c),q=B||j,ne=(x||Lg(c))&&Jt(c.value)&&Jt(k)||Yu(c)&&c.value===""||k===""||Array.isArray(k)&&!k.length,W=BH.bind(null,w,r,E),me=(fe,we,G,X=Ro.maxLength,Y=Ro.minLength)=>{const ie=fe?we:G;E[w]={type:fe?X:Y,message:ie,ref:c,...W(fe?X:Y,ie)}};if(a?!Array.isArray(k)||!k.length:d&&(!q&&(ne||xn(k))||ao(k)&&!k||j&&!rS(l).isValid||B&&!aS(l).isValid)){const{value:fe,message:we}=Xu(d)?{value:!!d,message:d}:Ga(d);if(fe&&(E[w]={type:Ro.required,message:we,ref:O,...W(Ro.required,we)},!r))return D(we),E}if(!ne&&(!xn(m)||!xn(y))){let fe,we;const G=Ga(y),X=Ga(m);if(!xn(k)&&!isNaN(k)){const Y=c.valueAsNumber||k&&+k;xn(G.value)||(fe=Y>G.value),xn(X.value)||(we=Y<X.value)}else{const Y=c.valueAsDate||new Date(k),ie=F=>new Date(new Date().toDateString()+" "+F),Z=c.type=="time",J=c.type=="week";so(G.value)&&k&&(fe=Z?ie(k)>ie(G.value):J?k>G.value:Y>new Date(G.value)),so(X.value)&&k&&(we=Z?ie(k)<ie(X.value):J?k<X.value:Y<new Date(X.value))}if((fe||we)&&(me(!!fe,G.message,X.message,Ro.max,Ro.min),!r))return D(E[w].message),E}if((h||p)&&!ne&&(so(k)||a&&Array.isArray(k))){const fe=Ga(h),we=Ga(p),G=!xn(fe.value)&&k.length>+fe.value,X=!xn(we.value)&&k.length<+we.value;if((G||X)&&(me(G,fe.message,we.message),!r))return D(E[w].message),E}if(v&&!ne&&so(k)){const{value:fe,message:we}=Ga(v);if(Qu(fe)&&!k.match(fe)&&(E[w]={type:Ro.pattern,message:we,ref:c,...W(Ro.pattern,we)},!r))return D(we),E}if(b){if(Nr(b)){const fe=await b(k,n),we=fS(fe,O);if(we&&(E[w]={...we,...W(Ro.validate,we.message)},!r))return D(we.message),E}else if(jt(b)){let fe={};for(const we in b){if(!_n(fe)&&!r)break;const G=fS(await b[we](k,n),O,we);G&&(fe={...G,...W(we,G.message)},D(G.message),r&&(E[w]=fe))}if(!_n(fe)&&(E[w]={ref:O,...fe},!r))return E}}return D(!0),E};const ZH={mode:Or.onSubmit,reValidateMode:Or.onChange,shouldFocusError:!0};function eU(t={}){let e={...ZH,...t},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:Nr(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=jt(e.defaultValues)||jt(e.values)?mn(e.defaultValues||e.values)||{}:{},a=e.shouldUnregister?{}:mn(o),c={action:!1,mount:!1,watch:!1},l={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},d,h=0;const p={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let m={...p};const y={array:QT(),state:QT()},v=cS(e.mode),b=cS(e.reValidateMode),w=e.criteriaMode===Or.all,x=R=>V=>{clearTimeout(h),h=setTimeout(R,V)},I=async R=>{if(!e.disabled&&(p.isValid||m.isValid||R)){const V=e.resolver?_n((await ne()).errors):await me(r,!0);V!==n.isValid&&y.state.next({isValid:V})}},k=(R,V)=>{!e.disabled&&(p.isValidating||p.validatingFields||m.isValidating||m.validatingFields)&&((R||Array.from(l.mount)).forEach(H=>{H&&(V?Dt(n.validatingFields,H,V):Qt(n.validatingFields,H))}),y.state.next({validatingFields:n.validatingFields,isValidating:!_n(n.validatingFields)}))},O=(R,V=[],H,re,he=!0,ue=!0)=>{if(re&&H&&!e.disabled){if(c.action=!0,ue&&Array.isArray(Re(r,R))){const be=H(Re(r,R),re.argA,re.argB);he&&Dt(r,R,be)}if(ue&&Array.isArray(Re(n.errors,R))){const be=H(Re(n.errors,R),re.argA,re.argB);he&&Dt(n.errors,R,be),QH(n.errors,R)}if((p.touchedFields||m.touchedFields)&&ue&&Array.isArray(Re(n.touchedFields,R))){const be=H(Re(n.touchedFields,R),re.argA,re.argB);he&&Dt(n.touchedFields,R,be)}(p.dirtyFields||m.dirtyFields)&&(n.dirtyFields=ac(o,a)),y.state.next({name:R,isDirty:we(R,V),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Dt(a,R,V)},D=(R,V)=>{Dt(n.errors,R,V),y.state.next({errors:n.errors})},E=R=>{n.errors=R,y.state.next({errors:n.errors,isValid:!1})},B=(R,V,H,re)=>{const he=Re(r,R);if(he){const ue=Re(a,R,Jt(H)?Re(o,R):H);Jt(ue)||re&&re.defaultChecked||V?Dt(a,R,V?ue:sS(he._f)):Y(R,ue),c.mount&&I()}},j=(R,V,H,re,he)=>{let ue=!1,be=!1;const qe={name:R};if(!e.disabled){if(!H||re){(p.isDirty||m.isDirty)&&(be=n.isDirty,n.isDirty=qe.isDirty=we(),ue=be!==qe.isDirty);const pt=di(Re(o,R),V);be=!!Re(n.dirtyFields,R),pt?Qt(n.dirtyFields,R):Dt(n.dirtyFields,R,!0),qe.dirtyFields=n.dirtyFields,ue=ue||(p.dirtyFields||m.dirtyFields)&&be!==!pt}if(H){const pt=Re(n.touchedFields,R);pt||(Dt(n.touchedFields,R,H),qe.touchedFields=n.touchedFields,ue=ue||(p.touchedFields||m.touchedFields)&&pt!==H)}ue&&he&&y.state.next(qe)}return ue?qe:{}},q=(R,V,H,re)=>{const he=Re(n.errors,R),ue=(p.isValid||m.isValid)&&ao(V)&&n.isValid!==V;if(e.delayError&&H?(d=x(()=>D(R,H)),d(e.delayError)):(clearTimeout(h),d=null,H?Dt(n.errors,R,H):Qt(n.errors,R)),(H?!di(he,H):he)||!_n(re)||ue){const be={...re,...ue&&ao(V)?{isValid:V}:{},errors:n.errors,name:R};n={...n,...be},y.state.next(be)}},ne=async R=>{k(R,!0);const V=await e.resolver(a,e.context,GH(R||l.mount,r,e.criteriaMode,e.shouldUseNativeValidation));return k(R),V},W=async R=>{const{errors:V}=await ne(R);if(R)for(const H of R){const re=Re(V,H);re?Dt(n.errors,H,re):Qt(n.errors,H)}else n.errors=V;return V},me=async(R,V,H={valid:!0})=>{for(const re in R){const he=R[re];if(he){const{_f:ue,...be}=he;if(ue){const qe=l.array.has(ue.name),pt=he._f&&jH(he._f);pt&&p.validatingFields&&k([re],!0);const ft=await hS(he,l.disabled,a,w,e.shouldUseNativeValidation&&!V,qe);if(pt&&p.validatingFields&&k([re]),ft[ue.name]&&(H.valid=!1,V))break;!V&&(Re(ft,ue.name)?qe?XH(n.errors,ft,ue.name):Dt(n.errors,ue.name,ft[ue.name]):Qt(n.errors,ue.name))}!_n(be)&&await me(be,V,H)}}return H.valid},fe=()=>{for(const R of l.unMount){const V=Re(r,R);V&&(V._f.refs?V._f.refs.every(H=>!Hg(H)):!Hg(V._f.ref))&&Me(R)}l.unMount=new Set},we=(R,V)=>!e.disabled&&(R&&V&&Dt(a,R,V),!di(xe(),o)),G=(R,V,H)=>$H(R,l,{...c.mount?a:Jt(V)?o:so(R)?{[R]:V}:V},H,V),X=R=>Wu(Re(c.mount?a:o,R,e.shouldUnregister?Re(o,R,[]):[])),Y=(R,V,H={})=>{const re=Re(r,R);let he=V;if(re){const ue=re._f;ue&&(!ue.disabled&&Dt(a,R,oS(V,ue)),he=Yu(ue.ref)&&xn(V)?"":V,XT(ue.ref)?[...ue.ref.options].forEach(be=>be.selected=he.includes(be.value)):ue.refs?oc(ue.ref)?ue.refs.length>1?ue.refs.forEach(be=>(!be.defaultChecked||!be.disabled)&&(be.checked=Array.isArray(he)?!!he.find(qe=>qe===be.value):he===be.value)):ue.refs[0]&&(ue.refs[0].checked=!!he):ue.refs.forEach(be=>be.checked=be.value===he):Lg(ue.ref)?ue.ref.value="":(ue.ref.value=he,ue.ref.type||y.state.next({name:R,values:mn(a)})))}(H.shouldDirty||H.shouldTouch)&&j(R,he,H.shouldTouch,H.shouldDirty,!0),H.shouldValidate&&te(R)},ie=(R,V,H)=>{for(const re in V){const he=V[re],ue=`${R}.${re}`,be=Re(r,ue);(l.array.has(R)||jt(he)||be&&!be._f)&&!Bi(he)?ie(ue,he,H):Y(ue,he,H)}},Z=(R,V,H={})=>{const re=Re(r,R),he=l.array.has(R),ue=mn(V);Dt(a,R,ue),he?(y.array.next({name:R,values:mn(a)}),(p.isDirty||p.dirtyFields||m.isDirty||m.dirtyFields)&&H.shouldDirty&&y.state.next({name:R,dirtyFields:ac(o,a),isDirty:we(R,ue)})):re&&!re._f&&!xn(ue)?ie(R,ue,H):Y(R,ue,H),uS(R,l)&&y.state.next({...n}),y.state.next({name:c.mount?R:void 0,values:mn(a)})},J=async R=>{c.mount=!0;const V=R.target;let H=V.name,re=!0;const he=Re(r,H),ue=be=>{re=Number.isNaN(be)||Bi(be)&&isNaN(be.getTime())||di(be,Re(a,H,be))};if(he){let be,qe;const pt=V.type?sS(he._f):MH(R),ft=R.type===JT.BLUR||R.type===JT.FOCUS_OUT,Dn=!qH(he._f)&&!e.resolver&&!Re(n.errors,H)&&!he._f.deps||JH(ft,Re(n.touchedFields,H),n.isSubmitted,b,v),Wn=uS(H,l,ft);Dt(a,H,pt),ft?(he._f.onBlur&&he._f.onBlur(R),d&&d(0)):he._f.onChange&&he._f.onChange(R);const Ft=j(H,pt,ft),Yn=!_n(Ft)||Wn;if(!ft&&y.state.next({name:H,type:R.type,values:mn(a)}),Dn)return(p.isValid||m.isValid)&&(e.mode==="onBlur"?ft&&I():ft||I()),Yn&&y.state.next({name:H,...Wn?{}:Ft});if(!ft&&Wn&&y.state.next({...n}),e.resolver){const{errors:Jn}=await ne([H]);if(ue(pt),re){const Qn=dS(n.errors,r,H),He=dS(Jn,r,Qn.name||H);be=He.error,H=He.name,qe=_n(Jn)}}else k([H],!0),be=(await hS(he,l.disabled,a,w,e.shouldUseNativeValidation))[H],k([H]),ue(pt),re&&(be?qe=!1:(p.isValid||m.isValid)&&(qe=await me(r,!0)));re&&(he._f.deps&&te(he._f.deps),q(H,qe,be,Ft))}},F=(R,V)=>{if(Re(n.errors,V)&&R.focus)return R.focus(),1},te=async(R,V={})=>{let H,re;const he=ic(R);if(e.resolver){const ue=await W(Jt(R)?R:he);H=_n(ue),re=R?!he.some(be=>Re(ue,be)):H}else R?(re=(await Promise.all(he.map(async ue=>{const be=Re(r,ue);return await me(be&&be._f?{[ue]:be}:be)}))).every(Boolean),!(!re&&!n.isValid)&&I()):re=H=await me(r);return y.state.next({...!so(R)||(p.isValid||m.isValid)&&H!==n.isValid?{}:{name:R},...e.resolver||!R?{isValid:H}:{},errors:n.errors}),V.shouldFocus&&!re&&cc(r,F,R?he:l.mount),re},xe=R=>{const V={...c.mount?a:o};return Jt(R)?V:so(R)?Re(V,R):R.map(H=>Re(V,H))},_e=(R,V)=>({invalid:!!Re((V||n).errors,R),isDirty:!!Re((V||n).dirtyFields,R),error:Re((V||n).errors,R),isValidating:!!Re(n.validatingFields,R),isTouched:!!Re((V||n).touchedFields,R)}),Te=R=>{R&&ic(R).forEach(V=>Qt(n.errors,V)),y.state.next({errors:R?n.errors:{}})},Ie=(R,V,H)=>{const re=(Re(r,R,{_f:{}})._f||{}).ref,he=Re(n.errors,R)||{},{ref:ue,message:be,type:qe,...pt}=he;Dt(n.errors,R,{...pt,...V,ref:re}),y.state.next({name:R,errors:n.errors,isValid:!1}),H&&H.shouldFocus&&re&&re.focus&&re.focus()},Ee=(R,V)=>Nr(R)?y.state.subscribe({next:H=>R(G(void 0,V),H)}):G(R,V,!0),Pe=R=>y.state.subscribe({next:V=>{YH(R.name,V.name,R.exact)&&WH(V,R.formState||p,Xt,R.reRenderRoot)&&R.callback({values:{...a},...n,...V})}}).unsubscribe,Fe=R=>(c.mount=!0,m={...m,...R.formState},Pe({...R,formState:m})),Me=(R,V={})=>{for(const H of R?ic(R):l.mount)l.mount.delete(H),l.array.delete(H),V.keepValue||(Qt(r,H),Qt(a,H)),!V.keepError&&Qt(n.errors,H),!V.keepDirty&&Qt(n.dirtyFields,H),!V.keepTouched&&Qt(n.touchedFields,H),!V.keepIsValidating&&Qt(n.validatingFields,H),!e.shouldUnregister&&!V.keepDefaultValue&&Qt(o,H);y.state.next({values:mn(a)}),y.state.next({...n,...V.keepDirty?{isDirty:we()}:{}}),!V.keepIsValid&&I()},Oe=({disabled:R,name:V})=>{(ao(R)&&c.mount||R||l.disabled.has(V))&&(R?l.disabled.add(V):l.disabled.delete(V))},Je=(R,V={})=>{let H=Re(r,R);const re=ao(V.disabled)||ao(e.disabled);return Dt(r,R,{...H||{},_f:{...H&&H._f?H._f:{ref:{name:R}},name:R,mount:!0,...V}}),l.mount.add(R),H?Oe({disabled:ao(V.disabled)?V.disabled:e.disabled,name:R}):B(R,!0,V.value),{...re?{disabled:V.disabled||e.disabled}:{},...e.progressive?{required:!!V.required,min:sc(V.min),max:sc(V.max),minLength:sc(V.minLength),maxLength:sc(V.maxLength),pattern:sc(V.pattern)}:{},name:R,onChange:J,onBlur:J,ref:he=>{if(he){Je(R,V),H=Re(r,R);const ue=Jt(he.value)&&he.querySelectorAll&&he.querySelectorAll("input,select,textarea")[0]||he,be=zH(ue),qe=H._f.refs||[];if(be?qe.find(pt=>pt===ue):ue===H._f.ref)return;Dt(r,R,{_f:{...H._f,...be?{refs:[...qe.filter(Hg),ue,...Array.isArray(Re(o,R))?[{}]:[]],ref:{type:ue.type,name:R}}:{ref:ue}}}),B(R,!1,void 0,ue)}else H=Re(r,R,{}),H._f&&(H._f.mount=!1),(e.shouldUnregister||V.shouldUnregister)&&!(LH(l.array,R)&&c.action)&&l.unMount.add(R)}}},ye=()=>e.shouldFocusError&&cc(r,F,l.mount),st=R=>{ao(R)&&(y.state.next({disabled:R}),cc(r,(V,H)=>{const re=Re(r,H);re&&(V.disabled=re._f.disabled||R,Array.isArray(re._f.refs)&&re._f.refs.forEach(he=>{he.disabled=re._f.disabled||R}))},0,!1))},Ct=(R,V)=>async H=>{let re;H&&(H.preventDefault&&H.preventDefault(),H.persist&&H.persist());let he=mn(a);if(y.state.next({isSubmitting:!0}),e.resolver){const{errors:ue,values:be}=await ne();n.errors=ue,he=be}else await me(r);if(l.disabled.size)for(const ue of l.disabled)Dt(he,ue,void 0);if(Qt(n.errors,"root"),_n(n.errors)){y.state.next({errors:{}});try{await R(he,H)}catch(ue){re=ue}}else V&&await V({...n.errors},H),ye(),setTimeout(ye);if(y.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:_n(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},nn=(R,V={})=>{Re(r,R)&&(Jt(V.defaultValue)?Z(R,mn(Re(o,R))):(Z(R,V.defaultValue),Dt(o,R,mn(V.defaultValue))),V.keepTouched||Qt(n.touchedFields,R),V.keepDirty||(Qt(n.dirtyFields,R),n.isDirty=V.defaultValue?we(R,mn(Re(o,R))):we()),V.keepError||(Qt(n.errors,R),p.isValid&&I()),y.state.next({...n}))},ln=(R,V={})=>{const H=R?mn(R):o,re=mn(H),he=_n(R),ue=he?o:re;if(V.keepDefaultValues||(o=H),!V.keepValues){if(V.keepDirtyValues){const be=new Set([...l.mount,...Object.keys(ac(o,a))]);for(const qe of Array.from(be))Re(n.dirtyFields,qe)?Dt(ue,qe,Re(a,qe)):Z(qe,Re(ue,qe))}else{if(Rg&&Jt(R))for(const be of l.mount){const qe=Re(r,be);if(qe&&qe._f){const pt=Array.isArray(qe._f.refs)?qe._f.refs[0]:qe._f.ref;if(Yu(pt)){const ft=pt.closest("form");if(ft){ft.reset();break}}}}for(const be of l.mount)Z(be,Re(ue,be))}a=mn(ue),y.array.next({values:{...ue}}),y.state.next({values:{...ue}})}l={mount:V.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},c.mount=!p.isValid||!!V.keepIsValid||!!V.keepDirtyValues,c.watch=!!e.shouldUnregister,y.state.next({submitCount:V.keepSubmitCount?n.submitCount:0,isDirty:he?!1:V.keepDirty?n.isDirty:!!(V.keepDefaultValues&&!di(R,o)),isSubmitted:V.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:he?{}:V.keepDirtyValues?V.keepDefaultValues&&a?ac(o,a):n.dirtyFields:V.keepDefaultValues&&R?ac(o,R):V.keepDirty?n.dirtyFields:{},touchedFields:V.keepTouched?n.touchedFields:{},errors:V.keepErrors?n.errors:{},isSubmitSuccessful:V.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Pt=(R,V)=>ln(Nr(R)?R(a):R,V),Rn=(R,V={})=>{const H=Re(r,R),re=H&&H._f;if(re){const he=re.refs?re.refs[0]:re.ref;he.focus&&(he.focus(),V.shouldSelect&&Nr(he.select)&&he.select())}},Xt=R=>{n={...n,...R}},$t={control:{register:Je,unregister:Me,getFieldState:_e,handleSubmit:Ct,setError:Ie,_subscribe:Pe,_runSchema:ne,_getWatch:G,_getDirty:we,_setValid:I,_setFieldArray:O,_setDisabledField:Oe,_setErrors:E,_getFieldArray:X,_reset:ln,_resetDefaultValues:()=>Nr(e.defaultValues)&&e.defaultValues().then(R=>{Pt(R,e.resetOptions),y.state.next({isLoading:!1})}),_removeUnmounted:fe,_disableForm:st,_subjects:y,_proxyFormState:p,get _fields(){return r},get _formValues(){return a},get _state(){return c},set _state(R){c=R},get _defaultValues(){return o},get _names(){return l},set _names(R){l=R},get _formState(){return n},get _options(){return e},set _options(R){e={...e,...R}}},subscribe:Fe,trigger:te,register:Je,handleSubmit:Ct,watch:Ee,setValue:Z,getValues:xe,reset:Pt,resetField:nn,clearErrors:Te,unregister:Me,setError:Ie,setFocus:Rn,getFieldState:_e};return{...$t,formControl:$t}}function tU(t={}){const e=M.useRef(void 0),n=M.useRef(void 0),[r,o]=M.useState({isDirty:!1,isValidating:!1,isLoading:Nr(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:Nr(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...t.formControl?t.formControl:eU(t),formState:r},t.formControl&&t.defaultValues&&!Nr(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions));const a=e.current.control;return a._options=t,UH(()=>{const c=a._subscribe({formState:a._proxyFormState,callback:()=>o({...a._formState}),reRenderRoot:!0});return o(l=>({...l,isReady:!0})),a._formState.isReady=!0,c},[a]),M.useEffect(()=>a._disableForm(t.disabled),[a,t.disabled]),M.useEffect(()=>{t.mode&&(a._options.mode=t.mode),t.reValidateMode&&(a._options.reValidateMode=t.reValidateMode),t.errors&&!_n(t.errors)&&a._setErrors(t.errors)},[a,t.errors,t.mode,t.reValidateMode]),M.useEffect(()=>{t.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,t.shouldUnregister]),M.useEffect(()=>{if(a._proxyFormState.isDirty){const c=a._getDirty();c!==r.isDirty&&a._subjects.state.next({isDirty:c})}},[a,r.isDirty]),M.useEffect(()=>{t.values&&!di(t.values,n.current)?(a._reset(t.values,a._options.resetOptions),n.current=t.values,o(c=>({...c}))):a._resetDefaultValues()},[a,t.values]),M.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),e.current.formState=HH(r,a),e.current}const pS=({className:t,children:e,content:n,side:r})=>{const[o,a]=M.useState(!1);return f.jsx(no,{delayDuration:0,children:f.jsxs(ro,{open:o,children:[f.jsx(oo,{asChild:!0,children:f.jsx("button",{type:"button",className:We("cursor-pointer",t),onClick:()=>a(!o),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onTouchStart:()=>a(!o),onKeyDown:c=>{c.preventDefault(),c.key==="Enter"&&a(!o)},children:e})}),f.jsx(kr,{side:r,className:n?"":"hidden",children:f.jsx("span",{className:"inline-block",children:n})})]})})},nU=(t,e)=>{const[n,r]=M.useState(t);return M.useEffect(()=>{const o=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(o)}},[t,e]),n},rU=({apiBaseUrl:t="http://localhost:3002"})=>{var B,j;const[e,n]=M.useState([]),[r,o]=M.useState(!1),[a,c]=M.useState([]),[l,d]=M.useState(1),[h,p]=M.useState(1),[m,y]=M.useState(null),[v,b]=M.useState(""),w=nU(v,500),x=q=>{const ne=q.match(/\d{6}/);if(!ne)return{month:"",year:""};const W=ne[0],me=W.substring(0,2),fe=W.substring(2);return{month:me,year:fe}},I=q=>q.map(W=>{let me=(W==null?void 0:W.month)||"",fe=(W==null?void 0:W.year)||"";if((!me||!fe)&&(W!=null&&W.file_name)){const we=x(W.file_name);me=me||we.month,fe=fe||we.year}return{id:W==null?void 0:W.id,prefix:(W==null?void 0:W.prefix)||"",model:(W==null?void 0:W.model)||"",fileName:(W==null?void 0:W.file_name)||"",code:(W==null?void 0:W.stock_id)||"",month:me,year:fe,content:(W==null?void 0:W.text_summary)||"",status:(W==null?void 0:W.status)||"",note:(W==null?void 0:W.note)||"",lastUpdate:W==null?void 0:W.updated_at,stock_id:W==null?void 0:W.stock_id}}),k=q=>{if(!(q!=null&&q.data))return[];const ne=I(q==null?void 0:q.data);n(ne),p(q.pagination.totalPages)},O=async(q=1,ne=15)=>{y(q),o(!0);try{const W=await Le.get(`${t}/api/latest-summaries`,{params:{page:q,limit:ne,search:v}});(W==null?void 0:W.status)===200?k(W.data):console.error(W)}catch(W){console.error("Error fetching data:",W)}finally{y(null),o(!1)}};M.useEffect(()=>{w&&d(1),O(l)},[l,w]);const D=M.useMemo(()=>[{id:"code",header:"Mã",accessorKey:"code",cell:({row:ne})=>f.jsx("span",{className:"flex flex-col",children:ne.original.code})},{id:"month",header:"Tháng",accessorKey:"month",cell:({row:ne})=>{const W=ne.original.month,me=ne.original.year;return f.jsx("span",{className:"flex flex-col",children:`${W.toString().padStart(2,"0")}/${me}`})}},{id:"content",header:"Nội dung",accessorKey:"content",cell:({row:ne})=>{const W=ne.getValue("content");return f.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:ne})=>{const me=ne.original.status!=="unpublish";return f.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0 text-[10px] font-bold ${me?"bg-green-50 text-green-700 ring-1 ring-inset ring-green-600/20":"bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/20"}`,children:me?"PUBLISHED":"UNPUBLISHED"})}},{id:"note",header:"Ghi chú",accessorKey:"note",cell:({row:ne})=>f.jsx(pS,{content:f.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:ne.original.note}),children:f.jsx("div",{className:"text-start truncate text-ellipsis overflow-hidden whitespace-nowrap max-w-[20dvw]",children:ne.original.note})})},{id:"last-update",header:"Cập nhật",accessorKey:"last-update",cell:({row:ne})=>{const W=new Date(ne.original.lastUpdate),me=W.getDate(),fe=W.getMonth()+1,we=`ngày ${me} tháng ${fe}`;return f.jsx("span",{className:"flex flex-col",children:we})}},{accessorKey:"actions",header:()=>f.jsx("div",{className:"font-medium text-right",children:"Hành động"}),cell:({row:ne})=>{const[W,me]=M.useState(!1),[fe,we]=M.useState(!1),[G,X]=M.useState(!1),{handleSubmit:Y,register:ie,reset:Z}=tU(),J=ne.original.id,F=ne.getValue("status"),te=ne.getValue("content"),[xe,_e]=M.useState(!1),Te=async()=>{try{_e(!0);const Ee=F==="unpublish"?"published":"unpublish",Pe=await Le.patch(`${t}/api/toggle-publish/${J}`,{id:J,typeAction:"update",status:F,idInput:J,stock_id:ne.original.stock_id,prefix:ne.original.prefix,model:ne.original.model,summary_result:ne.original.content,note:ne.original.note});Pe.status===200?n(Fe=>Fe.map(Me=>Me.id===J?{...Me,status:Ee}:Me)):console.error("Failed to toggle publish status:",Pe)}catch(Ee){console.error("Error toggling publish status:",Ee)}finally{_e(!1)}},Ie=async Ee=>{me(!0);try{const Pe=await Le.patch(`${t}/api/update-summary`,{note:Ee.note,text_summary:Ee.content,id:J});Pe.status===200?(await O(l),we(!1)):console.error("Failed to update summary:",Pe)}catch(Pe){console.error("Error updating summary:",Pe)}return me(!1)};return f.jsxs("div",{className:"flex items-center justify-end gap-2",children:[f.jsx($e,{variant:"outline",size:"sm",onClick:()=>X(!0),className:"px-2 py-0.5 h-7",children:f.jsx(PR,{className:"h-4 w-4"})}),f.jsx(Tr,{open:G,onOpenChange:X,children:f.jsxs(or,{className:"max-w-3xl max-h-[80vh]",children:[f.jsx(ir,{children:f.jsx(ar,{children:"Nội dung chi tiết"})}),f.jsx("div",{className:"mt-4 overflow-y-auto max-h-[60vh]",children:f.jsx("div",{className:"whitespace-pre-wrap text-[16px] leading-relaxed",children:te})})]})}),f.jsxs(Tr,{open:fe,onOpenChange:Ee=>{we(Ee),Ee?Z({content:ne.original.content,note:ne.original.note}):Z()},children:[f.jsx(Gs,{asChild:!0,children:f.jsx($e,{variant:"outline",size:"sm",onClick:()=>we(!0),className:"px-2 py-0.5 h-7",children:"Sửa"})}),f.jsx(or,{className:"rounded-lg sm:px-3 h-[calc(100dvh-200px)] min-w-[calc(100dvw-112px)]",children:f.jsxs(ir,{className:"flex flex-col gap-3",children:[f.jsx(ar,{className:"max-sm:hidden text-center",children:"Sửa summary"}),f.jsxs("form",{className:"flex flex-col gap-3 h-full justify-between",onSubmit:Y(Ie),children:[f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsxs("div",{className:"flex flex-col items-start",children:[f.jsx("span",{children:"Nội dung:"}),f.jsx(qs,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ne.original.answer||"",rows:10,...ie("content")})]}),f.jsxs("div",{className:"flex flex-col items-start",children:[f.jsx("span",{children:"Ghi chú:"}),f.jsx(qs,{placeholder:"Nội dung",className:"w-full input-scroll-bar",defaultValue:ne.original.note||"",rows:1,...ie("note")})]})]}),f.jsx("div",{className:"flex justify-end",children:f.jsx($e,{disabled:W,type:"submit",variant:"default",children:W?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):"Ok"})})]})]})})]}),f.jsx($e,{variant:"outline",size:"sm",onClick:Te,disabled:xe,className:"w-[70px] px-2 py-0.5 h-7",children:xe?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):F==="unpublish"?"Publish":"Unpublish"})]})}}],[]),E=tb({data:e,columns:D,state:{columnFilters:a},enableRowSelection:!0,onColumnFiltersChange:c,getFilteredRowModel:LP(),getCoreRowModel:eb()});return f.jsxs("div",{className:"space-y-4 s3-explr-container",children:[f.jsx("div",{className:"flex items-center space-x-4 s3-explr-toolbar",children:f.jsxs("div",{className:"relative max-w-sm",children:[f.jsx(Qr,{placeholder:"Tìm kiếm theo mã...",value:v,onChange:q=>b(q.target.value),className:"pr-8"}),v&&f.jsx($e,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>b(""),children:f.jsx(Ip,{className:"h-4 w-4"})})]})}),f.jsx("div",{className:"rounded-md border s3-explr-table-container",children:f.jsxs(Cu,{className:"s3-explr-table",children:[f.jsx(bu,{className:"s3-explr-table-header",children:E.getHeaderGroups().map(q=>f.jsx(Er,{className:"hover:bg-transparent s3-explr-header-row",children:q.headers.map(ne=>f.jsx(Xr,{className:"s3-explr-header-cell",children:ne.isPlaceholder?null:ql(ne.column.columnDef.header,ne.getContext())},ne.id))},q.id))}),f.jsx(xu,{className:"s3-explr-table-body",children:r?f.jsx(Er,{children:f.jsx(Nn,{colSpan:D.length,className:"h-24 text-center",children:"Đang tải dữ liệu..."})}):(B=E.getRowModel().rows)!=null&&B.length?(j=E.getRowModel().rows)==null?void 0:j.map(q=>f.jsx(Er,{className:"h-12 s3-explr-row",children:q.getVisibleCells().map(ne=>f.jsx(Nn,{className:"align-middle s3-explr-cell",children:ql(ne.column.columnDef.cell,ne.getContext())},ne.id))},q.id)):f.jsx(Er,{children:f.jsx(Nn,{colSpan:D.length,className:"h-24 text-center",children:"Không có kết quả."})})})]})}),f.jsx("div",{className:"mt-4",children:f.jsx(gu,{children:f.jsxs(mu,{children:[f.jsx(Sr,{children:f.jsx(vu,{onClick:()=>d(q=>Math.max(1,q-1)),className:l===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:h},(q,ne)=>ne+1).filter(q=>q===1||q===h||Math.abs(q-l)<=1).map((q,ne,W)=>f.jsxs(f.Fragment,{children:[ne>0&&W[ne-1]!==q-1&&f.jsx(Sr,{children:f.jsx(wu,{})},q+"..."),f.jsx(Sr,{children:f.jsx(Fa,{onClick:()=>d(q),isActive:l===q,className:`cursor-pointer ${r?"pointer-events-none":""}`,children:m===q?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):q})},q)]})),f.jsx(Sr,{children:f.jsx(yu,{onClick:()=>d(q=>Math.min(h,q+1)),className:l===h||m!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})},gS=10,oU=M.memo(({apiBaseUrl:t="http://localhost:3002"})=>{const[e,n]=M.useState(1),[r,o]=M.useState([]),[a,c]=M.useState({total:0,page:1,limit:gS,totalPages:1}),[l,d]=M.useState(!0),[h,p]=M.useState(null),[m,y]=M.useState(new Set),{toast:v}=Ou(),[b,w]=M.useState(!1),x=async E=>{try{p(E);const B=await Le.get(`${t}/api/jobs`,{params:{page:E.toString(),limit:gS.toString()}});o(B.data.data),c(B.data.pagination)}catch{v({variant:"destructive",title:"Error",description:"Failed to fetch jobs. Please try again."})}finally{p(null),d(!1)}};M.useEffect(()=>{x(e)},[e,t]);const I=async E=>{y(B=>new Set(B).add(E.toString()));try{await Le.post(`${t}/api/retry-job`,{jobId:E}),v({title:"Job Restarted",description:`Job ${E} has been successfully restarted.`}),x(e)}catch{v({variant:"destructive",title:"Retry Failed",description:`Failed to restart job ${E}. Please try again.`})}finally{y(B=>{const j=new Set(B);return j.delete(E.toString()),j})}},k=async()=>{w(!0),n(1),await x(1),w(!1)},O=E=>new Date(E).toLocaleString(),D=E=>{if(E=parseFloat(E),E<60)return`${E.toFixed(2)}s`;const B=Math.floor(E/60),j=(E%60).toFixed(0);return`${B}m ${j}s`};return f.jsxs("div",{children:[f.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[f.jsx(IR,{className:"w-8 h-8 text-primary"}),f.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Job Management"}),f.jsx($e,{variant:"outline",size:"icon",onClick:k,disabled:b||l,className:"ml-2",children:f.jsx(DR,{className:`h-4 w-4 ${b?"animate-spin":""}`})})]}),f.jsx("div",{className:"rounded-md border",children:f.jsxs(Cu,{children:[f.jsx(bu,{children:f.jsxs(Er,{children:[f.jsx(Xr,{children:"ID"}),f.jsx(Xr,{children:"Tên Công Việc"}),f.jsx(Xr,{children:"Thời Gian Bắt Đầu"}),f.jsx(Xr,{children:"Thời Gian Cập Nhật"}),f.jsx(Xr,{children:"Thời Gian Thực Thi"}),f.jsx(Xr,{children:"Trạng Thái"}),f.jsx(Xr,{children:"Thao Tác"})]})}),f.jsx(xu,{children:l&&r.length===0?f.jsx(Er,{children:f.jsx(Nn,{colSpan:7,className:"text-center py-4",children:f.jsx(zt,{className:"w-6 h-6 animate-spin mx-auto"})})}):r.map(E=>{var B,j;return f.jsxs(Er,{children:[f.jsx(Nn,{className:"!w-[100px]",children:E.id}),f.jsx(Nn,{className:"font-medium",children:(B=E.job_name)==null?void 0:B.replace("Upload file","Summary")}),f.jsx(Nn,{className:"!w-[200px]",children:O(E.created_at)}),f.jsx(Nn,{className:"!w-[200px]",children:O(E.updated_at)}),f.jsx(Nn,{className:"!w-[150px]",children:D(E.execution_time_seconds)}),f.jsx(Nn,{className:"!w-[200px]",children:f.jsx(pS,{content:E.status==="fail"&&E.error?f.jsx("div",{className:"font-medium text-[16px] max-w-[90dvw]",children:E.error}):null,children:f.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]
208
208
  ${E.status==="done"?"bg-green-100 text-green-800":E.status==="fail"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:E.status==="fail"?"FAILED":(j=E.status)==null?void 0:j.toUpperCase()})})}),f.jsx(Nn,{className:"!w-[200px]",children:E.status==="fail"?f.jsx($e,{variant:"outline",size:"sm",onClick:()=>I(E.id),disabled:m.has(E.id.toString()),className:"h-[32px]",children:m.has(E.id.toString())?f.jsxs(f.Fragment,{children:[f.jsx(zt,{className:"mr-2 h-4 w-4 animate-spin"}),"Đang thử lại..."]}):"Thử Lại"}):f.jsx("div",{className:"h-[32px]"})})]},E.id)})})]})}),f.jsx("div",{className:"mt-4",children:f.jsx(gu,{children:f.jsxs(mu,{children:[f.jsx(Sr,{children:f.jsx(vu,{onClick:()=>n(E=>Math.max(1,E-1)),className:e===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:a.totalPages},(E,B)=>B+1).filter(E=>E===1||E===a.totalPages||Math.abs(E-e)<=1).map((E,B,j)=>f.jsxs(f.Fragment,{children:[B>0&&j[B-1]!==E-1&&f.jsx(Sr,{children:f.jsx(wu,{})},E+"..."),f.jsx(Sr,{children:f.jsx(Fa,{onClick:()=>n(E),isActive:e===E,className:`cursor-pointer ${h!==null?"pointer-events-none":""}`,children:h===E?f.jsx(zt,{className:"h-4 w-4 animate-spin"}):E})},E)]})),f.jsx(Sr,{children:f.jsx(yu,{onClick:()=>n(E=>Math.min(a.totalPages,E+1)),className:e===a.totalPages||h!==null?"pointer-events-none opacity-50":"cursor-pointer"})})]})})}),f.jsx(g_,{})]})});hr.Job=oU,hr.S3Explorer=RH,hr.Summary=rU,Object.defineProperty(hr,Symbol.toStringTag,{value:"Module"})});
209
209
  //# sourceMappingURL=s3-explorer.umd.cjs.map