@emailmaker/filemanager 0.10.91 → 0.10.92

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.
@@ -6,5 +6,5 @@ import{jsx as e,jsxs as t,Fragment as o}from"react/jsx-runtime";import*as r from
6
6
  * Released under MIT license <https://lodash.com/license>
7
7
  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
8
8
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
9
- */var An,_n,Sn=(In||(In=1,An=Fn,_n=Fn.exports,function(){var e,t="Expected a function",o="__lodash_hash_undefined__",r="__lodash_placeholder__",n=32,i=128,a=256,l=1/0,s=9007199254740991,d=NaN,c=4294967295,u=[["ary",i],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",n],["partialRight",64],["rearg",a]],f="[object Arguments]",h="[object Array]",m="[object Boolean]",p="[object Date]",g="[object Error]",v="[object Function]",y="[object GeneratorFunction]",w="[object Map]",b="[object Number]",C="[object Object]",I="[object Promise]",F="[object RegExp]",A="[object Set]",_="[object String]",S="[object Symbol]",E="[object WeakMap]",x="[object ArrayBuffer]",P="[object DataView]",R="[object Float32Array]",N="[object Float64Array]",k="[object Int8Array]",O="[object Int16Array]",T="[object Int32Array]",L="[object Uint8Array]",M="[object Uint8ClampedArray]",U="[object Uint16Array]",j="[object Uint32Array]",D=/\b__p \+= '';/g,B=/\b(__p \+=) '' \+/g,z=/(__e\(.*?\)|\b__t\)) \+\n'';/g,q=/&(?:amp|lt|gt|quot|#39);/g,W=/[&<>"']/g,V=RegExp(q.source),$=RegExp(W.source),H=/<%-([\s\S]+?)%>/g,G=/<%([\s\S]+?)%>/g,K=/<%=([\s\S]+?)%>/g,Q=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,J=/^\w*$/,Y=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/[\\^$.*+?()[\]{}|]/g,X=RegExp(Z.source),ee=/^\s+/,te=/\s/,oe=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,re=/\{\n\/\* \[wrapped with (.+)\] \*/,ne=/,? & /,ie=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ae=/[()=,{}\[\]\/\s]/,le=/\\(\\)?/g,se=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,de=/\w*$/,ce=/^[-+]0x[0-9a-f]+$/i,ue=/^0b[01]+$/i,fe=/^\[object .+?Constructor\]$/,he=/^0o[0-7]+$/i,me=/^(?:0|[1-9]\d*)$/,pe=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,ge=/($^)/,ve=/['\n\r\u2028\u2029\\]/g,ye="\\ud800-\\udfff",we="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",be="\\u2700-\\u27bf",Ce="a-z\\xdf-\\xf6\\xf8-\\xff",Ie="A-Z\\xc0-\\xd6\\xd8-\\xde",Fe="\\ufe0e\\ufe0f",Ae="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",_e="['’]",Se="["+ye+"]",Ee="["+Ae+"]",xe="["+we+"]",Pe="\\d+",Re="["+be+"]",Ne="["+Ce+"]",ke="[^"+ye+Ae+Pe+be+Ce+Ie+"]",Oe="\\ud83c[\\udffb-\\udfff]",Te="[^"+ye+"]",Le="(?:\\ud83c[\\udde6-\\uddff]){2}",Me="[\\ud800-\\udbff][\\udc00-\\udfff]",Ue="["+Ie+"]",je="\\u200d",De="(?:"+Ne+"|"+ke+")",Be="(?:"+Ue+"|"+ke+")",ze="(?:['’](?:d|ll|m|re|s|t|ve))?",qe="(?:['’](?:D|LL|M|RE|S|T|VE))?",We="(?:"+xe+"|"+Oe+")?",Ve="["+Fe+"]?",$e=Ve+We+"(?:"+je+"(?:"+[Te,Le,Me].join("|")+")"+Ve+We+")*",He="(?:"+[Re,Le,Me].join("|")+")"+$e,Ge="(?:"+[Te+xe+"?",xe,Le,Me,Se].join("|")+")",Ke=RegExp(_e,"g"),Qe=RegExp(xe,"g"),Je=RegExp(Oe+"(?="+Oe+")|"+Ge+$e,"g"),Ye=RegExp([Ue+"?"+Ne+"+"+ze+"(?="+[Ee,Ue,"$"].join("|")+")",Be+"+"+qe+"(?="+[Ee,Ue+De,"$"].join("|")+")",Ue+"?"+De+"+"+ze,Ue+"+"+qe,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Pe,He].join("|"),"g"),Ze=RegExp("["+je+ye+we+Fe+"]"),Xe=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,et=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],tt=-1,ot={};ot[R]=ot[N]=ot[k]=ot[O]=ot[T]=ot[L]=ot[M]=ot[U]=ot[j]=!0,ot[f]=ot[h]=ot[x]=ot[m]=ot[P]=ot[p]=ot[g]=ot[v]=ot[w]=ot[b]=ot[C]=ot[F]=ot[A]=ot[_]=ot[E]=!1;var rt={};rt[f]=rt[h]=rt[x]=rt[P]=rt[m]=rt[p]=rt[R]=rt[N]=rt[k]=rt[O]=rt[T]=rt[w]=rt[b]=rt[C]=rt[F]=rt[A]=rt[_]=rt[S]=rt[L]=rt[M]=rt[U]=rt[j]=!0,rt[g]=rt[v]=rt[E]=!1;var nt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},it=parseFloat,at=parseInt,lt="object"==typeof $o&&$o&&$o.Object===Object&&$o,st="object"==typeof self&&self&&self.Object===Object&&self,dt=lt||st||Function("return this")(),ct=_n&&!_n.nodeType&&_n,ut=ct&&An&&!An.nodeType&&An,ft=ut&&ut.exports===ct,ht=ft&&lt.process,mt=function(){try{var e=ut&&ut.require&&ut.require("util").types;return e||ht&&ht.binding&&ht.binding("util")}catch(e){}}(),pt=mt&&mt.isArrayBuffer,gt=mt&&mt.isDate,vt=mt&&mt.isMap,yt=mt&&mt.isRegExp,wt=mt&&mt.isSet,bt=mt&&mt.isTypedArray;function Ct(e,t,o){switch(o.length){case 0:return e.call(t);case 1:return e.call(t,o[0]);case 2:return e.call(t,o[0],o[1]);case 3:return e.call(t,o[0],o[1],o[2])}return e.apply(t,o)}function It(e,t,o,r){for(var n=-1,i=null==e?0:e.length;++n<i;){var a=e[n];t(r,a,o(a),e)}return r}function Ft(e,t){for(var o=-1,r=null==e?0:e.length;++o<r&&!1!==t(e[o],o,e););return e}function At(e,t){for(var o=null==e?0:e.length;o--&&!1!==t(e[o],o,e););return e}function _t(e,t){for(var o=-1,r=null==e?0:e.length;++o<r;)if(!t(e[o],o,e))return!1;return!0}function St(e,t){for(var o=-1,r=null==e?0:e.length,n=0,i=[];++o<r;){var a=e[o];t(a,o,e)&&(i[n++]=a)}return i}function Et(e,t){return!(null==e||!e.length)&&Ut(e,t,0)>-1}function xt(e,t,o){for(var r=-1,n=null==e?0:e.length;++r<n;)if(o(t,e[r]))return!0;return!1}function Pt(e,t){for(var o=-1,r=null==e?0:e.length,n=Array(r);++o<r;)n[o]=t(e[o],o,e);return n}function Rt(e,t){for(var o=-1,r=t.length,n=e.length;++o<r;)e[n+o]=t[o];return e}function Nt(e,t,o,r){var n=-1,i=null==e?0:e.length;for(r&&i&&(o=e[++n]);++n<i;)o=t(o,e[n],n,e);return o}function kt(e,t,o,r){var n=null==e?0:e.length;for(r&&n&&(o=e[--n]);n--;)o=t(o,e[n],n,e);return o}function Ot(e,t){for(var o=-1,r=null==e?0:e.length;++o<r;)if(t(e[o],o,e))return!0;return!1}var Tt=zt("length");function Lt(e,t,o){var r;return o(e,function(e,o,n){if(t(e,o,n))return r=o,!1}),r}function Mt(e,t,o,r){for(var n=e.length,i=o+(r?1:-1);r?i--:++i<n;)if(t(e[i],i,e))return i;return-1}function Ut(e,t,o){return t==t?function(e,t,o){for(var r=o-1,n=e.length;++r<n;)if(e[r]===t)return r;return-1}(e,t,o):Mt(e,Dt,o)}function jt(e,t,o,r){for(var n=o-1,i=e.length;++n<i;)if(r(e[n],t))return n;return-1}function Dt(e){return e!=e}function Bt(e,t){var o=null==e?0:e.length;return o?Vt(e,t)/o:d}function zt(t){return function(o){return null==o?e:o[t]}}function qt(t){return function(o){return null==t?e:t[o]}}function Wt(e,t,o,r,n){return n(e,function(e,n,i){o=r?(r=!1,e):t(o,e,n,i)}),o}function Vt(t,o){for(var r,n=-1,i=t.length;++n<i;){var a=o(t[n]);a!==e&&(r=r===e?a:r+a)}return r}function $t(e,t){for(var o=-1,r=Array(e);++o<e;)r[o]=t(o);return r}function Ht(e){return e?e.slice(0,co(e)+1).replace(ee,""):e}function Gt(e){return function(t){return e(t)}}function Kt(e,t){return Pt(t,function(t){return e[t]})}function Qt(e,t){return e.has(t)}function Jt(e,t){for(var o=-1,r=e.length;++o<r&&Ut(t,e[o],0)>-1;);return o}function Yt(e,t){for(var o=e.length;o--&&Ut(t,e[o],0)>-1;);return o}var Zt=qt({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"}),Xt=qt({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function eo(e){return"\\"+nt[e]}function to(e){return Ze.test(e)}function oo(e){var t=-1,o=Array(e.size);return e.forEach(function(e,r){o[++t]=[r,e]}),o}function ro(e,t){return function(o){return e(t(o))}}function no(e,t){for(var o=-1,n=e.length,i=0,a=[];++o<n;){var l=e[o];l!==t&&l!==r||(e[o]=r,a[i++]=o)}return a}function io(e){var t=-1,o=Array(e.size);return e.forEach(function(e){o[++t]=e}),o}function ao(e){var t=-1,o=Array(e.size);return e.forEach(function(e){o[++t]=[e,e]}),o}function lo(e){return to(e)?function(e){for(var t=Je.lastIndex=0;Je.test(e);)++t;return t}(e):Tt(e)}function so(e){return to(e)?function(e){return e.match(Je)||[]}(e):function(e){return e.split("")}(e)}function co(e){for(var t=e.length;t--&&te.test(e.charAt(t)););return t}var uo=qt({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),fo=function te(ye){var we,be=(ye=null==ye?dt:fo.defaults(dt.Object(),ye,fo.pick(dt,et))).Array,Ce=ye.Date,Ie=ye.Error,Fe=ye.Function,Ae=ye.Math,_e=ye.Object,Se=ye.RegExp,Ee=ye.String,xe=ye.TypeError,Pe=be.prototype,Re=Fe.prototype,Ne=_e.prototype,ke=ye["__core-js_shared__"],Oe=Re.toString,Te=Ne.hasOwnProperty,Le=0,Me=(we=/[^.]+$/.exec(ke&&ke.keys&&ke.keys.IE_PROTO||""))?"Symbol(src)_1."+we:"",Ue=Ne.toString,je=Oe.call(_e),De=dt._,Be=Se("^"+Oe.call(Te).replace(Z,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ze=ft?ye.Buffer:e,qe=ye.Symbol,We=ye.Uint8Array,Ve=ze?ze.allocUnsafe:e,$e=ro(_e.getPrototypeOf,_e),He=_e.create,Ge=Ne.propertyIsEnumerable,Je=Pe.splice,Ze=qe?qe.isConcatSpreadable:e,nt=qe?qe.iterator:e,lt=qe?qe.toStringTag:e,st=function(){try{var e=ui(_e,"defineProperty");return e({},"",{}),e}catch(e){}}(),ct=ye.clearTimeout!==dt.clearTimeout&&ye.clearTimeout,ut=Ce&&Ce.now!==dt.Date.now&&Ce.now,ht=ye.setTimeout!==dt.setTimeout&&ye.setTimeout,mt=Ae.ceil,Tt=Ae.floor,qt=_e.getOwnPropertySymbols,ho=ze?ze.isBuffer:e,mo=ye.isFinite,po=Pe.join,go=ro(_e.keys,_e),vo=Ae.max,yo=Ae.min,wo=Ce.now,bo=ye.parseInt,Co=Ae.random,Io=Pe.reverse,Fo=ui(ye,"DataView"),Ao=ui(ye,"Map"),_o=ui(ye,"Promise"),So=ui(ye,"Set"),Eo=ui(ye,"WeakMap"),xo=ui(_e,"create"),Po=Eo&&new Eo,Ro={},No=Ui(Fo),ko=Ui(Ao),Oo=Ui(_o),To=Ui(So),Lo=Ui(Eo),Mo=qe?qe.prototype:e,Uo=Mo?Mo.valueOf:e,jo=Mo?Mo.toString:e;function Do(e){if(el(e)&&!Wa(e)&&!(e instanceof Wo)){if(e instanceof qo)return e;if(Te.call(e,"__wrapped__"))return ji(e)}return new qo(e)}var Bo=function(){function t(){}return function(o){if(!Xa(o))return{};if(He)return He(o);t.prototype=o;var r=new t;return t.prototype=e,r}}();function zo(){}function qo(t,o){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!o,this.__index__=0,this.__values__=e}function Wo(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=c,this.__views__=[]}function Vo(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function $o(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function Ho(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function Go(e){var t=-1,o=null==e?0:e.length;for(this.__data__=new Ho;++t<o;)this.add(e[t])}function Ko(e){var t=this.__data__=new $o(e);this.size=t.size}function Qo(e,t){var o=Wa(e),r=!o&&qa(e),n=!o&&!r&&Ga(e),i=!o&&!r&&!n&&sl(e),a=o||r||n||i,l=a?$t(e.length,Ee):[],s=l.length;for(var d in e)!t&&!Te.call(e,d)||a&&("length"==d||n&&("offset"==d||"parent"==d)||i&&("buffer"==d||"byteLength"==d||"byteOffset"==d)||yi(d,s))||l.push(d);return l}function Jo(t){var o=t.length;return o?t[Gr(0,o-1)]:e}function Yo(e,t){return Ti(Pn(e),ar(t,0,e.length))}function Zo(e){return Ti(Pn(e))}function Xo(t,o,r){(r!==e&&!Da(t[o],r)||r===e&&!(o in t))&&nr(t,o,r)}function er(t,o,r){var n=t[o];Te.call(t,o)&&Da(n,r)&&(r!==e||o in t)||nr(t,o,r)}function tr(e,t){for(var o=e.length;o--;)if(Da(e[o][0],t))return o;return-1}function or(e,t,o,r){return ur(e,function(e,n,i){t(r,e,o(e),i)}),r}function rr(e,t){return e&&Rn(t,Rl(t),e)}function nr(e,t,o){"__proto__"==t&&st?st(e,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):e[t]=o}function ir(t,o){for(var r=-1,n=o.length,i=be(n),a=null==t;++r<n;)i[r]=a?e:_l(t,o[r]);return i}function ar(t,o,r){return t==t&&(r!==e&&(t=t<=r?t:r),o!==e&&(t=t>=o?t:o)),t}function lr(t,o,r,n,i,a){var l,s=1&o,d=2&o,c=4&o;if(r&&(l=i?r(t,n,i,a):r(t)),l!==e)return l;if(!Xa(t))return t;var u=Wa(t);if(u){if(l=function(e){var t=e.length,o=new e.constructor(t);return t&&"string"==typeof e[0]&&Te.call(e,"index")&&(o.index=e.index,o.input=e.input),o}(t),!s)return Pn(t,l)}else{var h=mi(t),g=h==v||h==y;if(Ga(t))return Fn(t,s);if(h==C||h==f||g&&!i){if(l=d||g?{}:gi(t),!s)return d?function(e,t){return Rn(e,hi(e),t)}(t,function(e,t){return e&&Rn(t,Nl(t),e)}(l,t)):function(e,t){return Rn(e,fi(e),t)}(t,rr(l,t))}else{if(!rt[h])return i?t:{};l=function(e,t,o){var r,n=e.constructor;switch(t){case x:return An(e);case m:case p:return new n(+e);case P:return function(e,t){var o=t?An(e.buffer):e.buffer;return new e.constructor(o,e.byteOffset,e.byteLength)}(e,o);case R:case N:case k:case O:case T:case L:case M:case U:case j:return _n(e,o);case w:return new n;case b:case _:return new n(e);case F:return function(e){var t=new e.constructor(e.source,de.exec(e));return t.lastIndex=e.lastIndex,t}(e);case A:return new n;case S:return r=e,Uo?_e(Uo.call(r)):{}}}(t,h,s)}}a||(a=new Ko);var I=a.get(t);if(I)return I;a.set(t,l),il(t)?t.forEach(function(e){l.add(lr(e,o,r,e,t,a))}):tl(t)&&t.forEach(function(e,n){l.set(n,lr(e,o,r,n,t,a))});var E=u?e:(c?d?ni:ri:d?Nl:Rl)(t);return Ft(E||t,function(e,n){E&&(e=t[n=e]),er(l,n,lr(e,o,r,n,t,a))}),l}function sr(t,o,r){var n=r.length;if(null==t)return!n;for(t=_e(t);n--;){var i=r[n],a=o[i],l=t[i];if(l===e&&!(i in t)||!a(l))return!1}return!0}function dr(o,r,n){if("function"!=typeof o)throw new xe(t);return Ri(function(){o.apply(e,n)},r)}function cr(e,t,o,r){var n=-1,i=Et,a=!0,l=e.length,s=[],d=t.length;if(!l)return s;o&&(t=Pt(t,Gt(o))),r?(i=xt,a=!1):t.length>=200&&(i=Qt,a=!1,t=new Go(t));e:for(;++n<l;){var c=e[n],u=null==o?c:o(c);if(c=r||0!==c?c:0,a&&u==u){for(var f=d;f--;)if(t[f]===u)continue e;s.push(c)}else i(t,u,r)||s.push(c)}return s}Do.templateSettings={escape:H,evaluate:G,interpolate:K,variable:"",imports:{_:Do}},Do.prototype=zo.prototype,Do.prototype.constructor=Do,qo.prototype=Bo(zo.prototype),qo.prototype.constructor=qo,Wo.prototype=Bo(zo.prototype),Wo.prototype.constructor=Wo,Vo.prototype.clear=function(){this.__data__=xo?xo(null):{},this.size=0},Vo.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Vo.prototype.get=function(t){var r=this.__data__;if(xo){var n=r[t];return n===o?e:n}return Te.call(r,t)?r[t]:e},Vo.prototype.has=function(t){var o=this.__data__;return xo?o[t]!==e:Te.call(o,t)},Vo.prototype.set=function(t,r){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=xo&&r===e?o:r,this},$o.prototype.clear=function(){this.__data__=[],this.size=0},$o.prototype.delete=function(e){var t=this.__data__,o=tr(t,e);return!(o<0||(o==t.length-1?t.pop():Je.call(t,o,1),--this.size,0))},$o.prototype.get=function(t){var o=this.__data__,r=tr(o,t);return r<0?e:o[r][1]},$o.prototype.has=function(e){return tr(this.__data__,e)>-1},$o.prototype.set=function(e,t){var o=this.__data__,r=tr(o,e);return r<0?(++this.size,o.push([e,t])):o[r][1]=t,this},Ho.prototype.clear=function(){this.size=0,this.__data__={hash:new Vo,map:new(Ao||$o),string:new Vo}},Ho.prototype.delete=function(e){var t=di(this,e).delete(e);return this.size-=t?1:0,t},Ho.prototype.get=function(e){return di(this,e).get(e)},Ho.prototype.has=function(e){return di(this,e).has(e)},Ho.prototype.set=function(e,t){var o=di(this,e),r=o.size;return o.set(e,t),this.size+=o.size==r?0:1,this},Go.prototype.add=Go.prototype.push=function(e){return this.__data__.set(e,o),this},Go.prototype.has=function(e){return this.__data__.has(e)},Ko.prototype.clear=function(){this.__data__=new $o,this.size=0},Ko.prototype.delete=function(e){var t=this.__data__,o=t.delete(e);return this.size=t.size,o},Ko.prototype.get=function(e){return this.__data__.get(e)},Ko.prototype.has=function(e){return this.__data__.has(e)},Ko.prototype.set=function(e,t){var o=this.__data__;if(o instanceof $o){var r=o.__data__;if(!Ao||r.length<199)return r.push([e,t]),this.size=++o.size,this;o=this.__data__=new Ho(r)}return o.set(e,t),this.size=o.size,this};var ur=On(wr),fr=On(br,!0);function hr(e,t){var o=!0;return ur(e,function(e,r,n){return o=!!t(e,r,n)}),o}function mr(t,o,r){for(var n=-1,i=t.length;++n<i;){var a=t[n],l=o(a);if(null!=l&&(s===e?l==l&&!ll(l):r(l,s)))var s=l,d=a}return d}function pr(e,t){var o=[];return ur(e,function(e,r,n){t(e,r,n)&&o.push(e)}),o}function gr(e,t,o,r,n){var i=-1,a=e.length;for(o||(o=vi),n||(n=[]);++i<a;){var l=e[i];t>0&&o(l)?t>1?gr(l,t-1,o,r,n):Rt(n,l):r||(n[n.length]=l)}return n}var vr=Tn(),yr=Tn(!0);function wr(e,t){return e&&vr(e,t,Rl)}function br(e,t){return e&&yr(e,t,Rl)}function Cr(e,t){return St(t,function(t){return Ja(e[t])})}function Ir(t,o){for(var r=0,n=(o=wn(o,t)).length;null!=t&&r<n;)t=t[Mi(o[r++])];return r&&r==n?t:e}function Fr(e,t,o){var r=t(e);return Wa(e)?r:Rt(r,o(e))}function Ar(t){return null==t?t===e?"[object Undefined]":"[object Null]":lt&&lt in _e(t)?function(t){var o=Te.call(t,lt),r=t[lt];try{t[lt]=e;var n=!0}catch(e){}var i=Ue.call(t);return n&&(o?t[lt]=r:delete t[lt]),i}(t):function(e){return Ue.call(e)}(t)}function _r(e,t){return e>t}function Sr(e,t){return null!=e&&Te.call(e,t)}function Er(e,t){return null!=e&&t in _e(e)}function xr(t,o,r){for(var n=r?xt:Et,i=t[0].length,a=t.length,l=a,s=be(a),d=1/0,c=[];l--;){var u=t[l];l&&o&&(u=Pt(u,Gt(o))),d=yo(u.length,d),s[l]=!r&&(o||i>=120&&u.length>=120)?new Go(l&&u):e}u=t[0];var f=-1,h=s[0];e:for(;++f<i&&c.length<d;){var m=u[f],p=o?o(m):m;if(m=r||0!==m?m:0,!(h?Qt(h,p):n(c,p,r))){for(l=a;--l;){var g=s[l];if(!(g?Qt(g,p):n(t[l],p,r)))continue e}h&&h.push(p),c.push(m)}}return c}function Pr(t,o,r){var n=null==(t=Ei(t,o=wn(o,t)))?t:t[Mi(Qi(o))];return null==n?e:Ct(n,t,r)}function Rr(e){return el(e)&&Ar(e)==f}function Nr(t,o,r,n,i){return t===o||(null==t||null==o||!el(t)&&!el(o)?t!=t&&o!=o:function(t,o,r,n,i,a){var l=Wa(t),s=Wa(o),d=l?h:mi(t),c=s?h:mi(o),u=(d=d==f?C:d)==C,v=(c=c==f?C:c)==C,y=d==c;if(y&&Ga(t)){if(!Ga(o))return!1;l=!0,u=!1}if(y&&!u)return a||(a=new Ko),l||sl(t)?ti(t,o,r,n,i,a):function(e,t,o,r,n,i,a){switch(o){case P:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case x:return!(e.byteLength!=t.byteLength||!i(new We(e),new We(t)));case m:case p:case b:return Da(+e,+t);case g:return e.name==t.name&&e.message==t.message;case F:case _:return e==t+"";case w:var l=oo;case A:var s=1&r;if(l||(l=io),e.size!=t.size&&!s)return!1;var d=a.get(e);if(d)return d==t;r|=2,a.set(e,t);var c=ti(l(e),l(t),r,n,i,a);return a.delete(e),c;case S:if(Uo)return Uo.call(e)==Uo.call(t)}return!1}(t,o,d,r,n,i,a);if(!(1&r)){var I=u&&Te.call(t,"__wrapped__"),E=v&&Te.call(o,"__wrapped__");if(I||E){var R=I?t.value():t,N=E?o.value():o;return a||(a=new Ko),i(R,N,r,n,a)}}return!!y&&(a||(a=new Ko),function(t,o,r,n,i,a){var l=1&r,s=ri(t),d=s.length,c=ri(o),u=c.length;if(d!=u&&!l)return!1;for(var f=d;f--;){var h=s[f];if(!(l?h in o:Te.call(o,h)))return!1}var m=a.get(t),p=a.get(o);if(m&&p)return m==o&&p==t;var g=!0;a.set(t,o),a.set(o,t);for(var v=l;++f<d;){var y=t[h=s[f]],w=o[h];if(n)var b=l?n(w,y,h,o,t,a):n(y,w,h,t,o,a);if(!(b===e?y===w||i(y,w,r,n,a):b)){g=!1;break}v||(v="constructor"==h)}if(g&&!v){var C=t.constructor,I=o.constructor;C==I||!("constructor"in t)||!("constructor"in o)||"function"==typeof C&&C instanceof C&&"function"==typeof I&&I instanceof I||(g=!1)}return a.delete(t),a.delete(o),g}(t,o,r,n,i,a))}(t,o,r,n,Nr,i))}function kr(t,o,r,n){var i=r.length,a=i,l=!n;if(null==t)return!a;for(t=_e(t);i--;){var s=r[i];if(l&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++i<a;){var d=(s=r[i])[0],c=t[d],u=s[1];if(l&&s[2]){if(c===e&&!(d in t))return!1}else{var f=new Ko;if(n)var h=n(c,u,d,t,o,f);if(!(h===e?Nr(u,c,3,n,f):h))return!1}}return!0}function Or(e){return!(!Xa(e)||(t=e,Me&&Me in t))&&(Ja(e)?Be:fe).test(Ui(e));var t}function Tr(e){return"function"==typeof e?e:null==e?os:"object"==typeof e?Wa(e)?Br(e[0],e[1]):Dr(e):us(e)}function Lr(e){if(!Fi(e))return go(e);var t=[];for(var o in _e(e))Te.call(e,o)&&"constructor"!=o&&t.push(o);return t}function Mr(e){if(!Xa(e))return function(e){var t=[];if(null!=e)for(var o in _e(e))t.push(o);return t}(e);var t=Fi(e),o=[];for(var r in e)("constructor"!=r||!t&&Te.call(e,r))&&o.push(r);return o}function Ur(e,t){return e<t}function jr(e,t){var o=-1,r=$a(e)?be(e.length):[];return ur(e,function(e,n,i){r[++o]=t(e,n,i)}),r}function Dr(e){var t=ci(e);return 1==t.length&&t[0][2]?_i(t[0][0],t[0][1]):function(o){return o===e||kr(o,e,t)}}function Br(t,o){return bi(t)&&Ai(o)?_i(Mi(t),o):function(r){var n=_l(r,t);return n===e&&n===o?Sl(r,t):Nr(o,n,3)}}function zr(t,o,r,n,i){t!==o&&vr(o,function(a,l){if(i||(i=new Ko),Xa(a))!function(t,o,r,n,i,a,l){var s=xi(t,r),d=xi(o,r),c=l.get(d);if(c)Xo(t,r,c);else{var u=a?a(s,d,r+"",t,o,l):e,f=u===e;if(f){var h=Wa(d),m=!h&&Ga(d),p=!h&&!m&&sl(d);u=d,h||m||p?Wa(s)?u=s:Ha(s)?u=Pn(s):m?(f=!1,u=Fn(d,!0)):p?(f=!1,u=_n(d,!0)):u=[]:rl(d)||qa(d)?(u=s,qa(s)?u=gl(s):Xa(s)&&!Ja(s)||(u=gi(d))):f=!1}f&&(l.set(d,u),i(u,d,n,a,l),l.delete(d)),Xo(t,r,u)}}(t,o,l,r,zr,n,i);else{var s=n?n(xi(t,l),a,l+"",t,o,i):e;s===e&&(s=a),Xo(t,l,s)}},Nl)}function qr(t,o){var r=t.length;if(r)return yi(o+=o<0?r:0,r)?t[o]:e}function Wr(e,t,o){t=t.length?Pt(t,function(e){return Wa(e)?function(t){return Ir(t,1===e.length?e[0]:e)}:e}):[os];var r=-1;t=Pt(t,Gt(si()));var n=jr(e,function(e,o,n){var i=Pt(t,function(t){return t(e)});return{criteria:i,index:++r,value:e}});return function(e,t){var o=e.length;for(e.sort(t);o--;)e[o]=e[o].value;return e}(n,function(e,t){return function(e,t,o){for(var r=-1,n=e.criteria,i=t.criteria,a=n.length,l=o.length;++r<a;){var s=Sn(n[r],i[r]);if(s)return r>=l?s:s*("desc"==o[r]?-1:1)}return e.index-t.index}(e,t,o)})}function Vr(e,t,o){for(var r=-1,n=t.length,i={};++r<n;){var a=t[r],l=Ir(e,a);o(l,a)&&Zr(i,wn(a,e),l)}return i}function $r(e,t,o,r){var n=r?jt:Ut,i=-1,a=t.length,l=e;for(e===t&&(t=Pn(t)),o&&(l=Pt(e,Gt(o)));++i<a;)for(var s=0,d=t[i],c=o?o(d):d;(s=n(l,c,s,r))>-1;)l!==e&&Je.call(l,s,1),Je.call(e,s,1);return e}function Hr(e,t){for(var o=e?t.length:0,r=o-1;o--;){var n=t[o];if(o==r||n!==i){var i=n;yi(n)?Je.call(e,n,1):un(e,n)}}return e}function Gr(e,t){return e+Tt(Co()*(t-e+1))}function Kr(e,t){var o="";if(!e||t<1||t>s)return o;do{t%2&&(o+=e),(t=Tt(t/2))&&(e+=e)}while(t);return o}function Qr(e,t){return Ni(Si(e,t,os),e+"")}function Jr(e){return Jo(Dl(e))}function Yr(e,t){var o=Dl(e);return Ti(o,ar(t,0,o.length))}function Zr(t,o,r,n){if(!Xa(t))return t;for(var i=-1,a=(o=wn(o,t)).length,l=a-1,s=t;null!=s&&++i<a;){var d=Mi(o[i]),c=r;if("__proto__"===d||"constructor"===d||"prototype"===d)return t;if(i!=l){var u=s[d];(c=n?n(u,d,s):e)===e&&(c=Xa(u)?u:yi(o[i+1])?[]:{})}er(s,d,c),s=s[d]}return t}var Xr=Po?function(e,t){return Po.set(e,t),e}:os,en=st?function(e,t){return st(e,"toString",{configurable:!0,enumerable:!1,value:Xl(t),writable:!0})}:os;function tn(e){return Ti(Dl(e))}function on(e,t,o){var r=-1,n=e.length;t<0&&(t=-t>n?0:n+t),(o=o>n?n:o)<0&&(o+=n),n=t>o?0:o-t>>>0,t>>>=0;for(var i=be(n);++r<n;)i[r]=e[r+t];return i}function rn(e,t){var o;return ur(e,function(e,r,n){return!(o=t(e,r,n))}),!!o}function nn(e,t,o){var r=0,n=null==e?r:e.length;if("number"==typeof t&&t==t&&n<=2147483647){for(;r<n;){var i=r+n>>>1,a=e[i];null!==a&&!ll(a)&&(o?a<=t:a<t)?r=i+1:n=i}return n}return an(e,t,os,o)}function an(t,o,r,n){var i=0,a=null==t?0:t.length;if(0===a)return 0;for(var l=(o=r(o))!=o,s=null===o,d=ll(o),c=o===e;i<a;){var u=Tt((i+a)/2),f=r(t[u]),h=f!==e,m=null===f,p=f==f,g=ll(f);if(l)var v=n||p;else v=c?p&&(n||h):s?p&&h&&(n||!m):d?p&&h&&!m&&(n||!g):!m&&!g&&(n?f<=o:f<o);v?i=u+1:a=u}return yo(a,4294967294)}function ln(e,t){for(var o=-1,r=e.length,n=0,i=[];++o<r;){var a=e[o],l=t?t(a):a;if(!o||!Da(l,s)){var s=l;i[n++]=0===a?0:a}}return i}function sn(e){return"number"==typeof e?e:ll(e)?d:+e}function dn(e){if("string"==typeof e)return e;if(Wa(e))return Pt(e,dn)+"";if(ll(e))return jo?jo.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function cn(e,t,o){var r=-1,n=Et,i=e.length,a=!0,l=[],s=l;if(o)a=!1,n=xt;else if(i>=200){var d=t?null:Qn(e);if(d)return io(d);a=!1,n=Qt,s=new Go}else s=t?[]:l;e:for(;++r<i;){var c=e[r],u=t?t(c):c;if(c=o||0!==c?c:0,a&&u==u){for(var f=s.length;f--;)if(s[f]===u)continue e;t&&s.push(u),l.push(c)}else n(s,u,o)||(s!==l&&s.push(u),l.push(c))}return l}function un(e,t){return null==(e=Ei(e,t=wn(t,e)))||delete e[Mi(Qi(t))]}function fn(e,t,o,r){return Zr(e,t,o(Ir(e,t)),r)}function hn(e,t,o,r){for(var n=e.length,i=r?n:-1;(r?i--:++i<n)&&t(e[i],i,e););return o?on(e,r?0:i,r?i+1:n):on(e,r?i+1:0,r?n:i)}function mn(e,t){var o=e;return o instanceof Wo&&(o=o.value()),Nt(t,function(e,t){return t.func.apply(t.thisArg,Rt([e],t.args))},o)}function pn(e,t,o){var r=e.length;if(r<2)return r?cn(e[0]):[];for(var n=-1,i=be(r);++n<r;)for(var a=e[n],l=-1;++l<r;)l!=n&&(i[n]=cr(i[n]||a,e[l],t,o));return cn(gr(i,1),t,o)}function gn(t,o,r){for(var n=-1,i=t.length,a=o.length,l={};++n<i;){var s=n<a?o[n]:e;r(l,t[n],s)}return l}function vn(e){return Ha(e)?e:[]}function yn(e){return"function"==typeof e?e:os}function wn(e,t){return Wa(e)?e:bi(e,t)?[e]:Li(vl(e))}var bn=Qr;function Cn(t,o,r){var n=t.length;return r=r===e?n:r,!o&&r>=n?t:on(t,o,r)}var In=ct||function(e){return dt.clearTimeout(e)};function Fn(e,t){if(t)return e.slice();var o=e.length,r=Ve?Ve(o):new e.constructor(o);return e.copy(r),r}function An(e){var t=new e.constructor(e.byteLength);return new We(t).set(new We(e)),t}function _n(e,t){var o=t?An(e.buffer):e.buffer;return new e.constructor(o,e.byteOffset,e.length)}function Sn(t,o){if(t!==o){var r=t!==e,n=null===t,i=t==t,a=ll(t),l=o!==e,s=null===o,d=o==o,c=ll(o);if(!s&&!c&&!a&&t>o||a&&l&&d&&!s&&!c||n&&l&&d||!r&&d||!i)return 1;if(!n&&!a&&!c&&t<o||c&&r&&i&&!n&&!a||s&&r&&i||!l&&i||!d)return-1}return 0}function En(e,t,o,r){for(var n=-1,i=e.length,a=o.length,l=-1,s=t.length,d=vo(i-a,0),c=be(s+d),u=!r;++l<s;)c[l]=t[l];for(;++n<a;)(u||n<i)&&(c[o[n]]=e[n]);for(;d--;)c[l++]=e[n++];return c}function xn(e,t,o,r){for(var n=-1,i=e.length,a=-1,l=o.length,s=-1,d=t.length,c=vo(i-l,0),u=be(c+d),f=!r;++n<c;)u[n]=e[n];for(var h=n;++s<d;)u[h+s]=t[s];for(;++a<l;)(f||n<i)&&(u[h+o[a]]=e[n++]);return u}function Pn(e,t){var o=-1,r=e.length;for(t||(t=be(r));++o<r;)t[o]=e[o];return t}function Rn(t,o,r,n){var i=!r;r||(r={});for(var a=-1,l=o.length;++a<l;){var s=o[a],d=n?n(r[s],t[s],s,r,t):e;d===e&&(d=t[s]),i?nr(r,s,d):er(r,s,d)}return r}function Nn(e,t){return function(o,r){var n=Wa(o)?It:or,i=t?t():{};return n(o,e,si(r,2),i)}}function kn(t){return Qr(function(o,r){var n=-1,i=r.length,a=i>1?r[i-1]:e,l=i>2?r[2]:e;for(a=t.length>3&&"function"==typeof a?(i--,a):e,l&&wi(r[0],r[1],l)&&(a=i<3?e:a,i=1),o=_e(o);++n<i;){var s=r[n];s&&t(o,s,n,a)}return o})}function On(e,t){return function(o,r){if(null==o)return o;if(!$a(o))return e(o,r);for(var n=o.length,i=t?n:-1,a=_e(o);(t?i--:++i<n)&&!1!==r(a[i],i,a););return o}}function Tn(e){return function(t,o,r){for(var n=-1,i=_e(t),a=r(t),l=a.length;l--;){var s=a[e?l:++n];if(!1===o(i[s],s,i))break}return t}}function Ln(t){return function(o){var r=to(o=vl(o))?so(o):e,n=r?r[0]:o.charAt(0),i=r?Cn(r,1).join(""):o.slice(1);return n[t]()+i}}function Mn(e){return function(t){return Nt(Jl(ql(t).replace(Ke,"")),e,"")}}function Un(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var o=Bo(e.prototype),r=e.apply(o,t);return Xa(r)?r:o}}function jn(t){return function(o,r,n){var i=_e(o);if(!$a(o)){var a=si(r,3);o=Rl(o),r=function(e){return a(i[e],e,i)}}var l=t(o,r,n);return l>-1?i[a?o[l]:l]:e}}function Dn(o){return oi(function(r){var n=r.length,i=n,a=qo.prototype.thru;for(o&&r.reverse();i--;){var l=r[i];if("function"!=typeof l)throw new xe(t);if(a&&!s&&"wrapper"==ai(l))var s=new qo([],!0)}for(i=s?i:n;++i<n;){var d=ai(l=r[i]),c="wrapper"==d?ii(l):e;s=c&&Ci(c[0])&&424==c[1]&&!c[4].length&&1==c[9]?s[ai(c[0])].apply(s,c[3]):1==l.length&&Ci(l)?s[d]():s.thru(l)}return function(){var e=arguments,t=e[0];if(s&&1==e.length&&Wa(t))return s.plant(t).value();for(var o=0,i=n?r[o].apply(this,e):t;++o<n;)i=r[o].call(this,i);return i}})}function Bn(t,o,r,n,a,l,s,d,c,u){var f=o&i,h=1&o,m=2&o,p=24&o,g=512&o,v=m?e:Un(t);return function i(){for(var y=arguments.length,w=be(y),b=y;b--;)w[b]=arguments[b];if(p)var C=li(i),I=function(e,t){for(var o=e.length,r=0;o--;)e[o]===t&&++r;return r}(w,C);if(n&&(w=En(w,n,a,p)),l&&(w=xn(w,l,s,p)),y-=I,p&&y<u){var F=no(w,C);return Gn(t,o,Bn,i.placeholder,r,w,F,d,c,u-y)}var A=h?r:this,_=m?A[t]:t;return y=w.length,d?w=function(t,o){for(var r=t.length,n=yo(o.length,r),i=Pn(t);n--;){var a=o[n];t[n]=yi(a,r)?i[a]:e}return t}(w,d):g&&y>1&&w.reverse(),f&&c<y&&(w.length=c),this&&this!==dt&&this instanceof i&&(_=v||Un(_)),_.apply(A,w)}}function zn(e,t){return function(o,r){return function(e,t,o,r){return wr(e,function(e,n,i){t(r,o(e),n,i)}),r}(o,e,t(r),{})}}function qn(t,o){return function(r,n){var i;if(r===e&&n===e)return o;if(r!==e&&(i=r),n!==e){if(i===e)return n;"string"==typeof r||"string"==typeof n?(r=dn(r),n=dn(n)):(r=sn(r),n=sn(n)),i=t(r,n)}return i}}function Wn(e){return oi(function(t){return t=Pt(t,Gt(si())),Qr(function(o){var r=this;return e(t,function(e){return Ct(e,r,o)})})})}function Vn(t,o){var r=(o=o===e?" ":dn(o)).length;if(r<2)return r?Kr(o,t):o;var n=Kr(o,mt(t/lo(o)));return to(o)?Cn(so(n),0,t).join(""):n.slice(0,t)}function $n(t){return function(o,r,n){return n&&"number"!=typeof n&&wi(o,r,n)&&(r=n=e),o=fl(o),r===e?(r=o,o=0):r=fl(r),function(e,t,o,r){for(var n=-1,i=vo(mt((t-e)/(o||1)),0),a=be(i);i--;)a[r?i:++n]=e,e+=o;return a}(o,r,n=n===e?o<r?1:-1:fl(n),t)}}function Hn(e){return function(t,o){return"string"==typeof t&&"string"==typeof o||(t=pl(t),o=pl(o)),e(t,o)}}function Gn(t,o,r,i,a,l,s,d,c,u){var f=8&o;o|=f?n:64,4&(o&=~(f?64:n))||(o&=-4);var h=[t,o,a,f?l:e,f?s:e,f?e:l,f?e:s,d,c,u],m=r.apply(e,h);return Ci(t)&&Pi(m,h),m.placeholder=i,ki(m,t,o)}function Kn(e){var t=Ae[e];return function(e,o){if(e=pl(e),(o=null==o?0:yo(hl(o),292))&&mo(e)){var r=(vl(e)+"e").split("e");return+((r=(vl(t(r[0]+"e"+(+r[1]+o)))+"e").split("e"))[0]+"e"+(+r[1]-o))}return t(e)}}var Qn=So&&1/io(new So([,-0]))[1]==l?function(e){return new So(e)}:ls;function Jn(e){return function(t){var o=mi(t);return o==w?oo(t):o==A?ao(t):function(e,t){return Pt(t,function(t){return[t,e[t]]})}(t,e(t))}}function Yn(o,l,s,d,c,u,f,h){var m=2&l;if(!m&&"function"!=typeof o)throw new xe(t);var p=d?d.length:0;if(p||(l&=-97,d=c=e),f=f===e?f:vo(hl(f),0),h=h===e?h:hl(h),p-=c?c.length:0,64&l){var g=d,v=c;d=c=e}var y=m?e:ii(o),w=[o,l,s,d,c,g,v,u,f,h];if(y&&function(e,t){var o=e[1],n=t[1],l=o|n,s=l<131,d=n==i&&8==o||n==i&&o==a&&e[7].length<=t[8]||384==n&&t[7].length<=t[8]&&8==o;if(!s&&!d)return e;1&n&&(e[2]=t[2],l|=1&o?0:4);var c=t[3];if(c){var u=e[3];e[3]=u?En(u,c,t[4]):c,e[4]=u?no(e[3],r):t[4]}(c=t[5])&&(u=e[5],e[5]=u?xn(u,c,t[6]):c,e[6]=u?no(e[5],r):t[6]),(c=t[7])&&(e[7]=c),n&i&&(e[8]=null==e[8]?t[8]:yo(e[8],t[8])),null==e[9]&&(e[9]=t[9]),e[0]=t[0],e[1]=l}(w,y),o=w[0],l=w[1],s=w[2],d=w[3],c=w[4],!(h=w[9]=w[9]===e?m?0:o.length:vo(w[9]-p,0))&&24&l&&(l&=-25),l&&1!=l)b=8==l||16==l?function(t,o,r){var n=Un(t);return function i(){for(var a=arguments.length,l=be(a),s=a,d=li(i);s--;)l[s]=arguments[s];var c=a<3&&l[0]!==d&&l[a-1]!==d?[]:no(l,d);return(a-=c.length)<r?Gn(t,o,Bn,i.placeholder,e,l,c,e,e,r-a):Ct(this&&this!==dt&&this instanceof i?n:t,this,l)}}(o,l,h):l!=n&&33!=l||c.length?Bn.apply(e,w):function(e,t,o,r){var n=1&t,i=Un(e);return function t(){for(var a=-1,l=arguments.length,s=-1,d=r.length,c=be(d+l),u=this&&this!==dt&&this instanceof t?i:e;++s<d;)c[s]=r[s];for(;l--;)c[s++]=arguments[++a];return Ct(u,n?o:this,c)}}(o,l,s,d);else var b=function(e,t,o){var r=1&t,n=Un(e);return function t(){return(this&&this!==dt&&this instanceof t?n:e).apply(r?o:this,arguments)}}(o,l,s);return ki((y?Xr:Pi)(b,w),o,l)}function Zn(t,o,r,n){return t===e||Da(t,Ne[r])&&!Te.call(n,r)?o:t}function Xn(t,o,r,n,i,a){return Xa(t)&&Xa(o)&&(a.set(o,t),zr(t,o,e,Xn,a),a.delete(o)),t}function ei(t){return rl(t)?e:t}function ti(t,o,r,n,i,a){var l=1&r,s=t.length,d=o.length;if(s!=d&&!(l&&d>s))return!1;var c=a.get(t),u=a.get(o);if(c&&u)return c==o&&u==t;var f=-1,h=!0,m=2&r?new Go:e;for(a.set(t,o),a.set(o,t);++f<s;){var p=t[f],g=o[f];if(n)var v=l?n(g,p,f,o,t,a):n(p,g,f,t,o,a);if(v!==e){if(v)continue;h=!1;break}if(m){if(!Ot(o,function(e,t){if(!Qt(m,t)&&(p===e||i(p,e,r,n,a)))return m.push(t)})){h=!1;break}}else if(p!==g&&!i(p,g,r,n,a)){h=!1;break}}return a.delete(t),a.delete(o),h}function oi(t){return Ni(Si(t,e,Vi),t+"")}function ri(e){return Fr(e,Rl,fi)}function ni(e){return Fr(e,Nl,hi)}var ii=Po?function(e){return Po.get(e)}:ls;function ai(e){for(var t=e.name+"",o=Ro[t],r=Te.call(Ro,t)?o.length:0;r--;){var n=o[r],i=n.func;if(null==i||i==e)return n.name}return t}function li(e){return(Te.call(Do,"placeholder")?Do:e).placeholder}function si(){var e=Do.iteratee||rs;return e=e===rs?Tr:e,arguments.length?e(arguments[0],arguments[1]):e}function di(e,t){var o,r,n=e.__data__;return("string"==(r=typeof(o=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==o:null===o)?n["string"==typeof t?"string":"hash"]:n.map}function ci(e){for(var t=Rl(e),o=t.length;o--;){var r=t[o],n=e[r];t[o]=[r,n,Ai(n)]}return t}function ui(t,o){var r=function(t,o){return null==t?e:t[o]}(t,o);return Or(r)?r:e}var fi=qt?function(e){return null==e?[]:(e=_e(e),St(qt(e),function(t){return Ge.call(e,t)}))}:ms,hi=qt?function(e){for(var t=[];e;)Rt(t,fi(e)),e=$e(e);return t}:ms,mi=Ar;function pi(e,t,o){for(var r=-1,n=(t=wn(t,e)).length,i=!1;++r<n;){var a=Mi(t[r]);if(!(i=null!=e&&o(e,a)))break;e=e[a]}return i||++r!=n?i:!!(n=null==e?0:e.length)&&Za(n)&&yi(a,n)&&(Wa(e)||qa(e))}function gi(e){return"function"!=typeof e.constructor||Fi(e)?{}:Bo($e(e))}function vi(e){return Wa(e)||qa(e)||!!(Ze&&e&&e[Ze])}function yi(e,t){var o=typeof e;return!!(t=null==t?s:t)&&("number"==o||"symbol"!=o&&me.test(e))&&e>-1&&e%1==0&&e<t}function wi(e,t,o){if(!Xa(o))return!1;var r=typeof t;return!!("number"==r?$a(o)&&yi(t,o.length):"string"==r&&t in o)&&Da(o[t],e)}function bi(e,t){if(Wa(e))return!1;var o=typeof e;return!("number"!=o&&"symbol"!=o&&"boolean"!=o&&null!=e&&!ll(e))||J.test(e)||!Q.test(e)||null!=t&&e in _e(t)}function Ci(e){var t=ai(e),o=Do[t];if("function"!=typeof o||!(t in Wo.prototype))return!1;if(e===o)return!0;var r=ii(o);return!!r&&e===r[0]}(Fo&&mi(new Fo(new ArrayBuffer(1)))!=P||Ao&&mi(new Ao)!=w||_o&&mi(_o.resolve())!=I||So&&mi(new So)!=A||Eo&&mi(new Eo)!=E)&&(mi=function(t){var o=Ar(t),r=o==C?t.constructor:e,n=r?Ui(r):"";if(n)switch(n){case No:return P;case ko:return w;case Oo:return I;case To:return A;case Lo:return E}return o});var Ii=ke?Ja:ps;function Fi(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Ne)}function Ai(e){return e==e&&!Xa(e)}function _i(t,o){return function(r){return null!=r&&r[t]===o&&(o!==e||t in _e(r))}}function Si(t,o,r){return o=vo(o===e?t.length-1:o,0),function(){for(var e=arguments,n=-1,i=vo(e.length-o,0),a=be(i);++n<i;)a[n]=e[o+n];n=-1;for(var l=be(o+1);++n<o;)l[n]=e[n];return l[o]=r(a),Ct(t,this,l)}}function Ei(e,t){return t.length<2?e:Ir(e,on(t,0,-1))}function xi(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var Pi=Oi(Xr),Ri=ht||function(e,t){return dt.setTimeout(e,t)},Ni=Oi(en);function ki(e,t,o){var r=t+"";return Ni(e,function(e,t){var o=t.length;if(!o)return e;var r=o-1;return t[r]=(o>1?"& ":"")+t[r],t=t.join(o>2?", ":" "),e.replace(oe,"{\n/* [wrapped with "+t+"] */\n")}(r,function(e,t){return Ft(u,function(o){var r="_."+o[0];t&o[1]&&!Et(e,r)&&e.push(r)}),e.sort()}(function(e){var t=e.match(re);return t?t[1].split(ne):[]}(r),o)))}function Oi(t){var o=0,r=0;return function(){var n=wo(),i=16-(n-r);if(r=n,i>0){if(++o>=800)return arguments[0]}else o=0;return t.apply(e,arguments)}}function Ti(t,o){var r=-1,n=t.length,i=n-1;for(o=o===e?n:o;++r<o;){var a=Gr(r,i),l=t[a];t[a]=t[r],t[r]=l}return t.length=o,t}var Li=function(e){var t=Oa(e,function(e){return 500===o.size&&o.clear(),e}),o=t.cache;return t}(function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(Y,function(e,o,r,n){t.push(r?n.replace(le,"$1"):o||e)}),t});function Mi(e){if("string"==typeof e||ll(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Ui(e){if(null!=e){try{return Oe.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function ji(e){if(e instanceof Wo)return e.clone();var t=new qo(e.__wrapped__,e.__chain__);return t.__actions__=Pn(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}var Di=Qr(function(e,t){return Ha(e)?cr(e,gr(t,1,Ha,!0)):[]}),Bi=Qr(function(t,o){var r=Qi(o);return Ha(r)&&(r=e),Ha(t)?cr(t,gr(o,1,Ha,!0),si(r,2)):[]}),zi=Qr(function(t,o){var r=Qi(o);return Ha(r)&&(r=e),Ha(t)?cr(t,gr(o,1,Ha,!0),e,r):[]});function qi(e,t,o){var r=null==e?0:e.length;if(!r)return-1;var n=null==o?0:hl(o);return n<0&&(n=vo(r+n,0)),Mt(e,si(t,3),n)}function Wi(t,o,r){var n=null==t?0:t.length;if(!n)return-1;var i=n-1;return r!==e&&(i=hl(r),i=r<0?vo(n+i,0):yo(i,n-1)),Mt(t,si(o,3),i,!0)}function Vi(e){return null!=e&&e.length?gr(e,1):[]}function $i(t){return t&&t.length?t[0]:e}var Hi=Qr(function(e){var t=Pt(e,vn);return t.length&&t[0]===e[0]?xr(t):[]}),Gi=Qr(function(t){var o=Qi(t),r=Pt(t,vn);return o===Qi(r)?o=e:r.pop(),r.length&&r[0]===t[0]?xr(r,si(o,2)):[]}),Ki=Qr(function(t){var o=Qi(t),r=Pt(t,vn);return(o="function"==typeof o?o:e)&&r.pop(),r.length&&r[0]===t[0]?xr(r,e,o):[]});function Qi(t){var o=null==t?0:t.length;return o?t[o-1]:e}var Ji=Qr(Yi);function Yi(e,t){return e&&e.length&&t&&t.length?$r(e,t):e}var Zi=oi(function(e,t){var o=null==e?0:e.length,r=ir(e,t);return Hr(e,Pt(t,function(e){return yi(e,o)?+e:e}).sort(Sn)),r});function Xi(e){return null==e?e:Io.call(e)}var ea=Qr(function(e){return cn(gr(e,1,Ha,!0))}),ta=Qr(function(t){var o=Qi(t);return Ha(o)&&(o=e),cn(gr(t,1,Ha,!0),si(o,2))}),oa=Qr(function(t){var o=Qi(t);return o="function"==typeof o?o:e,cn(gr(t,1,Ha,!0),e,o)});function ra(e){if(!e||!e.length)return[];var t=0;return e=St(e,function(e){if(Ha(e))return t=vo(e.length,t),!0}),$t(t,function(t){return Pt(e,zt(t))})}function na(t,o){if(!t||!t.length)return[];var r=ra(t);return null==o?r:Pt(r,function(t){return Ct(o,e,t)})}var ia=Qr(function(e,t){return Ha(e)?cr(e,t):[]}),aa=Qr(function(e){return pn(St(e,Ha))}),la=Qr(function(t){var o=Qi(t);return Ha(o)&&(o=e),pn(St(t,Ha),si(o,2))}),sa=Qr(function(t){var o=Qi(t);return o="function"==typeof o?o:e,pn(St(t,Ha),e,o)}),da=Qr(ra),ca=Qr(function(t){var o=t.length,r=o>1?t[o-1]:e;return r="function"==typeof r?(t.pop(),r):e,na(t,r)});function ua(e){var t=Do(e);return t.__chain__=!0,t}function fa(e,t){return t(e)}var ha=oi(function(t){var o=t.length,r=o?t[0]:0,n=this.__wrapped__,i=function(e){return ir(e,t)};return!(o>1||this.__actions__.length)&&n instanceof Wo&&yi(r)?((n=n.slice(r,+r+(o?1:0))).__actions__.push({func:fa,args:[i],thisArg:e}),new qo(n,this.__chain__).thru(function(t){return o&&!t.length&&t.push(e),t})):this.thru(i)}),ma=Nn(function(e,t,o){Te.call(e,o)?++e[o]:nr(e,o,1)}),pa=jn(qi),ga=jn(Wi);function va(e,t){return(Wa(e)?Ft:ur)(e,si(t,3))}function ya(e,t){return(Wa(e)?At:fr)(e,si(t,3))}var wa=Nn(function(e,t,o){Te.call(e,o)?e[o].push(t):nr(e,o,[t])}),ba=Qr(function(e,t,o){var r=-1,n="function"==typeof t,i=$a(e)?be(e.length):[];return ur(e,function(e){i[++r]=n?Ct(t,e,o):Pr(e,t,o)}),i}),Ca=Nn(function(e,t,o){nr(e,o,t)});function Ia(e,t){return(Wa(e)?Pt:jr)(e,si(t,3))}var Fa=Nn(function(e,t,o){e[o?0:1].push(t)},function(){return[[],[]]}),Aa=Qr(function(e,t){if(null==e)return[];var o=t.length;return o>1&&wi(e,t[0],t[1])?t=[]:o>2&&wi(t[0],t[1],t[2])&&(t=[t[0]]),Wr(e,gr(t,1),[])}),_a=ut||function(){return dt.Date.now()};function Sa(t,o,r){return o=r?e:o,o=t&&null==o?t.length:o,Yn(t,i,e,e,e,e,o)}function Ea(o,r){var n;if("function"!=typeof r)throw new xe(t);return o=hl(o),function(){return--o>0&&(n=r.apply(this,arguments)),o<=1&&(r=e),n}}var xa=Qr(function(e,t,o){var r=1;if(o.length){var i=no(o,li(xa));r|=n}return Yn(e,r,t,o,i)}),Pa=Qr(function(e,t,o){var r=3;if(o.length){var i=no(o,li(Pa));r|=n}return Yn(t,r,e,o,i)});function Ra(o,r,n){var i,a,l,s,d,c,u=0,f=!1,h=!1,m=!0;if("function"!=typeof o)throw new xe(t);function p(t){var r=i,n=a;return i=a=e,u=t,s=o.apply(n,r)}function g(t){var o=t-c;return c===e||o>=r||o<0||h&&t-u>=l}function v(){var e=_a();if(g(e))return y(e);d=Ri(v,function(e){var t=r-(e-c);return h?yo(t,l-(e-u)):t}(e))}function y(t){return d=e,m&&i?p(t):(i=a=e,s)}function w(){var t=_a(),o=g(t);if(i=arguments,a=this,c=t,o){if(d===e)return function(e){return u=e,d=Ri(v,r),f?p(e):s}(c);if(h)return In(d),d=Ri(v,r),p(c)}return d===e&&(d=Ri(v,r)),s}return r=pl(r)||0,Xa(n)&&(f=!!n.leading,l=(h="maxWait"in n)?vo(pl(n.maxWait)||0,r):l,m="trailing"in n?!!n.trailing:m),w.cancel=function(){d!==e&&In(d),u=0,i=c=a=d=e},w.flush=function(){return d===e?s:y(_a())},w}var Na=Qr(function(e,t){return dr(e,1,t)}),ka=Qr(function(e,t,o){return dr(e,pl(t)||0,o)});function Oa(e,o){if("function"!=typeof e||null!=o&&"function"!=typeof o)throw new xe(t);var r=function(){var t=arguments,n=o?o.apply(this,t):t[0],i=r.cache;if(i.has(n))return i.get(n);var a=e.apply(this,t);return r.cache=i.set(n,a)||i,a};return r.cache=new(Oa.Cache||Ho),r}function Ta(e){if("function"!=typeof e)throw new xe(t);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}Oa.Cache=Ho;var La=bn(function(e,t){var o=(t=1==t.length&&Wa(t[0])?Pt(t[0],Gt(si())):Pt(gr(t,1),Gt(si()))).length;return Qr(function(r){for(var n=-1,i=yo(r.length,o);++n<i;)r[n]=t[n].call(this,r[n]);return Ct(e,this,r)})}),Ma=Qr(function(t,o){var r=no(o,li(Ma));return Yn(t,n,e,o,r)}),Ua=Qr(function(t,o){var r=no(o,li(Ua));return Yn(t,64,e,o,r)}),ja=oi(function(t,o){return Yn(t,a,e,e,e,o)});function Da(e,t){return e===t||e!=e&&t!=t}var Ba=Hn(_r),za=Hn(function(e,t){return e>=t}),qa=Rr(function(){return arguments}())?Rr:function(e){return el(e)&&Te.call(e,"callee")&&!Ge.call(e,"callee")},Wa=be.isArray,Va=pt?Gt(pt):function(e){return el(e)&&Ar(e)==x};function $a(e){return null!=e&&Za(e.length)&&!Ja(e)}function Ha(e){return el(e)&&$a(e)}var Ga=ho||ps,Ka=gt?Gt(gt):function(e){return el(e)&&Ar(e)==p};function Qa(e){if(!el(e))return!1;var t=Ar(e);return t==g||"[object DOMException]"==t||"string"==typeof e.message&&"string"==typeof e.name&&!rl(e)}function Ja(e){if(!Xa(e))return!1;var t=Ar(e);return t==v||t==y||"[object AsyncFunction]"==t||"[object Proxy]"==t}function Ya(e){return"number"==typeof e&&e==hl(e)}function Za(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=s}function Xa(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function el(e){return null!=e&&"object"==typeof e}var tl=vt?Gt(vt):function(e){return el(e)&&mi(e)==w};function ol(e){return"number"==typeof e||el(e)&&Ar(e)==b}function rl(e){if(!el(e)||Ar(e)!=C)return!1;var t=$e(e);if(null===t)return!0;var o=Te.call(t,"constructor")&&t.constructor;return"function"==typeof o&&o instanceof o&&Oe.call(o)==je}var nl=yt?Gt(yt):function(e){return el(e)&&Ar(e)==F},il=wt?Gt(wt):function(e){return el(e)&&mi(e)==A};function al(e){return"string"==typeof e||!Wa(e)&&el(e)&&Ar(e)==_}function ll(e){return"symbol"==typeof e||el(e)&&Ar(e)==S}var sl=bt?Gt(bt):function(e){return el(e)&&Za(e.length)&&!!ot[Ar(e)]},dl=Hn(Ur),cl=Hn(function(e,t){return e<=t});function ul(e){if(!e)return[];if($a(e))return al(e)?so(e):Pn(e);if(nt&&e[nt])return function(e){for(var t,o=[];!(t=e.next()).done;)o.push(t.value);return o}(e[nt]());var t=mi(e);return(t==w?oo:t==A?io:Dl)(e)}function fl(e){return e?(e=pl(e))===l||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}function hl(e){var t=fl(e),o=t%1;return t==t?o?t-o:t:0}function ml(e){return e?ar(hl(e),0,c):0}function pl(e){if("number"==typeof e)return e;if(ll(e))return d;if(Xa(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=Xa(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=Ht(e);var o=ue.test(e);return o||he.test(e)?at(e.slice(2),o?2:8):ce.test(e)?d:+e}function gl(e){return Rn(e,Nl(e))}function vl(e){return null==e?"":dn(e)}var yl=kn(function(e,t){if(Fi(t)||$a(t))Rn(t,Rl(t),e);else for(var o in t)Te.call(t,o)&&er(e,o,t[o])}),wl=kn(function(e,t){Rn(t,Nl(t),e)}),bl=kn(function(e,t,o,r){Rn(t,Nl(t),e,r)}),Cl=kn(function(e,t,o,r){Rn(t,Rl(t),e,r)}),Il=oi(ir),Fl=Qr(function(t,o){t=_e(t);var r=-1,n=o.length,i=n>2?o[2]:e;for(i&&wi(o[0],o[1],i)&&(n=1);++r<n;)for(var a=o[r],l=Nl(a),s=-1,d=l.length;++s<d;){var c=l[s],u=t[c];(u===e||Da(u,Ne[c])&&!Te.call(t,c))&&(t[c]=a[c])}return t}),Al=Qr(function(t){return t.push(e,Xn),Ct(Ol,e,t)});function _l(t,o,r){var n=null==t?e:Ir(t,o);return n===e?r:n}function Sl(e,t){return null!=e&&pi(e,t,Er)}var El=zn(function(e,t,o){null!=t&&"function"!=typeof t.toString&&(t=Ue.call(t)),e[t]=o},Xl(os)),xl=zn(function(e,t,o){null!=t&&"function"!=typeof t.toString&&(t=Ue.call(t)),Te.call(e,t)?e[t].push(o):e[t]=[o]},si),Pl=Qr(Pr);function Rl(e){return $a(e)?Qo(e):Lr(e)}function Nl(e){return $a(e)?Qo(e,!0):Mr(e)}var kl=kn(function(e,t,o){zr(e,t,o)}),Ol=kn(function(e,t,o,r){zr(e,t,o,r)}),Tl=oi(function(e,t){var o={};if(null==e)return o;var r=!1;t=Pt(t,function(t){return t=wn(t,e),r||(r=t.length>1),t}),Rn(e,ni(e),o),r&&(o=lr(o,7,ei));for(var n=t.length;n--;)un(o,t[n]);return o}),Ll=oi(function(e,t){return null==e?{}:function(e,t){return Vr(e,t,function(t,o){return Sl(e,o)})}(e,t)});function Ml(e,t){if(null==e)return{};var o=Pt(ni(e),function(e){return[e]});return t=si(t),Vr(e,o,function(e,o){return t(e,o[0])})}var Ul=Jn(Rl),jl=Jn(Nl);function Dl(e){return null==e?[]:Kt(e,Rl(e))}var Bl=Mn(function(e,t,o){return t=t.toLowerCase(),e+(o?zl(t):t)});function zl(e){return Ql(vl(e).toLowerCase())}function ql(e){return(e=vl(e))&&e.replace(pe,Zt).replace(Qe,"")}var Wl=Mn(function(e,t,o){return e+(o?"-":"")+t.toLowerCase()}),Vl=Mn(function(e,t,o){return e+(o?" ":"")+t.toLowerCase()}),$l=Ln("toLowerCase"),Hl=Mn(function(e,t,o){return e+(o?"_":"")+t.toLowerCase()}),Gl=Mn(function(e,t,o){return e+(o?" ":"")+Ql(t)}),Kl=Mn(function(e,t,o){return e+(o?" ":"")+t.toUpperCase()}),Ql=Ln("toUpperCase");function Jl(t,o,r){return t=vl(t),(o=r?e:o)===e?function(e){return Xe.test(e)}(t)?function(e){return e.match(Ye)||[]}(t):function(e){return e.match(ie)||[]}(t):t.match(o)||[]}var Yl=Qr(function(t,o){try{return Ct(t,e,o)}catch(e){return Qa(e)?e:new Ie(e)}}),Zl=oi(function(e,t){return Ft(t,function(t){t=Mi(t),nr(e,t,xa(e[t],e))}),e});function Xl(e){return function(){return e}}var es=Dn(),ts=Dn(!0);function os(e){return e}function rs(e){return Tr("function"==typeof e?e:lr(e,1))}var ns=Qr(function(e,t){return function(o){return Pr(o,e,t)}}),is=Qr(function(e,t){return function(o){return Pr(e,o,t)}});function as(e,t,o){var r=Rl(t),n=Cr(t,r);null!=o||Xa(t)&&(n.length||!r.length)||(o=t,t=e,e=this,n=Cr(t,Rl(t)));var i=!(Xa(o)&&"chain"in o&&!o.chain),a=Ja(e);return Ft(n,function(o){var r=t[o];e[o]=r,a&&(e.prototype[o]=function(){var t=this.__chain__;if(i||t){var o=e(this.__wrapped__);return(o.__actions__=Pn(this.__actions__)).push({func:r,args:arguments,thisArg:e}),o.__chain__=t,o}return r.apply(e,Rt([this.value()],arguments))})}),e}function ls(){}var ss=Wn(Pt),ds=Wn(_t),cs=Wn(Ot);function us(e){return bi(e)?zt(Mi(e)):function(e){return function(t){return Ir(t,e)}}(e)}var fs=$n(),hs=$n(!0);function ms(){return[]}function ps(){return!1}var gs,vs=qn(function(e,t){return e+t},0),ys=Kn("ceil"),ws=qn(function(e,t){return e/t},1),bs=Kn("floor"),Cs=qn(function(e,t){return e*t},1),Is=Kn("round"),Fs=qn(function(e,t){return e-t},0);return Do.after=function(e,o){if("function"!=typeof o)throw new xe(t);return e=hl(e),function(){if(--e<1)return o.apply(this,arguments)}},Do.ary=Sa,Do.assign=yl,Do.assignIn=wl,Do.assignInWith=bl,Do.assignWith=Cl,Do.at=Il,Do.before=Ea,Do.bind=xa,Do.bindAll=Zl,Do.bindKey=Pa,Do.castArray=function(){if(!arguments.length)return[];var e=arguments[0];return Wa(e)?e:[e]},Do.chain=ua,Do.chunk=function(t,o,r){o=(r?wi(t,o,r):o===e)?1:vo(hl(o),0);var n=null==t?0:t.length;if(!n||o<1)return[];for(var i=0,a=0,l=be(mt(n/o));i<n;)l[a++]=on(t,i,i+=o);return l},Do.compact=function(e){for(var t=-1,o=null==e?0:e.length,r=0,n=[];++t<o;){var i=e[t];i&&(n[r++]=i)}return n},Do.concat=function(){var e=arguments.length;if(!e)return[];for(var t=be(e-1),o=arguments[0],r=e;r--;)t[r-1]=arguments[r];return Rt(Wa(o)?Pn(o):[o],gr(t,1))},Do.cond=function(e){var o=null==e?0:e.length,r=si();return e=o?Pt(e,function(e){if("function"!=typeof e[1])throw new xe(t);return[r(e[0]),e[1]]}):[],Qr(function(t){for(var r=-1;++r<o;){var n=e[r];if(Ct(n[0],this,t))return Ct(n[1],this,t)}})},Do.conforms=function(e){return function(e){var t=Rl(e);return function(o){return sr(o,e,t)}}(lr(e,1))},Do.constant=Xl,Do.countBy=ma,Do.create=function(e,t){var o=Bo(e);return null==t?o:rr(o,t)},Do.curry=function t(o,r,n){var i=Yn(o,8,e,e,e,e,e,r=n?e:r);return i.placeholder=t.placeholder,i},Do.curryRight=function t(o,r,n){var i=Yn(o,16,e,e,e,e,e,r=n?e:r);return i.placeholder=t.placeholder,i},Do.debounce=Ra,Do.defaults=Fl,Do.defaultsDeep=Al,Do.defer=Na,Do.delay=ka,Do.difference=Di,Do.differenceBy=Bi,Do.differenceWith=zi,Do.drop=function(t,o,r){var n=null==t?0:t.length;return n?on(t,(o=r||o===e?1:hl(o))<0?0:o,n):[]},Do.dropRight=function(t,o,r){var n=null==t?0:t.length;return n?on(t,0,(o=n-(o=r||o===e?1:hl(o)))<0?0:o):[]},Do.dropRightWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!0,!0):[]},Do.dropWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!0):[]},Do.fill=function(t,o,r,n){var i=null==t?0:t.length;return i?(r&&"number"!=typeof r&&wi(t,o,r)&&(r=0,n=i),function(t,o,r,n){var i=t.length;for((r=hl(r))<0&&(r=-r>i?0:i+r),(n=n===e||n>i?i:hl(n))<0&&(n+=i),n=r>n?0:ml(n);r<n;)t[r++]=o;return t}(t,o,r,n)):[]},Do.filter=function(e,t){return(Wa(e)?St:pr)(e,si(t,3))},Do.flatMap=function(e,t){return gr(Ia(e,t),1)},Do.flatMapDeep=function(e,t){return gr(Ia(e,t),l)},Do.flatMapDepth=function(t,o,r){return r=r===e?1:hl(r),gr(Ia(t,o),r)},Do.flatten=Vi,Do.flattenDeep=function(e){return null!=e&&e.length?gr(e,l):[]},Do.flattenDepth=function(t,o){return null!=t&&t.length?gr(t,o=o===e?1:hl(o)):[]},Do.flip=function(e){return Yn(e,512)},Do.flow=es,Do.flowRight=ts,Do.fromPairs=function(e){for(var t=-1,o=null==e?0:e.length,r={};++t<o;){var n=e[t];r[n[0]]=n[1]}return r},Do.functions=function(e){return null==e?[]:Cr(e,Rl(e))},Do.functionsIn=function(e){return null==e?[]:Cr(e,Nl(e))},Do.groupBy=wa,Do.initial=function(e){return null!=e&&e.length?on(e,0,-1):[]},Do.intersection=Hi,Do.intersectionBy=Gi,Do.intersectionWith=Ki,Do.invert=El,Do.invertBy=xl,Do.invokeMap=ba,Do.iteratee=rs,Do.keyBy=Ca,Do.keys=Rl,Do.keysIn=Nl,Do.map=Ia,Do.mapKeys=function(e,t){var o={};return t=si(t,3),wr(e,function(e,r,n){nr(o,t(e,r,n),e)}),o},Do.mapValues=function(e,t){var o={};return t=si(t,3),wr(e,function(e,r,n){nr(o,r,t(e,r,n))}),o},Do.matches=function(e){return Dr(lr(e,1))},Do.matchesProperty=function(e,t){return Br(e,lr(t,1))},Do.memoize=Oa,Do.merge=kl,Do.mergeWith=Ol,Do.method=ns,Do.methodOf=is,Do.mixin=as,Do.negate=Ta,Do.nthArg=function(e){return e=hl(e),Qr(function(t){return qr(t,e)})},Do.omit=Tl,Do.omitBy=function(e,t){return Ml(e,Ta(si(t)))},Do.once=function(e){return Ea(2,e)},Do.orderBy=function(t,o,r,n){return null==t?[]:(Wa(o)||(o=null==o?[]:[o]),Wa(r=n?e:r)||(r=null==r?[]:[r]),Wr(t,o,r))},Do.over=ss,Do.overArgs=La,Do.overEvery=ds,Do.overSome=cs,Do.partial=Ma,Do.partialRight=Ua,Do.partition=Fa,Do.pick=Ll,Do.pickBy=Ml,Do.property=us,Do.propertyOf=function(t){return function(o){return null==t?e:Ir(t,o)}},Do.pull=Ji,Do.pullAll=Yi,Do.pullAllBy=function(e,t,o){return e&&e.length&&t&&t.length?$r(e,t,si(o,2)):e},Do.pullAllWith=function(t,o,r){return t&&t.length&&o&&o.length?$r(t,o,e,r):t},Do.pullAt=Zi,Do.range=fs,Do.rangeRight=hs,Do.rearg=ja,Do.reject=function(e,t){return(Wa(e)?St:pr)(e,Ta(si(t,3)))},Do.remove=function(e,t){var o=[];if(!e||!e.length)return o;var r=-1,n=[],i=e.length;for(t=si(t,3);++r<i;){var a=e[r];t(a,r,e)&&(o.push(a),n.push(r))}return Hr(e,n),o},Do.rest=function(o,r){if("function"!=typeof o)throw new xe(t);return Qr(o,r=r===e?r:hl(r))},Do.reverse=Xi,Do.sampleSize=function(t,o,r){return o=(r?wi(t,o,r):o===e)?1:hl(o),(Wa(t)?Yo:Yr)(t,o)},Do.set=function(e,t,o){return null==e?e:Zr(e,t,o)},Do.setWith=function(t,o,r,n){return n="function"==typeof n?n:e,null==t?t:Zr(t,o,r,n)},Do.shuffle=function(e){return(Wa(e)?Zo:tn)(e)},Do.slice=function(t,o,r){var n=null==t?0:t.length;return n?(r&&"number"!=typeof r&&wi(t,o,r)?(o=0,r=n):(o=null==o?0:hl(o),r=r===e?n:hl(r)),on(t,o,r)):[]},Do.sortBy=Aa,Do.sortedUniq=function(e){return e&&e.length?ln(e):[]},Do.sortedUniqBy=function(e,t){return e&&e.length?ln(e,si(t,2)):[]},Do.split=function(t,o,r){return r&&"number"!=typeof r&&wi(t,o,r)&&(o=r=e),(r=r===e?c:r>>>0)?(t=vl(t))&&("string"==typeof o||null!=o&&!nl(o))&&!(o=dn(o))&&to(t)?Cn(so(t),0,r):t.split(o,r):[]},Do.spread=function(e,o){if("function"!=typeof e)throw new xe(t);return o=null==o?0:vo(hl(o),0),Qr(function(t){var r=t[o],n=Cn(t,0,o);return r&&Rt(n,r),Ct(e,this,n)})},Do.tail=function(e){var t=null==e?0:e.length;return t?on(e,1,t):[]},Do.take=function(t,o,r){return t&&t.length?on(t,0,(o=r||o===e?1:hl(o))<0?0:o):[]},Do.takeRight=function(t,o,r){var n=null==t?0:t.length;return n?on(t,(o=n-(o=r||o===e?1:hl(o)))<0?0:o,n):[]},Do.takeRightWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!1,!0):[]},Do.takeWhile=function(e,t){return e&&e.length?hn(e,si(t,3)):[]},Do.tap=function(e,t){return t(e),e},Do.throttle=function(e,o,r){var n=!0,i=!0;if("function"!=typeof e)throw new xe(t);return Xa(r)&&(n="leading"in r?!!r.leading:n,i="trailing"in r?!!r.trailing:i),Ra(e,o,{leading:n,maxWait:o,trailing:i})},Do.thru=fa,Do.toArray=ul,Do.toPairs=Ul,Do.toPairsIn=jl,Do.toPath=function(e){return Wa(e)?Pt(e,Mi):ll(e)?[e]:Pn(Li(vl(e)))},Do.toPlainObject=gl,Do.transform=function(e,t,o){var r=Wa(e),n=r||Ga(e)||sl(e);if(t=si(t,4),null==o){var i=e&&e.constructor;o=n?r?new i:[]:Xa(e)&&Ja(i)?Bo($e(e)):{}}return(n?Ft:wr)(e,function(e,r,n){return t(o,e,r,n)}),o},Do.unary=function(e){return Sa(e,1)},Do.union=ea,Do.unionBy=ta,Do.unionWith=oa,Do.uniq=function(e){return e&&e.length?cn(e):[]},Do.uniqBy=function(e,t){return e&&e.length?cn(e,si(t,2)):[]},Do.uniqWith=function(t,o){return o="function"==typeof o?o:e,t&&t.length?cn(t,e,o):[]},Do.unset=function(e,t){return null==e||un(e,t)},Do.unzip=ra,Do.unzipWith=na,Do.update=function(e,t,o){return null==e?e:fn(e,t,yn(o))},Do.updateWith=function(t,o,r,n){return n="function"==typeof n?n:e,null==t?t:fn(t,o,yn(r),n)},Do.values=Dl,Do.valuesIn=function(e){return null==e?[]:Kt(e,Nl(e))},Do.without=ia,Do.words=Jl,Do.wrap=function(e,t){return Ma(yn(t),e)},Do.xor=aa,Do.xorBy=la,Do.xorWith=sa,Do.zip=da,Do.zipObject=function(e,t){return gn(e||[],t||[],er)},Do.zipObjectDeep=function(e,t){return gn(e||[],t||[],Zr)},Do.zipWith=ca,Do.entries=Ul,Do.entriesIn=jl,Do.extend=wl,Do.extendWith=bl,as(Do,Do),Do.add=vs,Do.attempt=Yl,Do.camelCase=Bl,Do.capitalize=zl,Do.ceil=ys,Do.clamp=function(t,o,r){return r===e&&(r=o,o=e),r!==e&&(r=(r=pl(r))==r?r:0),o!==e&&(o=(o=pl(o))==o?o:0),ar(pl(t),o,r)},Do.clone=function(e){return lr(e,4)},Do.cloneDeep=function(e){return lr(e,5)},Do.cloneDeepWith=function(t,o){return lr(t,5,o="function"==typeof o?o:e)},Do.cloneWith=function(t,o){return lr(t,4,o="function"==typeof o?o:e)},Do.conformsTo=function(e,t){return null==t||sr(e,t,Rl(t))},Do.deburr=ql,Do.defaultTo=function(e,t){return null==e||e!=e?t:e},Do.divide=ws,Do.endsWith=function(t,o,r){t=vl(t),o=dn(o);var n=t.length,i=r=r===e?n:ar(hl(r),0,n);return(r-=o.length)>=0&&t.slice(r,i)==o},Do.eq=Da,Do.escape=function(e){return(e=vl(e))&&$.test(e)?e.replace(W,Xt):e},Do.escapeRegExp=function(e){return(e=vl(e))&&X.test(e)?e.replace(Z,"\\$&"):e},Do.every=function(t,o,r){var n=Wa(t)?_t:hr;return r&&wi(t,o,r)&&(o=e),n(t,si(o,3))},Do.find=pa,Do.findIndex=qi,Do.findKey=function(e,t){return Lt(e,si(t,3),wr)},Do.findLast=ga,Do.findLastIndex=Wi,Do.findLastKey=function(e,t){return Lt(e,si(t,3),br)},Do.floor=bs,Do.forEach=va,Do.forEachRight=ya,Do.forIn=function(e,t){return null==e?e:vr(e,si(t,3),Nl)},Do.forInRight=function(e,t){return null==e?e:yr(e,si(t,3),Nl)},Do.forOwn=function(e,t){return e&&wr(e,si(t,3))},Do.forOwnRight=function(e,t){return e&&br(e,si(t,3))},Do.get=_l,Do.gt=Ba,Do.gte=za,Do.has=function(e,t){return null!=e&&pi(e,t,Sr)},Do.hasIn=Sl,Do.head=$i,Do.identity=os,Do.includes=function(e,t,o,r){e=$a(e)?e:Dl(e),o=o&&!r?hl(o):0;var n=e.length;return o<0&&(o=vo(n+o,0)),al(e)?o<=n&&e.indexOf(t,o)>-1:!!n&&Ut(e,t,o)>-1},Do.indexOf=function(e,t,o){var r=null==e?0:e.length;if(!r)return-1;var n=null==o?0:hl(o);return n<0&&(n=vo(r+n,0)),Ut(e,t,n)},Do.inRange=function(t,o,r){return o=fl(o),r===e?(r=o,o=0):r=fl(r),function(e,t,o){return e>=yo(t,o)&&e<vo(t,o)}(t=pl(t),o,r)},Do.invoke=Pl,Do.isArguments=qa,Do.isArray=Wa,Do.isArrayBuffer=Va,Do.isArrayLike=$a,Do.isArrayLikeObject=Ha,Do.isBoolean=function(e){return!0===e||!1===e||el(e)&&Ar(e)==m},Do.isBuffer=Ga,Do.isDate=Ka,Do.isElement=function(e){return el(e)&&1===e.nodeType&&!rl(e)},Do.isEmpty=function(e){if(null==e)return!0;if($a(e)&&(Wa(e)||"string"==typeof e||"function"==typeof e.splice||Ga(e)||sl(e)||qa(e)))return!e.length;var t=mi(e);if(t==w||t==A)return!e.size;if(Fi(e))return!Lr(e).length;for(var o in e)if(Te.call(e,o))return!1;return!0},Do.isEqual=function(e,t){return Nr(e,t)},Do.isEqualWith=function(t,o,r){var n=(r="function"==typeof r?r:e)?r(t,o):e;return n===e?Nr(t,o,e,r):!!n},Do.isError=Qa,Do.isFinite=function(e){return"number"==typeof e&&mo(e)},Do.isFunction=Ja,Do.isInteger=Ya,Do.isLength=Za,Do.isMap=tl,Do.isMatch=function(e,t){return e===t||kr(e,t,ci(t))},Do.isMatchWith=function(t,o,r){return r="function"==typeof r?r:e,kr(t,o,ci(o),r)},Do.isNaN=function(e){return ol(e)&&e!=+e},Do.isNative=function(e){if(Ii(e))throw new Ie("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return Or(e)},Do.isNil=function(e){return null==e},Do.isNull=function(e){return null===e},Do.isNumber=ol,Do.isObject=Xa,Do.isObjectLike=el,Do.isPlainObject=rl,Do.isRegExp=nl,Do.isSafeInteger=function(e){return Ya(e)&&e>=-9007199254740991&&e<=s},Do.isSet=il,Do.isString=al,Do.isSymbol=ll,Do.isTypedArray=sl,Do.isUndefined=function(t){return t===e},Do.isWeakMap=function(e){return el(e)&&mi(e)==E},Do.isWeakSet=function(e){return el(e)&&"[object WeakSet]"==Ar(e)},Do.join=function(e,t){return null==e?"":po.call(e,t)},Do.kebabCase=Wl,Do.last=Qi,Do.lastIndexOf=function(t,o,r){var n=null==t?0:t.length;if(!n)return-1;var i=n;return r!==e&&(i=(i=hl(r))<0?vo(n+i,0):yo(i,n-1)),o==o?function(e,t,o){for(var r=o+1;r--;)if(e[r]===t)return r;return r}(t,o,i):Mt(t,Dt,i,!0)},Do.lowerCase=Vl,Do.lowerFirst=$l,Do.lt=dl,Do.lte=cl,Do.max=function(t){return t&&t.length?mr(t,os,_r):e},Do.maxBy=function(t,o){return t&&t.length?mr(t,si(o,2),_r):e},Do.mean=function(e){return Bt(e,os)},Do.meanBy=function(e,t){return Bt(e,si(t,2))},Do.min=function(t){return t&&t.length?mr(t,os,Ur):e},Do.minBy=function(t,o){return t&&t.length?mr(t,si(o,2),Ur):e},Do.stubArray=ms,Do.stubFalse=ps,Do.stubObject=function(){return{}},Do.stubString=function(){return""},Do.stubTrue=function(){return!0},Do.multiply=Cs,Do.nth=function(t,o){return t&&t.length?qr(t,hl(o)):e},Do.noConflict=function(){return dt._===this&&(dt._=De),this},Do.noop=ls,Do.now=_a,Do.pad=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;if(!t||r>=t)return e;var n=(t-r)/2;return Vn(Tt(n),o)+e+Vn(mt(n),o)},Do.padEnd=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;return t&&r<t?e+Vn(t-r,o):e},Do.padStart=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;return t&&r<t?Vn(t-r,o)+e:e},Do.parseInt=function(e,t,o){return o||null==t?t=0:t&&(t=+t),bo(vl(e).replace(ee,""),t||0)},Do.random=function(t,o,r){if(r&&"boolean"!=typeof r&&wi(t,o,r)&&(o=r=e),r===e&&("boolean"==typeof o?(r=o,o=e):"boolean"==typeof t&&(r=t,t=e)),t===e&&o===e?(t=0,o=1):(t=fl(t),o===e?(o=t,t=0):o=fl(o)),t>o){var n=t;t=o,o=n}if(r||t%1||o%1){var i=Co();return yo(t+i*(o-t+it("1e-"+((i+"").length-1))),o)}return Gr(t,o)},Do.reduce=function(e,t,o){var r=Wa(e)?Nt:Wt,n=arguments.length<3;return r(e,si(t,4),o,n,ur)},Do.reduceRight=function(e,t,o){var r=Wa(e)?kt:Wt,n=arguments.length<3;return r(e,si(t,4),o,n,fr)},Do.repeat=function(t,o,r){return o=(r?wi(t,o,r):o===e)?1:hl(o),Kr(vl(t),o)},Do.replace=function(){var e=arguments,t=vl(e[0]);return e.length<3?t:t.replace(e[1],e[2])},Do.result=function(t,o,r){var n=-1,i=(o=wn(o,t)).length;for(i||(i=1,t=e);++n<i;){var a=null==t?e:t[Mi(o[n])];a===e&&(n=i,a=r),t=Ja(a)?a.call(t):a}return t},Do.round=Is,Do.runInContext=te,Do.sample=function(e){return(Wa(e)?Jo:Jr)(e)},Do.size=function(e){if(null==e)return 0;if($a(e))return al(e)?lo(e):e.length;var t=mi(e);return t==w||t==A?e.size:Lr(e).length},Do.snakeCase=Hl,Do.some=function(t,o,r){var n=Wa(t)?Ot:rn;return r&&wi(t,o,r)&&(o=e),n(t,si(o,3))},Do.sortedIndex=function(e,t){return nn(e,t)},Do.sortedIndexBy=function(e,t,o){return an(e,t,si(o,2))},Do.sortedIndexOf=function(e,t){var o=null==e?0:e.length;if(o){var r=nn(e,t);if(r<o&&Da(e[r],t))return r}return-1},Do.sortedLastIndex=function(e,t){return nn(e,t,!0)},Do.sortedLastIndexBy=function(e,t,o){return an(e,t,si(o,2),!0)},Do.sortedLastIndexOf=function(e,t){if(null!=e&&e.length){var o=nn(e,t,!0)-1;if(Da(e[o],t))return o}return-1},Do.startCase=Gl,Do.startsWith=function(e,t,o){return e=vl(e),o=null==o?0:ar(hl(o),0,e.length),t=dn(t),e.slice(o,o+t.length)==t},Do.subtract=Fs,Do.sum=function(e){return e&&e.length?Vt(e,os):0},Do.sumBy=function(e,t){return e&&e.length?Vt(e,si(t,2)):0},Do.template=function(t,o,r){var n=Do.templateSettings;r&&wi(t,o,r)&&(o=e),t=vl(t),o=bl({},o,n,Zn);var i,a,l=bl({},o.imports,n.imports,Zn),s=Rl(l),d=Kt(l,s),c=0,u=o.interpolate||ge,f="__p += '",h=Se((o.escape||ge).source+"|"+u.source+"|"+(u===K?se:ge).source+"|"+(o.evaluate||ge).source+"|$","g"),m="//# sourceURL="+(Te.call(o,"sourceURL")?(o.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tt+"]")+"\n";t.replace(h,function(e,o,r,n,l,s){return r||(r=n),f+=t.slice(c,s).replace(ve,eo),o&&(i=!0,f+="' +\n__e("+o+") +\n'"),l&&(a=!0,f+="';\n"+l+";\n__p += '"),r&&(f+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),c=s+e.length,e}),f+="';\n";var p=Te.call(o,"variable")&&o.variable;if(p){if(ae.test(p))throw new Ie("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(a?f.replace(D,""):f).replace(B,"$1").replace(z,"$1;"),f="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(i?", __e = _.escape":"")+(a?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var g=Yl(function(){return Fe(s,m+"return "+f).apply(e,d)});if(g.source=f,Qa(g))throw g;return g},Do.times=function(e,t){if((e=hl(e))<1||e>s)return[];var o=c,r=yo(e,c);t=si(t),e-=c;for(var n=$t(r,t);++o<e;)t(o);return n},Do.toFinite=fl,Do.toInteger=hl,Do.toLength=ml,Do.toLower=function(e){return vl(e).toLowerCase()},Do.toNumber=pl,Do.toSafeInteger=function(e){return e?ar(hl(e),-9007199254740991,s):0===e?e:0},Do.toString=vl,Do.toUpper=function(e){return vl(e).toUpperCase()},Do.trim=function(t,o,r){if((t=vl(t))&&(r||o===e))return Ht(t);if(!t||!(o=dn(o)))return t;var n=so(t),i=so(o);return Cn(n,Jt(n,i),Yt(n,i)+1).join("")},Do.trimEnd=function(t,o,r){if((t=vl(t))&&(r||o===e))return t.slice(0,co(t)+1);if(!t||!(o=dn(o)))return t;var n=so(t);return Cn(n,0,Yt(n,so(o))+1).join("")},Do.trimStart=function(t,o,r){if((t=vl(t))&&(r||o===e))return t.replace(ee,"");if(!t||!(o=dn(o)))return t;var n=so(t);return Cn(n,Jt(n,so(o))).join("")},Do.truncate=function(t,o){var r=30,n="...";if(Xa(o)){var i="separator"in o?o.separator:i;r="length"in o?hl(o.length):r,n="omission"in o?dn(o.omission):n}var a=(t=vl(t)).length;if(to(t)){var l=so(t);a=l.length}if(r>=a)return t;var s=r-lo(n);if(s<1)return n;var d=l?Cn(l,0,s).join(""):t.slice(0,s);if(i===e)return d+n;if(l&&(s+=d.length-s),nl(i)){if(t.slice(s).search(i)){var c,u=d;for(i.global||(i=Se(i.source,vl(de.exec(i))+"g")),i.lastIndex=0;c=i.exec(u);)var f=c.index;d=d.slice(0,f===e?s:f)}}else if(t.indexOf(dn(i),s)!=s){var h=d.lastIndexOf(i);h>-1&&(d=d.slice(0,h))}return d+n},Do.unescape=function(e){return(e=vl(e))&&V.test(e)?e.replace(q,uo):e},Do.uniqueId=function(e){var t=++Le;return vl(e)+t},Do.upperCase=Kl,Do.upperFirst=Ql,Do.each=va,Do.eachRight=ya,Do.first=$i,as(Do,(gs={},wr(Do,function(e,t){Te.call(Do.prototype,t)||(gs[t]=e)}),gs),{chain:!1}),Do.VERSION="4.17.21",Ft(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){Do[e].placeholder=Do}),Ft(["drop","take"],function(t,o){Wo.prototype[t]=function(r){r=r===e?1:vo(hl(r),0);var n=this.__filtered__&&!o?new Wo(this):this.clone();return n.__filtered__?n.__takeCount__=yo(r,n.__takeCount__):n.__views__.push({size:yo(r,c),type:t+(n.__dir__<0?"Right":"")}),n},Wo.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}}),Ft(["filter","map","takeWhile"],function(e,t){var o=t+1,r=1==o||3==o;Wo.prototype[e]=function(e){var t=this.clone();return t.__iteratees__.push({iteratee:si(e,3),type:o}),t.__filtered__=t.__filtered__||r,t}}),Ft(["head","last"],function(e,t){var o="take"+(t?"Right":"");Wo.prototype[e]=function(){return this[o](1).value()[0]}}),Ft(["initial","tail"],function(e,t){var o="drop"+(t?"":"Right");Wo.prototype[e]=function(){return this.__filtered__?new Wo(this):this[o](1)}}),Wo.prototype.compact=function(){return this.filter(os)},Wo.prototype.find=function(e){return this.filter(e).head()},Wo.prototype.findLast=function(e){return this.reverse().find(e)},Wo.prototype.invokeMap=Qr(function(e,t){return"function"==typeof e?new Wo(this):this.map(function(o){return Pr(o,e,t)})}),Wo.prototype.reject=function(e){return this.filter(Ta(si(e)))},Wo.prototype.slice=function(t,o){t=hl(t);var r=this;return r.__filtered__&&(t>0||o<0)?new Wo(r):(t<0?r=r.takeRight(-t):t&&(r=r.drop(t)),o!==e&&(r=(o=hl(o))<0?r.dropRight(-o):r.take(o-t)),r)},Wo.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},Wo.prototype.toArray=function(){return this.take(c)},wr(Wo.prototype,function(t,o){var r=/^(?:filter|find|map|reject)|While$/.test(o),n=/^(?:head|last)$/.test(o),i=Do[n?"take"+("last"==o?"Right":""):o],a=n||/^find/.test(o);i&&(Do.prototype[o]=function(){var o=this.__wrapped__,l=n?[1]:arguments,s=o instanceof Wo,d=l[0],c=s||Wa(o),u=function(e){var t=i.apply(Do,Rt([e],l));return n&&f?t[0]:t};c&&r&&"function"==typeof d&&1!=d.length&&(s=c=!1);var f=this.__chain__,h=!!this.__actions__.length,m=a&&!f,p=s&&!h;if(!a&&c){o=p?o:new Wo(this);var g=t.apply(o,l);return g.__actions__.push({func:fa,args:[u],thisArg:e}),new qo(g,f)}return m&&p?t.apply(this,l):(g=this.thru(u),m?n?g.value()[0]:g.value():g)})}),Ft(["pop","push","shift","sort","splice","unshift"],function(e){var t=Pe[e],o=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:pop|shift)$/.test(e);Do.prototype[e]=function(){var e=arguments;if(r&&!this.__chain__){var n=this.value();return t.apply(Wa(n)?n:[],e)}return this[o](function(o){return t.apply(Wa(o)?o:[],e)})}}),wr(Wo.prototype,function(e,t){var o=Do[t];if(o){var r=o.name+"";Te.call(Ro,r)||(Ro[r]=[]),Ro[r].push({name:t,func:o})}}),Ro[Bn(e,2).name]=[{name:"wrapper",func:e}],Wo.prototype.clone=function(){var e=new Wo(this.__wrapped__);return e.__actions__=Pn(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=Pn(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=Pn(this.__views__),e},Wo.prototype.reverse=function(){if(this.__filtered__){var e=new Wo(this);e.__dir__=-1,e.__filtered__=!0}else(e=this.clone()).__dir__*=-1;return e},Wo.prototype.value=function(){var e=this.__wrapped__.value(),t=this.__dir__,o=Wa(e),r=t<0,n=o?e.length:0,i=function(e,t,o){for(var r=-1,n=o.length;++r<n;){var i=o[r],a=i.size;switch(i.type){case"drop":e+=a;break;case"dropRight":t-=a;break;case"take":t=yo(t,e+a);break;case"takeRight":e=vo(e,t-a)}}return{start:e,end:t}}(0,n,this.__views__),a=i.start,l=i.end,s=l-a,d=r?l:a-1,c=this.__iteratees__,u=c.length,f=0,h=yo(s,this.__takeCount__);if(!o||!r&&n==s&&h==s)return mn(e,this.__actions__);var m=[];e:for(;s--&&f<h;){for(var p=-1,g=e[d+=t];++p<u;){var v=c[p],y=v.iteratee,w=v.type,b=y(g);if(2==w)g=b;else if(!b){if(1==w)continue e;break e}}m[f++]=g}return m},Do.prototype.at=ha,Do.prototype.chain=function(){return ua(this)},Do.prototype.commit=function(){return new qo(this.value(),this.__chain__)},Do.prototype.next=function(){this.__values__===e&&(this.__values__=ul(this.value()));var t=this.__index__>=this.__values__.length;return{done:t,value:t?e:this.__values__[this.__index__++]}},Do.prototype.plant=function(t){for(var o,r=this;r instanceof zo;){var n=ji(r);n.__index__=0,n.__values__=e,o?i.__wrapped__=n:o=n;var i=n;r=r.__wrapped__}return i.__wrapped__=t,o},Do.prototype.reverse=function(){var t=this.__wrapped__;if(t instanceof Wo){var o=t;return this.__actions__.length&&(o=new Wo(this)),(o=o.reverse()).__actions__.push({func:fa,args:[Xi],thisArg:e}),new qo(o,this.__chain__)}return this.thru(Xi)},Do.prototype.toJSON=Do.prototype.valueOf=Do.prototype.value=function(){return mn(this.__wrapped__,this.__actions__)},Do.prototype.first=Do.prototype.head,nt&&(Do.prototype[nt]=function(){return this}),Do}();ut?((ut.exports=fo)._=fo,ct._=fo):dt._=fo}.call(Fn.exports)),Fn.exports);const En=e=>null===e.parentId||"null"===e.parentId||!e.parentId,xn=async(e,t,o)=>{var r;if("file"===(null==t?void 0:t.itemType))return e;let n=[];if(!o)return e;{const e=await o({parentId:t.folderId});n=Array.isArray(e)?e:[]}let i=((e,t)=>{const o=Array.isArray(e)?e:[];return(r=t.folderId)&&"root"!==r&&"folders"!==r&&"null"!==r&&null!==r?o.filter(e=>e.parentId===t.folderId):o.filter(En);var r})(n,t);if(null===(r=null==t?void 0:t.search)||void 0===r?void 0:r.trim()){const e=t.search.trim().toLowerCase();i=i.filter(t=>{var o;return null===(o=t.name)||void 0===o?void 0:o.toLowerCase().includes(e)})}if(0===i.length)return e;const a=i.map(e=>({id:e.id,name:e.name,size:void 0,date:"-",isFolder:!0,folderId:e.parentId||"",type:"",selected:!1,extension:"",childCount:e.childCount}));if("folder"===(null==t?void 0:t.itemType))return a;const l=e.filter(e=>!e.isFolder);return[...a,...l]},Pn=e=>{var t,o,r,n;const{state:i,actions:l,options:s}=mn(),{searchTerm:u,sortBy:f,sortOrder:h,selectedFolder:m,pagination:p,pathHistory:g}=i,{setSearchTerm:v,setSortBy:y,setSortOrder:w,setPagination:b}=l,C=e||l.fetchFiles,I=c(null),F=c(Sn.debounce(e=>{const t=JSON.stringify(e);I.current!==t&&(I.current=t,null==C||C(e))},150)).current,A=d(()=>{const e=m||"";if(!e)return;const t=[...Array.isArray(g)?g:[]].reverse().find(t=>t.id===e);return null==t?void 0:t.name},[m,g]),_=d(()=>{var e;const t=null===(e=null==s?void 0:s.config)||void 0===e?void 0:e.disablePagination;return{folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:t?void 0:p.current,limit:t?void 0:p.pageSize,sortBy:f,sortOrder:h,itemType:"all"}},[m,A,u,p.current,p.pageSize,f,h,null===(t=null==s?void 0:s.config)||void 0===t?void 0:t.disablePagination]),S=d(e=>{var t,o;if(v&&v(e),b&&b({current:1,pageSize:p.pageSize,total:0}),C){const r={folderId:m||"",folderName:A(),search:(null==e?void 0:e.trim())||void 0,page:(null===(t=null==s?void 0:s.config)||void 0===t?void 0:t.disablePagination)?void 0:1,limit:(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)?void 0:p.pageSize,sortBy:f,sortOrder:h,itemType:"all"};C(r)}else console.error("🔎 useSortAndFilter: fetchFiles НЕ ОПРЕДЕЛЕНА!")},[v,b,p.pageSize,C,m,A,f,h,null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination]),E=d((e,t)=>{var o,r;null==y||y(e),null==w||w(t),C&&F({folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)?void 0:p.current,limit:(null===(r=null==s?void 0:s.config)||void 0===r?void 0:r.disablePagination)?void 0:p.pageSize,sortBy:e,sortOrder:t,itemType:"all"})},[y,w,F,m,A,u,p.current,p.pageSize,null===(r=null==s?void 0:s.config)||void 0===r?void 0:r.disablePagination]),x=d((e,t)=>{var o;(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)||(b&&b({current:e,pageSize:t||p.pageSize,total:p.total}),C&&F({folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:e,limit:t||p.pageSize,sortBy:f,sortOrder:h,itemType:"all"}))},[b,p.pageSize,p.total,F,m,A,u,f,h,null===(n=null==s?void 0:s.config)||void 0===n?void 0:n.disablePagination]);return a(()=>{if(C){const e=_();F(Object.assign(Object.assign({},e),{page:1}))}},[m]),a(()=>{C&&F(_())},[]),a(()=>()=>{var e;null===(e=F.cancel)||void 0===e||e.call(F)},[F]),{state:{searchTerm:u||"",sortBy:f||"name",sortOrder:h||"asc"},actions:{setSearchTerm:v||(()=>{}),setSortBy:y||(()=>{}),setSortOrder:w||(()=>{}),handleSearch:S,handleSort:E,handlePaginationChange:x,getCurrentQueryParams:_}}};function Rn(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(o[r[n]]=e[r[n]])}return o}"function"==typeof SuppressedError&&SuppressedError;const Nn=new Map;function kn(e){const t="id"in e&&void 0!==e.id?String(e.id):"unknown",o="data"in e?e.data:void 0;return`${e.type}:${t}:${function(e){if(null==e)return"";try{return JSON.stringify(e,Object.keys(e).sort())}catch(t){return String(e)}}(o)}`}const On=()=>{var e,t;const{notification:o}=C.useApp(),r=mn(),{options:n}=r,i=d(async e=>{let t;if(n.handleNotify){try{t=await n.handleNotify(e)}catch(e){console.error(e)}if(!1===t)return!1;"object"==typeof t&&t&&(e=t)}if("error"===e.type&&n.handleError){try{t=await n.handleError(e)}catch(e){console.error(e)}if(!1===t)return!1;"object"==typeof t&&t&&(e=t)}if("success"===e.type&&n.handleSuccess){try{t=await n.handleSuccess(e)}catch(e){console.error(e)}if(t)return!1}return t},[n]),a=d(async function(e,t=!1){var r,a,l,s,d;try{void 0===e.visibility&&(e.visibility=!t);const c=await i(e);"object"==typeof c&&(e=c);const u=null!==(a=null===(r=n.config)||void 0===r?void 0:r.notificationDedupeTtlMs)&&void 0!==a?a:12e3,f="error"===e.type&&!0===e.notificationDedupe;f&&function(e,t){if(t<=0)return;const o=kn(e),r=Date.now(),n=Nn.get(o);void 0!==n&&r-n<t&&(e.visibility=!1)}(e,u);if(!(!1!==e.visibility&&!1!==c&&!1!==(null===(l=n.config)||void 0===l?void 0:l.showNotifications)))return e;const h=o[e.type];if("function"==typeof h){const t=e,{message:o,btn:r}=t,n=Rn(t,["message","btn"]);h(Object.assign(Object.assign(Object.assign({},n),{title:null!==(s=n.title)&&void 0!==s?s:o}),void 0!==r?{actions:r}:{})),f&&(d=e,u<=0||Nn.set(kn(d),Date.now()))}else console.warn(`Unknown notification type: ${e.type}`,e)}catch(e){console.error(e)}return e},[o,i,null===(e=n.config)||void 0===e?void 0:e.notificationDedupeTtlMs,null===(t=n.config)||void 0===t?void 0:t.showNotifications]);return u(()=>({error:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"error"}),t),success:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"success"}),t),warning:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"warning"}),t),notify:a}),[a])},Tn=()=>C.useApp().message,Ln={FileNotFound:"File not found or no longer available.",FileAlreadyExists:"File with this name already exists.",FileInvalidName:"File name is not valid. Allowed characters: {{allowedChars}}",FileAccessDenied:"You don't have permission to access this file.",FileReadError:"Failed to read the file.",FileWriteError:"Failed to write the file.",FileTooLarge:"File is too large ({{fileSize}}). Maximum allowed size: {{maxSize}}.",FileTypeNotAllowed:"This file type is not allowed.",FileCorrupted:"The file appears to be corrupted.",FileChecksumMismatch:"File integrity check failed.",FileStorageQuotaExceeded:"Storage quota exceeded. Please free up space.",FileLocked:"File is locked by another process or user.",FileVersionConflict:"File version conflict. Please refresh and try again.",FolderNotFound:"Folder not found or no longer available.",FolderAlreadyExists:"Folder with this name already exists.",FolderInvalidName:"Folder name is not valid. Allowed characters: {{allowedChars}}",FolderAccessDenied:"You don't have permission to access this folder.",FolderReadError:"Failed to read the folder contents.",FolderWriteError:"Failed to write to the folder.",FolderQuotaExceeded:"Folder storage quota exceeded.",FolderNotEmpty:"Folder is not empty.",FolderBackendError:"Server error while processing the folder.",FolderTimeout:"Folder operation took too long.",RenameNotAllowed:"Renaming is not allowed for this item.",MoveNotAllowed:"Moving is not allowed for this item.",CopyNotAllowed:"Copying is not allowed for this item.",DeleteNotAllowed:"Deleting is not allowed for this item.",MoveIntoSelf:"Cannot move an item into itself.",MoveIntoDescendant:"Cannot move an item into its descendant folder.",CopyIntoSelf:"Cannot copy an item into itself.",UnsupportedOperation:"This operation is not supported.",ConfigError:"Configuration error occurred.",FileUploadQuotaExceeded:"You have exceeded the upload quota.",FileUploadNetworkError:"Network error while uploading the file.",FileUploadTimeout:"File upload took too long.",FileUploadBackendError:"Server error while uploading the file.",UploadUrlInvalid:"The specified URL is not valid.",UploadUrlNotReachable:"The specified URL is not reachable.",UploadUrlContentTypeNotAllowed:"Content type at the URL is not allowed.",UploadUrlDownloadFailed:"Failed to download file from the URL.",FileLookupFailed:"Failed to find existing file by URL.",FileProxyFailed:"Failed to load file through proxy.",FileProxyNotConfigured:"File proxy is not configured.",FileDownloadNetworkError:"Network error while downloading the file.",FileDownloadTimeout:"File download took too long.",FileDownloadBackendError:"Server error while downloading the file.",BatchPartialFailure:"Some items could not be processed.",BatchAllFailed:"Failed to process all items in the batch.",BatchConflict:"Some items in the batch are in a conflicting state.",BatchValidationFailed:"Some items in the batch did not pass validation.",BatchItemLimitExceeded:"Batch operation exceeds the maximum number of items allowed.",ValidationError:"Some of the provided data is invalid.",PayloadTooLarge:"File is too large ({{fileSize}}). Maximum allowed size: {{maxSize}}.",UnsupportedMediaType:"This media type is not supported.",NetworkError:"Network error. Please check your connection and try again.",BackendError:"Server error. Please try again later.",Timeout:"The operation took too long. Please try again.",AuthenticationFailed:"Authentication failed. Please sign in again.",AuthorizationFailed:"You are not allowed to perform this action.",RateLimitExceeded:"Too many requests. Please try again a bit later.",ServiceUnavailable:"Service is temporarily unavailable. Please try again later.",AIResponseInvalid:"AI service returned an invalid response.",AIImageGenerationFailed:"Failed to generate image using AI.",AIImageGenerationLimitExceeded:"You have reached the AI image generation limit.",IntegrationError:"Error in external integration.",ThirdPartyError:"Error in a third-party service.",UnknownError:"An unknown error occurred."},Mn={FileTooLarge:"File is too large to upload.",PayloadTooLarge:"File is too large to upload."},Un=(e,t,o)=>{var r,n,i;if(!e)return;const a=Ln[e];if(!a)return;const l=null!==(r=null==o?void 0:o.fileSize)&&void 0!==r?r:"",s=null!==(n=null==o?void 0:o.maxSize)&&void 0!==n?n:"";if(("FileTooLarge"===e||"PayloadTooLarge"===e)&&!(!!l&&!!s)){const o=Mn[e];return o?t(o):t(a,{fileSize:"?",maxSize:"?"})}return t(a,{allowedChars:null!==(i=null==o?void 0:o.allowedChars)&&void 0!==i?i:"a-z A-Z 0-9 . _ -",fileSize:l,maxSize:s})},jn=e=>{if(!e||"string"!=typeof e)return;const t=e.toLowerCase();return(t.includes("maximum number of files")||t.includes("number of files exceeded"))&&(t.includes("allowed")||t.includes("received"))?"BatchItemLimitExceeded":t.includes("exceeds")||t.includes("maximum")||t.includes("too large")||t.includes("size limit")||t.includes("object size")||t.includes("размер")||t.includes("превышен")?"PayloadTooLarge":t.includes("403")||t.includes("forbidden")||t.includes("access denied")||t.includes("доступ запрещён")?"AuthorizationFailed":t.includes("404")||t.includes("not found")||t.includes("не найден")?"UploadUrlNotReachable":t.includes("already exists")||t.includes("уже существует")||t.includes("дубликат")?"FileAlreadyExists":t.includes("invalid")&&(t.includes("name")||t.includes("имя")||t.includes("назва"))?"FileInvalidName":t.includes("type")&&(t.includes("not allowed")||t.includes("не поддерживается"))?"FileTypeNotAllowed":void 0},Dn=e=>{var t,o,r,n,i,a,l,s,d,c,u,f,h,m,p,g,v,y;if(!e)return{message:"Unknown error",raw:e};if("string"==typeof e)return{message:e};if(e instanceof Error){const i=e;return{message:null!==(t=i.message)&&void 0!==t?t:e.message,code:i.code,status:null!==(o=i.status)&&void 0!==o?o:i.httpStatus,stack:null!==(r=i.stack)&&void 0!==r?r:e.stack,raw:null!==(n=i.raw)&&void 0!==n?n:e}}if("object"==typeof e){const t=e,o=null!==(i=t.data)&&void 0!==i?i:t,r=null!==(a=null==o?void 0:o.data)&&void 0!==a?a:o,n=null!==(d=null!==(s=null!==(l=t.message)&&void 0!==l?l:null==o?void 0:o.message)&&void 0!==s?s:t.error)&&void 0!==d?d:t.reason,w=null!==(f=null!==(u=null!==(c=t.status)&&void 0!==c?c:t.httpStatus)&&void 0!==u?u:null==r?void 0:r.status)&&void 0!==f?f:null==o?void 0:o.status,b=null!==(h=t.code)&&void 0!==h?h:null==o?void 0:o.code,C=t.stack,I=null!==(m=t.raw)&&void 0!==m?m:e,F=null!==(g=null!==(p=t.fileSize)&&void 0!==p?p:null==r?void 0:r.fileSize)&&void 0!==g?g:null==o?void 0:o.fileSize,A=null!==(y=null!==(v=t.maxSize)&&void 0!==v?v:null==r?void 0:r.maxSize)&&void 0!==y?y:null==o?void 0:o.maxSize;if(n||b||w||C||I)return Object.assign(Object.assign({message:n,code:b,status:w,stack:C,raw:I},null!=F&&{fileSize:F}),null!=A&&{maxSize:A})}return{message:String(e),raw:e}};const Bn=(e,t,o)=>{const r=Dn(e),n=null==r?void 0:r.code;if("FileTooLarge"===n&&null!=(null==o?void 0:o.fileSize)&&null!=(null==o?void 0:o.maxSize))return t("File too large ({{size}}). Maximum allowed size: {{maxSize}}",{size:Nr(o.fileSize),maxSize:Nr(o.maxSize)});if(("BatchItemLimitExceeded"===n||"exceeded_max_files"===n)&&(null==r?void 0:r.message)){const{allowed:e,received:o}=function(e){const t=e.match(/Allowed:\s*(\d+)/i),o=e.match(/received:\s*(\d+)/i);return{allowed:t?parseInt(t[1],10):void 0,received:o?parseInt(o[1],10):void 0}}(r.message);if(null!=e&&null!=o)return t("Maximum number of files exceeded. Allowed: {{allowed}}, received: {{received}}",{allowed:e,received:o})}if((null==r?void 0:r.message)&&"Unknown error"!==r.message)return r.message;const i=null!=(null==o?void 0:o.fileSize)&&null!=(null==o?void 0:o.maxSize)?{fileSize:Nr(o.fileSize),maxSize:Nr(o.maxSize)}:void 0,a=Un(n,t,i);return null!=a?a:t("Error uploading file")},zn=e=>{const t=Dn(e);return"path_folder_not_found"===(null==t?void 0:t.code)},qn=["file_get_contents","open stream","failed to open stream","http request failed","curl_error"];const Wn=(e,t,o)=>{var r;if(!e)return t("Error when downloading a file by URL");const n=null!==(r=(e=>{const t=jn(e);if("AuthorizationFailed"===t){const t=(e||"").toLowerCase();if(t.includes("download")||t.includes("url")||t.includes("file_get_contents")||t.includes("failed to download"))return"UploadUrlNotReachable"}return t})(null==e?void 0:e.message))&&void 0!==r?r:null==e?void 0:e.code,i=Un(n,t,o);if(i)return i;const a=(null==e?void 0:e.message)&&"string"==typeof e.message?e.message.trim():null;return a&&function(e){if(!e||e.length>200)return!1;const t=e.toLowerCase();return!qn.some(e=>t.includes(e))}(a)?a:t("Failed to download file from the URL.")},Vn=e=>Array.isArray(e)?e.filter(e=>(null==e?void 0:e.id)&&"folders"!==e.id).map(e=>e.name).filter(Boolean).join("/"):"",$n=e=>{const t=e.trim();if(!t)return"";const o=t.toLowerCase(),r=[o.indexOf(" and "),o.indexOf(" or "),t.indexOf(","),t.indexOf(";"),o.indexOf(". ")].filter(e=>e>=0);if(0===r.length)return t;const n=Math.min(...r);return t.slice(0,n).trim()||t},Hn=(e,t)=>{const o=(e=>{var t,o,r,n;if(e&&"object"==typeof e){const i=e,a=null!==(r=null===(o=null===(t=i.data)||void 0===t?void 0:t.data)||void 0===o?void 0:o.path_folder)&&void 0!==r?r:null===(n=i.data)||void 0===n?void 0:n.path_folder;if("string"==typeof a&&a.trim())return $n(a)||null}const i=Dn(e),a=null==i?void 0:i.message;if(!a)return null;const l=a.toLowerCase(),s=["не существует:","not exists:","not exist:","not found:"];for(const e of s){const t=l.indexOf(e);if(t>=0){const o=a.slice(t+e.length).trim();return $n(o)||null}}const d=["not exists ","not exist ","not found "];for(const e of d){const t=l.indexOf(e);if(t>=0){const o=a.slice(t+e.length).trim();return $n(o)||null}}return null})(e);return o?(e=>{const t=e.split("/").filter(Boolean);return t.length<=1?"":(t.pop(),t.join("/"))})(o):Vn(t)},Gn=async e=>{var t;const{options:o,pathFolder:r,dataProviders:n}=e;if(null==n?void 0:n.clearCache)return void await n.clearCache(r||null);const i=null===(t=null==o?void 0:o.apiEndpoints)||void 0===t?void 0:t.clearCache;if(!i)return;const a=i.includes("?");let l=i;r&&r.length>0&&(l=`${i}${a?"&":"?"}path_folder=${encodeURIComponent(r)}`);const s=await fetch(l,{method:"POST"});if(!s.ok)throw new Error(`Cache clear failed: ${s.status}`)},Kn=()=>{var e,t;const{state:o,actions:n,options:i}=mn(),{t:a}=dr(),l=On(),{folders:s,selectedFolder:c,pathHistory:u,form:f,loading:h,isModalVisible:m}=o,{setFolders:p,setLoading:g,setIsModalVisible:v}=n,{dataProviders:y,config:w}=i,b=d(e=>(Array.isArray(e)?e:[]).filter(e=>e&&e.id&&e.name).map(e=>({id:e.id,name:e.name,parentId:e.folderId?e.folderId:null})),[]),C=d(async(e=!1)=>{null==g||g(!0);try{let e=[];const t="lazy"===(null==w?void 0:w.folderTreeLoading);if(!(null==y?void 0:y.getFolders)){if(null==y?void 0:y.getFiles){const e=async o=>{const{files:r}=await y.getFiles({itemType:"folder",folderId:null!=o?o:void 0}),n=b(r);if(t)return n;const i=await Promise.all(n.map(t=>e(t.id)));return[...n,...i.flat()]},o=await e(null);return void(p&&p(e=>{const r=Array.isArray(e)?e:[];if(!t){const e=o,t=e.filter(e=>e.id===e.parentId);return t.length>0&&console.warn("Folders with cyclic dependencies detected:",t),e}const n=[...r.filter(e=>e.parentId),...o],i=n.filter(e=>e.id===e.parentId);return i.length>0&&console.warn("Folders with cyclic dependencies detected:",i),n}))}return void console.error("DataProvider for folders is not defined")}{const o=!t;e=await y.getFolders({parentId:null,deep:o})}const o=Array.isArray(e)?e:[];null==p||p(o);const r=o.filter(e=>e.id===e.parentId);r.length>0&&console.warn("Folders with cyclic dependencies detected:",r)}catch(t){console.error("Error loading folders:",t);const o=Dn(t);if(!e&&(404===(null==o?void 0:o.status)||"FileNotFound"===(null==o?void 0:o.code))){const e=Hn(t,u||[]);try{return await Gn({options:i,pathFolder:e,dataProviders:null==i?void 0:i.dataProviders}),void await C(!0)}catch(e){console.error("Cache clear failed:",e)}}const r=Un(null==o?void 0:o.code,a);l.error({id:"FOLDERS_FETCH_FAILED",message:null!=r?r:a("Failed to load folders"),description:a("Folders"),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{reason:t instanceof Error?t.message:String(t),folderId:null,folderName:a("Folders")}})}finally{null==g||g(!1)}},[null==y?void 0:y.getFiles,null==y?void 0:y.getFolders,p,g,null==w?void 0:w.folderTreeLoading,b,l,a,u,i]),I=d(()=>C(),[C]),F=d(async e=>{try{let t,o;if(null==y?void 0:y.getFolders){t=await y.getFolders({parentId:e,deep:!1});const r=Array.isArray(s)?s:[],n=new Set(t.map(e=>e.id)),i=r.filter(t=>t.parentId!==e||n.has(t.id));o=[...i,...t.filter(e=>!i.some(t=>t.id===e.id))]}else{if(!(null==y?void 0:y.getFiles))return[];{const{files:r}=await y.getFiles({itemType:"folder",folderId:null!=e?e:void 0});t=b(r);const n=Array.isArray(s)?s:[],i=new Set(t.map(e=>e.id)),a=n.filter(t=>t.parentId!==e||i.has(t.id));o=[...a,...t.filter(e=>!a.some(t=>t.id===e.id))]}}let r=o,n=0;for(;n!==r.length;){n=r.length;const e=new Set(r.map(e=>e.id));r=r.filter(t=>!t.parentId||e.has(t.parentId))}return null==p||p(r),t}catch(e){return console.error("Error loading child folders:",e),[]}},[y,s,p,b]),A=d(()=>{var e;const t=null!==(e=null==w?void 0:w.defaultFolderName)&&void 0!==e?e:a("New folder");f.setFieldsValue({folderName:t}),null==v||v(!0)},[f,v,a,null==w?void 0:w.defaultFolderName]),_=d(async(e,t)=>{const o=[...(Array.isArray(s)?s:[]).filter(t=>t.id!==e.id),e];if(null==p||p(o),e.parentId&&(await F(e.parentId),await new Promise(e=>setTimeout(e,50))),!(null==t?void 0:t.preserveSelection)&&n.setSelectedFolder&&n.setSelectedFolder(e.id),!(null==t?void 0:t.preserveSelection)&&n.setPathHistory){const t=Array.isArray(o)?o:[],r=(e,o=new Set)=>{if(o.has(e))return console.warn(`Cycle detected in the path to the folder with id=${e}`),[];const n=t.find(t=>t.id===e);if(!n)return[];const i=new Set(o);return i.add(e),n.parentId?[...r(n.parentId,i),{id:n.id,name:n.name}]:[{id:n.id,name:n.name}]},i=r(e.id),l=[{id:"folders",name:a("Folders")},...i];n.setPathHistory(l)}},[s,p,n,o.pathHistory,F,a]),S=d(async e=>{try{if(null==y?void 0:y.getFolders){const t=await y.getFolders(),o=Array.isArray(t)?t:[];return o.some(t=>t.id===e)}if(null==y?void 0:y.getFiles){const t=new Set,o=async r=>{const{files:n}=await y.getFiles({itemType:"folder",folderId:null!=r?r:void 0}),i=b(n);for(const r of i){if(t.has(r.id))continue;if(t.add(r.id),r.id===e)return!0;if(await o(r.id))return!0}return!1};return await o(null)}}catch(e){console.warn("⚠️ Error checking the folder:",e)}return!1},[null==y?void 0:y.getFolders,null==y?void 0:y.getFiles,b]),E=d(async e=>{var t;let o,r,n=null;try{const i=await(e?e.validateFields():f.validateFields());if(o=i.folderName.trim(),!o){const e=i.targetFolder||(c&&"folders"!==c?c:null);return void l.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:a("Folder name cannot be empty"),placement:"bottomRight",data:{folderName:o,folderId:null!=e?e:null,reason:"emptyName",is_force_create:!!i.is_force_create}})}r=Zt(o,w);const d=i.targetFolder;if(d)n="folders"!==d?d:null;else if(c&&"folders"!==c)n=c;else if(Array.isArray(u)&&u.length>1){const e=u[u.length-1];n=(null==e?void 0:e.id)&&"folders"!==e.id?e.id:null}if(Xt(w)&&(null==y?void 0:y.getFolders))try{const e=(await y.getFolders({parentId:n,deep:!1})||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean);if(e.includes(o.trim().toLowerCase()))return void l.error({id:"FOLDER_ALREADY_EXISTS",message:a("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,folderId:n}})}catch(e){}let h;if(!(null==y?void 0:y.createFolder))return void l.error({id:"FOLDER_CREATE_PROVIDER_NOT_CONFIGURED",message:a("Folder creation provider is not configured"),placement:"bottomRight",data:{folderName:r,folderId:null!=n?n:null,is_force_create:!!i.is_force_create}});h=await y.createFolder({name:r,parentId:n,is_force_create:!!i.is_force_create}),(e=>{if(!e||!e.id)throw new Error(a("Invalid server response: folder ID is missing"));if(e.id===e.parentId&&e.parentId)throw console.error("Circular dependency detected: folder cannot be its own parent"),new Error(a("Error: folder cannot be its own parent"))})(h);const m={id:h.id,name:h.name,parentId:null!=n?n:null,childCount:h.childCount},g=[...(Array.isArray(s)?s:[]).filter(e=>e.id!==m.id),m];if(null==p||p(g),l.success({id:"FOLDER_CREATE_SUCCESS",message:a("Folder created"),placement:"bottomRight",data:{itemIds:[m.id],folderId:null!==(t=m.parentId)&&void 0!==t?t:null,folderName:m.name}}),e||null==v||v(!1),(async()=>{try{await _(m,{preserveSelection:Boolean(e)}),await I(),await new Promise(e=>setTimeout(e,200));await S(h.id)||console.warn("⚠️ Could not confirm the creation of the folder on the server, but continuing...")}catch(e){console.error("Error performing background operations after creating the folder:",e)}})(),e)return h}catch(e){console.error("❌ Error creating the folder:",e);const t=Dn(e),i=Un(null==t?void 0:t.code,a);l.error({id:"FOLDER_CREATE_FAILED",message:null!=i?i:a("Failed to create folder"),placement:"bottomRight",innerException:e,data:{folderName:r||o,folderId:null!=n?n:null,reason:e instanceof Error?e.message:String(e)}})}},[f,c,y,_,I,S,v,l,a,s,p,w,u]),x=d(()=>{null==v||v(!1)},[v]),P=d((e,t=new Set)=>{const o=Array.isArray(s)?s:[];return e.map(e=>{if(t.has(e.id))return console.warn(`Cycle detected in the folder structure with id=${e.id}. Skipping child elements processing.`),{key:e.id,label:e.name+" "+a("(error)"),icon:r.createElement(se,{style:{color:"red"}})};const n=new Set(t);n.add(e.id);const i=o.filter(t=>t.parentId===e.id&&t.id!==e.id);return{key:e.id,label:e.name,children:i.length>0?P(i,n):void 0}})},[s]),R=d(()=>{const e=Array.isArray(s)?s:[],t={key:"folders",label:a("Folders"),children:[]},o=e.filter(e=>null===e.parentId||!e.parentId);return t.children=P(o),[t]},[s,a,P]),N=d(async(e,t)=>{var o,r,d,c;let u;try{const f=t.trim(),h=null==s?void 0:s.find(t=>t.id===e);if(!f)return void l.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:a("Folder name cannot be empty"),placement:"bottomRight",data:{folderId:e,folderName:t,reason:"emptyName"}});u=Zt(f,w);if(!(!1!==(null===(o=null==w?void 0:w.features)||void 0===o?void 0:o.enableRenameFolder)))return void l.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:a("Folder rename is disabled by config"),placement:"bottomRight",data:{itemId:e,itemName:null!==(r=null==h?void 0:h.name)&&void 0!==r?r:u}});if(!(null===(d=i.dataProviders)||void 0===d?void 0:d.renameFolder))return void l.error({id:"FOLDER_RENAME_FAILED",message:a("Folder rename provider is not configured"),placement:"bottomRight",data:{itemId:e,itemName:u,error:{message:"providerNotConfigured"}}});const m=await i.dataProviders.renameFolder(e,u);if(!(null==m?void 0:m.id))return void l.error({id:"FOLDER_RENAME_FAILED",message:a("Unexpected response when renaming folder"),placement:"bottomRight",data:{itemId:e,itemName:u,error:{message:"invalidResponse"}}});await I(),e!==m.id&&n.setSelectedFolder&&n.setSelectedFolder(m.id),l.success({id:"FOLDER_RENAME_SUCCESS",message:a("Folder renamed"),placement:"bottomRight",data:{itemId:m.id,itemName:m.name,folderId:null!==(c=m.parentId)&&void 0!==c?c:null}})}catch(o){console.error("Error renaming the folder:",o),l.error({id:"FOLDER_RENAME_FAILED",message:a("Failed to rename folder"),placement:"bottomRight",innerException:o,data:{itemId:e,itemName:u||t,error:{message:o instanceof Error?o.message:String(o)}}})}},[I,s,null===(e=i.dataProviders)||void 0===e?void 0:e.renameFolder,null===(t=null==w?void 0:w.features)||void 0===t?void 0:t.enableRenameFolder,w,n.setSelectedFolder,l,a]);return{state:{folders:s,isCreatingFolder:m,loading:h},actions:{fetchFolders:I,fetchChildFolders:F,handleCreateFolder:A,handleModalOk:E,handleModalCancel:x,generateMenuItems:R,renameFolder:N}}},Qn=()=>{const{options:e,actions:t}=mn(),{dataProviders:o,config:r}=e,{setUndoDeletion:n}=t,{t:i}=dr(),a=On(),l=d(async({items:e,selectedFolder:t,getItemNameById:l,showNotifications:s=!1})=>{let d=0,c=0;const u=[],f=async t=>{if(null==o?void 0:o.deleteItems)try{const r=await o.deleteItems(e.map(e=>e.id),{permanent:t}),n=r.detailed;if(n){const e=n.filter(e=>e.success),t=n.filter(e=>!e.success),o=t.filter(e=>{var t;const o=null!==(t=e.innerException)&&void 0!==t?t:e.error;return zn(o)}),r=t.filter(e=>{var t;const o=null!==(t=e.innerException)&&void 0!==t?t:e.error;return!zn(o)});return d+=e.length+o.length,c+=r.length,void r.forEach(e=>{var t;const o=(e=>{var t;return null!==(t=e.requestId)&&void 0!==t?t:e.id})(e),r=null!==(t=e.innerException)&&void 0!==t?t:e.error,n=Dn(r);u.push({itemId:o,itemName:l(o),error:n})})}if(r.success)d+=e.length;else{const t=r.error;if(zn(t))d+=e.length;else if(t){c+=e.length;const o=Dn(t);u.push({error:o})}else c+=e.length}return}catch(o){if(zn(o))d+=e.length;else{const r=t?"Ошибка при удалении":"Ошибка при перемещении в корзину";console.error(r,o),c+=e.length;const n=Dn(o);u.push({error:n})}}const r=t?"DataProvider для удаления файлов не настроен":"DataProvider для перемещения не настроен";console.warn(r)},h=(null==r?void 0:r.enableTrashFolder)&&"Trash"===t;return(null==r?void 0:r.enableTrashFolder)&&!h?await f(!1):await f(!0),d>0&&(null==r?void 0:r.enableTrashFolder)&&!h&&(null==n||n({itemIds:e.map(e=>e.id),sourceFolderId:t||"folders"})),s&&(d>0&&a.success({id:"FILES_DELETE_SUCCESS",message:i("Files deleted"),placement:"bottomRight",data:{successCount:d,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:t||null}}),c>0&&a.error({id:"FILES_DELETE_ERROR",message:i("Error when deleting a file"),placement:"bottomRight",data:{failCount:c,totalCount:e.length,itemIds:e.map(e=>e.id),itemNames:e.map(e=>l(e.id)),folderId:t||null,errors:u}})),{successCount:d,failCount:c,errorDetails:u}},[o,r,n,i,a]);return{deleteItems:l}};class Jn extends Error{constructor(e,t,o,r){super(e),this.code=t,this.status=o,this.details=r,this.name="FileManagerApiError",Error.captureStackTrace&&Error.captureStackTrace(this,Jn)}}const Yn=/^(localhost|127\.0\.0\.1|0\.0\.0\.0|::1)$/i,Zn=/^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)/;function Xn(e,t){const o=e.trim();if(!o)throw new Jn(t("Enter the URL of the image"),"UploadUrlInvalid");if(o.length>8192)throw new Jn(t("URL too long"),"UploadUrlInvalid");let r;try{r=new URL(o)}catch(e){throw new Jn(t("The specified URL is not valid."),"UploadUrlInvalid")}const n=r.protocol.toLowerCase();if("http:"!==n&&"https:"!==n)throw new Jn(t("Only http and https URLs are supported"),"UploadUrlInvalid");const i=r.hostname.toLowerCase();if(Yn.test(i)&&("undefined"==typeof window||!Yn.test(window.location.hostname.toLowerCase())))throw new Jn(t("Private and local URLs are not allowed"),"UploadUrlInvalid");if(Zn.test(i))throw new Jn(t("Private and local URLs are not allowed"),"UploadUrlInvalid")}function ei(e,t){var o;if(null==e?void 0:e.extension){const t=e.extension.toLowerCase(),o={jpg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},jpeg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},png:{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},gif:{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},webp:{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},svg:{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(o[t])return o[t]}if(null==e?void 0:e.type){const t=Nt(e.type),o={"image/jpeg":{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},"image/png":{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},"image/gif":{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},"image/webp":{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},"image/svg+xml":{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(o[t])return o[t]}if(null==e?void 0:e.name){const t=null===(o=e.name.split(".").pop())||void 0===o?void 0:o.toLowerCase();if(t){const e={jpg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},jpeg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},png:{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},gif:{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},webp:{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},svg:{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(e[t])return e[t]}}if(t){const e=Nt(t),o=Tt(e);let r="jpeg";return"png"===o?r="png":"svg"===o?r="svg":"jpeg"===o&&(r="jpeg"),{extension:o,mimeType:e,format:o,pixieFormat:r}}return{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"}}const ti={MAX_SIZE_MB:.48,MAX_WIDTH_OR_HEIGHT:2e3,QUALITY:.8},oi=["gif","svg"];function ri(e,t){const{colorHex:o,colorHex2:r,colorHex3:n}=t,i=[`--icon-grad-1: ${o}`,`--icon-grad-2: ${r}`,`--icon-stroke-1: ${o}`,`--icon-stroke-2: ${r}`,`--icon-stroke-3: ${n}`,`--icon-fill-1: ${o}`,`--icon-fill-2: ${r}`,`--icon-fill-3: ${n}`,`color: ${o}`].join(";");let a=e.replace(/<svg([^>]*)>/i,(e,t)=>{let o=t;return/style="/i.test(o)?o=o.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};${i}"`):o+=` style="${i}"`,`<svg${o}>`});return a=a.replace(/var\(--icon-color-1\)/g,o).replace(/var\(--icon-color-2\)/g,r).replace(/var\(--icon-color-3\)/g,n).replace(/var\(--icon-fill-1\)/g,o).replace(/var\(--icon-fill-2\)/g,r).replace(/var\(--icon-fill-3\)/g,n).replace(/var\(--icon-stroke-1\)/g,o).replace(/var\(--icon-stroke-2\)/g,r).replace(/var\(--icon-stroke-3\)/g,n).replace(/var\(--icon-grad-1\)/g,o).replace(/var\(--icon-grad-2\)/g,r).replace(/currentColor/g,o),a}function ni(e,t){const o=e.match(/\swidth="([0-9.]+)(px)?"/i),r=e.match(/\sheight="([0-9.]+)(px)?"/i);if(o&&r){const e=parseFloat(o[1]),n=parseFloat(r[1]);if(Number.isFinite(e)&&Number.isFinite(n)&&e>0&&n>0){const o=e/n;return o>=1?{width:t,height:Math.max(1,Math.round(t/o))}:{width:Math.max(1,Math.round(t*o)),height:t}}}const n=e.match(/viewBox="([^"]+)"/i);if(n){const e=n[1].trim().split(/\s+/);if(4===e.length){const o=parseFloat(e[2]),r=parseFloat(e[3]);if(Number.isFinite(o)&&Number.isFinite(r)&&o>0&&r>0){const e=o/r;return e>=1?{width:t,height:Math.max(1,Math.round(t/e))}:{width:Math.max(1,Math.round(t*e)),height:t}}}}return{width:t,height:t}}function ii(e){if(!e)return null;const t=e.trim();if(t.endsWith("%"))return null;const o=parseFloat(t.replace(/px$/i,""));return Number.isFinite(o)&&o>0?o:null}function ai(e,t=2,o=4096){const{width:r,height:n}=function(e){var t,o,r,n,i;const a=null!==(o=null===(t=e.match(/<\s*svg\b[\s\S]*?>/i))||void 0===t?void 0:t[0])&&void 0!==o?o:"",l=null===(r=a.match(/\bwidth\s*=\s*["']([^"']*)["']/i))||void 0===r?void 0:r[1],s=null===(n=a.match(/\bheight\s*=\s*["']([^"']*)["']/i))||void 0===n?void 0:n[1],d=ii(l),c=ii(s);if(null!=d&&null!=c)return{width:d,height:c};const u=null===(i=e.match(/viewBox\s*=\s*["']([^"']+)["']/i))||void 0===i?void 0:i[1];if(u){const e=u.trim().split(/[\s,]+/);if(4===e.length){const t=parseFloat(e[2]),o=parseFloat(e[3]);if(Number.isFinite(t)&&Number.isFinite(o)&&t>0&&o>0)return{width:t,height:o}}}return null!=d?{width:d,height:d}:null!=c?{width:c,height:c}:{width:300,height:300}}(e);let i=Math.max(1,Math.round(r*t)),a=Math.max(1,Math.round(n*t));const l=Math.max(64,o),s=Math.max(i,a);if(s>l){const e=l/s;i=Math.max(1,Math.round(i*e)),a=Math.max(1,Math.round(a*e))}return{width:i,height:a}}async function li(e,t,o,r,n){var i;const a=null!==(i=null==n?void 0:n.canvasScale)&&void 0!==i?i:2,l=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(l);try{const e=new Image;await new Promise((t,o)=>{e.onload=()=>t(),e.onerror=()=>o(new Error("Failed to load SVG image")),e.src=s});const r=document.createElement("canvas"),n=Math.max(1,Math.round(t*a)),i=Math.max(1,Math.round(o*a));r.width=n,r.height=i;const l=r.getContext("2d");if(!l)throw new Error("Canvas 2D context is not available");return l.clearRect(0,0,n,i),l.drawImage(e,0,0,n,i),function(e){return new Promise((t,o)=>{e.toBlob(e=>{e?t(e):o(new Error("canvas.toBlob returned null"))},"image/png")})}(r)}finally{URL.revokeObjectURL(s)}}async function si(e,t,o,r,n){const i=await li(e,t,o,0,n);return a=i,new Promise((e,t)=>{const o=new FileReader;o.onload=()=>e(o.result),o.onerror=()=>{var e;return t(null!==(e=o.error)&&void 0!==e?e:new Error("readAsDataURL failed"))},o.readAsDataURL(a)});var a}function di(e,t,o,r){return new File([e],t,{type:o,lastModified:r})}function ci(e,t){return t&&t!==e.name?di(e,t,e.type,e.lastModified):e}async function ui(e,t={}){const{maxSizeMB:o=ti.MAX_SIZE_MB,maxWidthOrHeight:r=ti.MAX_WIDTH_OR_HEIGHT,mimeType:n,fileName:i,libURL:a,enableCompression:l=!0,convertSvgToPng:s=!1}=t;if(!(e&&e instanceof File))return e;let d=e,c=!1;if(s){const t=(d.type||"").toLowerCase(),o=/\.svg$/i.test(d.name.trim()),n=t.includes("svg");let a=!1;if(!n&&!o)try{const e=await async function(e,t=24e3){const o=Math.min(t,Math.max(0,e.size));return e.slice(0,o).text()}(d);a=function(e){const t=e.trimStart().replace(/^\uFEFF/,"");return!!t.startsWith("<")&&/<\s*svg[\s>/]/i.test(t)}(e)}catch(e){a=!1}if(n||o||a)try{d=await async function(e,t={}){var o,r,n;const i=null!==(o=t.pixelScale)&&void 0!==o?o:2,a=null!==(r=t.maxLongEdge)&&void 0!==r?r:4096,l=await e.text(),{width:s,height:d}=ai(l,i,a),c=await li(l,s,d,0,{canvasScale:1}),u=null!==(n=t.outputFileName)&&void 0!==n?n:e.name,f=/\.svg$/i.test(u)?u.replace(/\.svg$/i,".png"):`${u}.png`;return new File([c],f,{type:"image/png",lastModified:e.lastModified})}(d,{maxLongEdge:r,outputFileName:null!=i?i:d.name}),c=!0}catch(t){console.warn("prepareImageForUpload: SVG to PNG conversion failed, using original",t),d=e}}if(c)return d;const u=(d.type&&""!==d.type.trim()?d.type:Lt(d.name))||n||"image/jpeg",f=Nt(u);if(!f.startsWith("image/"))return ci(d,i);const h="image/webp"===(m=f)?"image/jpeg":m;var m;const p=Tt(f),g=Tt(h),v=h!==f?function(e,t){const o=t.startsWith(".")?t.slice(1):t,r=e.lastIndexOf(".");return r>0?`${e.substring(0,r)}.${o}`:`${e}.${o}`}(null!=i?i:d.name,g):null!=i?i:d.name,y=l&&(w=p,!oi.includes(w));var w;if(!y&&!(h!==f))return ci(d,v);try{const t={libURL:a,useWebWorker:!0,fileType:h};y?(t.maxSizeMB=o,t.maxWidthOrHeight=r):(t.maxSizeMB=Math.max(e.size/1048576+1,1),t.initialQuality=1,t.alwaysKeepResolution=!0);const n=await $e(d,t);return function(e,t,o,r){const n=null!=r?r:t.name;return e instanceof File?e.type!==o||e.lastModified!==t.lastModified||e.name!==n?di(e,n,o,t.lastModified):e:di(e,n,o,t.lastModified)}(n,d,Nt(n.type||h),v)}catch(e){console.error("prepareImageForUpload failed",e);try{return ci(d,v)}catch(e){return console.error("Failed to create File with normalized name after image preparation error",e),d}}}async function fi(e){const{folderId:t,dataProviders:o,folders:r,pathHistory:n,t:i}=e,a=null==t?"":String(t);if(!a||"folders"===a)return i("Folders");if("Trash"===a)return i("Trash");const l=n||[],s=l[l.length-1];if((null==s?void 0:s.id)===a&&s.name)return s.name;const d=[...l].reverse().find(e=>e.id===a);if(null==d?void 0:d.name)return d.name;const c=null==o?void 0:o.getItem;if(c)try{const e=await Promise.resolve(c(a));if(null==e?void 0:e.name)return e.name}catch(e){}const u=null==r?void 0:r.find(e=>e.id===a);return(null==u?void 0:u.name)?u.name:a}const hi=/^(utm_[a-z0-9_]+|fbclid|gclid|igshid|mc_cid|mc_eid)$/i;function mi(e){const t=new URL(e.trim());t.hash="",t.hostname=t.hostname.toLowerCase(),("https:"===t.protocol&&"443"===t.port||"http:"===t.protocol&&"80"===t.port)&&(t.port="");const o=Array.from(t.searchParams.entries()).filter(([e])=>!hi.test(e)).sort(([e,t],[o,r])=>{const n=e.localeCompare(o);return 0!==n?n:t.localeCompare(r)});return t.search="",o.forEach(([e,o])=>t.searchParams.append(e,o)),t.toString()}function pi(e){if(function(e){return"object"==typeof e&&null!==e&&("name"in e&&"DirectResourceFetchError"===e.name?!("final"in e)||!1!==e.final:"final"in e&&!0===e.final)}(e)||e instanceof Jn)throw e}async function gi(e,t,o,r,n){const{fetchWithProxy:i,handleFileProxy:a,handleProxyUrl:l}=t,s=Object.assign({mode:"cors"},null==n?void 0:n.fetchInit);let d;if(a)try{const t=await Promise.resolve(a(e));if(t)return r(t)}catch(e){pi(e),d=e,console.warn("handleFileProxy failed, falling back to next strategy",e)}if(l)try{const t=await Promise.resolve(l(e));if(t&&t!==e){return r(await o(t))}}catch(e){pi(e),d=e,console.warn("handleProxyUrl fetch failed, falling back to next strategy",e)}if(i)try{const t=await Promise.resolve(i(e,s,{intent:"downloadBlob"}));if(!t.ok)throw new Error(`HTTP ${t.status}`);return r(await t.blob())}catch(e){pi(e),d=e,console.warn("fetchWithProxy failed",e)}if(!i)try{return r(await o(e))}catch(e){pi(e),d=e}throw d instanceof Error?d:new Error("Failed to download file from the URL")}function vi(e){return!!(null==e?void 0:e.startsWith("image/"))&&"image/gif"!==e}function yi(e,t){if(t===e.name)return e;try{return new File([e],t,{type:e.type,lastModified:e.lastModified})}catch(t){return console.warn("Failed to create normalized File:",t),e}}function wi(e){return new Promise((t,o)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>{var e;return o(null!==(e=r.error)&&void 0!==e?e:new Error("Failed to read proxied file"))},r.readAsDataURL(e)})}function bi(e){try{const t=new URL(e).pathname.split("/").pop();return t?decodeURIComponent(t):void 0}catch(e){return}}function Ci(e){return null==e||""===e||"folders"===e?null:e}async function Ii(e){const t=await fetch(e,{mode:"cors"});if(!t.ok)throw new Jn(`HTTP ${t.status}`,"UploadUrlDownloadFailed",t.status);return t.blob()}function Fi(e,t){var o,r;if(!(e instanceof Blob)||0===e.size)throw new Jn(t("Failed to download file from the URL."),"UploadUrlDownloadFailed");const n=(null===(r=null===(o=e.type)||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim())||"image/png";if(!n.startsWith("image/"))throw new Jn(t("Content type at the URL is not allowed."),"UploadUrlContentTypeNotAllowed");return{blob:e,mimeType:n}}const Ai=()=>{var e,t,o,r;const{state:i,actions:a,options:l}=mn(),s=Pn(),{sortBy:c,sortOrder:u}=s.state,{actions:{fetchFolders:f}}=Kn(),{t:h}=dr(),m=On(),{deleteItems:p}=Qn(),{selectedFolder:g,urlForm:v,pagination:y,files:w,pathHistory:b,folders:C}=i,I=n.useRef(null),F=n.useRef([]);I.current=y,F.current=Array.isArray(w)?w:[];const A=n.useRef(null),{setFiles:_,setLoading:S,setIsUrlModalVisible:E,setActiveLibraryItem:x,setPagination:P,setSelectedFolder:R,setPathHistory:N}=a,{dataProviders:k}=l,O=d(async e=>{var t,o,r,n,i;if(!(null==k?void 0:k.getFiles))return[];const a=null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.disablePagination,s=a?void 0:null!==(o=null==e?void 0:e.page)&&void 0!==o?o:1,d=a?void 0:null!==(r=null==e?void 0:e.limit)&&void 0!==r?r:20,{files:c,pagination:u}=await k.getFiles({folderId:"folders"!==(null==e?void 0:e.folderId)?null==e?void 0:e.folderId:void 0,noFolder:null==e?void 0:e.noFolder,search:(null===(n=null==e?void 0:e.search)||void 0===n?void 0:n.trim())||void 0,sortBy:null==e?void 0:e.sortBy,sortOrder:null==e?void 0:e.sortOrder,page:s,limit:d,itemType:(null==e?void 0:e.itemType)||"all"});return P&&((null===(i=null==l?void 0:l.config)||void 0===i?void 0:i.disablePagination)?P({current:1,pageSize:c.length||1,total:c.length||0}):u&&P({current:u.page,pageSize:u.limit,total:u.total})),c},[k,null===(e=null==l?void 0:l.config)||void 0===e?void 0:e.disablePagination,P]),T=d(async(e,t,o)=>Lr(k,e,t,o,Xt(null==l?void 0:l.config)),[k,null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient]),L=d(async(e,t=!1)=>{var o,r,n,i,a;try{null==S||S(!0);let t=[];if(!(null==k?void 0:k.getFiles))return void console.error("DataProvider for getting files is not defined");t=await O(e);const o=null!=e?e:{folderId:g||"",itemType:"all"};"file"!==o.itemType&&(t=await xn(t,o,null==k?void 0:k.getFolders)),"Trash"!==(g||"")&&(t=t.filter(e=>!(e.isFolder&&"Trash"===e.id))),null==_||_(t);const r=Ci(o.folderId);if(r===Ci(g)){const e=Array.isArray(b)?b:[];A.current={selectedFolder:null!=g?g:null,pathHistory:e.map(e=>Object.assign({},e))}}}catch(s){if("StaleLoad"===(null==s?void 0:s.name))return;const d=Dn(s),c=404===(null==d?void 0:d.status)||"FileNotFound"===(null==d?void 0:d.code)||"path_folder_not_found"===(null==d?void 0:d.code);if(c||console.error("Error loading files:",s),!t&&c){const t=Hn(s,b||[]);try{return await Gn({options:l,pathFolder:t,dataProviders:null==l?void 0:l.dataProviders}),void await L(e,!0)}catch(e){console.error("Cache clear failed:",e)}}if(c&&R&&N){const t=Array.isArray(b)?b:[];if(t.length>1){const r=t.slice(0,-1),n=r[r.length-1],i=null!==(o=null==n?void 0:n.id)&&void 0!==o?o:"folders";return N(r),R(i),await f(),m.success({id:"FOLDER_NOT_FOUND_NAVIGATE",message:h("Folder not found"),description:h("Navigated to parent folder"),placement:"bottomRight"}),void await L(Object.assign(Object.assign({},e),{folderId:i}),!1)}return N([{id:"folders",name:h("Folders")}]),R("folders"),await f(),m.success({id:"FOLDER_NOT_FOUND_NAVIGATE",message:h("Folder not found"),description:h("Navigated to root folder"),placement:"bottomRight"}),void await L(Object.assign(Object.assign({},e),{folderId:"folders"}),!1)}const u=A.current;if(u&&R&&N){const e=Array.isArray(b)?b:[],t=(null!==(r=u.selectedFolder)&&void 0!==r?r:null)===(null!=g?g:null),o=(i=u.pathHistory,a=e,i.length===a.length&&i.every((e,t)=>{var o;return e.id===(null===(o=a[t])||void 0===o?void 0:o.id)}));t&&o||(R(u.selectedFolder),N(u.pathHistory.map(e=>Object.assign({},e))),l.onPathChange&&l.onPathChange(u.pathHistory.map(e=>e.name)))}const p=Un(null==d?void 0:d.code,h),v=null!=e?e:{folderId:g||"",itemType:"all"},y=void 0!==v.folderId&&""!==v.folderId?v.folderId:g||"",w=Array.isArray(b)?b.map(e=>Object.assign({},e)):[],I=null===(n=v.folderName)||void 0===n?void 0:n.trim(),F=I&&I.length>0?I:await fi({folderId:y,dataProviders:k,folders:Array.isArray(C)?C:[],pathHistory:w,t:h}),_=h("Failed to load files"),S=h("Failed to load files in folder",{folderName:F}),E=p&&p!==_?p:void 0;m.error({id:"FILES_FETCH_FAILED",message:S,description:E,placement:"bottomRight",innerException:s,notificationDedupe:!0,data:{params:Object.assign(Object.assign({},v),{folderName:F}),folderName:F}})}finally{null==S||S(!1)}},[k,_,S,R,N,O,f,g,C,m,h,b,l]),M=d(e=>L(e),[L]),U=d(async(e,t)=>{var o;if(!(null==k?void 0:k.findFileByUrl))return null;const r=mi(e);try{return null!==(o=await k.findFileByUrl(r))&&void 0!==o?o:null}catch(e){return console.warn("findFileByUrl failed, falling back to direct loading",e),null}},[k]),j=d(async(e,t)=>{var o,r,n;Xn(e,h);const i=mi(e),a=await U(i,t);if(a)return{kind:"existing",file:a,normalizedUrl:i};let s,d;try{const e=await gi(i,{fetchWithProxy:null===(o=null==l?void 0:l.config)||void 0===o?void 0:o.fetchWithProxy,handleFileProxy:null===(r=null==l?void 0:l.config)||void 0===r?void 0:r.handleFileProxy,handleProxyUrl:null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.handleProxyUrl},Ii,e=>Fi(e,h));s=e.blob,d=e.mimeType}catch(e){if(e instanceof Jn)throw e;throw e instanceof Error?e:new Jn(h("Failed to download file from the URL."),"UploadUrlDownloadFailed")}const c=Tt(d),u=bi(i)||"uploaded-file",f=u.replace(/\.[^.]+$/,"")||"uploaded-file";return{kind:"blob",blob:s,normalizedUrl:i,mimeType:d,extension:c,fileName:Yt(u.includes(".")?u:`${f}.${c}`,null==l?void 0:l.config)}},[U,null==l?void 0:l.config,h]),D=d(async(e,t)=>{var o,r,n,i;Xn(e,h);const a=mi(e);try{const e=await j(a,t);if("existing"===e.kind)return e.file;return{thumbnail:await wi(e.blob),name:e.fileName,type:e.mimeType,extension:e.extension,size:e.blob.size,sourceUrl:e.normalizedUrl,saveWithoutFolder:!0}}catch(e){let c=e;if(null==k?void 0:k.uploadFileByUrl)try{const e=null!=g?g:"",t=Yt(bi(a)||"uploaded-file",null==l?void 0:l.config),n=await T(t,e,!1),i=await k.uploadFileByUrl({url:a,folderId:e,name:n,eventSource:"pixie"}),s=Fi(null!==(o=(null==i?void 0:i.id)&&k.getFileData?await k.getFileData(i.id):void 0)&&void 0!==o?o:(null==i?void 0:i.url)?await Ii(i.url):(null==i?void 0:i.thumbnailUrl)?await Ii(i.thumbnailUrl):(null==i?void 0:i.sourceUrl)?await Ii(i.sourceUrl):void 0,h),d=await wi(s.blob);return Object.assign(Object.assign({},i),{thumbnail:d,type:i.type||s.mimeType,extension:i.extension||Tt(s.mimeType),size:null!==(r=i.size)&&void 0!==r?r:s.blob.size,sourceUrl:i.sourceUrl||a})}catch(e){c=e,console.warn("Failed to prepare file for Pixie via uploadByUrl fallback",e)}const u=Dn(c),f=(s=null==u?void 0:u.code,d="UploadUrlDownloadFailed","string"==typeof s?s:d),p=c instanceof Jn?c:new Jn(null!==(i=null!==(n=Un(f,h))&&void 0!==n?n:null==u?void 0:u.message)&&void 0!==i?i:h("Failed to download file from the URL."),f,null==u?void 0:u.status);throw p.notificationShown=!0,await m.error({id:"EDITOR_PROXY_FILE_FAILED",message:p.message,placement:"bottomRight",data:{url:a,folderId:g||null,error:u,eventSource:"pixie"},innerException:c},t),p}var s,d},[k,m,null==l?void 0:l.config,j,T,g,h]),B=d(async e=>{const t=I.current;try{const o=F.current.find(t=>t.id===e),r=e=>{if(!e)return;const t=w.find(t=>t.id===e);return null==t?void 0:t.name};await p({items:[{id:e,isFolder:null==o?void 0:o.isFolder}],selectedFolder:g,getItemNameById:r,showNotifications:!0});const n=Object.assign({},t);let i=t.current;1===w.length&&(i=n.current>1?n.current-1:1),await M({folderId:g||"",page:i,limit:t.pageSize,sortBy:c,sortOrder:u})}catch(t){console.error("ОError when deleting a file:",t);const o=t;(null==o?void 0:o.notificationShown)||m.error({id:"FILES_DELETE_ERROR",message:h("Error when deleting a file"),placement:"bottomRight",innerException:t,data:{failCount:1,totalCount:1,itemIds:[e],folderId:g||null,errors:[{itemId:e,error:Dn(t)}]}})}},[p,M,g,h,m,w,c,u]),z=d(async e=>{try{const t=I.current;if(!(null==k?void 0:k.deleteFolder))return void m.error({id:"FOLDER_DELETE_ERROR",message:h("DataProvider for folder deletion is not configured"),placement:"bottomRight",data:{totalCount:1,failCount:1,itemIds:[e],folderId:e}});if(!await k.deleteFolder(e)){const e=new Error("Не удалось удалить папку");throw e.notificationShown=!1,e}m.success({id:"FOLDER_DELETE_SUCCESS",message:h("Folder deleted"),placement:"bottomRight",data:{successCount:1,totalCount:1,itemIds:[e],folderId:e}});g===e?await M({page:t.current,limit:t.pageSize,sortBy:c,sortOrder:u}):await M({folderId:g||"",sortBy:c,sortOrder:u,page:t.current,limit:t.pageSize})}catch(t){console.error("Error when deleting a folder:",t);const o=t;(null==o?void 0:o.notificationShown)||m.error({id:"FOLDER_DELETE_ERROR",message:h("Error when deleting a folder"),innerException:t,placement:"bottomRight",data:{totalCount:1,failCount:1,itemIds:[e],folderId:e,errors:[{itemId:e,error:Dn(t)}]}})}},[k,g,m,h,M,c,u]),q=d(async(e,t)=>{var o,r;try{if(null==k?void 0:k.getFileData){const t=await k.getFileData(e);if(t)return t;throw new Error(h("Failed to download file"))}{const t=await fetch(`/api/files/${e}/content`);if(!t.ok)throw new Error(h("Error loading image"));return await t.blob()}}catch(n){console.error("Error when loading a file:",n);const i=F.current.find(t=>t.id===e);t||m.error({id:"FILE_DOWNLOAD_FAILED",message:h("Failed to download file"),placement:"bottomRight",description:(null==i?void 0:i.name)||e,innerException:n,notificationDedupe:!1,data:{itemId:e,itemName:(null==i?void 0:i.name)||e,folderId:null!==(o=null==i?void 0:i.folderId)&&void 0!==o?o:null,thumbnail:null!==(r=null==i?void 0:i.thumbnail)&&void 0!==r?r:null}},t)}},[k,m,h]),W=d(async(e,t,o,r)=>{var n,a,s,d,c,u,f,p,v,y,w,b,C,I,F;if("Trash"===(r?"":null!=t?t:g||""))throw new Error(h("Upload to Trash is forbidden"));const A=Yt(e.name,null==l?void 0:l.config),_=A.split(".").pop()||"",S=r?"":null!=t?t:g||"";let E=e;try{if(Mt(e)){const t=null!==(a=null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.compressMaxSize)&&void 0!==a?a:ti.MAX_SIZE_MB,o=null!==(d=null===(s=null==l?void 0:l.config)||void 0===s?void 0:s.compressMaxWidthOrHeight)&&void 0!==d?d:2e3,r=null!==(u=null===(c=null==l?void 0:l.config)||void 0===c?void 0:c.compessorUrl)&&void 0!==u?u:null===(f=null==l?void 0:l.config)||void 0===f?void 0:f.compressorUrl,i=(null===(p=e.type)||void 0===p?void 0:p.trim())||Lt(e.name)||e.type;E=await ui(e,{maxSizeMB:t,maxWidthOrHeight:o,mimeType:i,fileName:A,libURL:r,enableCompression:vi(i),convertSvgToPng:!0})}else E=yi(e,A)}catch(t){console.warn("Image preparation failed, uploading original file",t),E=yi(e,A)}let P=E.name;const R=Xt(null==l?void 0:l.config);R&&(P=await T(P,S,r)),R&&(E=yi(E,P));try{if(null==k?void 0:k.uploadFiles)try{const t=await k.uploadFiles({items:[{name:P,size:E.size,type:E.type||e.type,folderId:S,data:E,extension:_,noFolder:r}],folderId:S});if(t.success&&t.detailed&&t.detailed.length>0){const n=t.detailed[0];if(!n.success||!n.data){if(!o){const e=(null==n?void 0:n.error)?String(n.error):h("Failed to upload file");m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:e,placement:"bottomRight",description:A,innerException:null==n?void 0:n.error,data:{itemName:A,folderId:S||null,eventSource:"upload"}})}return void(x&&x(at))}{const t=n.data;if(t.id){const o=(null!==(v=t.folderId)&&void 0!==v?v:S)||void 0,n=null!==(y=null!=o?o:g)&&void 0!==y?y:"";await M({folderId:n,noFolder:r});let a=i.files.find(e=>e.id===t.id);if(!a)try{a=(await O({folderId:o,noFolder:r,itemType:"all"})).find(e=>e.id===t.id)}catch(e){console.warn("uploadFileWithProvider: не удалось получить свежий список файлов",e)}return x&&x(at),a||Object.assign(Object.assign({},t),{id:t.id,name:t.name||A,folderId:null!==(b=null!==(w=t.folderId)&&void 0!==w?w:S)&&void 0!==b?b:null,type:E.type||e.type,size:E.size,extension:_||A.split(".").pop()||"",thumbnail:null!==(C=t.thumbnail)&&void 0!==C?C:void 0,url:null!==(I=t.url)&&void 0!==I?I:void 0,thumbnailUrl:null!==(F=t.thumbnailUrl)&&void 0!==F?F:void 0,isFolder:!1,selected:!1})}}}else if(!t.success){if(!o){const e=t.error?String(t.error):h("Failed to upload file");m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:e,placement:"bottomRight",description:A,innerException:t.error,data:{itemName:A,folderId:S||null,eventSource:"upload"}})}return void(x&&x(at))}return void(x&&x(at))}catch(e){throw e}if(null==k?void 0:k.uploadFile){const t=await k.uploadFile({name:P,size:E.size,type:E.type||e.type,folderId:S,noFolder:r,data:E,extension:_});return x&&x(at),t}return void(o||m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"}))}catch(e){const t=Dn(e),r=Un(null==t?void 0:t.code,h);return o?void 0:void m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:null!=r?r:h("Failed to upload file"),placement:"bottomRight",description:A,innerException:e,data:{itemName:A,folderId:S||null,error:Dn(e),eventSource:"upload"}})}},[k,g,x,i.files,M,O,m,h,null==l?void 0:l.config]),V=d(async(e,t)=>{var o;if(!(null==k?void 0:k.getFolders)||!(null==k?void 0:k.createFolder))return e||"";try{const r=await k.getFolders(),n=Array.isArray(r)?r:[],i=(e,t)=>n.find(o=>{var r;return(null!==(r=o.parentId)&&void 0!==r?r:null)===(null!=e?e:null)&&o.name===t});let a=null!=e?e:"";for(const e of t){if(!e)continue;let t=i(a,e);if(!t){const o=await k.createFolder({name:e,parentId:null!=a?a:null});n.push(o),t=o}a=t.id}return null!==(o=a)&&void 0!==o?o:e||""}catch(t){return console.warn("ensureFolderPath: unable to guarantee the path",t),e||""}},[k]),$=d(async(e,t)=>{var o,r,n,i;if(!(null===(r=null===(o=e.type)||void 0===o?void 0:o.startsWith)||void 0===r?void 0:r.call(o,"image/")))return null!=t?t:null;const a=null==e?void 0:e.webkitRelativePath;let l=t||"";if(a&&a.includes("/")){const e=a.split("/");e.pop();const o=e.filter(Boolean);o.length&&(l=await V(t||"",o)||t||"")}return null!==(i=null!==(n=l)&&void 0!==n?n:t)&&void 0!==i?i:null},[V]);d(async e=>{var t,o,r,n,i,a,l,s,d,c,u,f;const{file:h,selectedFolderId:m,uploadFn:p,progressCallbacks:g}=e;if(!(null===(o=null===(t=h.type)||void 0===t?void 0:t.startsWith)||void 0===o?void 0:o.call(t,"image/")))return{success:!0,fileName:h.name,folderId:null!=m?m:null};const v=null!==(n=null!==(r=await $(h,m))&&void 0!==r?r:m)&&void 0!==n?n:null,y=null!==(i=null!=v?v:m)&&void 0!==i?i:null;let w;null===(a=null==g?void 0:g.onStart)||void 0===a||a.call(g,h);try{if(null==g?void 0:g.onProgress){let e=0;w=window.setInterval(()=>{var t;e=Math.min(e+10+Math.floor(Date.now()%10),90),null===(t=null==g?void 0:g.onProgress)||void 0===t||t.call(g,h.name,e)},200)}const e=await p(h,null!=y?y:void 0);return(null==g?void 0:g.onProgress)&&(null===(l=null==g?void 0:g.onProgress)||void 0===l||l.call(g,h.name,100)),null===(s=null==g?void 0:g.onComplete)||void 0===s||s.call(g,h.name),{success:!0,fileName:h.name,fileId:null==e?void 0:e.id,folderId:null!==(c=null!==(d=null==e?void 0:e.folderId)&&void 0!==d?d:y)&&void 0!==c?c:null}}catch(e){const t=e instanceof Error?e.message:String(e);return null===(u=null==g?void 0:g.onError)||void 0===u||u.call(g,h.name,t),{success:!1,fileName:h.name,folderId:null!==(f=null!=y?y:m)&&void 0!==f?f:null,error:t}}finally{void 0!==w&&clearInterval(w)}},[$]);const H=d(async(e,t)=>{var o,r,n,i,a,s,d,c,u,f,p,v,y,w,b,C,I,F,A,_,S,E,P,R,N,O,T,L,M,U,j,D,B,z,q;if(0===e.length)return{successCount:0,failCount:0,successes:[],errors:[],totalCount:0};null===(o=null==t?void 0:t.onStartBatch)||void 0===o||o.call(t,e);const W=e=>{const t=e.filter(Boolean);return t.length>0&&t.length<=5?t.join(", "):null},V=[];for(let o=0;o<e.length;o++){const v=e[o];if(!Mt(v)){const e=await m.warning({id:"FILES_UPLOAD_UNSUPPORTED_TYPE",message:h("Unsupported file type"),placement:"bottomRight",data:{itemName:v.name,fileType:v.type,folderId:g||null}});null===(r=null==t?void 0:t.onError)||void 0===r||r.call(t,v.name,e.message);continue}const y=Yt(v.name,null==l?void 0:l.config);let w=v;try{if(Mt(v)){const e=null!==(i=null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.compressMaxSize)&&void 0!==i?i:ti.MAX_SIZE_MB,t=null!==(s=null===(a=null==l?void 0:l.config)||void 0===a?void 0:a.compressMaxWidthOrHeight)&&void 0!==s?s:2e3,o=null!==(c=null===(d=null==l?void 0:l.config)||void 0===d?void 0:d.compessorUrl)&&void 0!==c?c:null===(u=null==l?void 0:l.config)||void 0===u?void 0:u.compressorUrl,r=(null===(f=v.type)||void 0===f?void 0:f.trim())||Lt(v.name)||v.type;w=await ui(v,{maxSizeMB:e,maxWidthOrHeight:t,mimeType:r,fileName:y,libURL:o,enableCompression:vi(r),convertSvgToPng:!0})}else w=yi(v,y)}catch(e){console.warn("Image preparation failed, uploading original file",e),w=yi(v,y)}const b=`${Date.now()}-${o}-${Math.random().toString(36).slice(2,8)}`,C=await $(w,g);null===(p=null==t?void 0:t.onStart)||void 0===p||p.call(t,w),V.push({file:w,targetFolderId:C,requestId:b,originalFileName:v.name,originalIndex:o})}const H=V.length;if(0===H)return{successCount:0,failCount:0,successes:[],errors:[],totalCount:0};const G=Xt(null==l?void 0:l.config),K=new Map;if(G&&(null==k?void 0:k.getFiles)){const e=[...new Set(V.map(e=>{var t,o;return null!==(o=null!==(t=e.targetFolderId)&&void 0!==t?t:g)&&void 0!==o?o:""}).filter(e=>null!=e))];for(const t of e)try{const{files:e}=await k.getFiles({folderId:""===t?"":null!=t?t:void 0,itemType:"all",page:1,limit:1e4});let o=(e||[]).map(e=>e.name).filter(e=>!!e);if(null==k?void 0:k.getFolders){const e=(await k.getFolders({parentId:t||null,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);o=[...o,...e]}K.set(t,o)}catch(e){console.warn("Could not fetch files for duplicate check:",e)}}const Q=new Map,J=V.map(e=>{const t=G?((e,t)=>{const o=null!=e?e:"";let r=K.get(o)||[],n=Q.get(o);n||(n=new Set(r.map(e=>e.toLowerCase())),Q.set(o,n));const i=Tr(t,Array.from(n));return n.add(i.toLowerCase()),i})(e.targetFolderId,e.file.name):e.file.name,o=G?yi(e.file,t):e.file;return Object.assign(Object.assign({},e),{resolvedUploadName:t,uploadFile:o})}),Y=!t,Z=1===H&&Y,X=[],ee=[],te=[],oe=[],re=new Map;let ne=0,ie=0;const ae=null!==(y=null===(v=null==l?void 0:l.config)||void 0===v?void 0:v.maxFileSize)&&void 0!==y?y:52428800,le=async(e,o,r,n)=>{var i,a;const{emitProgress:l=!0,emitNotification:s=!0}=null!=n?n:{};ne++,X.push(e),ee.push(null!=r?r:e),await((e,t,o,r)=>{var n;return m.success({id:"FILE_UPLOAD_ITEM_SUCCESS",message:`${h("File")} ${e} ${h("has been successfully uploaded")}`,placement:"bottomRight",data:{itemId:o,itemName:e,folderId:null!==(n=null!=t?t:g)&&void 0!==n?n:null,eventSource:"upload"}},r||!Y)})(e,o,r,!s),l&&(null===(i=null==t?void 0:t.onProgress)||void 0===i||i.call(t,e,100),null===(a=null==t?void 0:t.onComplete)||void 0===a||a.call(t,e))},se=async(e,o,r,n)=>{var i;const{emitProgress:a=!0,emitNotification:l=!0,fileSize:s,progressCallbackName:d,progressCallbackIndex:c}=null!=n?n:{};ie++;const u=null!=s?{fileSize:s,maxSize:ae}:void 0,f=await((e,t,o,r,n)=>{var i,a,l,s,d,c,u;const f=Dn(o),p=null!==(i=null==n?void 0:n.fileSize)&&void 0!==i?i:null==f?void 0:f.fileSize,v=null!==(l=null!==(a=null==n?void 0:n.maxSize)&&void 0!==a?a:null==f?void 0:f.maxSize)&&void 0!==l?l:ae,y={allowedChars:"a-z A-Z 0-9 . _ -",fileSize:null!=p?Nr(Number(p)):void 0,maxSize:null!=v?Nr(Number(v)):void 0},w=null==f?void 0:f.code,b="BatchItemLimitExceeded"===w||"exceeded_max_files"===w?w:null!==(s=jn(null==f?void 0:f.message))&&void 0!==s?s:w,C="BatchItemLimitExceeded"===b||"exceeded_max_files"===b?Bn(o,h):Un(b,h,y),I=(null==f?void 0:f.message)&&"string"==typeof f.message&&f.message.length>0?f.message:null,F=o instanceof Error?o.message:"string"==typeof o?o:null,A=F&&"[object Object]"!==F?F:null;return m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:null!==(c=null!==(d=null!=I?I:C)&&void 0!==d?d:A)&&void 0!==c?c:h("Error uploading file {{fileName}}",{fileName:e}),placement:"bottomRight",data:{itemName:e,folderId:null!==(u=null!=t?t:g)&&void 0!==u?u:null,error:Dn(o),eventSource:"upload"},innerException:o},r||!Y)})(e,o,r,!l,u);a&&(null===(i=null==t?void 0:t.onError)||void 0===i||i.call(t,null!=d?d:e,f.message,c)),oe.push({itemId:void 0,itemName:e,error:Dn(r)}),te.push({fileName:e,error:f.message})};let de;if(!(null==k?void 0:k.uploadFiles))return m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"}),{successCount:0,failCount:H,successes:[],errors:[],totalCount:H};{const e=[];try{(null==t?void 0:t.onProgress)&&V.forEach(o=>{let r=0;const n=window.setInterval(()=>{var e;r=Math.min(r+10+Math.floor(Date.now()%10),90),null===(e=null==t?void 0:t.onProgress)||void 0===e||e.call(t,o.file.name,r)},200);e.push(n)}),de=await k.uploadFiles({items:J.map(e=>{var t,o;return{requestId:e.requestId,name:e.resolvedUploadName,size:e.uploadFile.size,type:e.uploadFile.type,folderId:null!==(o=null!==(t=e.targetFolderId)&&void 0!==t?t:g)&&void 0!==o?o:null,data:e.uploadFile,extension:e.uploadFile.name.split(".").pop()||""}}),folderId:null!=g?g:null}),e.forEach(e=>window.clearInterval(e)),e.length=0;const o=null!==(w=de.detailed)&&void 0!==w?w:[],r=new Map(o.filter(e=>e.requestId).map(e=>[e.requestId,e]));if(o.length>0)for(let e=0;e<J.length;e++){const t=J[e],n=null!==(b=t.requestId?r.get(t.requestId):void 0)&&void 0!==b?b:o[e];if(n&&n.success){const e=n.data,o=null!==(C=null==e?void 0:e.name)&&void 0!==C?C:t.resolvedUploadName,r=null!==(A=null!==(F=null!==(I=null==e?void 0:e.folderId)&&void 0!==I?I:t.targetFolderId)&&void 0!==F?F:g)&&void 0!==A?A:null,i=null==e?void 0:e.id;re.set(o,{id:i,name:o,folderId:r,size:null==e?void 0:e.size,originalFileName:t.originalFileName,originalIndex:t.originalIndex}),await le(o,r,i,{emitNotification:Z})}else{const e=null==n?void 0:n.data,o=null!==(_=null==e?void 0:e.name)&&void 0!==_?_:t.resolvedUploadName,r=null!==(P=null!==(E=null!==(S=null==e?void 0:e.folderId)&&void 0!==S?S:t.targetFolderId)&&void 0!==E?E:g)&&void 0!==P?P:null;await se(o,r,null!==(R=null==n?void 0:n.error)&&void 0!==R?R:new Error(h("Error uploading file")),{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}else if(de.success)for(const e of J){const t=e.resolvedUploadName,o=null!==(O=null!==(N=e.targetFolderId)&&void 0!==N?N:g)&&void 0!==O?O:null;await le(t,o,void 0,{emitNotification:Z})}else{const e=null!==(T=de.error)&&void 0!==T?T:new Error(h("Error uploading file"));for(const t of J){const o=t.resolvedUploadName,r=null!==(M=null!==(L=t.targetFolderId)&&void 0!==L?L:g)&&void 0!==M?M:null;await se(o,r,e,{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}}catch(e){for(const t of J){const o=t.resolvedUploadName,r=null!==(j=null!==(U=t.targetFolderId)&&void 0!==U?U:g)&&void 0!==j?j:null;await se(o,r,null!=e?e:new Error(h("Error uploading file")),{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}finally{e.forEach(e=>window.clearInterval(e))}}if(ne>0&&(x&&x(at),H>1&&Y)){const e=W(X),t=e?h("Uploaded",{names:e}):h("uploads_success_summary",{successCount:ne,totalCount:H});m.success({id:"FILES_UPLOAD_BATCH_SUCCESS",message:t,placement:"bottomRight",data:{successCount:ne,totalCount:H,itemIds:ee,itemNames:X,folderId:null!=g?g:null,eventSource:"upload"}})}if(ie>0&&Y&&!Z)if(H>1){const e=te.map(e=>e.fileName),t=W(e),o=t?h("Failed",{names:t}):h("uploads_fail_summary",{failCount:ie,totalCount:H});m.error({id:"FILES_UPLOAD_BATCH_FAILED",message:o,placement:"bottomRight",data:{failCount:ie,totalCount:H,itemNames:e,folderId:null!=g?g:null,errors:oe,eventSource:"upload"}})}else if(1===H&&oe.length>0&&(null===(D=oe[0].error)||void 0===D?void 0:D.code)){const e=Un(null===(B=oe[0].error)||void 0===B?void 0:B.code,h),t=null!==(q=null===(z=te[0])||void 0===z?void 0:z.fileName)&&void 0!==q?q:"",o=null!=e?e:t?`${h("Failed to upload files")}: ${t}`:h("Failed to upload files");m.error({id:"FILES_UPLOAD_BATCH_FAILED",message:o,placement:"bottomRight",data:{failCount:ie,totalCount:H,itemNames:[t],folderId:null!=g?g:null,errors:oe,eventSource:"upload"}})}return{successCount:ne,failCount:ie,successes:X,errors:te,totalCount:H,uploadedFiles:re.size>0?re:void 0}},[k,null===(o=null==l?void 0:l.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient,m,$,g,x,h,null==l?void 0:l.config]),G=d(async e=>{var t;if(!(null==k?void 0:k.uploadFiles))return void m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"});if("Trash"===g)return void m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}});const o=I.current,r=document.createElement("input");r.type="file",r.accept="image/*",r.multiple=!0;try{!(!(null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.features)||!l.config.features.enableDirectoryUpload)&&(r.webkitdirectory=!0)}catch(e){}r.onchange=async t=>{var r;const n=t.target.files;if(!n||0===n.length)return;const i=Array.from(n);try{null==S||S(!0);const{successes:t,errors:n,uploadedFiles:a}=await H(i,e);null===(r=null==e?void 0:e.onBatchComplete)||void 0===r||r.call(e,{files:i,successes:t,errors:n,uploadedFiles:a}),await f(),await M({folderId:g||"",sortBy:c,sortOrder:u,page:o.current,limit:o.pageSize})}catch(e){console.error("Error when loading files:",e)}finally{null==S||S(!1)}},r.click()},[null==k?void 0:k.uploadFiles,g,m,h,S,M,f,c,u,H,null===(r=null==l?void 0:l.config)||void 0===r?void 0:r.features]),K=d(async(e,t,o,r="uploadByUrl")=>{const n=I.current,i=Boolean(e&&String(e).trim());let a,s=null!=e?e:null;try{if(!t&&"Trash"===g)throw o||m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}}),new Jn(h("Cannot upload files to Trash"),"UploadUrlDownloadFailed");let e,d;if(!s&&v&&(e=await v.validateFields(),s=null==e?void 0:e.fileUrl),!s)throw o||m.error({id:"FILES_UPLOAD_URL_VALIDATION_FAILED",message:h("Please fill in all fields"),placement:"bottomRight",data:{url:null!=s?s:null,folderId:g||null,eventSource:r}}),new Jn(h("Please fill in all fields"),"UploadUrlInvalid");if(Xn(s,h),s=mi(s),null==S||S(!0),s){const e=s.split("?")[0].split("#")[0].split("/");d=e[e.length-1]||"uploaded-file",d=Yt(d,null==l?void 0:l.config)}const f=t?"":g||"",p=Boolean((null==k?void 0:k.uploadFiles)||(null==k?void 0:k.uploadFile)),y=Boolean(null==k?void 0:k.uploadFileByUrl);let w=d;w&&y&&(w=await T(w,f,t));try{const e=await j(s,o);if("existing"===e.kind)a=e.file;else if(p){const o=new File([e.blob],e.fileName,{type:e.mimeType,lastModified:Date.now()});try{a=await W(o,f,!0,t)}catch(e){throw e.uploadUrlStage="binaryUpload",e}if(!a){const e=new Jn(h("Failed to upload file"),"FileUploadBackendError");throw e.uploadUrlStage="binaryUpload",e}}else{if(!y)throw o||m.error({id:"FILES_UPLOAD_URL_NOT_SUPPORTED",message:h("Upload by URL is not supported"),placement:"bottomRight",data:{url:s,folderId:g||null,eventSource:r}}),new Jn(h("Upload by URL is not supported"),"UploadUrlDownloadFailed");a=await k.uploadFileByUrl({url:s,folderId:g||"",noFolder:t,name:w,eventSource:r})}}catch(e){const o=e;if("binaryUpload"===(null==o?void 0:o.uploadUrlStage)||!y)throw e;console.warn("Failed to fetch file by URL locally, falling back to uploadByUrl",e),a=await k.uploadFileByUrl({url:s,folderId:g||"",noFolder:t,name:w,eventSource:r})}const b=(null==e?void 0:e.name)||(null==a?void 0:a.name)||"unnamed file";return a&&m.success({id:"FILE_UPLOAD_ITEM_SUCCESS",message:`${h("File")} ${b} ${h("successfully uploaded")}`,placement:"bottomRight",data:{itemName:b,itemId:null==a?void 0:a.id,folderId:g||null,eventSource:r}},o),(e||i)&&(null==E||E(!1),null==v||v.resetFields()),x&&x(at),await M({folderId:g||"",noFolder:t,sortBy:c,sortOrder:u,page:n.current,limit:n.pageSize}),a}catch(e){if(console.error("Error when loading a file by URL:",e),!o){const t=Dn(e),o=t,n=e,i=Number(null==o?void 0:o.fileSize),a=Number(null==o?void 0:o.maxSize),l=Number.isFinite(i)&&Number.isFinite(a)?{fileSize:i,maxSize:a}:void 0,d="binaryUpload"===(null==n?void 0:n.uploadUrlStage)?Bn(t,h,l):Wn(t,h);m.error({id:"FILES_UPLOAD_BY_URL_FAILED",message:d,placement:"bottomRight",data:{url:null!=s?s:null,folderId:g||null,error:t,eventSource:r},innerException:e})}throw e}finally{null==S||S(!1)}},[v,S,k,m,h,E,x,M,g,c,u,T,j,W,null==l?void 0:l.config]),Q=d(async e=>{if(!e.length)return;const t=I.current;"Trash"!==g?(await H(e),await M({folderId:g||"",sortBy:c,sortOrder:u,page:t.current,limit:t.pageSize})):m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}})},[M,g,c,u,H,m,h]);return{fetchFiles:M,handleDeleteFile:B,handleDeleteFolder:z,handleAddFile:G,handleAddFileByUrl:K,handleDroppedFiles:Q,getFileData:q,findFileByUrl:U,resolveFileForEditByUrl:D,uploadFileWithProvider:W}},_i=e=>{let t;const o=new Set,r=(e,r)=>{const n="function"==typeof e?e(t):e;if(!Object.is(n,t)){const e=t;t=(null!=r?r:"object"!=typeof n||null===n)?n:Object.assign({},t,n),o.forEach(o=>o(t,e))}},n=()=>t,i={setState:r,getState:n,getInitialState:()=>a,subscribe:e=>(o.add(e),()=>o.delete(e))},a=t=e(r,n,i);return i},Si=e=>e;const Ei=e=>{const t=(e=>e?_i(e):_i)(e),o=e=>function(e,t=Si){const o=n.useSyncExternalStore(e.subscribe,n.useCallback(()=>t(e.getState()),[e,t]),n.useCallback(()=>t(e.getInitialState()),[e,t]));return n.useDebugValue(o),o}(t,e);return Object.assign(o,t),o};function xi(e,t){if(e.size!==t.size)return!1;for(const o of e)if(!t.has(o))return!1;return!0}const Pi=(Ri=e=>({selectedFiles:new Set,visibleFileIds:[],anchorId:null,multiSelect:!0,setMultiSelect:t=>{e(e=>{var o;if(e.multiSelect===t)return e;if(t)return{multiSelect:!0};const r=null!==(o=Array.from(e.selectedFiles)[0])&&void 0!==o?o:null;return{multiSelect:!1,selectedFiles:r?new Set([r]):new Set,anchorId:r}})},syncVisibleFiles:t=>{const o=Array.isArray(t)?t.map(e=>e.id):[];e(e=>{const t=new Set(o),r=new Set(Array.from(e.selectedFiles).filter(e=>t.has(e))),n=e.anchorId&&t.has(e.anchorId)?e.anchorId:null,i=function(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o+=1)if(e[o]!==t[o])return!1;return!0}(e.visibleFileIds,o),a=xi(e.selectedFiles,r),l=e.anchorId===n;return i&&a&&l?e:{visibleFileIds:o,selectedFiles:r,anchorId:n}})},setSelectedFiles:t=>{e(e=>{var o;const r=new Set(e.visibleFileIds),n=new Set(Array.from(t).filter(e=>r.has(e)));return xi(e.selectedFiles,n)?e:{selectedFiles:n,anchorId:null!==(o=Array.from(n)[0])&&void 0!==o?o:null}})},clearSelection:()=>{e(e=>0===e.selectedFiles.size&&null===e.anchorId?e:{selectedFiles:new Set,anchorId:null})},selectAllVisible:()=>{e(e=>{var t;const o=new Set(e.visibleFileIds),r=null!==(t=e.visibleFileIds[0])&&void 0!==t?t:null;return xi(e.selectedFiles,o)&&e.anchorId===r?e:{selectedFiles:o,anchorId:r}})},toggleFileSelection:(t,o)=>{e(e=>{const r=!1!==e.multiSelect,n=Boolean(null==o?void 0:o.shiftKey)&&r,i=Boolean(null==o?void 0:o.metaKey)||Boolean(null==o?void 0:o.ctrlKey)||Boolean(null==o?void 0:o.forceToggle),a=e.visibleFileIds,l=new Set(a);if(a.length>0&&!l.has(t))return e;if(!r){const o=new Set([t]);return xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}if(n&&e.anchorId&&l.has(e.anchorId)){const o=a.indexOf(e.anchorId),r=a.indexOf(t);if(-1===o||-1===r)return e;const[n,l]=o<r?[o,r]:[r,o],s=a.slice(n,l+1),d=i?new Set(e.selectedFiles):new Set;return s.forEach(e=>{d.add(e)}),xi(e.selectedFiles,d)?e:{selectedFiles:d}}if(n&&!e.anchorId){const o=new Set([t]);return xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}if(i){const o=new Set(e.selectedFiles);return o.has(t)?o.delete(t):o.add(t),xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}const s=new Set([t]);return xi(e.selectedFiles,s)&&e.anchorId===t?e:{selectedFiles:s,anchorId:t}})}}),Ri?Ei(Ri):Ei);var Ri;const Ni=e=>{var t,o,r,n;const{state:i,actions:a,options:l}=mn(),{t:s}=dr(),c=Kn(),u=On(),{fetchFolders:f}=c.actions,{renameItem:h}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=d(async({itemId:r,newName:n,isFolder:i})=>{var a,l,s,d,c,u,f,h;try{if(i){if(!(null==t?void 0:t.renameFolder))throw new Error(o("renameFolder is not implemented in dataProviders"));const i=Zt(n.trim(),e.config),d=await t.renameFolder(r,i);return{success:!0,renamedItem:{id:d.id,name:null!==(a=d.name)&&void 0!==a?a:i,parentId:null!==(l=d.parentId)&&void 0!==l?l:null,folderId:null!==(s=d.parentId)&&void 0!==s?s:null}}}if(!(null==t?void 0:t.renameFile))throw new Error(o("renameFile is not implemented in dataProviders"));const m=Yt(n,e.config),p=await t.renameFile(r,m);return{success:!0,renamedItem:{id:null!==(d=null==p?void 0:p.id)&&void 0!==d?d:r,name:null!==(c=null==p?void 0:p.name)&&void 0!==c?c:m,folderId:null!==(u=null==p?void 0:p.folderId)&&void 0!==u?u:null,parentId:null!==(h=null!==(f=null==p?void 0:p.parentId)&&void 0!==f?f:null==p?void 0:p.folderId)&&void 0!==h?h:null}}}catch(e){return{success:!1,error:Dn(e)}}},[t,o,e.config]);return{renameItem:r}})(),{files:m,selectedFolder:p,fileToRename:g,renameForm:v,isRenameModalVisible:y,pagination:w}=i,{setFileToRename:b,setIsRenameModalVisible:C}=a,{dataProviders:I,config:F}=l,A=e=>{var t,o;if(!e)return null;const r=e;return null!==(o=null!==(t=r.folderId)&&void 0!==t?t:r.parentId)&&void 0!==o?o:null},_=(e,t)=>{var o;return{itemId:null!==(o=null==e?void 0:e.id)&&void 0!==o?o:t,itemName:null==e?void 0:e.name,folderId:A(e)}},S=d(e=>{var t,o;const r=null==m?void 0:m.find(t=>t.id===e);if((null==r?void 0:r.isFolder)||e.startsWith("folder_")){if(!(!1!==(null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder)))return void u.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:s("Folder rename is disabled by config"),placement:"bottomRight",data:_(r,e)});if(!(null==I?void 0:I.renameFolder))throw new Error(s("renameFolder is not implemented in dataProviders"))}else{if(!(!1!==(null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile)))return void u.error({id:"FILE_RENAME_DISABLED_BY_CONFIG",message:s("File rename is disabled by config"),placement:"bottomRight",data:_(r,e)});if(!(null==I?void 0:I.renameFile))throw new Error(s("renameFile is not implemented in dataProviders"))}null==b||b(e),null==C||C(!0),r&&v&&v.setFieldsValue({newFileName:r.name})},[m,b,C,v,null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder,null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile,null==I?void 0:I.renameFolder,null==I?void 0:I.renameFile,u,s]),E=d(()=>{null==C||C(!1),null==b||b(null),null==v||v.resetFields()},[C,b,v]),x=d(async()=>{var t,o,r,n,i,l,d,c,y,b,C,I;if(!g||!v)return;const A=null==m?void 0:m.find(e=>e.id===g);try{const m=await v.validateFields();if(!(null==m?void 0:m.newFileName))return;const S=(null==A?void 0:A.isFolder)||g.startsWith("folder_");if(S){if(!(!1!==(null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder)))return void u.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:s("Folder rename is disabled by config"),placement:"bottomRight",data:_(A,g)})}else{if(!(!1!==(null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile)))return void u.error({id:"FILE_RENAME_DISABLED_BY_CONFIG",message:s("File rename is disabled by config"),placement:"bottomRight",data:_(A,g)})}const x=await h({itemId:g,newName:m.newFileName,isFolder:S});if(!x.success){const e=Un(null===(r=x.error)||void 0===r?void 0:r.code,s);return void u.error({id:"ITEM_RENAME_FAILED",message:null!==(i=null!=e?e:null===(n=x.error)||void 0===n?void 0:n.message)&&void 0!==i?i:s("Error renaming"),placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{error:x.error}),innerException:x.error})}const P=x.renamedItem;S?(u.success({id:"FOLDER_RENAME_SUCCESS",message:s(`${s("Folder renamed to")} ${null!==(l=null==P?void 0:P.name)&&void 0!==l?l:m.newFileName}`),placement:"bottomRight",data:{itemId:null!==(d=null==P?void 0:P.id)&&void 0!==d?d:g,itemName:null!==(c=null==P?void 0:P.name)&&void 0!==c?c:m.newFileName,folderId:null!==(b=null!==(y=null==P?void 0:P.parentId)&&void 0!==y?y:null==P?void 0:P.folderId)&&void 0!==b?b:null}}),await f(),(null==P?void 0:P.id)&&P.id!==g&&a.setSelectedFolder&&a.setSelectedFolder(P.id)):u.success({id:"FILE_RENAME_SUCCESS",message:`${s("File renamed to")} ${null!==(C=null==P?void 0:P.name)&&void 0!==C?C:m.newFileName}`,placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{itemName:null!==(I=null==P?void 0:P.name)&&void 0!==I?I:m.newFileName})}),E(),await e({folderId:p||"",page:w.current,limit:w.pageSize})}catch(e){console.error("Error when renaming:",e);const t=Dn(e),o=Un(null==t?void 0:t.code,s);u.error({id:"ITEM_RENAME_FAILED",message:null!=o?o:e instanceof Error?e.message:s("Error renaming"),placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{error:t}),innerException:e})}},[g,v,m,a,E,e,p,s,w,null===(r=null==F?void 0:F.features)||void 0===r?void 0:r.enableRenameFolder,null===(n=null==F?void 0:F.features)||void 0===n?void 0:n.enableRenameFile,u,f,h]);return{state:{isRenamingFile:y||!1,fileToRename:g},actions:{showRenameModal:S,handleRenameCancel:E,handleRenameOk:x}}},ki=e=>{const t=t=>{if(!t)return;const o=e.find(e=>e.id===t);return null==o?void 0:o.name};return{getItemNameById:t,getItemNamesByIds:e=>e.map(t).filter(e=>Boolean(e)),getNamesPreview:e=>e.length>0&&e.length<=5?e.join(", "):null}},Oi=(e,t,o,r,n)=>({itemIds:e,itemNames:n&&n.length?n:void 0,successCount:t,totalCount:o,folderId:null!=r?r:null}),Ti=(e,t,o,r,n,i)=>({itemIds:e,itemNames:i&&i.length?i:void 0,failCount:t,totalCount:o,folderId:null!=r?r:null,errors:n}),Li=()=>{const e=On(),{t:t}=dr(),{state:o,options:r}=mn(),{folders:n,pathHistory:i}=o,{dataProviders:a}=r,{actions:{fetchFolders:l,fetchChildFolders:s}}=Kn();return{refreshFolders:d(async({parentIds:o,selectedFolder:r})=>{try{if(await l(),o&&s)for(const e of o)e&&await s(e)}catch(o){console.error("Error when updating the folder tree:",o);const r=t("Folders");e.error({id:"FOLDERS_FETCH_FAILED",message:t("Failed to refresh folder tree"),description:r,placement:"bottomRight",innerException:o,notificationDedupe:!0,data:{folderId:null,folderName:r,reason:o instanceof Error?o.message:String(o)}})}},[e,t,l,s]),refreshFiles:d(async({fetchFiles:o,selectedFolder:r,page:l,limit:s})=>{try{await o({folderId:r||"",page:l,limit:s})}catch(o){console.error("Ошибка при обновлении списка файлов:",o);const d=await fi({folderId:r||"",dataProviders:a,folders:Array.isArray(n)?n:[],pathHistory:i,t:t}),c=t("Failed to load files"),u=o instanceof Error?o.message:String(o);e.error({id:"FILES_FETCH_FAILED",message:t("Failed to load files in folder",{folderName:d}),description:u&&u!==c?u:void 0,placement:"bottomRight",innerException:o,notificationDedupe:!0,data:{params:{folderId:r||void 0,page:l,limit:s,folderName:d},folderName:d}})}},[e,t,a,n,i])}},Mi=e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),l=Pi(e=>e.selectedFiles),s=Pi(e=>e.clearSelection),{files:c,selectedFolder:u,moveForm:f,pagination:h,currentMenuFile:m}=o,{setIsMoveModalVisible:p,setPagination:g}=r,{dataProviders:v}=n,{moveItems:y}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=On(),n=d(async({items:e,targetFolderId:n,getItemNameById:i,showNotifications:a=!1})=>{let l=0,s=0;const d=[];if(null==t?void 0:t.moveItems)try{const o=await t.moveItems("folders"===n?"":n,e.map(e=>e.id)),r=o.detailed;if(r){const e=r.filter(e=>e.success),t=r.filter(e=>!e.success);l+=e.length,s+=t.length,t.forEach(e=>{const t=null!==(r=(o=e).requestId)&&void 0!==r?r:o.id;var o,r;const n=e.error,a=Dn(n);d.push({itemId:t,itemName:i(t),error:a})})}else if(o.success)l+=e.length;else{const t=o.error;if(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length}}catch(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length,d.push({error:{message:"Move provider is not configured"}});return a&&(l>0&&r.success({id:"FILES_MOVE_SUCCESS",message:o("Files moved"),placement:"bottomRight",data:{successCount:l,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:"folders"===n?null:n}}),s>0&&r.error({id:"FILES_MOVE_ERROR",message:o("Errors occurred while moving"),placement:"bottomRight",innerException:d.length?d:void 0,data:{failCount:s,totalCount:e.length,itemIds:e.map(e=>e.id),errors:d.length?d:void 0}})),{successCount:l,failCount:s,errorDetails:d}},[t,r,o]);return{moveItems:n}})(),{refreshFolders:w,refreshFiles:b}=Li(),{getItemNameById:C,getItemNamesByIds:I,getNamesPreview:F}=ki(c),A=d(()=>{null==p||p(!0)},[p]),_=d(()=>{null==p||p(!1),null==f||f.resetFields()},[p,f]),S=d(async t=>{var o,r,d,p,A,S,E,x;if(!((null==m?void 0:m.length)||l&&0!==l.size))return;const P=c.length,R=Object.assign({},h),N=Array.from((null==m?void 0:m.length)?[m]:l),k=N.length;let O=0,T=0;const L=[],M=N.map(e=>c.find(t=>t.id===e)).filter(e=>Boolean(e)),U=M.some(e=>(null==e?void 0:e.isFolder)||e.id.startsWith("folder_"));try{let l=t;if(!t){const e=await f.validateFields();l=null==e?void 0:e.targetFolder}if(!l)return void a.error({id:"FILES_MOVE_DIRECTORY_NOT_SELECTED",message:i("Select destination folder"),placement:"bottomRight"});const c="folders"===l?null:l,h=null!=c?c:u,m=!0===(null===(o=null==n?void 0:n.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient);if(m&&(null==v?void 0:v.getFolders))try{const e=await v.getFolders({parentId:c,deep:!1}),t=new Set((e||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean));for(const e of M){if(!e.isFolder&&!(null===(d=(r=e.id).startsWith)||void 0===d?void 0:d.call(r,"folder_")))continue;const o=e.name||C(e.id)||"";if(o&&t.has(o.toLowerCase()))return void a.error({id:"FOLDER_ALREADY_EXISTS_MOVE",message:i("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,targetFolderId:l}})}}catch(e){console.warn("Could not check folder duplicates for move:",e)}if(m&&(null==v?void 0:v.getFiles)&&(null==v?void 0:v.renameFile))try{let e=[];if(null==v?void 0:v.getFiles){const{files:t}=await v.getFiles({folderId:null!=c?c:void 0,itemType:"all",page:1,limit:1e4});e=(t||[]).map(e=>e.name).filter(e=>!!e)}if(null==v?void 0:v.getFolders){const t=(await v.getFolders({parentId:c,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);e=[...e,...t]}const t=new Set(e.map(e=>null==e?void 0:e.toLowerCase()).filter(Boolean));for(const e of M){if(e.isFolder||(null===(A=(p=e.id).startsWith)||void 0===A?void 0:A.call(p,"folder_")))continue;const o=e.name||C(e.id)||"";if(!o||!t.has(o.toLowerCase())){t.add(o.toLowerCase());continue}const r=Tr(o,Array.from(t));await v.renameFile(e.id,r),t.add(r.toLowerCase())}}catch(e){console.warn("Could not check duplicates for move:",e)}const j=await y({items:M,targetFolderId:l,getItemNameById:C,showNotifications:!1});if(O=j.successCount,T=j.failCount,L.push(...j.errorDetails),O>0){const e=I(N),t=F(e),o=t?i("Moved",{names:t}):i("move_success_summary",{successCount:O,totalCount:k});a.success({id:"FILES_MOVE_SUCCESS",message:o,placement:"bottomRight",data:Oi(N,O,k,c,e)})}if(T>0){const e=I(N),t=F(e);let o;if(1===k&&L.length>0&&(null===(S=L[0].error)||void 0===S?void 0:S.code)){const e=Un(null===(E=L[0].error)||void 0===E?void 0:E.code,i);o=null!=e?e:t?i("Failed",{names:t}):i("move_fail_summary",{failCount:T,totalCount:k})}else o=t?i("Failed",{names:t}):i("move_fail_summary",{failCount:T,totalCount:k});a.error({id:"FILES_MOVE_ERROR",message:o,placement:"bottomRight",innerException:L.length?L:void 0,data:Ti(N,T,k,c,L.length?L:void 0,e)})}_(),s();let D=R.current;if(O>0&&P>0&&O>=P&&R.current>1&&(D=R.current-1),O>0&&R.total>=O){const e=Math.max(0,(null!==(x=R.total)&&void 0!==x?x:0)-O);null==g||g({current:D,pageSize:R.pageSize,total:e})}U&&await w({parentIds:void 0,selectedFolder:h}),await b({fetchFiles:e,selectedFolder:u,page:D,limit:R.pageSize})}catch(e){console.error("Error when moving:",e);const t=Un(Dn(e).code,i);a.error({id:"FILES_MOVE_ERROR",innerException:e,message:null!=t?t:i("Error moving"),placement:"bottomRight",data:Ti(N,k,k,u||null,[{error:Dn(e)}],I(N))})}},[m,l,f,e,u,h,c,a,g,i,y,s,p,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient,null==v?void 0:v.getFiles,null==v?void 0:v.renameFile,C]);return{actions:{showMoveModal:A,handleMoveCancel:_,handleMoveOk:S}}},Ui=e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),l=Pi(e=>e.selectedFiles),s=Pi(e=>e.clearSelection),{files:c,selectedFolder:u,copyForm:f,pagination:h,currentMenuFile:m}=o,{setIsCopyModalVisible:p}=r,{dataProviders:g}=n,{copyItems:v}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=On(),n=d(async({items:e,targetFolderId:n,getItemNameById:i,showNotifications:a=!1})=>{let l=0,s=0;const d=[],c="folders"===n?"":n;if(null==t?void 0:t.copyItems)try{const o=await t.copyItems(c,e.map(e=>({id:e.id,newName:e.newName}))),r=o.detailed;if(r){const e=r.filter(e=>e.success),t=r.filter(e=>!e.success);l+=e.length,s+=t.length,t.forEach(e=>{const t=null!==(r=(o=e).requestId)&&void 0!==r?r:o.id;var o,r;const n=e.error,a=Dn(n);d.push({itemId:t,itemName:i(t),error:a})})}else if(o.success)l+=e.length;else{const t=o.error;if(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length}}catch(t){s+=e.length;const o=Dn(t);d.push({error:o})}else if(null==t?void 0:t.copyItem)for(const o of e)try{const e=(null==o?void 0:o.isFolder)||o.id.startsWith("folder_");await t.copyItem({itemId:o.id,targetFolderId:c,isFolder:e,newName:o.newName})?l++:s++}catch(e){s++;const t=Dn(e);d.push({itemId:o.id,itemName:i(o.id),error:t})}else s+=e.length,d.push({error:{message:"Copy provider is not configured"}});return a&&(l>0&&r.success({id:"FILES_COPY_SUCCESS",message:o("Files copied"),placement:"bottomRight",data:{successCount:l,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:"folders"===n?null:n}}),s>0&&r.error({id:"FILES_COPY_ERROR",message:o("Errors occurred while copying"),placement:"bottomRight",innerException:d.length?d:void 0,data:{failCount:s,totalCount:e.length,itemIds:e.map(e=>e.id),errors:d.length?d:void 0}})),{successCount:l,failCount:s,errorDetails:d}},[t,r,o]);return{copyItems:n}})(),{refreshFolders:y,refreshFiles:w}=Li(),{getItemNameById:b,getItemNamesByIds:C,getNamesPreview:I}=ki(c),F=d(()=>{null==p||p(!0)},[p]),A=d(()=>{null==p||p(!1),null==f||f.resetFields()},[p,f]),_=d(async t=>{var o,r,d,p,F;if(!((null==m?void 0:m.length)||l&&0!==l.size))return;const _=Array.from((null==m?void 0:m.length)?[m]:l),S=_.length;let E=0,x=0;const P=[],R=_.map(e=>c.find(t=>t.id===e)).filter(e=>Boolean(e)),N=R.some(e=>(null==e?void 0:e.isFolder)||e.id.startsWith("folder_"));try{let l=t;if(!t){const e=await f.validateFields();l=null==e?void 0:e.targetFolder}if(!l)return void a.error({id:"FILES_COPY_DIRECTORY_NOT_SELECTED",message:i("Select destination folder"),placement:"bottomRight"});const c="folders"===l?null:l,m=null!=c?c:u;let k=R.map(e=>({id:e.id,isFolder:(null==e?void 0:e.isFolder)||e.id.startsWith("folder_")}));const O=!0===(null===(o=null==n?void 0:n.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient);if(O&&(null==g?void 0:g.getFolders))try{const e=await g.getFolders({parentId:c,deep:!1}),t=new Set((e||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean));for(const e of R){if(!e.isFolder&&!(null===(d=(r=e.id).startsWith)||void 0===d?void 0:d.call(r,"folder_")))continue;const o=e.name||b(e.id)||"";if(o&&t.has(o.toLowerCase()))return void a.error({id:"FOLDER_ALREADY_EXISTS_COPY",message:i("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,targetFolderId:l}})}}catch(e){console.warn("Could not check folder duplicates for copy:",e)}if(O&&(null==g?void 0:g.getFiles))try{let e=[];const{files:t}=await g.getFiles({folderId:null!=c?c:void 0,itemType:"all",page:1,limit:1e4});if(e=(t||[]).map(e=>e.name).filter(e=>!!e),null==g?void 0:g.getFolders){const t=(await g.getFolders({parentId:c,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);e=[...e,...t]}const o=[...e];k=R.map(e=>{var t,r;if(e.isFolder||(null===(r=(t=e.id).startsWith)||void 0===r?void 0:r.call(t,"folder_")))return{id:e.id,isFolder:!0};const n=R.find(t=>t.id===e.id),i=(null==n?void 0:n.name)||b(e.id)||"",a=Tr(i,o);return o.push(a),{id:e.id,isFolder:!1,newName:a!==i?a:void 0}})}catch(e){console.warn("Could not check duplicates for copy:",e)}else k=R.map(e=>({id:e.id,isFolder:(null==e?void 0:e.isFolder)||e.id.startsWith("folder_")}));const T=await v({items:k,targetFolderId:l,getItemNameById:b,showNotifications:!1});if(E=T.successCount,x=T.failCount,P.push(...T.errorDetails),E>0){const e=C(_),t=I(e),o=t?i("Copied",{names:t}):i("copy_success_summary",{successCount:E,totalCount:S});a.success({id:"FILES_COPY_SUCCESS",message:o,placement:"bottomRight",data:Oi(_,E,S,c,e)})}if(x>0){const e=C(_),t=I(e);let o;if(1===S&&P.length>0&&(null===(p=P[0].error)||void 0===p?void 0:p.code)){const e=Un(null===(F=P[0].error)||void 0===F?void 0:F.code,i);o=null!=e?e:t?i("Failed",{names:t}):i("copy_fail_summary",{failCount:x,totalCount:S})}else o=t?i("Failed",{names:t}):i("copy_fail_summary",{failCount:x,totalCount:S});a.error({id:"FILES_COPY_ERROR",message:o,placement:"bottomRight",innerException:P.length?P:void 0,data:Ti(_,x,S,c,P.length?P:void 0,e)})}A(),s(),N&&await y({parentIds:void 0,selectedFolder:m}),await w({fetchFiles:e,selectedFolder:u,page:h.current,limit:h.pageSize})}catch(e){console.error("Error when copying:",e);const t=Un(Dn(e).code,i);a.error({id:"FILES_COPY_ERROR",message:null!=t?t:i("Error copying"),innerException:e,placement:"bottomRight",data:Ti(_,S,S,u||null,[{error:Dn(e)}],C(_))})}},[m,l,f,e,u,h,c,a,i,v,s,p,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient,null==g?void 0:g.getFiles,b]);return{actions:{showCopyModal:F,handleCopyCancel:A,handleCopyOk:_}}},ji=e=>{const t=Ni(e),o=Mi(e),r=Ui(e),n=(e=>{const{state:t,actions:o,options:r}=mn(),{t:n}=dr(),i=On(),a=Pi(e=>e.selectedFiles),l=Pi(e=>e.clearSelection),{files:s,selectedFolder:c,pagination:u,currentMenuFile:f}=t,{setIsDeleteConfirmVisible:h,setUndoDeletion:m,setPagination:p}=o,{config:g}=r,{deleteItems:v}=Qn(),{refreshFolders:y,refreshFiles:w}=Li(),{getItemNameById:b,getItemNamesByIds:C,getNamesPreview:I}=ki(s),F=d(()=>{null==h||h(!0)},[h]),A=d(()=>{null==h||h(!1)},[h]),_=d(async()=>{var t,o,r;if(!((null==f?void 0:f.length)||a&&0!==a.size))return void(null==h||h(!1));const d=s.length,F=Object.assign({},u),A=Array.from(f?[f]:a),_=A.map(e=>s.find(t=>t.id===e)).filter(e=>Boolean(e)),S=new Set;_.forEach(e=>{(null==e?void 0:e.isFolder)&&S.add((e=>{var t,o;if(!e)return null;const r=e;return null!==(o=null!==(t=r.folderId)&&void 0!==t?t:r.parentId)&&void 0!==o?o:null})(e))});let E=0,x=0;const P=[];try{const a=await v({items:_,selectedFolder:c,getItemNameById:b,showNotifications:!1});E=a.successCount,x=a.failCount,P.push(...a.errorDetails);const s=(null==g?void 0:g.enableTrashFolder)&&"Trash"===c;if(E>0&&(null==g?void 0:g.enableTrashFolder)&&!s&&(null==m||m({itemIds:A,sourceFolderId:c||"folders"})),E>0){const e=A.length;(null==g?void 0:g.enableTrashFolder)&&!s?await i.success({id:"FILES_DELETE_SUCCESS",message:n("moved_to_trash",{count:E}),placement:"bottomRight",data:{successCount:E,totalCount:e,itemIds:A,folderId:c||null}}):await i.success({id:"FILES_DELETE_SUCCESS",message:n("Files deleted"),placement:"bottomRight",data:{successCount:E,totalCount:e,itemIds:A,folderId:c||null}})}if(x>0){const e=C(A),r=I(e),a=A.length,l=1===a&&P.length>0&&(null===(t=P[0].error)||void 0===t?void 0:t.code),d=(null==g?void 0:g.enableTrashFolder)&&!s,c=n(d?"При перемещении в корзину произошли ошибки":"При удалении произошли ошибки"),u=l?Un(null===(o=P[0].error)||void 0===o?void 0:o.code,n):void 0,f=null!=u?u:r?n("Failed",{names:r}):c;i.error({id:"FILES_DELETE_ERROR",message:f,placement:"bottomRight",innerException:P.length?P:void 0,data:{failCount:x,isTrashMove:d,totalCount:a,itemNames:e,errors:P.length?P:void 0}})}l(),null==h||h(!1),await y({parentIds:Array.from(S),selectedFolder:c});let u=F.current;if(E>0&&d>0&&E>=d&&F.current>1&&(u=F.current-1),E>0&&F.total>=E){const e=Math.max(0,(null!==(r=F.total)&&void 0!==r?r:0)-E);null==p||p({current:u,pageSize:F.pageSize,total:e})}await w({fetchFiles:e,selectedFolder:c,page:u,limit:F.pageSize})}catch(e){console.error("Error when deleting:",e),i.error({id:"FILES_DELETE_ERROR",message:n("Error deleting"),placement:"bottomRight",innerException:e,data:{failCount:x,totalCount:_.length}})}},[f,a,h,e,c,u,m,p,s,n,i,v,l,null==g?void 0:g.enableTrashFolder]);return{actions:{showDeleteConfirm:F,handleDeleteConfirmCancel:A,handleDeleteConfirmOk:_}}})(e);return{state:t.state,actions:Object.assign(Object.assign(Object.assign(Object.assign({},t.actions),o.actions),r.actions),n.actions)}},Di=()=>{const{state:e}=mn(),{files:t,loading:o,isUrlModalVisible:r}=e,n=Ai(),i=(()=>{const{state:e}=mn(),t=e.multiSelect,o=Pi(e=>e.selectedFiles),r=Pi(e=>e.toggleFileSelection),n=Pi(e=>e.setMultiSelect);return a(()=>{n(!1!==t)},[t,n]),{state:{selectedFiles:o},actions:{toggleFileSelection:r}}})(),l=ji(n.fetchFiles);return{state:{files:t||[],selectedFiles:i.state.selectedFiles,loading:o||!1,isAddingFileByUrl:r||!1,isRenamingFile:l.state.isRenamingFile,fileToRename:l.state.fileToRename},actions:{fetchFiles:n.fetchFiles,handleDeleteFile:n.handleDeleteFile,handleDeleteFolder:n.handleDeleteFolder,handleAddFile:n.handleAddFile,handleAddFileByUrl:n.handleAddFileByUrl,handleDroppedFiles:n.handleDroppedFiles,uploadFileWithProvider:n.uploadFileWithProvider,toggleFileSelection:i.actions.toggleFileSelection,showRenameModal:l.actions.showRenameModal,handleRenameCancel:l.actions.handleRenameCancel,handleRenameOk:l.actions.handleRenameOk,showMoveModal:l.actions.showMoveModal,handleMoveCancel:l.actions.handleMoveCancel,handleMoveOk:l.actions.handleMoveOk,showCopyModal:l.actions.showCopyModal,handleCopyCancel:l.actions.handleCopyCancel,handleCopyOk:l.actions.handleCopyOk,showDeleteConfirm:l.actions.showDeleteConfirm,handleDeleteConfirmCancel:l.actions.handleDeleteConfirmCancel,handleDeleteConfirmOk:l.actions.handleDeleteConfirmOk}}};function Bi({maxConcurrent:e=6}={}){const t=c(new Map),o=c([]),r=c(0),n=u(()=>{const n=e=>({status:e.status,shouldLoad:"loading"===e.status||"loaded"===e.status||"error"===e.status}),i=e=>{const t=n(e);e.listeners.forEach(e=>e(t))},a=e=>{0!==o.current.length&&(o.current=o.current.filter(t=>t!==e))},l=(e,o)=>{const r=t.current.get(e);if(!r){const r={id:e,src:o,status:"idle",listeners:new Set,active:!1};return t.current.set(e,r),r}return r.src!==o&&(a(e),r.src=o,r.status="idle"),r},s=()=>{for(;r.current<e&&o.current.length>0;){const e=o.current.shift();if(!e)break;const n=t.current.get(e);n&&n.active&&"queued"===n.status&&(n.status="loading",r.current+=1,i(n))}},d=(e,t)=>{"loading"===e.status&&(e.status=t,r.current=Math.max(0,r.current-1),i(e),s())};return{getSnapshot:(e,t)=>n(l(e,t)),subscribe:(e,o,r)=>{const i=l(e,o);return i.listeners.add(r),r(n(i)),()=>{const o=t.current.get(e);o&&(o.listeners.delete(r),o.active||0!==o.listeners.size||"loading"===o.status||t.current.delete(e))}},setActive:(e,t,n)=>{const d=l(e,t);d.active=n,n?"loaded"!==d.status&&"loading"!==d.status&&"queued"!==d.status?(d.status="queued",i(d),o.current.includes(e)||o.current.push(e),s()):i(d):"queued"===d.status?(a(e),d.status="idle",i(d)):"loading"===d.status&&(r.current=Math.max(0,r.current-1),d.status="idle",i(d),s())},markLoaded:e=>{const o=t.current.get(e);o&&d(o,"loaded")},markError:e=>{const o=t.current.get(e);o&&d(o,"error")},release:e=>{const o=t.current.get(e);o&&(o.active=!1,"queued"===o.status?(a(e),o.status="idle"):"loading"===o.status&&(r.current=Math.max(0,r.current-1),o.status="idle",s()),0===o.listeners.size&&t.current.delete(e))}}},[e]);return a(()=>()=>{o.current=[],t.current.clear(),r.current=0},[]),n}function zi(e){var t;if(e&&"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQABLAEsAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAAEsAAAAAQAAASwAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAQOgAwAEAAAAAQAAAMoAAAAA/+EJ2Wh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8APD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1wTU06RG9jdW1lbnRJRD0iYWRvYmU6ZG9jaWQ6c3RvY2s6Mzk2MmU4NTQtNjA1NC00MGZmLWEwYzMtYjJkNjcwMzQ2OWFhIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOmE5M2NiZTgyLWI5NjEtNGUzNS1iYmQ0LWJjZWE1Zjc1YTQwZiIvPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDw/eHBhY2tldCBlbmQ9InciPz4A/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIAMoBAwMBIgACEQADEQD/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/3QAEABH/2gAMAwEAAhEDEQA/APsuiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoqG7uIbWB55nCooyTS208VxCssLh0boRQBLRRRQAUUUUAFFFFAH/9D7LooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAqG7uIrWBppnCoo5Jou7iK1gaaZwqKM5NcRq2oXOsXqxQq2wnEcYPX3NABq2oXOr3qwxK3l5xHGO/ua6nw7pzadZ7ZJGaR+WBPA9hUfh7R49Pi82TDXDDkkfd9hWxQAUUUUAFFFFABRRRQB//9H7LooooAKKKKACiiuOv/EOpQX88KNDsSQqMp6H60AdjRXD/wDCTapn70P/AH7/APr0f8JPqn96H/v3/wDXoA7iiuH/AOEn1T+9D/37/wDr0f8ACT6p/eh/79//AF6AO4orh/8AhJ9U/vQ/9+//AK9H/CT6p/eh/wC/f/16AO4orh/+En1T+9D/AN+//r0f8JPqn96H/v3/APXoA7iiuH/4SfVP70P/AH7/APr0f8JPqn96H/v3/wDXoA7iiuH/AOEn1T+9D/37/wDr0f8ACT6p/eh/79//AF6AO4orh/8AhJ9U/vQ/9+//AK9H/CT6p/eh/wC/f/16AO4orh/+En1T+9D/AN+//r0f8JPqn96H/v3/APXoA7iobq4itYHmncIijJJrE0jUdQlt2v8AUJIYrNVyMJgv9Oaw9X1C51e8WGJWMecRxr39zQAatqNzq94kUasELYjjB6/Wul8P6NHp8Qlkw1ww5P8Ad9hWRmDw9bfwTajIv4Riqw8Tap6wf98f/XoA7elrh/8AhJtU/vQ/9+//AK9avhnWL3UL94bgx7BGWG1cdwPX3oA6OiiigAooooAKKKKAP//S+y6KKKACiiigArgHAbxSVYAg3mCD3+eu/rgT/wAjV/2+f+z0Adt9jtMf8esH/fsUfY7T/n1g/wC/Yqeh2CIWY4AGSaAK7WlmqktbQADkkxr/AIVUe50JJPLZ7EN6YWuX17WJr+dkRylurYVQfve5rKJoA9Ghh0+Zd0MVtIvqqKaf9jtP+fWD/v2K89sry4sphLbyFD3HY/Wu+0e9TULFLhQATww9DQBJ9jtP+fWD/v2KattZM7ILe3LL94bF4p99cx2lpJcS/dRc/X2rjdG1eSLWmuZ2Oy4bEnoPQ/hQB2P2O0/59YP+/Yo+x2n/AD6wf9+xU4IPSloAr/Y7T/n1g/79ij7Haf8APrB/37FWKKAK/wBjtP8An1g/79ij7Haf8+sH/fsVYooAr/Y7T/n1g/79ioruPTrWBppoLdUUckxj/Cp7u4itYGnmcKijJJriNX1C61i9EUKtsziOMHr7mgBNVv7jVrxYII/3YOIYl/ma6bw9o8enxCSTD3DDkn+H2FHh/R49Pi8yTDXDDkkfd9hWxQBC9rbOxZ7eJmPUlATTfsdp/wA+sH/fsVYooAztXtbVdLumW3hBELkEIOPlNc74H/5Csv8A1xP8xXUaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5igDs6KKKACiiigAooooA//0/suiiigAooooAK4E/8AI1f9vn/s9d9XAn/kav8At8/9noA72s/xI7R6HdMpwdmPzODWhUN/ALqymt26SIVoA816UlS3ML207wSrtdCQai+lAC11HgN2xdx4+XKH6Hn/AArl++K6jSv+JN4flvJhiWfBRe/Tj+ZNAEHjLUfOnFjEw2R/NJju3Yfl/Oudp0jtJIzucsxJJ96bQB2/hLUftdkLeRh50OF+q9jW3XnOkXrWF/HcDJUHDjPUV6HDIssSSIQVYAg0APooooAKhu7iK1gaeZwqKM5NF3cQ2sDTTOFRRk5riNW1C51i9WKJW8vOI4x39zQAavqF1rF6IYVbZnEcYPX3NdL4e0ePT4hLIA1w45JH3fYUeHtHj0+LzJcNcMOTj7vsK2KACiiigAooooAqaz/yCbz/AK4v/wCgmuX8D/8AIWl/64n+YrqNZ/5BN5/1xf8A9BNcv4H/AOQtL/1xP8xQB2dFFFABRRRQAUUUUAf/1PsuiiigAooooAK4E/8AI1f9vn/s9d9XAn/kav8At8/9noA72lpKWgDO1bSLXUQDKCsg6OvX/wCvWFJ4Tn3fJdxFc8FkOa66igDC0zw3a2riadzPIOeRhR+FYXinUPtl+Yoz+5h+VcdCe5/p+FdH4n1H7DYFYziaX5U9vU1wn40AFFFFABXW+DNR3xtp8x+ZPmjyeo7j/PrXJVNZzva3UdxG2HjbP/1qAPTKhu7iK2gaaZwqKOSahTULf+zFv3bZEybsmuP1XULnV70QxK3l7sRxr39zQAmrahc6xerFEreXnEcY7+5rpfD2jx6fF5suGuGHJx932FHh7R49PiEkuGuGHJ/u+wrYoAKKKKACiiigAooooAqaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5iuo1n/AJBN5/1xf/0E1y/gf/kLS/8AXE/zFAHZ0UUUAFFFFABRRRQB/9X7LooooAKKKKACuBP/ACNX/b5/7PXfVwJ/5Gr/ALfP/Z6AO9paSloAKazBVZicBRkmnVz3jHUfs9qLOJsSy/ex2XvQBzuu351DUXlDfu1+WMewqhRRQAUUUv40AFbGi6ZG8TahqB8uzTkA9ZP/AK1Gi6ZG8TajqJ2WcfIB/wCWn/1qi1W+uNWu0hhQiIHbFEv86ADU7+fVbpIIU2xZ2xRL/M103h7R00+LzZcPcMOTj7vsKyCYfD9sQNsupSr+EY/z+ddDot8uoWCTj7/Rx6N3oAvUUUUAFZ17rFta6jDZydZPvNnhPTNSaxqEWn2bTv8AM3RF9TXntxLJPK8sp3O5yx9TQB6dmlrA8Kar9qg+yzt+/jHBP8QrfoAKKKKAKms/8gm8/wCuL/8AoJrl/A//ACFpf+uJ/mK6jWf+QTef9cX/APQTXL+B/wDkLS/9cT/MUAdnRRRQAUUUUAFFFFAH/9b7LooooAKKKKACuBP/ACNX/b5/7PXfVwJ/5Gr/ALfP/Z6AO9paSloAjuZo7eB5pThEGSa851G6e9vJLl+rngeg7Ct/xpqOWXT4m6fNLj9B/X8q5mgBKKKO9AADzWzoumRvEdQ1A7LOPkA/8tP/AK1JoulxvE2oagQlnHyAf+Wn/wBaotVv59WukhhjIizthiX+dABql/catdJBDGRHnbDEv86vkweH7bHyy6jKv4Rj/P8An0UmDw/bEfLLqMq/hGP8/n/Ln5JHlkaSRi7scsx70AEkjySNLIxd2OWY961fCuo/Y78RSNiGY7T7Hsax6WgD1EGmyuscbSOwVVBJPoKy/DGofbrABzmaLCvk9fQ1k+MNU3MdPgY4X/WkevpQBla7qLajel84iTiMe3rWdS0lAEtrPJbXMdxC2HQ5HvXoWlXsd/ZpPGevDD0PevOK0/D2pHTr0FiTBJgOP60Ad/RTUYOoZSCCMg06gCprP/IJvP8Ari//AKCa5fwP/wAhaX/rif5iuo1n/kE3n/XF/wD0E1y/gf8A5C0v/XE/zFAHZ0UUUAFFFFABRRRQB//X+y6KKKACiiigArgT/wAjV/2+f+z131cCf+Rq/wC3z/2egDvarapeJY2Mlw/8I+UZ6nsKs1xni7UftN39ljb91Eecd2/z/WgDFnlknmeaRsu5JJqOigdeKAFrX0XS43iOoagQlnHyAf8Alp/9al0XTI3ibUNQISzj5Ab/AJaf/WqHVb+41a6SGGMrEDtiiX+dAC6rfT6tdJBChEWdsMS/zq+TB4ftj92XUZV/CMf5/P8AkhMPh+2x8suoyr+EY/z+f8sCSR5ZGlkYu7HLMe9ABJI8sjSSMXdjlmPemUUUAFLSUUAWtOvp7CZ5YD8zIVOenNVmJZixJJPUmkooAKKKKAClFJRQB1Pg/VOBp87Dj/VEn9K6jPFeYRs0bh0JDqQQR2Nd7oGpJqNkGJxKnEg/rQBY1n/kE3n/AFxf/wBBNcv4H/5C0v8A1xP8xXUaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5igDs6KKKACiiigAooooA//0PsuiiigAooooAK4E/8AI1f9vn/s9d8a89u5RB4hlnYEiO5LkDvhs0Adtq808Ni7W0TyTEbUCjkE964c6TqhJJspyTySVroB4stsY+xzf99Cj/hK7X/nzl/76FAHPnSdTx/x4z/981d0zRvL33eqr5NtFztbq5/wro7PVo5rF72SB7eBfutIcbvpXLatqFzq94IokYpnEca859zQAmq31xq12sEEZEQOIol/nWxBYzaPZeZBavc30oxlVyIxUVsbLw6i+epuL1wCyp/AP6VY/wCEstv+fSb/AL6FAGBLpmrSyNJJZ3DuxyzFetN/sjU/+fGf/vmug/4Su1/585f++hR/wldr/wA+cv8A30KAOf8A7I1P/nxn/wC+aP7I1P8A58Z/++a6D/hK7X/nzl/76FH/AAldr/z5y/8AfQoA5/8AsjU/+fGf/vmj+yNT/wCfGf8A75roP+Ertf8Anzl/76FH/CV2v/PnL/30KAOf/sjU/wDnxn/75o/sjU/+fGf/AL5roP8AhK7X/nzl/wC+hR/wldr/AM+cv/fQoA5/+yNT/wCfGf8A75o/sjU/+fGf/vmug/4Su1/585f++hR/wldr/wA+cv8A30KAOf8A7I1P/nxn/wC+aP7I1P8A58Z/++a6D/hK7X/nzl/76FH/AAldr/z5y/8AfQoA5/8AsjU/+fGf/vmrmkW+r6ferOllPtzh12n5hWp/wldr/wA+cv8A30KP+Ertf+fOX/voUAa+rNu0a6bBGYGOD1HymuZ8D/8AIWl/64n+YqzfeJre4spoBayqZI2UEkcZGKreB/8AkKyn/pif5igDs6KKKACiiigAooooA//R+y6KKKACiiigArHn8OadPO80nm73YscNjknNbFFAGJ/wjGmf9N/+/lRXGg6NZxG4nMnlpyQ0mQfatq7uIrWBppnCoozk1xGrajdaxeLFCh2E4jjHf3NACapfT6tdpBDGfKU4hjUfrXTeH9HTT4vNkw1yw5JH3fYUeHtHj0+LzZMNcMOSR932FbFAGNL4b0+WRpJXuHdjks0nJNN/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTPSf/v5VrTNGs9PnM1v5m4qVO5s8ZB/pWjRQAUUUUAFFFFABRRRQB//0vsuiiigAooooAKhu7mK1t2nmYKijkmpq5fxda6jNcReXukgYgBVHQ+9AGVq2oXOsXqxRK2zdiNB39zXS+H9Hj0+ISSYa4Ycn+77Cjw/o8enxebLhrhhySPu+wrYoAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9P7LooooAKKKKACkxS0UAFFFFABRRTW6D6igB1FN7n8KQE+YRQA+iiigAopsnEZI64pR90UALRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAH//2Q=="!==e){if(e.startsWith("data:image/")){const t=e.split(",")[1];return t&&t.length>20?e:void 0}return e.startsWith("blob:")?e:e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?null!==(t=(e=>{if(e&&"string"==typeof e){if(e.startsWith("data:")||e.startsWith("blob:"))return e;try{if(e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")){const t=new URL(e.startsWith("/")?`https://x${e}`:e),o=e.startsWith("/")?"":`${t.protocol}//${t.host}`,r=t.pathname.split("/").map(e=>{if(!e)return"";try{return encodeURIComponent(decodeURIComponent(e))}catch(t){return encodeURIComponent(e)}}).join("/");return e.startsWith("/")?r+(t.search||"")+(t.hash||""):`${o}${r}${t.search}${t.hash}`}}catch(e){}return e}})(e))&&void 0!==t?t:e:void 0}}function qi(e,t){var o;if(!e)return null;const r=zi(null!==(o=e.src)&&void 0!==o?o:void 0);return e.exhausted?Object.assign(Object.assign({},e),{src:null}):r?Object.assign(Object.assign({},e),{src:r}):Object.assign(Object.assign({},e),{src:null!=t?t:null,changed:!1,reason:"unchanged"})}function Wi(e){var t;const{options:o}=mn(),r=null===(t=o.config)||void 0===t?void 0:t.getProxiedUrl,n=c([]),l=c(!1),s=c(0),f=c(null),[h,m]=i(!1),p=u(()=>{const t=e.map(e=>zi(e)).filter((e,t,o)=>Boolean(e)&&o.indexOf(e)===t);return(o=n.current)===(r=t)||o.length===r.length&&o.every((e,t)=>e===r[t])?n.current:(n.current=t,t);var o,r},[e]),[g,v]=i([]),[y,w]=i(0);a(()=>{let e=!1;if(w(0),l.current=!1,s.current=0,f.current=null,m(!1),0!==p.length)return(async()=>{const t=await Promise.all(p.map(async e=>{if(!r||!(t=e).startsWith("http://")&&!t.startsWith("https://"))return[{originalSrc:e,src:e}];var t;try{const t=await Promise.resolve(r(e)),o=zi(null==t?void 0:t.src);return o?[{originalSrc:e,src:o,stabilityKey:t.stabilityKey,handleChangeSrc:t.handleChangeSrc,handleSuccess:t.handleSuccess,handleError:t.handleError,subscribeToSrcChange:t.subscribeToSrcChange}]:[{originalSrc:e,src:e}]}catch(t){return[{originalSrc:e,src:e}]}}));if(!e){const e=function(e){const t=new Set;return e.filter(e=>!(!e.src||t.has(e.src)||(t.add(e.src),0)))}(t.flat());v(t=>function(e,t){return e===t||e.length===t.length&&e.every((e,o)=>{const r=t[o];return e.originalSrc===r.originalSrc&&e.src===r.src&&e.stabilityKey===r.stabilityKey})}(t,e)?t:e)}})(),()=>{e=!0};v(e=>0===e.length?e:[])},[r,p]);const b=g[y];a(()=>{if(!(null==b?void 0:b.subscribeToSrcChange))return;let e,t=!1;return Promise.resolve(b.subscribeToSrcChange(e=>{if(t||l.current)return;const o=qi(e,b.src);(null==o?void 0:o.changed)&&o.src&&!t&&v(e=>e.map((e,t)=>t===y?Object.assign(Object.assign({},e),{src:o.src}):e))})).then(o=>{t?null==o||o():e=o}),()=>{t=!0,null==e||e()}},[b,y]),a(()=>{var e;if(!(null==b?void 0:b.handleChangeSrc))return;if(l.current)return;const t=`${b.originalSrc}::${null!==(e=b.stabilityKey)&&void 0!==e?e:""}::${y}`;if(f.current===t)return;f.current=t;let o=!1;return Promise.resolve(b.handleChangeSrc()).then(e=>{const t=qi(e,b.src);(null==t?void 0:t.changed)&&t.src&&!o&&v(e=>e.map((e,o)=>o===y?Object.assign(Object.assign({},e),{src:t.src}):e))}),()=>{o=!0}},[b,y]);const C=d(async()=>{var e;if(!(null==b?void 0:b.handleChangeSrc))return{src:null!==(e=null==b?void 0:b.src)&&void 0!==e?e:null,changed:!1,exhausted:!1,reason:"unchanged"};if(l.current)return{src:null,changed:!1,exhausted:!0,reason:"exhausted"};const t=qi(await Promise.resolve(b.handleChangeSrc()),b.src);return(null==t?void 0:t.changed)&&t.src&&t.src!==b.src?(v(e=>e.map((e,o)=>o===y?Object.assign(Object.assign({},e),{src:t.src}):e)),t):null!=t?t:{src:b.src,changed:!1,exhausted:!1,reason:"unchanged"}},[b,y]),I=d(async()=>{var e,t;if(l.current)return{src:null,changed:!1,exhausted:!0,reason:"exhausted"};if(!b)return l.current=!0,m(!0),{src:null,changed:!1,exhausted:!0,reason:"exhausted"};const o=(r=g.length,Math.max(8,6*r));var r;if(s.current>=o)return l.current=!0,m(!0),{src:null,changed:!1,exhausted:!0,reason:"exhausted"};s.current+=1;const n=b.handleError?qi(await Promise.resolve(b.handleError()),b.src):null;return(null==n?void 0:n.exhausted)?(l.current=!0,m(!0),n):(null==n?void 0:n.changed)&&n.src&&n.src!==b.src?(v(e=>e.map((e,t)=>t===y?Object.assign(Object.assign({},e),{src:n.src}):e)),n):y+1>=g.length?(l.current=!0,m(!0),null!=n?n:{src:null,changed:!1,exhausted:!0,reason:"exhausted"}):(w(e=>e+1),{src:null!==(t=null===(e=g[y+1])||void 0===e?void 0:e.src)&&void 0!==t?t:null,changed:!0,exhausted:!1,reason:"candidate-fallback"})},[b,y,g]),F=d(()=>{var e;l.current||b&&(s.current=0,null===(e=b.handleSuccess)||void 0===e||e.call(b))},[b]);return{src:h||null==b?void 0:b.src,hasNextCandidate:y+1<g.length,handleError:I,handleLoad:F,handleChangeSrc:C}}const Vi=/(auto|scroll|overlay)/;function $i(e,t){const o=Math.max(0,null!=t?t:e.clientWidth);return Math.max(1,Math.round(o-function(e){if("undefined"==typeof window)return 0;const t=window.getComputedStyle(e);return(Number.parseFloat(t.paddingLeft||"0")||0)+(Number.parseFloat(t.paddingRight||"0")||0)}(e)))}function Hi(e){if("undefined"==typeof window)return!1;const t=window.getComputedStyle(e);return Vi.test(t.overflowY)||Vi.test(t.overflow)||Vi.test(t.overflowX)}function Gi(e){if("undefined"==typeof window)return e;let t=e;for(;t;){if(Hi(t))return t;t=t.parentElement}return null}function Ki(e){if("undefined"==typeof window)return[e];const t=Gi(e);return t?t===e?[window,e]:[window,t]:[window]}function Qi(e,t,o){Math.max(0,e.clientHeight),Math.max(0,Math.round(e.getBoundingClientRect().height));return Math.max(1,t)}function Ji(e,t){if(e===t){const o=function(e){var t;if("undefined"==typeof window)return Math.max(1,e.clientHeight);const o=e.getBoundingClientRect(),r=window.innerHeight||(null===(t=document.documentElement)||void 0===t?void 0:t.clientHeight)||0,n=Math.max(0,o.top),i=Math.min(r,o.bottom);return Math.max(0,Math.round(i-n))}(t);return{scrollTop:t.scrollTop,viewportHeight:Qi(e,Math.min(t.clientHeight,o||t.clientHeight)),viewportWidth:$i(t),scrollHeight:e.scrollHeight}}const o=t.getBoundingClientRect(),r=e.getBoundingClientRect(),n=Math.max(o.top,r.top),i=Math.min(o.bottom,r.bottom),a=Math.max(o.left,r.left),l=Math.min(o.right,r.right),s=Math.max(0,Math.round(i-n)),d=Math.max(0,Math.round(l-a));return{scrollTop:Math.max(0,Math.round(n-r.top)),viewportHeight:Qi(e,s),viewportWidth:$i(e,d||t.clientWidth||e.clientWidth),scrollHeight:e.scrollHeight}}function Yi(e){if("undefined"==typeof window)return{scrollTop:e.scrollTop,viewportHeight:Math.max(1,e.clientHeight),viewportWidth:$i(e),scrollHeight:e.scrollHeight};const t=Gi(e);return t&&function(e){return e.scrollHeight-e.clientHeight>1}(t)?Ji(e,t):function(e){var t,o;const r=e.getBoundingClientRect(),n=window.innerHeight||(null===(t=document.documentElement)||void 0===t?void 0:t.clientHeight)||0,i=window.innerWidth||(null===(o=document.documentElement)||void 0===o?void 0:o.clientWidth)||r.width,a=Math.max(0,r.top),l=Math.min(n,r.bottom),s=Math.max(0,Math.round(l-a));return{scrollTop:Math.max(0,Math.round(-r.top)),viewportHeight:Qi(e,s),viewportWidth:$i(e,Math.min(Math.round(r.width),i)),scrollHeight:e.scrollHeight}}(e)}function Zi(e,t){const o=c(null),r=d(t=>{e(Yi(t))},[e]);return a(()=>{o.current&&r(o.current)},[r,...t]),a(()=>{if(!o.current||"undefined"==typeof ResizeObserver)return;const e=o.current,t=new ResizeObserver(()=>{r(e)});return t.observe(e),()=>t.disconnect()},[r]),a(()=>{const e=o.current;if(!e)return;const t=()=>{r(e)},n=Ki(e);return n.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{n.forEach(e=>{e.removeEventListener("scroll",t)})}},[r,...t]),o}const Xi=({onSearch:t,placeholder:o,className:r})=>{const{t:n}=dr(),[l,s]=i(""),d=c(null),{options:u}=mn(),{config:f}=u,h=o||n("Search files...");a(()=>(d.current=Sn.debounce(e=>{t(e)},500),()=>{var e;null===(e=d.current)||void 0===e||e.cancel()}),[t]);return e(I,{value:l,onChange:e=>{var t;const o=e.target.value;s(o),null===(t=d.current)||void 0===t||t.call(d,o)},placeholder:h,prefix:e(_e,{size:16,strokeWidth:null==f?void 0:f.iconStrokeWidth}),className:r,allowClear:!0,onClear:()=>{s(""),t("")}})},ea=[{value:"date-desc",labelKey:"Newest first"},{value:"date-asc",labelKey:"Oldest first"},{value:"size-desc",labelKey:"Largest first"},{value:"size-asc",labelKey:"Smallest first"},{value:"name-asc",labelKey:"A-Z"},{value:"name-desc",labelKey:"Z-A"},{value:"type-asc",labelKey:"By type"}];var ta={contentLayout:"contentLayout",headerContainer:"headerContainer",actionsContainer:"actionsContainer",filesContainer:"filesContainer",filesLoadingOverlay:"filesLoadingOverlay",emptyStateWrapper:"emptyStateWrapper",paginationContainer:"paginationContainer",uploadIcon:"uploadIcon",tableContainer:"tableContainer",tableLoadingWrapper:"tableLoadingWrapper",imagePreview:"imagePreview",fileManagerTableFolder:"fileManagerTableFolder",fileManagerTableFolderInner:"fileManagerTableFolderInner",sortSelect:"sortSelect",fileNameCol:"fileNameCol",fileItemCount:"fileItemCount",fileSize:"fileSize",fileDate:"fileDate",tableMenu:"tableMenu",tableImagePreview:"tableImagePreview",tableFolderIcon:"tableFolderIcon",buttonDeselected:"buttonDeselected",buttonSelectAll:"buttonSelectAll",gridRow:"gridRow",gridCard:"gridCard",selectedRow:"selectedRow",gridCardSelected:"gridCardSelected",gridCheckbox:"gridCheckbox",gridCardContent:"gridCardContent",gridPreviewContainer:"gridPreviewContainer",gridPreviewContainerFolder:"gridPreviewContainerFolder",gridFolderIcon:"gridFolderIcon",gridFolderIconImage:"gridFolderIconImage",gridFileName:"gridFileName",gridFileInfo:"gridFileInfo",gridFileMenu:"gridFileMenu",gridFileMenuButton:"gridFileMenuButton",actionsBox:"actionsBox",uploadContainer:"uploadContainer",uploadArea:"uploadArea",blockText:"blockText",textTitle:"textTitle",textDescription:"textDescription",buttons:"buttons",btnAi:"btnAi",btnPhoto:"btnPhoto",dragOverlay:"dragOverlay",dragOverlayInner:"dragOverlayInner",dragCaptureLayer:"dragCaptureLayer",dragOverlayGlobal:"dragOverlayGlobal",noFiles:"noFiles",noFilesIcon:"noFilesIcon",textTitle_trash:"textTitle_trash",textDescription_trash:"textDescription_trash"};const{Text:oa}=F,{Option:ra}=A;const na=n.memo(({files:o,filesById:r,currentSortOption:n,isSmallScreen:i,iconStrokeWidth:a,multiSelectEnabled:l=!0,features:s,viewMode:d,setViewMode:c,handleSearch:f,handleSortOptionChange:h,sortOptions:m,onClearSelection:p,onRename:g,onDelete:v,onCopy:y,onMove:w,onEdit:b,t:C})=>{const I=u(()=>(null==m?void 0:m.length)?ea.filter(e=>m.includes(e.value)):ea,[m]),F=u(()=>I.map(e=>e.value).join("|")||"all",[I]),P=Pi(e=>e.selectedFiles),R=Pi(e=>e.selectedFiles.size),N=Pi(e=>e.selectAllVisible),k=o.length>0&&R===o.length,O=u(()=>Array.from(P)[0],[P]),T=u(()=>O?r.get(O):void 0,[r,O]),L=(null==T?void 0:T.isFolder)?!1!==(null==s?void 0:s.enableRenameFolder):!1!==(null==s?void 0:s.enableRenameFile),M=u(()=>Array.from(P).every(e=>{const t=r.get(e);return!!t&&(t.isFolder?!1!==(null==s?void 0:s.enableMoveFolder):!1!==(null==s?void 0:s.enableMoveItem))}),[s,r,P]),U=u(()=>Array.from(P).every(e=>{const t=r.get(e);return!!t&&(t.isFolder?!1!==(null==s?void 0:s.enableCopyFolder):!1!==(null==s?void 0:s.enableCopyItem))}),[s,r,P]),j=u(()=>1===R&&function(e){var t,o,r;if(!e||e.isFolder)return!1;const n=e.extension||(e.name&&e.name.includes(".")?e.name.split(".").pop():void 0)||((null===(t=e.type)||void 0===t?void 0:t.startsWith("image/"))?null===(r=null===(o=e.type.split("/")[1])||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim():void 0);return Boolean(n&&bt.includes(n.toLowerCase()))}(T),[R,T]);return t("div",R>0?{className:`header-container ${ta.headerContainer}`,children:[t(oa,{type:"secondary",className:"selected-text",children:[t("div",{children:[R," ",C("selected")]}),l&&e(_,{title:i?C("Select all"):null,children:e(S,{className:ta.buttonSelectAll,onClick:N,disabled:k||0===o.length,children:C("Select all")})}),e(_,{title:i?C("Deselected"):null,children:e(S,{className:ta.buttonDeselected,icon:e(Se,{size:16,strokeWidth:a}),onClick:p,children:C("Deselected")})})]}),t(E,{children:[j&&!1!==(null==s?void 0:s.enableEdit)&&e(_,{title:i?C("Edit"):null,children:e(S,{icon:e(Ee,{size:16,strokeWidth:a}),onClick:()=>b(T),disabled:!j,children:C("Edit")})}),M&&e(_,{title:i?C("Move to"):null,children:e(S,{icon:e(xe,{size:16,strokeWidth:a}),onClick:w,children:C("Move to")})}),U&&e(_,{title:i?C("Copy"):null,children:e(S,{icon:e(Pe,{size:16,strokeWidth:a}),onClick:y,children:C("Copy")})}),1===R&&L&&e(_,{title:i?C("Rename"):null,children:e(S,{icon:e(Re,{size:16,strokeWidth:a}),onClick:()=>g(),disabled:1!==R||!L,children:C("Rename")})}),!1!==(null==s?void 0:s.enableDelete)&&e(_,{title:i?C("Delete"):null,children:e(S,{danger:!0,icon:e(Ne,{size:16,strokeWidth:a}),onClick:e=>{e.stopPropagation(),e.preventDefault(),v()},children:C("Delete")})})]})]}:{className:ta.headerContainer,children:[e("div",{className:"search-container",children:e(Xi,{placeholder:C("Search file or folder"),onSearch:f,className:ta.searchInput})}),t("div",{className:ta.actionsBox,children:[e("div",{className:"sort-container",children:e(A,{value:n,onChange:h,className:ta.sortSelect,popupMatchSelectWidth:!1,suffixIcon:e(ke,{size:16,strokeWidth:a}),children:I.map(({value:t,labelKey:o})=>e(ra,{value:t,children:C(o)},t))},F)}),e("div",{className:ta.actionsContainer,children:e(x,{options:[{value:"grid",icon:e(Oe,{size:16,strokeWidth:a})},{value:"table",icon:e(Te,{size:20,strokeWidth:a})}],value:d,onChange:e=>c(e)})})]})]})});na.displayName="FileContentHeader";const ia=n.memo(({fileId:t,style:o})=>{const r=Pi(e=>e.selectedFiles.has(t)),n=Pi(e=>e.toggleFileSelection);return e(P,{checked:r,style:o,onClick:e=>{e.stopPropagation()},onChange:e=>{const o=e.nativeEvent;n(t,{metaKey:o.metaKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey,forceToggle:!0})}})});ia.displayName="FileSelectionCheckbox";const aa=n.memo(t=>{var{className:o}=t,r=Rn(t,["className"]);const n=r["data-row-key"],i=null==n?"":String(n),a=[o,Pi(e=>!!i&&e.selectedFiles.has(i))?ta.selectedRow:""].filter(Boolean).join(" ");return e("tr",Object.assign({},r,{className:a}))});aa.displayName="SelectableTableRow";const la=n.memo(({item:t,variant:o="table",t:r,iconStrokeWidth:n,setCurrentMenuFile:a,showMoveModal:l,showCopyModal:s,showRenameModal:c,showDeleteConfirm:f,onEdit:h})=>{const[m,p]=i(!1),g=u(()=>{if(!m)return[];const o=[];return t.canEdit&&o.push({key:"edit",label:r("Edit"),icon:e(Ee,{size:16,strokeWidth:n})}),t.canMove&&o.push({key:"move",label:r("Move to"),icon:e(xe,{size:16,strokeWidth:n})}),t.canCopy&&o.push({key:"copy",label:r("Copy"),icon:e(Pe,{size:16,strokeWidth:n})}),t.canRename&&o.push({key:"rename",label:r("Rename"),icon:e(Re,{size:16,strokeWidth:n})}),t.canDelete&&o.push({key:"delete",label:r("Delete"),icon:e(Ne,{size:16,strokeWidth:n}),style:{color:"#ff4d4f"}}),o},[n,m,t.canCopy,t.canDelete,t.canEdit,t.canMove,t.canRename,r]),v=d(({key:e})=>{switch(t.id&&(null==a||a(t.id)),e){case"edit":h(t.file);break;case"move":l();break;case"copy":s();break;case"rename":c(t.id);break;case"delete":null==f||f();break;default:null==a||a("")}},[t,h,a,s,f,l,c]),y=u(()=>({items:g,onClick:v}),[v,g]);return e(R,{arrow:!0,placement:"bottom",menu:y,trigger:["hover"],onOpenChange:p,children:"grid"===o?e(S,{type:"default",className:`${ta.gridFileMenuButton} gridFileMenuButton`,onClick:e=>{e.stopPropagation(),e.preventDefault()},children:e(Le,{size:16,strokeWidth:n})}):e("span",{className:`${ta.tableMenu} tableMenuButton`,onClick:e=>{e.stopPropagation(),e.preventDefault()},children:e(Le,{size:16,strokeWidth:n})})})});la.displayName="FileItemActionsDropdown";const sa=({thumbnailSrc:t,previewSrc:o,lightboxSrc:r,alt:i,className:l,width:s,height:f,preview:h=!1})=>{var m,p;const g=u(()=>[t,o],[t,o]),v=u(()=>[r,o,t],[r,o,t]),y=Wi(g),w=Wi(v),{handleError:b,handleLoad:C}=w,I=null!==(m=y.src)&&void 0!==m?m:wt,F=null!==(p=w.src)&&void 0!==p?p:y.src,A=c(!1);a(()=>{A.current=!1},[F]);const _=d(e=>n.cloneElement(e,{key:null!=F?F:wt,src:null!=F?F:wt,fallback:void 0,onError:()=>{A.current||(A.current=!0,b().finally(()=>{A.current=!1}).catch(()=>{}))},onLoad:()=>{C()}}),[F,b,C]),S=u(()=>!(!h||!F)&&{src:F,actionsRender:()=>null,destroyOnHidden:!0,cover:e(de,{style:{fontSize:"20px"}}),imageRender:_},[h,F,_]);return e(N,{className:l,src:I,alt:i,width:s,height:f,preview:S,onLoad:y.handleLoad,onError:()=>{y.handleError().catch(()=>{})},fallback:wt})},da=n.memo(({item:t,variant:o="table",FolderIcon:r,getFileData:n,className:i,width:a,height:l})=>t.isFolder?e("div","grid"===o?{className:ta.gridFolderIcon,children:e(r,{className:ta.gridFolderIconImage})}:{className:ta.fileManagerTableFolder,children:e("div",{className:ta.fileManagerTableFolderInner,children:e(r,{className:ta.tableFolderIcon,style:{width:null!=a?a:40,height:null!=l?l:40}})})}):t.thumbnailSrc||t.previewSrc?e(sa,{className:i,thumbnailSrc:t.thumbnailSrc,previewSrc:t.previewSrc,lightboxSrc:t.lightboxSrc,alt:t.file.name,width:a,height:l,preview:!0,file:t.file,getFileData:n}):null);da.displayName="FileItemPreview";const ca=[".ant-image",".ant-image-preview-root",".ant-image-preview-wrap",".ant-image-preview-mask",".ant-image-preview-close",".ant-image-preview-operations"].join(","),ua=e=>Boolean(e.closest(ca));function fa(e){var t,o,r;if(e.isFolder)return!1;const n="string"==typeof e.name?e.name:"",i=n?null===(t=n.split(".").pop())||void 0===t?void 0:t.toLowerCase():void 0,a=null!==(r=null===(o=e.extension)||void 0===o?void 0:o.toLowerCase())&&void 0!==r?r:i;return"string"==typeof e.type&&e.type.startsWith("image/")||"string"==typeof a&&Ct.includes(a)}const ha=n.memo(({item:o,t:r,iconStrokeWidth:n,FolderIcon:i,handleItemClick:a,setCurrentMenuFile:l,showMoveModal:s,showCopyModal:c,showRenameModal:u,showDeleteConfirm:f,onEdit:h,onEditorOk:m,getFileData:p,showSelectionCheckbox:g=!0})=>{const v=Pi(e=>e.selectedFiles.has(o.id)),y=d(e=>{const t=e.target;t.closest(".gridFileMenuButton")||t.closest(".ant-dropdown-menu")||ua(t)||1===e.detail&&(o.isFolder?a(o.file):m&&fa(o.file)&&m(o.file))},[a,o.file,o.isFolder,m]);return e(k,{className:ta.gridCard_col,style:{padding:0},children:t(O,{hoverable:!0,cover:e("div",{className:o.isFolder?ta.gridPreviewContainerFolder:ta.gridPreviewContainer,onClick:e=>{e.stopPropagation(),y(e)},children:e(da,{item:o,variant:"grid",FolderIcon:i,getFileData:p,className:ta.gridImagePreview})}),className:`${ta.gridCard} ${v?ta.gridCardSelected:""}`,onClick:e=>{e.stopPropagation(),e.preventDefault(),y(e)},children:[t("div",{className:ta.gridCardContent,onClick:e=>{e.stopPropagation(),e.preventDefault(),y(e)},children:[e("div",{className:ta.gridFileName,children:o.nameText||r("Untitled")}),e("div",{className:ta.gridFileInfo,children:o.gridInfoText})]}),e("div",{className:ta.gridFileMenu,onClick:e=>{e.stopPropagation()},children:e(la,{item:o,variant:"grid",t:r,iconStrokeWidth:n,setCurrentMenuFile:l,showMoveModal:s,showCopyModal:c,showRenameModal:u,showDeleteConfirm:f,onEdit:h})}),g?e("div",{onClick:e=>{e.stopPropagation()},className:ta.gridCheckbox,children:e(ia,{fileId:o.id,style:{height:20}})}):null]})})});ha.displayName="FileGridItem";const ma=n.memo(({rows:t,topOffset:r=0,bottomOffset:n=0,t:i,iconStrokeWidth:a,FolderIcon:l,handleItemClick:s,setCurrentMenuFile:d,showMoveModal:c,showCopyModal:u,showRenameModal:f,showDeleteConfirm:h,onEdit:m,onEditorOk:p,getFileData:g,showSelectionCheckbox:v=!0})=>e(o,{children:e("div",{style:{paddingTop:r,paddingBottom:n},children:e(T,{gutter:[16,16],className:ta.gridRow,style:{gap:20,padding:"0 24px 24px",margin:0},children:t.map(t=>e(ha,{item:t,handleItemClick:s,iconStrokeWidth:a,t:i,FolderIcon:l,setCurrentMenuFile:d,showMoveModal:c,showCopyModal:u,showRenameModal:f,showDeleteConfirm:h,onEdit:m,onEditorOk:p,getFileData:g,showSelectionCheckbox:v},t.id))})})}));ma.displayName="FileGridView";const pa=n.memo(({rows:t,columns:r,topOffset:n=0,bottomOffset:i=0,onRow:a,components:l})=>{const s=u(()=>e("div",{style:{paddingTop:n,paddingBottom:i},children:e(w,{renderEmpty:()=>e(M,{image:e(o,{}),description:""}),children:e(L,{dataSource:t,columns:r,rowKey:"id",pagination:!1,tableLayout:"fixed",onRow:a,components:l,showHeader:!1})})}),[i,r,l,a,t,n]);return e("div",{className:ta.tableLoadingWrapper,children:s})});pa.displayName="FileTableView";const ga=n.memo(({item:t})=>t.dateText?e(_,{title:t.dateText,placement:"bottom",className:ta.fileDate,children:t.dateText}):null);ga.displayName="FileItemDate";const va=n.memo(({item:o})=>t("div",{className:ta.fileName,children:[o.nameText,o.isFolder&&e("div",{className:ta.fileItemCount,children:o.folderItemsText})]}));va.displayName="FileItemName";const ya="filemanager_view_mode";class wa{constructor(){this.rowsById=new Map}reconcile(e,t,o){const r=new Map,n=[];for(const i of e){const e=t.getId(i),a=t.buildSignature(i,o),l=this.rowsById.get(e);if(l&&l.signature===a){r.set(e,l),n.push(l);continue}const s=t.buildRowModel(i,o,{id:e,signature:a});r.set(e,s),n.push(s)}return this.rowsById=r,n}}class ba{createRenderWindow(e,t){var o,r,n,i,a,l,s,d,c,u,f,h,m,p,g,v,y,w,b,C,I,F,A,_,S;const E=null!==(o=null==t?void 0:t.renderStrategy)&&void 0!==o?o:"full";if("windowed"!==E){if("positioned"===E){const o=null!==(n=null===(r=null==t?void 0:t.positioned)||void 0===r?void 0:r.layout)&&void 0!==n?n:[],v=null!==(a=null===(i=null==t?void 0:t.positioned)||void 0===i?void 0:i.viewportTop)&&void 0!==a?a:0,y=null!==(s=null===(l=null==t?void 0:t.positioned)||void 0===l?void 0:l.viewportBottom)&&void 0!==s?s:Number.MAX_SAFE_INTEGER,w=Math.max(0,null!==(c=null===(d=null==t?void 0:t.positioned)||void 0===d?void 0:d.overscanPx)&&void 0!==c?c:0),b=Math.max(0,null!==(f=null===(u=null==t?void 0:t.positioned)||void 0===u?void 0:u.containerHeight)&&void 0!==f?f:0),C=o.filter(e=>e.bottom>=v-w&&e.top<=y+w).map(t=>({row:e[t.index],layout:t})).filter(e=>Boolean(e.row)),I=null!==(m=null===(h=C[0])||void 0===h?void 0:h.layout.index)&&void 0!==m?m:-1,F=null!==(g=null===(p=C[C.length-1])||void 0===p?void 0:p.layout.index)&&void 0!==g?g:-1;return{rows:C.map(e=>e.row),startIndex:I,endIndex:F,topOffset:0,bottomOffset:0,totalCount:e.length,containerHeight:b,positionedItems:C}}return{rows:e,startIndex:0,endIndex:e.length>0?e.length-1:-1,topOffset:0,bottomOffset:0,totalCount:e.length}}const x=Math.max(0,null!==(y=null===(v=null==t?void 0:t.windowed)||void 0===v?void 0:v.startIndex)&&void 0!==y?y:0),P=null!==(b=null===(w=null==t?void 0:t.windowed)||void 0===w?void 0:w.endIndex)&&void 0!==b?b:e.length-1,R=Math.max(0,null!==(I=null===(C=null==t?void 0:t.windowed)||void 0===C?void 0:C.overscan)&&void 0!==I?I:0),N=Math.max(1,null!==(A=null===(F=null==t?void 0:t.windowed)||void 0===F?void 0:F.estimatedItemSize)&&void 0!==A?A:1),k=Math.max(1,null!==(S=null===(_=null==t?void 0:t.windowed)||void 0===_?void 0:_.itemsPerLane)&&void 0!==S?S:1),O=Math.ceil(e.length/k),T=Math.min(e.length-1,P),L=Math.floor(x/k),M=Math.floor(Math.max(x,T)/k),U=Math.max(0,L-R),j=Math.min(O-1,M+R),D=U*k,B=Math.min(e.length-1,(j+1)*k-1),z=Math.max(0,O-j-1);return{rows:e.slice(D,B+1),startIndex:D,endIndex:B,topOffset:U*N,bottomOffset:z*N,totalCount:e.length}}}function Ca({items:e,context:t,adapter:o,options:r}){const n=c(null),i=c(null);n.current||(n.current=new wa),i.current||(i.current=new ba);const a=u(()=>n.current.reconcile(e,o,t),[o,t,e]),l=u(()=>i.current.createRenderWindow(a,r),[r,a]);return{rowModels:a,renderWindow:l}}function Ia({totalCount:e,plan:t}){const[o,r]=i(null);return{engineOptions:u(()=>{var r,n;if(!t.enabled)return{renderStrategy:"full"};const i=function(e,t){var o;return Math.max(1,null!==(o=null==e?void 0:e.viewportHeight)&&void 0!==o?o:t)}(o,null!==(r=t.fallbackViewportHeight)&&void 0!==r?r:800),a=Math.max(1,Math.ceil(i/t.estimatedItemSize)),l=Math.max(1,Math.ceil(e/t.itemsPerLane)),s=Math.min(l-1,Math.max(0,Math.floor((null!==(n=null==o?void 0:o.scrollTop)&&void 0!==n?n:0)/t.estimatedItemSize))),d=s+a-1;return{renderStrategy:"windowed",windowed:{startIndex:s*t.itemsPerLane,endIndex:Math.min(e-1,(d+1)*t.itemsPerLane-1),overscan:t.overscan,estimatedItemSize:t.estimatedItemSize,itemsPerLane:t.itemsPerLane}}},[t.enabled,t.estimatedItemSize,t.fallbackViewportHeight,t.itemsPerLane,t.overscan,e,o]),handleViewportChange:d(e=>{r(t=>(null==t?void 0:t.viewportHeight)===e.viewportHeight&&(null==t?void 0:t.viewportWidth)===e.viewportWidth&&(null==t?void 0:t.scrollHeight)===e.scrollHeight&&(null==t?void 0:t.scrollTop)===e.scrollTop?t:e)},[])}}function Fa(e,t){if("number"==typeof e.childCount)return e.childCount;const o=t[e.id];return null===o?null:null!=o?o:0}function Aa(e){var t,o,r;const n=e.extension||(e.name&&e.name.includes(".")?e.name.split(".").pop():void 0)||((null===(t=e.type)||void 0===t?void 0:t.startsWith("image/"))?null===(r=null===(o=e.type.split("/")[1])||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim():void 0);return Boolean(n&&bt.includes(n.toLowerCase()))}function _a(e,t){if(!e)return"";const o=new Date(e);if(Number.isNaN(o.getTime()))return"";const r=[t("months.january"),t("months.february"),t("months.march"),t("months.april"),t("months.may"),t("months.june"),t("months.july"),t("months.august"),t("months.september"),t("months.october"),t("months.november"),t("months.december")];return t("Added",{date:`${o.getDate()} ${r[o.getMonth()]} ${o.getFullYear()}`})}const Sa={getId:e=>e.id,buildSignature:(e,t)=>function(e,t){var o,r,n,i,a,l,s,d;const c=Boolean(e.isFolder),u=c?Fa(e,t.folderFileCounts):null,f=c?null===u?"u":String(u):"0",h=_a(e.date,t.t),m=!c&&e.size?String(e.size):"",p=e.thumbnailUrl||e.thumbnail,g=e.url&&Aa(e)?e.url:"",v=t.previewFallbackToFileUrl?g:"",y=[!1!==(null===(o=t.features)||void 0===o?void 0:o.enableEdit),!1!==(null===(r=t.features)||void 0===r?void 0:r.enableMoveFolder),!1!==(null===(n=t.features)||void 0===n?void 0:n.enableMoveItem),!1!==(null===(i=t.features)||void 0===i?void 0:i.enableCopyFolder),!1!==(null===(a=t.features)||void 0===a?void 0:a.enableCopyItem),!1!==(null===(l=t.features)||void 0===l?void 0:l.enableRenameFolder),!1!==(null===(s=t.features)||void 0===s?void 0:s.enableRenameFile),!1!==(null===(d=t.features)||void 0===d?void 0:d.enableDelete)].join("|"),w=[p||"",v,g].join("::");return[e.id,e.name,e.folderId,e.type||"",e.extension||"",w,w,e.dimensions||"",m,h,c?"1":"0",f,y].join("::")}(e,t),buildRowModel:(e,t,o)=>{var r,n,i,a,l,s,d,c;const u=Boolean(e.isFolder),f=u?Fa(e,t.folderFileCounts):null,h=u&&null===f?"—":u?`${f} ${1===f?t.t("item"):t.t("items")}`:"",m=e.dimensions||"",p=!u&&e.size?Or(e.size):"",g=u?t.t("Folder"):function(e){var t,o,r;return e.extension||(null===(t=e.name.split(".").pop())||void 0===t?void 0:t.toLowerCase())||(e.url?null===(r=null===(o=e.url.split("?")[0].split("/").pop())||void 0===o?void 0:o.split(".").pop())||void 0===r?void 0:r.toLowerCase():"")||""}(e),v=_a(e.date,t.t),y=u?h:[m,p,g].filter(Boolean).join(" • "),w=e.thumbnailUrl||e.thumbnail,b=e.url&&Aa(e)?e.url:void 0,C=t.previewFallbackToFileUrl?b:void 0;return{id:o.id,signature:o.signature,item:e,file:e,isFolder:u,nameText:e.name||t.t("No name"),folderItemsText:h,dimensionsText:m,sizeText:p,typeText:g,dateText:v,gridInfoText:y,thumbnailSrc:w,previewSrc:C,lightboxSrc:b,canEdit:!u&&!1!==(null===(r=t.features)||void 0===r?void 0:r.enableEdit)&&Aa(e),canMove:u?!1!==(null===(n=t.features)||void 0===n?void 0:n.enableMoveFolder):!1!==(null===(i=t.features)||void 0===i?void 0:i.enableMoveItem),canCopy:u?!1!==(null===(a=t.features)||void 0===a?void 0:a.enableCopyFolder):!1!==(null===(l=t.features)||void 0===l?void 0:l.enableCopyItem),canRename:u?!1!==(null===(s=t.features)||void 0===s?void 0:s.enableRenameFolder):!1!==(null===(d=t.features)||void 0===d?void 0:d.enableRenameFile),canDelete:!1!==(null===(c=t.features)||void 0===c?void 0:c.enableDelete)}}};const Ea=n.memo(({files:o,searchTerm:r,handleSearch:n,sortBy:l,sortOrder:s,handleSortOptionChange:f,pagination:h,setPagination:m,loading:p,handleItemClick:g,onClearSelection:v,onRename:y,onDelete:w,onCopy:b,onMove:C,showRenameModal:I,showDeleteConfirm:F,showCopyModal:A,showMoveModal:_,onEdit:S,getFileData:E,handleAddFile:x})=>{var P;const{t:R}=dr(),N=On(),{DropZoneFileIcon:k,BigStockIcon:O,BigAIIcon:T,FolderIcon:L}=gn(),{options:M,actions:D,state:B}=mn(),{dataProviders:z,config:q}=M,W=null==q?void 0:q.disablePagination,{setCurrentMenuFile:V,setActiveLibraryItem:$}=D,H="Trash"===(null==B?void 0:B.selectedFolder),G=!1!==(null==B?void 0:B.multiSelect),{viewMode:K,setViewMode:Q}=(()=>{const[e,t]=i(()=>{try{return localStorage.getItem(ya)||"table"}catch(e){return"table"}}),o=d(e=>{t(e);try{localStorage.setItem(ya,e)}catch(e){console.warn("Не удалось сохранить режим отображения:",e)}},[]),r=d(()=>{o("table"===e?"grid":"table")},[e,o]);return{viewMode:e,setViewMode:o,toggleViewMode:r}})(),[J,Y]=i({}),[Z,X]=i(!1),ee=c(0),te=c(null);a(()=>{const e=window.matchMedia("(max-width: 1199px)"),t=e=>{X(e.matches)};t(e);const o=e=>t(e);return"function"==typeof e.addEventListener?(e.addEventListener("change",o),()=>e.removeEventListener("change",o)):(e.addListener(o),()=>e.removeListener(o))},[]);const oe=u(()=>(null==q?void 0:q.features)||{},[null==q?void 0:q.features]),re=null==q?void 0:q.iconStrokeWidth,ne=null==q?void 0:q.sortOptions,ie=u(()=>(null==ne?void 0:ne.length)?new Set(ne):null,[ne]),ae=`${l}-${s}`;a(()=>{var e;if(ie&&!ie.has(ae)){const t=null===(e=ea.find(e=>ie.has(e.value)))||void 0===e?void 0:e.value;t&&f(t)}},[ie,ae,f]);const le=u(()=>new Map(o.map(e=>[e.id,e])),[o]),{renderRows:se,renderWindow:de,hasAnyValidDate:ce,handleViewportChange:ue}=function({files:e,folderFileCounts:t,features:o,t:r,viewMode:n,previewFallbackToFileUrl:a}){const l=u(()=>({folderFileCounts:t,features:o,t:r,previewFallbackToFileUrl:a}),[o,t,r,a]),[s,c]=i(()=>Math.max(1,Math.floor(5))),f=u(()=>{const t=e.length>150;return"table"===n?{enabled:t,estimatedItemSize:56,overscan:10,itemsPerLane:1,fallbackViewportHeight:800}:{enabled:t,estimatedItemSize:320,overscan:2,itemsPerLane:s,fallbackViewportHeight:800}},[e.length,s,n]),{engineOptions:h,handleViewportChange:m}=Ia({totalCount:e.length,plan:f}),{rowModels:p,renderWindow:g}=Ca({items:e,context:l,adapter:Sa,options:h}),v=u(()=>p.some(e=>Boolean(e.dateText)),[p]),y=d(e=>{if("grid"===n){const t=Math.max(1,Math.floor(e.viewportWidth/240));c(e=>e===t?e:t)}m(e)},[m,n]);return{rowModels:p,renderRows:g.rows,renderWindow:g,hasAnyValidDate:v,handleViewportChange:y}}({files:o,folderFileCounts:J,features:oe,t:R,viewMode:K,previewFallbackToFileUrl:null==q?void 0:q.previewFallbackToFileUrl}),fe=d(async e=>{var t,o,r,n;try{if(null==z?void 0:z.getChildrenCount)return await z.getChildrenCount("folders"===e?void 0:e);if(null==z?void 0:z.getFiles){const{files:o,pagination:r}=await z.getFiles({folderId:"folders"===e?void 0:e,itemType:"all",page:W?void 0:1,limit:W?void 0:1});return W?Array.isArray(o)?o.length:0:null!==(t=null==r?void 0:r.total)&&void 0!==t?t:Array.isArray(o)?o.length:0}return 0}catch(t){if("StaleLoad"===(null==t?void 0:t.name))return 0;const i=t;if(404===(null==i?void 0:i.status)||"FileNotFound"===(null==i?void 0:i.code)||"path_folder_not_found"===(null==i?void 0:i.code)||"path_folder_not_found"===(null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.code)||404===(null===(n=null===(r=null==i?void 0:i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status))return 0;console.error(`Error getting the number of files for the folder ${e}:`,t);const a=await fi({folderId:e,dataProviders:z,folders:Array.isArray(B.folders)?B.folders:[],pathHistory:B.pathHistory,t:R});return N.error({id:"FOLDER_CHILDREN_COUNT_FAILED",message:R("Failed to load folder items count in folder",{folderName:a}),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{folderId:"folders"===e?null:e,folderName:a,reason:t instanceof Error?t.message:String(t)}}),null}},[z,W,N,B.folders,B.pathHistory,R]),he=d(async()=>{const e=ee.current+1;ee.current=e;const t=o.filter(e=>e.isFolder);if(0===t.length)return void Y(e=>0===Object.keys(e).length?e:{});const r={},n=t.map(async e=>{"number"!=typeof e.childCount?r[e.id]=await fe(e.id):r[e.id]=e.childCount});await Promise.all(n),ee.current===e&&Y(e=>{const t=Object.keys(e),o=Object.keys(r);return t.length===o.length&&t.every(t=>e[t]===r[t])?e:r})},[o,fe]);a(()=>{he()},[he]),a(()=>{te.current&&ue(Yi(te.current))},[o.length,ue,K]),a(()=>{if(!te.current||"undefined"==typeof ResizeObserver)return;const e=te.current,t=new ResizeObserver(()=>{ue(Yi(e))});return t.observe(e),()=>{t.disconnect()}},[ue]);const me=d(e=>{const t=Yi(e);ue(t)},[ue]);a(()=>{const e=te.current;if(!e)return;const t=()=>{me(e)},o=Ki(e);return o.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{o.forEach(e=>{e.removeEventListener("scroll",t)})}},[o.length,me,K]);const pe=d((e,t)=>e!==t,[]),ge=u(()=>[...G?[{key:"selection",width:46,shouldCellUpdate:pe,render:(t,o)=>e(ia,{fileId:o.id})}]:[],{key:"preview",width:60,shouldCellUpdate:pe,render:(t,o)=>e(da,{item:o,variant:"table",FolderIcon:L,getFileData:E,className:`${ta.imagePreview} ${ta.tableImagePreview}`,width:40,height:40})},{title:R("Name"),width:"calc(100% - 430px)",dataIndex:"nameText",key:"name",className:ta.fileNameCol,shouldCellUpdate:pe,render:(t,o)=>e(va,{item:o})},{title:R("Dimensions"),key:"dimensions",width:100,shouldCellUpdate:pe,render:(t,o)=>o.dimensionsText&&e("div",{className:ta.fileSize,children:o.dimensionsText})},{title:R("Size"),key:"size",width:90,shouldCellUpdate:pe,render:(t,o)=>o.sizeText?e("div",{className:ta.fileSize,children:o.sizeText}):null},{title:R("Type"),key:"type",width:90,shouldCellUpdate:pe,render:(t,o)=>e("div",{className:ta.fileSize,children:o.typeText})},...ce?[{title:R("Date"),dataIndex:"dateText",key:"date",width:200,shouldCellUpdate:pe,render:(t,o)=>e(ga,{item:o})}]:[],{width:40,title:"",dataIndex:"",key:"x",onCell:()=>({style:{padding:0}}),shouldCellUpdate:pe,render:(t,o)=>e(la,{item:o,variant:"table",t:R,iconStrokeWidth:re,setCurrentMenuFile:V,showMoveModal:_,showCopyModal:A,showRenameModal:I,showDeleteConfirm:F,onEdit:S})}],[L,E,ce,re,G,S,V,pe,A,F,_,I,R]),ve=u(()=>({body:{row:aa}}),[]),ye=d(e=>({onClick:t=>{if(t.stopPropagation(),t.preventDefault(),1!==t.detail)return;const o=t.target,r=Boolean(o.closest(".ant-checkbox-wrapper")),n=Boolean(o.closest(".tableMenuButton")),i=Boolean(o.closest(".ant-dropdown-menu"));r||ua(o)||n||i||(e.isFolder?g(e.file):M.onEditorOk&&fa(e.file)&&M.onEditorOk(e.file))}}),[g,M]);let we="table"===K?e(pa,{rows:se,columns:ge,topOffset:de.topOffset,bottomOffset:de.bottomOffset,onRow:ye,components:ve}):e(ma,{rows:se,topOffset:de.topOffset,bottomOffset:de.bottomOffset,t:R,iconStrokeWidth:re,FolderIcon:L,handleItemClick:g,setCurrentMenuFile:V,showMoveModal:_,showCopyModal:A,showRenameModal:I,showDeleteConfirm:F,onEdit:S,onEditorOk:M.onEditorOk,getFileData:E,showSelectionCheckbox:G});r&&!o.length&&(we=e(Cn,{}));const be=null===(P=null==q?void 0:q.availableImageExtensions)||void 0===P?void 0:P.map(e=>"."+e).join(", "),Ce=t("div",H?{className:`${ta.noFiles} ant-layout-sider-light`,children:[e(Me,{size:48,className:ta.noFilesIcon}),e("div",{className:`${ta.textTitle_trash} ant-menu-submenu-title`,children:R("Trash is empty")}),e("div",{className:`${ta.textDescription_trash} ant-menu-submenu-title`,children:R("Deleted files will be displayed here")})]}:{className:ta.uploadContainer,children:[t("div",{className:`${ta.uploadArea} `,onClick:x,children:[e("div",{className:ta.uploadIcon,children:e(k,{})}),e("div",{className:ta.textTitle,children:R("Click here to select a file")}),e("div",{className:ta.textDescription,children:R("Supported files:")+" "+(be||"jpeg, .svg, .png")})]}),t("div",{className:ta.buttons,children:[t("button",{className:ta.btnPhoto,onClick:()=>{$&&$(st)},children:[e("div",{className:ta.icon,children:e(O,{})}),t("div",{className:ta.blockText,children:[e("div",{className:ta.textTitle,children:R("Stock")}),e("div",{className:ta.textDescription,children:R("Select an image from our library")})]})]}),t("button",{className:ta.btnAi,onClick:()=>{$&&$(ct)},children:[e("div",{className:ta.icon,children:e(T,{})}),t("div",{className:ta.blockText,children:[e("div",{className:ta.textTitle,children:R("AI generation")}),e("div",{className:ta.textDescription,children:R("Creating an image on demand")})]})]})]})]});return e("div",{className:`content-layout ${ta.contentLayout}`,children:p||0!==(null==o?void 0:o.length)||r?t("div",{className:ta.tableContainer,children:[e(na,{files:o,filesById:le,currentSortOption:ae,isSmallScreen:Z,iconStrokeWidth:re,multiSelectEnabled:G,features:oe,viewMode:K,setViewMode:Q,handleSearch:n,handleSortOptionChange:f,sortOptions:ne,onClearSelection:v,onRename:y,onDelete:w,onCopy:b,onMove:C,onEdit:S,t:R}),t("div",{ref:te,className:ta.filesContainer,children:[we,p?e("div",{className:ta.filesLoadingOverlay,"aria-busy":"true","aria-live":"polite",children:e(U,{size:"large"})}):null]}),!W&&h.total>h.pageSize&&e("div",{className:ta.paginationContainer,children:e(j,{current:h.current,pageSize:h.pageSize,total:h.total,onChange:(e,t)=>m({current:e,pageSize:t,total:h.total}),showSizeChanger:!0,showTotal:e=>R("total pages",{total:e})})})]}):e("div",{className:ta.emptyStateWrapper,children:Ce})})});Ea.displayName="FileContent";var xa="folderTree",Pa="emptyFolderContainer",Ra="folderItemContainer",Na="folderLabel",ka="folderLabelItem",Oa="fileCount",Ta="foldersTitle",La="foldersTitleItem",Ma="folderMenu";const Ua=({selectedFolder:o,onSelect:r,onExpand:n,generateMenuItems:l,fetchChildFolders:s,disabledFolders:c=[],showFileCounts:f=!1,folderFileCounts:h={},className:m="",expandedKeys:p,setExpandedKeys:g,showTrashFolder:v=!1,mode:y="navigation",defaultExpandAll:w=!1})=>{const{t:b}=dr(),{options:C}=mn(),{config:I}=C,{ExpandArrowIcon:F,CollapseArrowIcon:A,CollapseFolderIcon:_,ExpandFolderIcon:S,EmptyFolderIcon:E}=gn(),x=d(e=>{const t=[],o=e=>{e.forEach(e=>{t.push(e.key),e.children&&o(e.children)})};return o(e),t},[]),[P,R]=i(()=>{if(w||"selection"===y&&w){const e=l();return x(e)}return[]}),N=void 0!==p?p:P,k=void 0!==g?g:R;a(()=>{if(w||"selection"===y&&w){const e=l(),t=x(e);void 0===p&&R(t)}},[w,y,l,x,p]);const O=d(async e=>{const t=e[0];t&&"empty"!==t&&!t.endsWith("_input")&&(null==r||r(e),await(null==s?void 0:s("folders"===t?null:t)))},[r,s]),T=d(async(e,t)=>{var o;k(e),null==n||n(e,t);if(!("lazy"===(null==I?void 0:I.folderTreeLoading)))return;const r=(null===(o=null==t?void 0:t.node)||void 0===o?void 0:o.key)||void 0;if(r&&"folders"!==r)try{await(null==s?void 0:s(r))}catch(e){console.warn("Failed to load child folders for",r,e)}},[null==I?void 0:I.folderTreeLoading,s,n,k]),L=d(()=>{var r,n;const i=l(),a=e=>e.filter(e=>"Trash"!==e.key).map(e=>Object.assign(Object.assign({},e),{children:e.children?a(e.children):void 0})),s=v?a(i):i,d=e=>{"selection"!==y?(N.includes(e)&&o===e?k(N.filter(t=>t!==e)):N.includes(e)||k([...N,e]),O([e])):O([e])},u=0===s.length||1===s.length&&(!s[0].children||0===s[0].children.length),m=o=>{var r;const n=f?h[o.key]:void 0,i=f&&null===n?null:f&&null!=n?n:0,a=N.includes(o.key),l=c.includes(o.key),s=(()=>{var t;return(null===(t=o.children)||void 0===t?void 0:t.length)?e(a?_:S,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}):e(E,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth})})(),u=t("div",{className:`${Ra} folder-item-container`,onClick:()=>!l&&d(o.key),style:{opacity:l?.5:1,cursor:l?"not-allowed":"pointer"},children:[t("div",{className:Na,children:[void 0!==o.icon?o.icon:s,e("span",{className:ka,children:o.label})]}),f&&e("div",{className:Oa,title:null===i?void 0:`${i} ${b(1===i?"item":"items")}`,children:null===i?"—":i})]});return{key:o.key,title:u,children:null===(r=o.children)||void 0===r?void 0:r.map(m),disabled:l}},p=N.includes("folders"),g=e("div",{className:Ta,onClick:()=>d("folders"),children:t("div",{className:La,children:[e(p?_:S,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}),e("span",{className:`${ka} folder-label-item`,children:"folders"===(null===(r=s[0])||void 0===r?void 0:r.key)?s[0].label:b("Folders")})]})}),w=()=>({key:"Trash",title:e("div",{className:Ta,onClick:()=>d("Trash"),children:t("div",{className:La,children:[e(Ne,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}),e("span",{className:ka,children:b("Trash")})]})}),children:void 0});if(u){if(!v)return[{key:"empty",title:e("div",{className:Pa,children:b("No folders yet")}),disabled:!0}];const t=[];return s.length>0&&"folders"===s[0].key&&t.push({key:"folders",title:g,children:[]}),t.push(w()),t}if(s.length>0&&"folders"===s[0].key){const e=[{key:"folders",title:g,children:null===(n=s[0].children)||void 0===n?void 0:n.map(m)}];return v&&e.push(w()),e}return s.map(m)},[l,N,_,null==I?void 0:I.iconStrokeWidth,S,b,o,O,f,h,E,c,v,y,k]),M=u(()=>L(),[L]);return e(D,{className:`${xa} ${Ma} ${m}`,selectedKeys:o?[o]:[],expandedKeys:N,onSelect:O,onExpand:T,treeData:M,switcherIcon:({expanded:t})=>e(t?A:F,{}),showLine:!1,focusable:"selection"!==y})},ja=({style:t={},wrap:o=!1})=>{const r=Object.assign({width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},t);return e(E,{size:"large",style:r,wrap:o,children:e(U,{})})};var Da={formFooter:"formFooter",folderButton:"folderButton",foldersWrapper:"foldersWrapper",formItem:"formItem",folderToolsField:"folderToolsField",inputButtonOk:"inputButtonOk",permanentDeleteWarning:"permanentDeleteWarning",clearTrashProgress:"clearTrashProgress",progressText:"progressText",closeIcon:"closeIcon",modalContentWithLoader:"modalContentWithLoader",modalLoaderOverlay:"modalLoaderOverlay"};const Ba=({folderId:r,activeFormField:n,EmptyFolderIcon:i,targetForm:a,handleModalOk:l,onComplete:s,setIsLoading:d,t:c})=>e(b.Item,{className:"form-item form-item-moveto "+(n===r?"form-item_active":""),name:"folderName",rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(c("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{className:"form-input",autoFocus:!0,onFocus:e=>e.stopPropagation(),prefix:e(i,{style:{marginRight:6}}),suffix:t(o,{children:[e(_,{placement:"top",title:"Clean",children:e(S,{icon:e(ce,{style:{fontSize:10}}),className:Da.inputButtonClose,type:"text",onClick:()=>{a.setFieldsValue({folderName:""})}})}),e(S,{className:Da.inputButtonOk,type:"text",onClick:()=>{d(!0),l(a).then(e=>{const t=null==e?void 0:e.id;s(t)}).finally(()=>d(!1))},children:c("Create")})]})})});function za({folders:r,selectedFolder:i,EmptyFolderIcon:a,handleCreateFolderModalOk:l,setIsLoading:s,t:d}){const[c,u]=n.useState(""),f=n.useCallback((t,o)=>r=>e(Ba,{folderId:r,activeFormField:c,EmptyFolderIcon:a,targetForm:t,handleModalOk:l,onComplete:o,setIsLoading:s,t:d},r),[a,c,l,s,d]),h=n.useCallback(e=>{const{folderId:t,targetForm:o,onTreeSelect:r,onComplete:n}=e;return{handleAddFolder:e=>{e.preventDefault(),e.stopPropagation(),u(t),o.setFieldsValue({folderName:d("New folder"),targetFolder:t})},handleSelectFolder:e=>{e.preventDefault(),e.stopPropagation(),r([t]).then(()=>n(t))}}},[d]),m=n.useCallback(n=>{const{targetForm:a,onTreeSelect:l,onComplete:s,actionButtonText:u}=n,m=f(a,s),p=Array.isArray(r)?r:[],g=(r=null,n=new Set)=>p.filter(e=>{const t=null===r&&!e.parentId,o=e.parentId===r;return t||o}).map(r=>{if(n.has(r.id))return{key:r.id,label:`${r.name} (циклическая ссылка)`};const d=new Set(n);d.add(r.id);const f=g(r.id,d),{handleAddFolder:p,handleSelectFolder:v}=h({folderId:r.id,targetForm:a,onTreeSelect:l,onComplete:s}),y=c===r.id?[{key:`${r.id}_input`,label:m(r.id),icon:null},...f]:f;return{key:r.id,label:t(o,{children:[r.name,i!==r.id&&t("div",{className:`${Da.folderToolsField} folder-tools-field`,children:[e(S,{onClick:p,children:"+"}),e(S,{onClick:v,children:u})]})]}),children:y}}),v=g(),{handleAddFolder:y,handleSelectFolder:w}=h({folderId:"folders",targetForm:a,onTreeSelect:l,onComplete:s}),b="folders"===c?[{key:"folders_input",label:m("folders"),icon:null},...v]:v;return[{key:"folders",label:t(o,{children:[d("Folders"),"folders"!==i&&null!==i&&t("div",{className:`${Da.folderToolsField} folder-tools-field`,children:[e(S,{onClick:y,children:"+"}),e(S,{onClick:w,children:u})]})]}),children:b}]},[c,f,h,r,i,d]);return{activeFormField:c,setActiveFormField:u,generateMenuItemsFromFolders:m}}const qa=h(({folderId:t,activeFormField:o,EmptyFolderIcon:r,targetForm:n,handleModalOk:i,onComplete:a,t:l,setIsLoading:s,defaultFolderName:c})=>{const u=d(()=>{s(!0),i(n).then(e=>a(null==e?void 0:e.id)).finally(()=>s(!1))},[i,n,a,s]);return e(b.Item,{className:"form-item form-item-moveto "+(o===t?"form-item_active":""),name:"folderName",initialValue:c,rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(l("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{className:"form-input",autoFocus:!0,prefix:e(r,{style:{marginRight:6}}),suffix:e(S,{className:Da.inputButtonOk,type:"text",onClick:()=>{s(!0),u()},children:l("Create")})})})});qa.displayName="CustomFolderInput";const Wa=({isModalVisible:r,handleModalOk:n,handleModalCancel:l,form:s,selectedFolder:c,folders:f,isUrlModalVisible:h,setIsUrlModalVisible:m,handleAddFileByUrl:p,urlForm:g,isRenameModalVisible:v,handleRenameOk:y,handleRenameCancel:w,renameForm:C,fileToRename:F,files:A,isMoveModalVisible:_,handleMoveOk:E,handleMoveCancel:x,moveForm:P,selectedFiles:R,isRenameFolderModalVisible:N,handleRenameFolderOk:k,handleRenameFolderCancel:O,renameFolderForm:T,folderToRename:L,isCopyModalVisible:M,handleCopyOk:U,handleCopyCancel:j,copyForm:D,isDeleteConfirmVisible:q,handleDeleteConfirmOk:W,handleDeleteConfirmCancel:V,isClearTrashConfirmVisible:$,handleClearTrashConfirm:H,handleClearTrashCancel:G,fetchChildFolders:K})=>{var Q,J,Y;const{t:Z}=dr(),{state:X,actions:ee,options:te}=mn(),{setCurrentMenuFile:oe}=ee,{config:re,getModalContainer:ne}=te,{currentMenuFile:ie}=X,ae=b.useWatch("folderName",s),{EmptyFolderIcon:le}=gn(),[se,de]=i(!1),ue=u(()=>{var e;return(null===(e=null==re?void 0:re.defaultFolderName)||void 0===e?void 0:e.trim())||Z("New folder")},[null==re?void 0:re.defaultFolderName,Z]),fe=!ae||0===String(ae).trim().length,he=u(()=>Array.isArray(A)?A:[],[A]),me=F?null===(Q=he.find(e=>e.id===F))||void 0===Q?void 0:Q.name:"",pe=Array.isArray(f)?f:[],ge=L?null===(J=pe.find(e=>e.id===L))||void 0===J?void 0:J.name:"",{activeFormField:ve,setActiveFormField:ye,generateMenuItemsFromFolders:we}=za({folders:pe,selectedFolder:c,EmptyFolderIcon:le,handleCreateFolderModalOk:n,setIsLoading:e=>de(Boolean(e)),t:Z});a(()=>{if(q){const e=setTimeout(()=>{const e=document.querySelector(".deleteModal");if(e){const t=e.querySelector(".ant-modal-footer");if(t){const e=t.querySelector(".ant-btn-primary");e&&e.focus()}}},100);return()=>clearTimeout(e)}},[q]);const be=F?he.find(e=>e.id===F):null,Ce=(null==be?void 0:be.isFolder)||(null==F?void 0:F.startsWith("folder_")),Ie=d(async e=>{e.length>0&&(P.setFieldsValue({targetFolder:e[0]}),ve!==e[0].toString()&&ye(""))},[P,ve,ye]),Fe=d(async e=>{e.length>0&&(D.setFieldsValue({targetFolder:e[0]}),ve!==e[0].toString()&&ye(""))},[ve,D,ye]),_e=d(async e=>{de(!0);try{await E(e)}finally{de(!1)}},[E]),Se=d(async e=>{de(!0);try{await U(e)}finally{de(!1)}},[U]),Ee=u(()=>{const e=Array.from(R).filter(e=>{const t=he.find(t=>t.id===e);return(null==t?void 0:t.isFolder)||f.some(t=>t.id===e)});return c&&"folders"!==c?e.push(c):c&&"folders"!==c||e.push("folders"),e},[R,he,f,c]);return t(o,{children:[e(B,{title:e("div",{className:"modal-title",children:Z("Creating a new folder")}),open:r,onOk:()=>n(),onCancel:l,okText:Z("Create"),cancelText:Z("Cancel"),okButtonProps:{disabled:fe,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>de(!1),centered:!0,getContainer:ne,children:t(b,{form:s,layout:"vertical",children:[e(b.Item,{name:"folderName",label:e("div",{className:"form-label",children:Z("Folder name")}),rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],initialValue:ue,className:"form-item",style:{marginBottom:5},children:e(I,{autoFocus:!0,className:"form-input",disabled:se,placeholder:Z("Enter the name"),onPressEnter:async()=>{de(!0);try{await s.validateFields(),fe||await n()}catch(e){de(!1)}}})}),e("div",{children:c&&"folders"!==c?t("p",{className:"fm-note",children:[Z("A folder will be created inside:")," ",(null===(Y=pe.find(e=>e.id===c))||void 0===Y?void 0:Y.name)||Z("selected folder"),"."]}):e("p",{className:"fm-note",children:Z("The folder will be created in the root directory.")})})]})}),e(B,{title:e("div",{className:"modal-title",children:Z("Upload file by URL")}),open:h,onOk:async()=>{var e;de(!0);try{const t=await g.validateFields(),o=String(null!==(e=t.fileUrl)&&void 0!==e?e:"").trim();await p(o,void 0,void 0,"uploadByUrl")}catch(e){}finally{de(!1)}},onCancel:()=>m(!1),okText:Z("Download"),okButtonProps:{loading:se},cancelText:Z("Cancel"),cancelButtonProps:{disabled:se},afterClose:()=>de(!1),centered:!0,getContainer:ne,children:e(b,{form:g,layout:"vertical",children:e(b.Item,{name:"fileUrl",label:e("div",{className:"form-label",children:Z("File URL")}),rules:[{required:!0,message:Z("Enter the URL of the image")},{validator:(e,t)=>{if(!t||!String(t).trim())return Promise.resolve();try{return Xn(String(t),Z),Promise.resolve()}catch(e){return Promise.reject(new Error(e instanceof Error?e.message:Z("The specified URL is not valid.")))}}}],validateTrigger:"onBlur",className:"form-item",children:e(I,{className:"form-input",placeholder:"https://example.com/image.jpg",autoFocus:!0,disabled:se,onPressEnter:async()=>{var e;de(!0);try{const t=await g.validateFields(),o=String(null!==(e=t.fileUrl)&&void 0!==e?e:"").trim();await p(o,void 0,void 0,"uploadByUrl")}catch(e){}finally{de(!1)}}})})})}),e(B,{title:e("div",{className:"modal-title",children:Ce?`${Z("Rename folder")} ${me}`:Z("Rename file",{currentFileName:me})}),open:v,onOk:y,okText:Z("Rename"),okButtonProps:{loading:se},onCancel:w,cancelText:Z("Cancel"),cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},centered:!0,getContainer:ne,children:e(b,{form:C,layout:"vertical",children:e(b.Item,{name:"newFileName",label:e("div",{className:"form-label",children:Z(Ce?"New folder name":"New file name")}),rules:[{required:!0,message:Z(Ce?"Enter a new folder name":"Enter a new file name")}],className:"form-item",children:e(I,{autoFocus:!0,className:"form-input",disabled:se,onPressEnter:async()=>{de(!0);try{await C.validateFields(),y()}catch(e){de(!1)}}})})})}),e(B,{title:e("div",{className:"modal-title",children:Z("Move to")}),open:_,onCancel:x,footer:t("div",{className:Da.formFooter,children:[t(S,{className:Da.folderButton,onClick:()=>{const e=null!=c?c:"folders";ye(e),P.setFieldsValue({folderName:ue,targetFolder:e})},loading:se,children:[e(Ae,{size:18,strokeWidth:null==re?void 0:re.iconStrokeWidth}),Z("Create folder")]}),e(S,{type:"primary",className:Da.folderButton,onClick:x,loading:se,children:Z("Done")})]}),afterClose:()=>{oe&&oe(""),ye(""),de(!1)},loading:se,centered:!0,getContainer:ne,children:t("div",{className:Da.modalContentWithLoader,children:[se&&e("div",{className:Da.modalLoaderOverlay,children:e(ja,{})}),e(b,{form:P,layout:"vertical",initialValues:{targetFolder:"folders",folderName:ue,is_force_create:!1},children:t("div",{className:Da.foldersWrapper,children:[e(b.Item,{name:"targetFolder",rules:[{required:!0,message:Z("Select the destination folder")}],className:Da.formItem,children:e(Ua,{onSelect:Ie,generateMenuItems:()=>we({targetForm:P,onTreeSelect:Ie,onComplete:_e,actionButtonText:Z("Move here")}),fetchChildFolders:K,disabledFolders:Ee,mode:"selection",className:"folderSelectionTree",defaultExpandAll:!0})}),e(b.Item,{name:"folderName",style:{display:"none"},rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{})}),e(b.Item,{name:"is_force_create",style:{display:"none"},children:e(I,{})})]})})]})}),e(B,{title:e("div",{className:"modal-title",children:Z("Copy to folder")}),open:M,onCancel:j,footer:t("div",{className:Da.formFooter,children:[t(S,{className:Da.folderButton,onClick:()=>{const e=null!=c?c:"folders";ye(e),D.setFieldsValue({folderName:ue,targetFolder:e})},loading:se,children:[e(Ae,{size:18,strokeWidth:null==re?void 0:re.iconStrokeWidth}),Z("Create folder")]}),e(S,{type:"primary",className:Da.folderButton,onClick:j,loading:se,children:Z("Done")})]}),afterClose:()=>{oe&&oe(""),ye(""),de(!1)},loading:se,centered:!0,getContainer:ne,children:t("div",{className:Da.modalContentWithLoader,children:[se&&e("div",{className:Da.modalLoaderOverlay,children:e(ja,{})}),e(b,{form:D,layout:"vertical",initialValues:{targetFolder:"folders",folderName:ue,is_force_create:!1},children:t("div",{className:Da.foldersWrapper,children:[e(b.Item,{name:"targetFolder",rules:[{required:!0,message:Z("Select the destination folder")}],className:Da.formItem,children:e(Ua,{onSelect:Fe,generateMenuItems:()=>we({targetForm:D,onTreeSelect:Fe,onComplete:Se,actionButtonText:Z("Copy here")}),fetchChildFolders:K,disabledFolders:Ee,mode:"selection",className:"folderSelectionTree",defaultExpandAll:!0})}),e(b.Item,{name:"folderName",style:{display:"none"},rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{})}),e(b.Item,{name:"is_force_create",style:{display:"none"},children:e(I,{})})]})})]})}),e(B,{title:t("div",{className:"modal-title",children:[Z("Rename folder")," ",ge]}),open:N,onOk:k,onCancel:O,okText:Z("Rename"),cancelText:Z("Cancel"),okButtonProps:{loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},centered:!0,getContainer:ne,children:e(b,{form:T,layout:"vertical",children:e(b.Item,{name:"newFolderName",label:e("div",{className:"form-label",children:Z("New folder name")}),rules:[{required:!0,message:Z("Enter a new folder name")}],className:"form-item",children:e(I,{autoFocus:!0,className:"form-input",disabled:se,onPressEnter:async()=>{de(!0);try{await T.validateFields(),k()}catch(e){de(!1)}}})})})}),e(B,{className:`${Da.deleteModal} deleteModal`,title:(()=>{const t=!!(null==re?void 0:re.enableTrashFolder)&&"Trash"===c||!(null==re?void 0:re.enableTrashFolder),o=Z(t?"Permanently delete":"Move to Trash");return e("div",{className:"modal-title",children:o})})(),open:!!q,onOk:()=>{de(!0);try{W&&W()}catch(e){console.error(e),de(!1)}},onCancel:()=>V&&V(),okText:(null==re?void 0:re.enableTrashFolder)&&"Trash"===c?Z("Delete permanently"):(null==re?void 0:re.enableTrashFolder)?Z("Move to Trash"):Z("Delete"),cancelText:Z("Cancel"),okButtonProps:{danger:!(null==re?void 0:re.enableTrashFolder)||"Trash"===c,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},closeIcon:e(ce,{className:Da.closeIcon}),centered:!0,getContainer:ne,children:(()=>{var o,r;const n=(ie?[ie]:Array.from(R||[])).map(e=>he.find(t=>t.id===e)).filter(e=>!!e),i=n.filter(e=>e.isFolder||e.id.startsWith("folder_")),a=n.filter(e=>!(e.isFolder||e.id.startsWith("folder_"))),l=n.length,s=i.length,d=a.length,u=!!(null==re?void 0:re.enableTrashFolder);if(!u||u&&"Trash"===c){let r;if(1===l&&1===s){const e=i[0],t=(null==e?void 0:e.name)||"",n=null!==(o=null==e?void 0:e.childCount)&&void 0!==o?o:0;r=Z("delete_folder_permanent",{name:t,count:n})}else r=0===s&&d>0?Z("delete_files_permanent",{count:d}):Z("delete_mixed_permanent",{total:l,folders:s,images:d});return t("div",{children:[e("div",{children:r}),e("p",{className:Da.permanentDeleteWarning,children:Z("permanent_delete_warning")})]})}if(1===l&&1===s){const t=i[0],o=(null==t?void 0:t.name)||"",n=null!==(r=null==t?void 0:t.childCount)&&void 0!==r?r:0;return e("div",{children:Z("move_folder_to_trash",{name:o,count:n})})}return e("div",0===s&&d>0?{children:Z("move_files_to_trash",{count:d})}:{children:Z("move_mixed_to_trash",{total:l,folders:s,images:d})})})()}),t(B,{className:`${Da.deleteModal} deleteModal`,title:e("div",{className:"modal-title",children:Z("Clear Trash")}),open:!!$,onOk:async()=>{de(!0),H&&await H(),de(!1)},onCancel:()=>G&&G(),okText:Z("Delete permanently"),cancelText:Z("Cancel"),okButtonProps:{danger:!0,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1)},closeIcon:e(ce,{className:Da.closeIcon}),centered:!0,getContainer:ne,children:[e("div",{children:Z("Are you sure you want to permanently delete all items from Trash?")}),se&&t("div",{className:Da.clearTrashProgress,children:[e(z,{percent:99,status:"active",showInfo:!1}),e("div",{className:Da.progressText,children:Z("Deleting items...")})]})]})]})};var Va={button:"button",folderActions:"folderActions",uploadButton:"uploadButton",foldersContainer:"foldersContainer",buttonWrapper:"buttonWrapper",uploadButtonTitle:"uploadButtonTitle"};const $a=h(m(({selectedFolder:o,generateMenuItems:r,onFolderSelect:n,folders:l,fetchChildFolders:s,handleAddFile:f,setIsUrlModalVisible:h,handleCreateFolder:m,activeLibraryItem:g,setActiveLibraryItem:v},y)=>{var w,b,C,I;const F=u(()=>Array.isArray(l)?l:[],[l]),{t:A}=dr(),_=On(),[E,x]=i({}),{options:P,state:R}=mn(),{dataProviders:N,config:k}=P,O=R.pathHistory,T=!1!==(null===(w=null==k?void 0:k.features)||void 0===w?void 0:w.enableGif)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("gif")),L=!1!==(null===(b=null==k?void 0:k.features)||void 0===b?void 0:b.enableStockImages)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("stock")),M=!1!==(null===(C=null==k?void 0:k.features)||void 0===C?void 0:C.enableIconStock)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("icons")),U=!1!==(null===(I=null==k?void 0:k.features)||void 0===I?void 0:I.enableQrBarcodeTab)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("codes")),j=d(e=>{const t=[],o=e=>{e.forEach(e=>{t.push(e.key),e.children&&o(e.children)})};return o(e),t},[]),[D,B]=i(()=>{if(!0===(null==k?void 0:k.expandAllFoldersOnInit)&&"lazy"!==(null==k?void 0:k.folderTreeLoading)){const e=r();return j(e)}return!0===(null==k?void 0:k.expandRootFolderOnInit)?["folders"]:[]}),z=c(!1),V=c(!1);a(()=>{if(z.current)return;"lazy"===(null==k?void 0:k.folderTreeLoading)&&!0===(null==k?void 0:k.expandRootFolderOnInit)&&(z.current=!0,(async()=>{try{await(null==s?void 0:s(null))}catch(e){console.warn("Could not load the root child folders during initialization",e)}})())},[null==k?void 0:k.folderTreeLoading,null==k?void 0:k.expandRootFolderOnInit,s]),a(()=>{!0===(null==k?void 0:k.expandRootFolderOnInit)&&Array.isArray(F)&&F.length>0&&(V.current||D&&0!==D.length||(V.current=!0,B(["folders"])))},[null==k?void 0:k.expandRootFolderOnInit,F,D]),a(()=>{if(!0===(null==k?void 0:k.expandAllFoldersOnInit)&&"lazy"!==(null==k?void 0:k.folderTreeLoading)){const e=r(),t=j(e);return void B(t)}!0===(null==k?void 0:k.expandRootFolderOnInit)&&B(e=>e&&e.length>0?[...e]:["folders"])},[F,r,j,null==k?void 0:k.expandAllFoldersOnInit,null==k?void 0:k.folderTreeLoading,null==k?void 0:k.expandRootFolderOnInit]);const $=null==k?void 0:k.disablePagination,H=d(async e=>{var t,o,r,n;try{if(null==N?void 0:N.getChildrenCount)return await N.getChildrenCount("folders"===e?void 0:e);if(null==N?void 0:N.getFiles){const{files:o,pagination:r}=await N.getFiles({folderId:"folders"===e?void 0:e,itemType:"all",page:$?void 0:1,limit:$?void 0:1});return $?Array.isArray(o)?o.length:0:null!==(t=null==r?void 0:r.total)&&void 0!==t?t:Array.isArray(o)?o.length:0}return 0}catch(t){if("StaleLoad"===(null==t?void 0:t.name))return 0;const i=t;if(404===(null==i?void 0:i.status)||"FileNotFound"===(null==i?void 0:i.code)||"path_folder_not_found"===(null==i?void 0:i.code)||"path_folder_not_found"===(null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.code)||404===(null===(n=null===(r=null==i?void 0:i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status))return 0;console.error(`Error getting the number of files for the folder ${e}:`,t);const a=await fi({folderId:e,dataProviders:N,folders:F,pathHistory:O,t:A});return _.error({id:"FOLDER_CHILDREN_COUNT_FAILED",message:A("Failed to load folder items count in folder",{folderName:a}),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{folderId:"folders"===e?null:e,folderName:a,reason:t instanceof Error?t.message:String(t)}}),null}},[N,$,_,O,F,A]),G=d(async()=>{if(0===F.length)return;const e={};e.folders=await H("folders");const t=F.map(async t=>{"number"!=typeof t.childCount?e[t.id]=await H(t.id):e[t.id]=t.childCount});await Promise.all(t),x(e)},[F,H]),K=d(async e=>{const t=await H(e);x(o=>Object.assign(Object.assign({},o),{[e]:t}))},[H]);p(y,()=>({refreshFileCounts:G}),[G]),a(()=>{G()},[G]),a(()=>{if(!o||"folders"===o)return;const e=(t,o=new Set)=>{if(o.has(t))return console.warn(`Cycle detected in the path to the folder with id=${t}`),[];const r=F.find(e=>e.id===t);if(!r)return[];if(!r.parentId)return[];const n=new Set(o);n.add(t);return[...e(r.parentId,n),r.parentId]},t=e(o);t.length>0?B(e=>{const o=new Set(e);return t.forEach(e=>o.add(e)),o.add("folders"),Array.from(o)}):B(e=>e.includes("folders")?e:[...e,"folders"])},[o,F]);const Q=d(async()=>{await f(),o?await K(o):await K("folders")},[f,o,K]),J=[{key:at,label:A("My files"),icon:e(Ue,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth})},{key:lt,label:A("GIF"),icon:e(je,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!T},{key:st,label:A("Stock images"),icon:e(De,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!L},{key:dt,label:A("Icons"),icon:e(ue,{size:20}),disabled:!M},{key:ut,label:A("QR & Barcode"),icon:e(Be,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!U},{key:ct,label:A("AI"),icon:e(ze,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!(null==k?void 0:k.sseQuery)}].filter(e=>!e.disabled),Y=d(async e=>{const t=e[0];t&&"empty"!==t&&(g!==at&&v(at),null==n||n(t),await(null==s?void 0:s(t)))},[n,g,v,s]),Z=d(({key:e})=>{v(e)},[v]),X=d(async(e,t)=>{var o;B(e);if(!("lazy"===(null==k?void 0:k.folderTreeLoading)))return;const r=(null===(o=null==t?void 0:t.node)||void 0===o?void 0:o.key)||void 0;if(r&&"folders"!==r)try{await(null==s?void 0:s(r))}catch(e){console.warn("Could not load the child folders for",r,e);const t=await fi({folderId:r,dataProviders:N,folders:F,pathHistory:O,t:A});_.error({id:"FOLDER_CHILDREN_FETCH_FAILED",message:A("Failed to load subfolders in folder",{folderName:t}),placement:"bottomRight",innerException:e,notificationDedupe:!0,data:{folderId:r,folderName:t,reason:e instanceof Error?e.message:String(e)}})}},[null==k?void 0:k.folderTreeLoading,N,s,_,O,F,A]);return t("div",{className:"sidebar-container",children:[t("div",{className:Va.buttonWrapper,children:[e(S,{type:"primary",size:"large",icon:e(qe,{size:24,strokeWidth:null==k?void 0:k.iconStrokeWidth}),onClick:Q,className:Va.uploadButton,style:{whiteSpace:"nowrap"},disabled:"Trash"===o,children:e("span",{className:Va.uploadButtonTitle,children:A("Upload file")})}),e(S,{type:"primary",size:"large",icon:e(We,{size:24,strokeWidth:null==k?void 0:k.iconStrokeWidth}),onClick:()=>null==h?void 0:h(!0),className:Va.uploadByURLButton,style:{whiteSpace:"nowrap"},disabled:"Trash"===o})]}),e(q,{className:"folder-menu",items:J,defaultSelectedKeys:[at],onSelect:({key:e})=>Z({key:e}),selectedKeys:[g]}),e(W,{className:Va.divider}),t("div",{className:Va.foldersContainer,children:[e(Ua,{selectedFolder:o,onSelect:Y,onExpand:X,generateMenuItems:r,fetchChildFolders:s,showFileCounts:!0,folderFileCounts:E,expandedKeys:D,setExpandedKeys:B,showTrashFolder:null==k?void 0:k.enableTrashFolder}),e("div",{className:Va.folderActions,children:e(S,{onClick:e=>{e.stopPropagation(),m()},className:Va.button,icon:e(Ae,{size:18,strokeWidth:null==k?void 0:k.iconStrokeWidth}),size:"middle"})})]})]})}));function Ha(e){if(!this.backgroundColor)return;const t=this._getNonTransformedDimensions(),o=-t.x/2,r=-t.y/2,n=t.x,i=t.y,a=this.backgroundColor;if("string"==typeof a||a instanceof CanvasGradient||a instanceof CanvasPattern)e.fillStyle=a,e.fillRect(o,r,n,i);else if("object"!=typeof a||!("type"in a)||"linear"!==a.type&&"radial"!==a.type){if("source"in a&&(a.source instanceof HTMLImageElement||a.source instanceof HTMLCanvasElement))if(a.repeat){const t=e.createPattern(a.source,a.repeat);t&&(e.fillStyle=t,e.fillRect(o,r,n,i))}else e.drawImage(a.source,o,r,n,i)}else{const t=function(e,t,o,r){var n,i;if("linear"===t.type){const n=e.createLinearGradient(o+t.coords.x1,r+t.coords.y1,o+t.coords.x2,r+t.coords.y2);return t.colorStops.forEach(e=>n.addColorStop(e.offset,e.color)),n}if("radial"===t.type){const a=e.createRadialGradient(o+t.coords.x1,r+t.coords.y1,null!==(n=t.coords.r1)&&void 0!==n?n:0,o+t.coords.x2,r+t.coords.y2,null!==(i=t.coords.r2)&&void 0!==i?i:0);return t.colorStops.forEach(e=>a.addColorStop(e.offset,e.color)),a}throw new Error("Unknown gradient type")}(e,a,o,r);e.fillStyle=t,e.fillRect(o,r,n,i)}this._removeShadow(e)}$a.displayName="FolderSidebar";const Ga="fm-pixie-editor";const Ka=new class{constructor(){this._container=document.createElement("div"),this._instance=null,this._container.classList.add(Ga),this._container.style.width="100%",this._container.style.height="85vh",this._container.style.minHeight="400px"}get className(){return`.${Ga}`}get canvas(){var e,t;return null===(t=null===(e=this._instance)||void 0===e?void 0:e.state.canvasRef)||void 0===t?void 0:t.current}get tools(){var e;return null===(e=this._instance)||void 0===e?void 0:e.tools}isLoaded(){return!!this._instance}async _setConfig(e){var t;this._instance?await this._instance.resetEditor(e):this._instance=await He.init(Object.assign(Object.assign({},e),{selector:this.className})),(t=this._instance).fabric?t.fabric.on("object:added",e=>{const t=e.target;t&&"text"===t.name&&(t._renderBackground=Ha)}):console.warn("Pixie fabric instance is not available")}async show(e,t,o=t.firstChild){t.insertBefore(this._container,o),await this._setConfig(e),this._instance.open()}close(){var e;null===(e=this._container.parentNode)||void 0===e||e.removeChild(this._container)}};function Qa(e,t){if(!e)return t;if(!t)return e;return`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`}function Ja(e){const t="undefined"!=typeof __webpack_public_path__?__webpack_public_path__:"";if(e&&/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(e))return e;let o=Qa(t,e||"");return!o||o.startsWith("/")||/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(o)||(o="/"+o),o}function Ya(e,t){if(/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(t))return t;const o=Qa(Ja(e),t||"");return!o||o.startsWith("/")||/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(o)?o:"/"+o}var Za,Xa;!function(e){e.TOP="top",e.BOTTOM="bottom",e.HIDDEN=""}(Za||(Za={})),function(e){e.TOP="top",e.BOTTOM="bottom",e.HIDDEN=""}(Xa||(Xa={}));const el=(e,t="image/png")=>fetch(`data:${t};base64,${e}`).then(e=>e.blob());function tl(e){return new Promise((t,o)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>{var e;return o(null!==(e=r.error)&&void 0!==e?e:new Error("Failed to convert blob to data URL"))},r.readAsDataURL(e)})}const ol=({visible:o,onClose:r,file:i,onSave:a,onSaveCopy:l})=>{var s;const{t:d}=dr(),c=n.useRef(null),u=On(),f=Ai(),{options:h,actions:m}=mn(),{i18n:p}=dr(),{config:g}=h,{setCurrentMenuFile:v}=m,{getFileData:y,resolveFileForEditByUrl:w}=f,[b,C]=n.useState(!1),[I,F]=n.useState(null),[A,_]=n.useState(""),[E,x]=n.useState(!1),[P,R]=n.useState(!1),[N,k]=n.useState(null),O=n.useRef(!1),T=n.useRef(),L=n.useRef(),M=n.useRef("saveCopy"),U=n.useRef(void 0);T.current=a,L.current=l,n.useEffect(()=>{i&&!O.current&&(async()=>{if(U.current!==i)if("object"!=typeof i){U.current=i,C(!0);try{if(i.startsWith("data:"))k({thumbnail:i,saveWithoutFolder:!0});else{const e=await w(i);U.current===i&&k(e)}}catch(e){console.error("Failed to load file for editor:",e),U.current===i&&(U.current=null),null==r||r()}finally{C(!1)}}else k(i)})()},[i,r,w]);const j=n.useCallback(async e=>{try{if("string"==typeof e.thumbnail&&e.thumbnail.startsWith("data:"))return e.thumbnail;const t=await y(e.id,!0);if(!t)throw new Error(d("Error loading image"));return new Promise(e=>{const o=new FileReader;o.onload=()=>e(o.result),o.readAsDataURL(t)})}catch(e){throw console.error("Error getting the image data:",e),e}},[y,d]);n.useEffect(()=>{if(!I&&o&&N){let e=!1;const t=async()=>{var t,o,n;C(!0);try{const t=await j(N);if(!t||"string"!=typeof t||""===t.trim())throw new Error("Invalid image data: empty or null");if(!t.startsWith("data:"))throw new Error("Invalid image data: not a valid data URL");const o=t.match(/^data:([^;]+);base64,(.+)$/);if(!o)throw new Error("Invalid image data: malformed data URL format");const[,r,n]=o;if(!r.startsWith("image/"))throw new Error(`Invalid image data: unsupported MIME type ${r}`);if(n.length<10)throw new Error("Invalid image data: base64 content too short");if(!/^[A-Za-z0-9+/]+=*$/.test(n))throw new Error("Invalid image data: corrupted base64 content");if(!e){F(t);const e=ei(N,"image/png");_(e.mimeType)}}catch(i){e||(u.error({id:"IMAGE_DOWNLOAD_FAILED",innerException:i,message:d("Error loading image"),placement:"bottomRight",data:{itemId:null!==(t=null==N?void 0:N.id)&&void 0!==t?t:void 0,itemName:null!==(o=null==N?void 0:N.name)&&void 0!==o?o:void 0,folderId:null!==(n=null==N?void 0:N.folderId)&&void 0!==n?n:null,thumbnail:null==N?void 0:N.thumbnail}}),null==r||r())}finally{C(!1)}};return t(),()=>{e=!0}}},[N,j,I,r,d,o]);const D=n.useCallback(async(e,t,o)=>{var r;let n=await function(e,t){if("json"===e)return new Blob([t],{type:"application/json"});if("svg"===e)return new Blob([t],{type:"image/svg+xml"});let o=`image/${e}`;if(t.startsWith("data:")){const e=kt(t);e&&e.startsWith("image/")&&(o=e);const r=t.replace(/data:image\/[^;]+;base64,/,"");return el(r,Nt(o))}return el(t,Nt(o))}(o,e),i=Nt(n.type||`image/${o}`);const a=null!==(r=null==g?void 0:g.compessorUrl)&&void 0!==r?r:null==g?void 0:g.compressorUrl;if(i.startsWith("image/"))try{const e=new File([n],t,{type:i}),o=await ui(e,{maxSizeMB:null==g?void 0:g.compressMaxSize,maxWidthOrHeight:null==g?void 0:g.compressMaxWidthOrHeight,mimeType:i,fileName:t,libURL:a,enableCompression:Boolean(g)&&"image/gif"!==i});n=o,i=o.type}catch(e){console.warn("Image preparation failed, using original:",e)}return{blob:n,mimeType:i,thumbnailDataUrl:await tl(n)}},[g]),z=n.useCallback(async(e,t,o,r)=>{var n,i,a,l,s,c;const f="save"===r?T.current:L.current;if(!N||!f)return;const h="object"==typeof N&&null!==N?N:null;let m=null;try{C(!0);const{blob:i,mimeType:a,thumbnailDataUrl:l}=await D(e,t,o),s=Object.assign(Object.assign({},N),{thumbnail:l,size:i.size,date:(new Date).toISOString().split("T")[0],type:a,folderId:N.folderId||"",name:N.name||t,extension:N.extension||(null===(n=(N.name||t).split(".").pop())||void 0===n?void 0:n.toLowerCase())||""});m=s;const c={blob:i,mimeType:a,thumbnail:l,mode:r},u=await f(s,c);if(u)return C(!1),u;throw new Error(d("saveCopy"===r?"Failed to save image copy":"Failed to save changes"))}catch(e){console.error("Error saving:",e);const o=null!=m?m:h,n=e;if(!(null==n?void 0:n.notificationShown)){const n=Dn(e),f=null!==(a=null!==(i=Un(null==n?void 0:n.code,d))&&void 0!==i?i:null==n?void 0:n.message)&&void 0!==a?a:d("saveCopy"===r?"Failed to save image copy":"Error saving image");u.error({id:"saveCopy"===r?"IMAGE_SAVE_COPY_FAILED":"IMAGE_SAVE_FAILED",message:f,placement:"bottomRight",data:{itemId:null!==(l=null==o?void 0:o.id)&&void 0!==l?l:void 0,itemName:null!==(s=null==o?void 0:o.name)&&void 0!==s?s:t,folderId:null!==(c=null==o?void 0:o.folderId)&&void 0!==c?c:null,thumbnail:null==o?void 0:o.thumbnail},innerException:e})}C(!1)}},[N,u,D,d]),q=n.useCallback(async e=>{var t;if(!Ka.isLoaded()||!N)return void console.error("❌ Pixie instance or file is missing");M.current=e;const o=N.name||"edited-image",r=ei(N,A);try{await(null===(t=Ka.tools)||void 0===t?void 0:t.export.save(o.replace(/\.[^/.]+$/,""),r.pixieFormat,ti.QUALITY))}catch(t){console.error("🎨 Error saving through the button:",t);try{const t=Ka.canvas,n=t?t.toDataURL(r.mimeType):null;n&&await z(n,o,r.extension,e)}catch(e){console.error("🎨 Alternative method also did not work:",e)}}},[N,A,z]),W=n.useCallback(async()=>{var t;if(I&&o&&E&&!O.current)try{O.current=!0;const o=c.current;let n=0;for(;n<20&&(0===o.clientWidth||0===o.clientHeight);)await new Promise(e=>setTimeout(e,50)),n++;const i=(null==g?void 0:g.locale)?null==g?void 0:g.locale.replace("_","-"):"en",a=matchMedia(vt).matches?pt:mt,l=(null==g?void 0:g.theme)===gt?a:null==g?void 0:g.theme,s=((null==g?void 0:g.locale)||p.language||"en").split("-")[0].split("_")[0],d=(p.getResourceBundle(s,"translation")||{}).pixie||{},u=e=>e.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "),f={};Object.entries(d).forEach(([e,t])=>{const o=u(e);f[o]=t,f[e]=t});const h={[i]:f},m=ei(N,A),v={selector:"#pixie-editor",baseUrl:Ya((null==g?void 0:g.baseUrl)||"",(null==g?void 0:g.assetsUrl)||"assets/image-editor"),image:I,activeLanguage:i,languages:h,ui:{activeTheme:l,mode:"inline",forceOverlayModeOnMobile:!1,visible:!0,menubar:{replaceDefaultItems:!0,position:Za.TOP,items:[{type:"undoWidget",align:"left"},{type:"zoomWidget",align:"center",desktopOnly:!0},{type:"button",align:"right",desktopOnly:!0,icon:()=>e(fe,{style:{fontSize:20}}),action:e=>{e.togglePanel("history")}},{type:"button",icon:()=>e(ce,{style:{fontSize:20}}),align:"right",desktopOnly:!0,action:r}]},nav:{position:Xa.TOP}},tools:{export:{defaultFormat:m.pixieFormat,defaultQuality:ti.QUALITY,defaultName:(null===(t=null==N?void 0:N.name)||void 0===t?void 0:t.replace(/\.[^/.]+$/,""))||"image"},text:{replaceDefaultItems:!0,defaultText:"Handwriting",items:[{family:"Inter",src:"fonts/inter-v20-cyrillic_latin-regular.woff2"},{family:"Commissioner",src:"fonts/commissioner-v24-cyrillic_latin-regular.woff2"},{family:"Montserrat Light",src:"fonts/Montserrat-Light.woff2"},{family:"Montserrat Regular",src:"fonts/Montserrat-Regular.woff2"},{family:"Montserrat Bold",src:"fonts/Montserrat-Bold.woff2"},{family:"Montserrat Black",src:"fonts/Montserrat-Black.woff2"},{family:"Roboto Light",src:"fonts/Roboto-Light.woff2"},{family:"Roboto Regular",src:"fonts/Roboto-Regular.woff2"},{family:"Roboto Bold",src:"fonts/Roboto-Bold.woff2"},{family:"Roboto Black",src:"fonts/Roboto-Black.woff2"},{family:"Lato Light",src:"fonts/Lato-Light.woff2"},{family:"Lato Regular",src:"fonts/Lato-Regular.woff2"},{family:"Lato Bold",src:"fonts/Lato-Bold.woff2"},{family:"Lato Black",src:"fonts/Lato-Black.woff2"},{family:"Rubik Light",src:"fonts/Rubik-Light.woff2"},{family:"Rubik Regular",src:"fonts/Rubik-Regular.woff2"},{family:"Rubik Bold",src:"fonts/Rubik-Bold.woff2"},{family:"Rubik Black",src:"fonts/Rubik-Black.woff2"},{family:"Bebas Neue Light",src:"fonts/BebasNeueLight.woff2"},{family:"Bebas Neue Regular",src:"fonts/BebasNeueRegular.woff2"},{family:"Bebas Neue Book",src:"fonts/BebasNeueBook.woff2"},{family:"Bebas Neue Bold",src:"fonts/BebasNeueBold.woff2"},{family:"Fira Sans",src:"fonts/fira-sans-v11-latin-ext_latin_cyrillic-regular.woff2"},{family:"Lobster",src:"fonts/Lobster.woff2"},{family:"Pacifico",src:"fonts/pacifico-v23-cyrillic_latin-regular.woff2"},{family:"Playfair Display",src:"fonts/playfair-display-v40-cyrillic_latin-regular.woff2"},{family:"Oswald",src:"fonts/oswald-v57-cyrillic_latin-regular.woff2"},{family:"Caveat",src:"fonts/caveat-v23-cyrillic_latin-regular.woff2"}]}},onSave:async function(e,t,o){try{C(!0);return await z(e,t,o,M.current)}catch(e){throw console.error("🎨 PIXIE onSave ERROR:",e),C(!1),e}}};try{R(!1),await Ka.show(v,c.current);const e=Ka.canvas;e&&e.focus(),R(!0),C(!1)}catch(e){console.error("init pixie failed:",e)}}catch(e){console.error("Error initializing Pixie:",e),u.error({id:"EDITOR_INIT_FAILED",message:d("Error initializing editor"),placement:"bottomRight",innerException:e}),O.current=!1,null==r||r()}},[N,A,I,o,E,null==g?void 0:g.locale,null==g?void 0:g.theme,null==g?void 0:g.baseUrl,null==g?void 0:g.assetsUrl,r,z,u,p,d]);n.useEffect(()=>{o&&I&&E&&W()},[o,I,E,W]),n.useEffect(()=>{if(!o){try{Ka.close()}catch(e){console.warn("Error closing Pixie:",e)}C(!1),F(null),_(""),O.current=!1,x(!1),R(!1)}return()=>{try{Ka.close()}catch(e){console.warn("Error closing Pixie when unmounting:",e)}}},[o]);const V=Boolean(null==N?void 0:N.id)&&!1!==(null===(s=null==g?void 0:g.features)||void 0===s?void 0:s.enableUpdateFile);return e(B,{title:(null==N?void 0:N.name)?d("Editing: {{name}}",{name:N.name}):d("Editing image"),open:o,closeIcon:null,onCancel:r,afterOpenChange:e=>x(e),forceRender:!0,width:"100vw",getContainer:h.getModalContainer,style:{top:0,height:"100vh",maxWidth:"none",padding:10},styles:{body:{height:"85vh",padding:0}},footer:[e(S,{onClick:r,disabled:!E||b,children:d("Cancel")},"cancel"),e(S,{type:"primary",onClick:()=>q("saveCopy"),loading:b,children:d("Save as copy and choose")},"save-copy"),...V?[e(S,{type:"primary",onClick:()=>q("save"),loading:b,children:d("Save and choose")},"save")]:[]],mask:{closable:!1},destroyOnHidden:!1,afterClose:()=>{v&&v("")},children:t("div",{ref:c,style:{position:"relative",width:"100%",height:"100%"},children:[o&&!P?e("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(255,255,255,0.45)",backdropFilter:"blur(1px)",pointerEvents:"all",zIndex:10},children:e("span",{style:{fontSize:14,color:"#555"},children:d("Loading editor...")})}):null,b&&P&&e(ja,{style:{position:"absolute",top:0,background:"var(--colorBgLayout)",zIndex:100,opacity:.7}})]})})};var rl="uploadProgress",nl="uploadProgress__card",il="uploadProgress__header",al="uploadProgress__header-title",ll="uploadProgress__header-buttons",sl="uploadProgress__header-button",dl="uploadProgress__close-icon",cl="uploadProgress__body",ul="uploadProgress__common-error",fl="uploadProgress__common-error-row",hl="uploadProgress__common-error-hint",ml="uploadProgress__list-wrapper",pl="uploadProgress__status-icon",gl="uploadProgress__file-item",vl="uploadProgress__file-item--error",yl="uploadProgress__body--error",wl="uploadProgress__error-item",bl="uploadProgress__error-message",Cl="uploadProgress__error-hint",Il="uploadProgress__file-avatar",Fl="uploadProgress__file-info",Al="uploadProgress__file-name",_l="uploadProgress__file-size",Sl="uploadProgress__progress-bar",El="uploadProgress__minimized",xl="uploadProgress__minimized-button",Pl="uploadProgress__file-list";const{Text:Rl}=F,Nl=({visible:o,files:r,totalFiles:n,completedFiles:i,onClose:a,onMinimize:l,onInsert:s,minimized:d=!1})=>{var c;const{token:u}=y.useToken(),{t:f}=dr();if(!o)return null;const h=t=>{switch(t){case"success":return e("div",{className:pl,children:e(pe,{style:{color:u.colorSuccess}})});case"error":return e(he,{style:{color:u.colorError}});default:return e(me,{style:{color:"#1890ff"}})}},m=t=>"success"===t.status?[e(S,{type:"primary",size:"small",onClick:()=>s(t),children:f("Insert")},"insert")]:[];if(d)return e("div",{className:El,children:e(S,{type:"primary",size:"small",onClick:l,className:xl,children:f("Upload progress",{completed:i,total:n})})});const p=r.filter(e=>"uploading"===e.status).length,g=r.filter(e=>"success"===e.status).length,v=r.filter(e=>"error"===e.status).length,w=r.filter(e=>"error"===e.status),b=w.length>1&&w.every(e=>{var t;return e.error&&e.error===(null===(t=w[0])||void 0===t?void 0:t.error)}),C=b?null===(c=w[0])||void 0===c?void 0:c.error:null;return e("div",{className:rl+" fm-upload-progress",children:t("div",{className:nl,children:[t("div",{className:il,children:[e(Rl,{strong:!0,className:al,children:p>0?f("Uploading files",{completed:i,total:n}):g>0?f("Uploaded files",{success:g,total:n}):f("Upload error files",{errorCount:v})}),e("div",{className:ll,children:e(S,{type:"text",size:"small",icon:e(ce,{className:dl}),onClick:a,className:sl})})]}),t("div",{className:`${cl} ${r.some(e=>"error"===e.status)?yl:""}`,children:[e("div",{className:ml,children:e(V,{className:Pl,size:"small",dataSource:r,renderItem:o=>{const r="error"===o.status,n=r?(e=>{if(!e)return null;const t=e.toLowerCase();return t.includes("type")||t.includes("format")||t.includes("формат")||t.includes("тип")||t.includes("not allowed")||t.includes("дозволен")||t.includes("name")||t.includes("invalid")||t.includes("назва")||t.includes("неприпустим")||t.includes("allowed characters")?null:t.includes("large")||t.includes("size")||t.includes("розмір")||t.includes("размер")?f("upload_error_hint_size"):t.includes("exists")||t.includes("вже існує")||t.includes("уже существует")?f("upload_error_hint_exists"):null})(o.error):null;return e(V.Item,{className:`${gl} ${r?vl:""}`,actions:m(o),children:e(V.Item.Meta,{avatar:e($,{size:"small",icon:h(o.status),className:Il}),title:t("div",{className:Fl,children:[e(Rl,{ellipsis:!0,className:Al,children:o.name}),e(Rl,{type:"secondary",className:_l,children:void 0!==o.size?Or(o.size):""})]}),description:"uploading"===o.status?e(z,{percent:o.progress,size:"small",status:"active",showInfo:!1,className:Sl}):r?b?null:t("div",{className:wl,children:[e(Rl,{type:"danger",className:bl,children:o.error||f("Error")}),n&&e(Rl,{type:"secondary",className:Cl,children:n})]}):null})})}})}),C&&t("div",{className:ul,children:[t("div",{className:fl,children:[e(he,{style:{color:u.colorError,marginRight:8,flexShrink:0}}),e(Rl,{type:"danger",children:C})]}),e(Rl,{type:"secondary",className:hl,children:f("Applies to all {{count}} files",{count:w.length})})]})]})]})})},{Header:kl}=H,{Title:Ol}=F,Tl=({activeLibraryItem:o,selectedFolder:n,isTrashFolder:i,onClearTrash:a,files:l,loading:s,onRefresh:d,refreshDisabled:c,showRefresh:u=!1})=>{const{t:f}=dr(),h=o===at&&(null!=i?i:n===ht),[m,p]=r.useState(!1),g={[at]:f("My files"),[lt]:f("GIF"),[st]:f("Stock images"),[dt]:f("Icons"),[ut]:f("QR & Barcode"),[ct]:f("AI image generation")};let v;return r.useEffect(()=>{const e=setTimeout(()=>{p(h&&l.length>0&&!s)},200);return()=>clearTimeout(e)},[h,l.length,s]),v=o===at?h?f("Trash"):n:g[o],e(kl,{className:"actions-header",children:t("div",{className:"header-title-container",children:[e(Ol,{level:5,className:"header-title",children:v}),m&&a&&e(S,{type:"default",onClick:a,className:"clear-trash-button","aria-label":f("Clear Trash"),children:f("Clear")}),o===at&&u&&d&&e(_,{title:f("Refresh"),children:e(S,{type:"text",className:"folder-refresh-button",icon:e(Ve,{size:16}),onClick:d,disabled:c})})]})})};function Ll(e,t){return!e||!t||e<=0||t<=0?1:e/t}const Ml=1200;function Ul({items:e,getId:t,getPreviewSrc:o,getAltText:r,getWidth:n,getHeight:a,layoutMode:l="masonry",minColumnWidth:s=240,estimatedItemHeight:d=240,gap:c=20,overscanPx:f=800,prefetchThresholdPx:h=1200,resolveColumnCount:m,virtualizationThreshold:p=40}){var g,v;const[y,w]=i({scrollTop:0,viewportHeight:800,viewportWidth:Ml,scrollHeight:0}),b=u(()=>function(e){return{getId:e,buildSignature:(t,o)=>{var r,n;const i=o.getPreviewSrc(t)||"",a=o.getAltText(t),l=null===(r=o.getWidth)||void 0===r?void 0:r.call(o,t),s=null===(n=o.getHeight)||void 0===n?void 0:n.call(o,t);return[e(t),i,a,null!=l?l:"",null!=s?s:""].join("::")},buildRowModel:(e,t,o)=>{var r,n;const i=null===(r=t.getWidth)||void 0===r?void 0:r.call(t,e),a=null===(n=t.getHeight)||void 0===n?void 0:n.call(t,e);return{id:o.id,signature:o.signature,item:e,previewSrc:t.getPreviewSrc(e),altText:t.getAltText(e),width:i,height:a,aspectRatio:Ll(i,a)}}}}(t),[t]),C=u(()=>({getPreviewSrc:o,getAltText:r,getWidth:n,getHeight:a}),[r,a,o,n]),I=u(()=>{const e=Math.max(1,y.viewportWidth||Ml);return m?Math.max(1,m(e)):Math.max(1,Math.floor((e+c)/(s+c)))},[c,s,m,y.viewportWidth]),F=u(()=>{const e=Math.max(1,y.viewportWidth||Ml);return Math.max(1,(e-c*Math.max(0,I-1))/I)},[I,c,y.viewportWidth]),A=u(()=>{const t=new Array(I).fill(0),o=[];e:for(let r=0;r<e.length;r+=1){const i=e[r],s=null==n?void 0:n(i),u=null==a?void 0:a(i),f=s&&u&&s>0&&u>0?s/u:void 0,h=f?F/f:d;if("grid"===l){const e=Math.floor(r/I)*(h+c),t=r%I*(F+c);o.push({index:r,top:e,left:t,width:F,height:h,bottom:e+h});continue e}let m=0;for(let e=1;e<t.length;e+=1)t[e]<t[m]&&(m=e);const p=t[m],g=m*(F+c);t[m]=p+h+c,o.push({index:r,top:p,left:g,width:F,height:h,bottom:p+h})}const r=0===o.length?0:"grid"===l?Math.max(...o.map(e=>e.bottom)):Math.max(0,...t.map(e=>e-c));return{positionedItems:o,containerHeight:r}},[I,F,d,c,a,n,e,l]),_=u(()=>e.length<=p?{renderStrategy:"full"}:{renderStrategy:"positioned",positioned:{layout:A.positionedItems,viewportTop:y.scrollTop,viewportBottom:y.scrollTop+y.viewportHeight,overscanPx:f,containerHeight:A.containerHeight}},[e.length,A.containerHeight,A.positionedItems,f,y.scrollTop,y.viewportHeight,p]),{rowModels:S,renderWindow:E}=Ca({items:e,context:C,adapter:b,options:_}),x=null!==(g=E.positionedItems)&&void 0!==g?g:S.map((e,t)=>{var o;return{row:e,layout:null!==(o=A.positionedItems[t])&&void 0!==o?o:{index:t,top:0,left:0,width:F,height:d,bottom:d}}}),P=null!==(v=E.containerHeight)&&void 0!==v?v:A.containerHeight,R=P>0&&y.scrollTop+y.viewportHeight>=P-h;return{rowModels:S,renderRows:E.rows,renderWindow:E,positionedItems:x,containerHeight:P,isNearEnd:R,viewportMetrics:y,handleViewportChange:e=>{w(t=>t.scrollTop===e.scrollTop&&t.viewportHeight===e.viewportHeight&&t.viewportWidth===e.viewportWidth&&t.scrollHeight===e.scrollHeight?t:e)}}}const jl=t=>{var o,{imageId:r,sourceUrl:n,shouldLoad:l=!0,loader:s,onLoad:d}=t,f=Rn(t,["imageId","sourceUrl","shouldLoad","loader","onLoad"]);const h=Wi(u(()=>[n],[n])),[m,p]=i(()=>s.getSnapshot(r,n)),g=c(null);return a(()=>(p(s.getSnapshot(r,n)),s.subscribe(r,n,p)),[r,s,n]),a(()=>(s.setActive(r,n,l),()=>{s.setActive(r,n,!1),s.release(r)}),[r,s,l,n]),m.shouldLoad&&h.src?e("img",Object.assign({},f,{ref:g,src:h.src,loading:null!==(o=f.loading)&&void 0!==o?o:"lazy",onLoad:e=>{h.handleLoad(),s.markLoaded(r),null==d||d(e)},onError:async e=>{var t;(await h.handleError()).exhausted&&s.markError(r),null===(t=f.onError)||void 0===t||t.call(f,e)}})):null};var Dl={gifTab:"gifTab",scrollableDiv:"scrollableDiv",gifSearchInput:"gifSearchInput",search:"search",searchResults:"searchResults",virtualCanvas:"virtualCanvas",listItem:"listItem",loaded:"loaded",loadedImage:"loadedImage",searchOutputWrapper:"searchOutputWrapper",divider:"divider",resultsContainer:"resultsContainer",playButton:"playButton",title:"title",subtitle:"subtitle"};const Bl=e=>{const t="undefined"!=typeof window?window.innerWidth:e;return t<=700?1:t<=1100?2:t<=1600?3:4},zl=e=>e.images.downsized.url,ql=({setImageGifList:r,imageGifList:n=[],currentReqGif:l,setCurrentReqGif:s,inputRef:u,customRequest:f})=>{const{t:h}=dr(),{GifPlayIcon:m}=gn(),{options:p}=mn(),{config:g}=p,v=Bi({maxConcurrent:6}),[y,w]=i(null),[C,F]=i(new Set),[A,_]=i(!1),[S,E]=i(!1),[x,P]=i(!1),[R]=b.useForm(),N=c(l),k=c(null),O=c(null),T=c(null),L=c(0),M=c(0),j=c(new Set);a(()=>{N.current=l},[l]),a(()=>{R.setFieldsValue({keywords:l.keywords})},[]);const D=null==g?void 0:g.handleProxyUrl,B=null==g?void 0:g.fetchWithProxy,z=async e=>{if(!D)return e;const t=await Promise.resolve(D(e));return null!=t?t:e},q=d(async e=>B?Promise.resolve(B(e,void 0,{intent:"metadata"})):fetch(await z(e)),[B,z]),W=async function({query:e,page:t}){var o;const r=e.keywords.replace(/[^\w\sа-яёА-ЯЁ]|_/g,"").replace(/[\s_-]+/g," ");try{const e=`https://api.giphy.com/v1/gifs/search?api_key=${null!==(o=null==g?void 0:g.REACT_APP_GIPHY_KEY)&&void 0!==o?o:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F"}&q=${encodeURIComponent(r)}&limit=50&offset=${t}&lang=en`,n=await q(e);return{data:await n.json()}}catch(e){console.warn(e)}},{positionedItems:V,containerHeight:$,isNearEnd:H,viewportMetrics:G,handleViewportChange:K}=Ul({items:n,getId:e=>e.id,getPreviewSrc:zl,getAltText:e=>e.title,getWidth:e=>e.images.downsized.width?Number(e.images.downsized.width):void 0,getHeight:e=>e.images.downsized.height?Number(e.images.downsized.height):void 0,layoutMode:"masonry",minColumnWidth:240,estimatedItemHeight:220,prefetchThresholdPx:320,resolveColumnCount:Bl}),Q=Zi(K,[n.length]),J=()=>{k.current&&(clearTimeout(k.current),k.current=null)},Y=e=>!j.current.has(e)&&(j.current.add(e),!0),Z=e=>{j.current.delete(e)},X=d(async()=>{var e,t,o;const n=null===(e=N.current.keywords)||void 0===e?void 0:e.trim();if(!n||A||S||!x)return;const i=`gif:${n}:${M.current}`;if(!Y(i))return;const a=L.current;E(!0);try{const e=await W({query:N.current,page:M.current});if(a!==L.current)return;const n=null!==(o=null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.data)&&void 0!==o?o:[];if(!Array.isArray(n)||0===n.length)return void P(!1);const i=n;if(a!==L.current)return;r(e=>{const t=new Set(e.map(e=>e.id)),o=i.filter(e=>!t.has(e.id));return o.length>0?[...e,...o]:e}),M.current+=n.length,P(50===n.length)}finally{Z(i),a===L.current&&E(!1)}},[x,A,S,r]),ee=async()=>{var e,t;J();const o=null===(e=N.current.keywords)||void 0===e?void 0:e.trim();if(!o)return O.current=null,T.current=null,L.current+=1,M.current=0,r([]),F(new Set),P(!1),void E(!1);if(T.current===o)return;if(O.current===o||A&&O.current===o)return;const n=`gif:${o}:0`;if(!Y(n))return;const i=L.current+1;L.current=i,O.current=o,M.current=0,r([]),F(new Set),P(!1),E(!1),_(!0);try{const e=await W({query:N.current,page:0});if(i!==L.current)return;const n=null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.data;if(Array.isArray(n)&&n.length>0){const e=n;if(i!==L.current)return;r(e),M.current=n.length,P(50===n.length)}else r([]),P(!1);T.current=o}catch(e){P(!1)}finally{Z(n),O.current===o&&(O.current=null),_(!1)}};return a(()=>()=>{J()},[]),a(()=>{!A&&!S&&x&&n.length>0&&H&&X()},[x,n.length,H,X,A,S]),e("div",{className:Dl.gifTab,children:e("div",{className:Dl.searchOutputWrapper,children:t("div",{id:"scrollableDiv",ref:Q,className:Dl.scrollableDiv,children:[t(b,{form:R,onValuesChange:e=>{if(void 0!==e.keywords){const t=Object.assign(Object.assign({},N.current),{keywords:e.keywords});s(t),N.current=t,J(),k.current=setTimeout(ee,800)}},className:n.length>0?Dl.searchResults:Dl.search,children:[e(b.Item,{name:"keywords",className:Dl.gifSearchInput,children:e(I,{onPressEnter:()=>{ee()},allowClear:!0,placeholder:h("Search GIFs"),ref:u,spellCheck:"false",prefix:e(_e,{size:16,strokeWidth:null==g?void 0:g.iconStrokeWidth,onClick:()=>{ee()}})})}),n.length>0&&!A&&e("div",{className:`ant-divider ${Dl.divider}`,role:"separator"})]}),!n.length&&!A&&e(o,{children:l.keywords?e(Cn,{}):t("div",{className:Dl.resultsContainer,children:[e("div",{className:Dl.videoIcon,children:e(m,{className:Dl.playButton})}),e("h1",{className:Dl.title,children:h("Over 350,000 live images")}),e("p",{className:Dl.subtitle,children:h("Enter a search query and we'll find the perfect image for you")})]})}),!n.length&&A&&e(ja,{}),n.length>0&&t(o,{children:[e("div",{className:Dl.virtualCanvas,style:{height:$},children:V.map(({row:o,layout:r})=>{const n=o.item,i=C.has(n.id),a=zl(n),l=r.bottom>=G.scrollTop-240&&r.top<=G.scrollTop+G.viewportHeight+240;return t("div",{className:`${Dl.listItem} ${i?Dl.loaded:""}`,onClick:()=>(async(e,t)=>{var o;w(t),setTimeout(()=>{w(null)},2e3);let r=e.split("?")[0].split("#")[0].split("/"),n=r[r.length-1]||"uploaded-file";n.includes(".")&&(null===(o=n.split(".").pop())||void 0===o?void 0:o.length)&&n.split(".").pop().length<=5||(n+=".gif"),f(e,n)})(n.images.downsized.url,n.id,n.title),style:{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height,minHeight:r.height,maxHeight:"none",marginBottom:0},children:[e(jl,{imageId:n.id,sourceUrl:a,shouldLoad:l,loader:v,className:y===n.id?Dl.loadedImage:"",width:"100%",height:"100%",alt:n.title,decoding:"async",onLoad:()=>{F(e=>{if(e.has(n.id))return e;const t=new Set(e);return t.add(n.id),t})}}),e("a",{rel:"noreferrer",href:"https://giphy.com/",target:"_blank",onClick:e=>e.stopPropagation()}),y===n.id&&e(U,{className:Dl.antSpin})]},n.id)})}),S&&e(ja,{})]})]})})})};var Wl={stockTab:"stockTab",stockSearchInput:"stockSearchInput",searchOutputWrapper:"searchOutputWrapper",divider:"divider",search:"search",searchResults:"searchResults",virtualCanvas:"virtualCanvas",scrollableDiv:"scrollableDiv",listItem:"listItem",loaded:"loaded",loadedImage:"loadedImage",creatorInfo:"creatorInfo",stockColorFilter:"stockColorFilter",allColors:"allColors",blackColor:"blackColor",bwColor:"bwColor",whiteColor:"whiteColor",orangeColor:"orangeColor",redColor:"redColor",purpleColor:"purpleColor",magentaColor:"magentaColor",greenColor:"greenColor",tealColor:"tealColor",blueColor:"blueColor",resultsContainer:"resultsContainer",playButton:"playButton",title:"title",subtitle:"subtitle"};const Vl=e=>{const t="undefined"!=typeof window?window.innerWidth:e;return t<=650?1:t<=1e3?2:t<=1450?3:4},$l=(e,t)=>{const o=new URL(e);return o.searchParams.set("w",t.toString()),o.toString()},Hl=({imageStockList:r,setImageStockList:n,currentReq:l,setCurrentReq:s,inputRef:u,customRequest:f})=>{var h,m;const{t:p}=dr(),{StockBigIcon:g,MixedViewIcon:v,LandscapeViewIcon:y,PortraitViewIcon:w,SquareViewIcon:C}=gn(),{options:F}=mn(),{config:A}=F,S=Bi({maxConcurrent:6}),[E,x]=i(!1),[P,R]=i(!1),[N,O]=i(!1),[L,M]=i(null),[j,D]=i(new Set),[B]=b.useForm(),z=null==A?void 0:A.fetchWithProxy,q=null==A?void 0:A.handleProxyUrl,W=null!==(h=null==A?void 0:A.UNSPLASH_KEY)&&void 0!==h?h:"HX2_qqq3F3ljmtYtfmb9P6h0dn2u9mnnOl36IdV8el0",V=(null===(m=null==A?void 0:A.locale)||void 0===m?void 0:m.slice(0,2))||"ru",$=c(l),H=c(null),K=c(null),Q=c(0),J=c(1),Y=c(new Set),Z=async e=>{if(!q)return e;const t=await Promise.resolve(q(e));return null!=t?t:e},X=d(async e=>z?Promise.resolve(z(e,void 0,{intent:"metadata"})):fetch(await Z(e)),[z,Z]),ee=()=>{H.current&&(clearTimeout(H.current),H.current=null)},te=e=>!Y.current.has(e)&&(Y.current.add(e),!0),oe=e=>{Y.current.delete(e)},re=e=>e.map(e=>Object.assign(Object.assign({},e),{urls:{raw:$l(e.urls.raw,1200),small:$l(e.urls.raw,540)}}));a(()=>{$.current=l},[l]),a(()=>{0===r.length&&B.setFieldsValue({color:"",orientation:""})},[r,B]),a(()=>{B.setFieldsValue({keywords:l.keywords,color:l.color,orientation:l.orientation})},[]);const ne=async function({query:e,page:t}){const o=e.keywords.replace(/[^\w\sа-яёА-ЯЁ]|_/g,"").replace(/[\s_-]+/g," ");try{let r=`https://api.unsplash.com/search/photos?client_id=${W}&lang=${V}&per_page=30&query=${encodeURIComponent(o)}&page=${t}`;""!==e.color&&(r+=`&color=${e.color}`),""!==e.orientation&&(r+=`&orientation=${e.orientation}`);const n=await X(r);return{data:await n.json()}}catch(e){console.warn(e)}},{positionedItems:ie,containerHeight:ae,isNearEnd:le,viewportMetrics:se,handleViewportChange:de}=Ul({items:r,getId:e=>e.id,getPreviewSrc:e=>e.urls.small,getAltText:e=>e.description||e.user.name,getWidth:e=>e.width,getHeight:e=>e.height,layoutMode:"masonry",minColumnWidth:240,estimatedItemHeight:220,prefetchThresholdPx:320,resolveColumnCount:Vl}),ce=Zi(de,[r.length]),ue=d(async()=>{var e,t;if(E||P||!N||!$.current.keywords.trim())return;const o=Q.current,r=J.current,i=`stock:${`${$.current.keywords.trim()}|${$.current.color}|${$.current.orientation}`}:${r}`;if(te(i)){R(!0);try{const i=await ne({query:$.current,page:r});if(o!==Q.current)return;const a=null!==(t=null===(e=null==i?void 0:i.data)||void 0===e?void 0:e.results)&&void 0!==t?t:[];if(0===a.length)return void O(!1);const l=re(a);if(o!==Q.current)return;n(e=>{const t=new Set(e.map(e=>e.id)),o=l.filter(e=>!t.has(e.id));return o.length>0?[...e,...o]:e}),J.current=r+1,O(30===a.length)}finally{oe(i),o===Q.current&&R(!1)}}},[N,E,P,n]),fe=async()=>{var e,t;ee();const o=`${$.current.keywords.trim()}|${$.current.color}|${$.current.orientation}`;if(!$.current.keywords.trim())return void(K.current=null);if(K.current===o)return;const r=`stock:${o}:1`;if(!te(r))return;const i=Q.current+1;Q.current=i,x(!0),R(!1),O(!1),J.current=1,n([]),D(new Set);try{const r=await ne({query:$.current,page:1});if(i!==Q.current)return;const a=null!==(t=null===(e=null==r?void 0:r.data)||void 0===e?void 0:e.results)&&void 0!==t?t:[];if(a.length>0){const e=re(a);if(i!==Q.current)return;n(e),J.current=2,O(30===a.length)}else O(!1);K.current=o}finally{oe(r),x(!1)}};a(()=>()=>{ee()},[]),a(()=>{!E&&!P&&N&&r.length>0&&le&&ue()},[N,r.length,le,ue,E,P]);const he=async(e,t,o,r)=>{var n;!async function(e){try{const t=`${e}${e.includes("?")?"&":"?"}client_id=${W}`,o=await X(t);return{data:await o.json()}}catch(e){console.warn(e)}}(t.download_location),M(o),setTimeout(()=>M(null),2e3);const i=e.raw,a=i.split("?")[0].split("#")[0].split("/");let l=a[a.length-1]||"uploaded-file";l.includes(".")&&(null===(n=l.split(".").pop())||void 0===n?void 0:n.length)&&l.split(".").pop().length<=5||(l+=".jpg"),f(i,l)};return e("div",{className:Wl.stockTab,children:e("div",{className:Wl.searchOutputWrapper,children:t("div",{className:Wl.scrollableDiv,id:"scrollableDiv",ref:ce,children:[t(b,{form:B,initialValues:It,onValuesChange:(e,t)=>{const o=Object.assign(Object.assign({},It),t);s(o),$.current=o,ee(),""!==o.keywords?H.current=setTimeout(fe,800):(K.current=null,Q.current+=1,J.current=1,n([]),D(new Set),O(!1),R(!1),s(Object.assign({},It)),$.current=It,B.resetFields())},className:r.length>0?Wl.searchResults:Wl.search,children:[t(T,{gutter:24,children:[e(k,{span:r.length>0?void 0:24,children:e(b.Item,{name:"keywords",className:Wl.stockSearchInput,children:e(I,{allowClear:!0,placeholder:p("Search image"),ref:u,spellCheck:"false",prefix:e(_e,{size:16,strokeWidth:null==A?void 0:A.iconStrokeWidth})})})}),!!r.length&&t(o,{children:[e(k,{children:e(b.Item,{name:"orientation",children:t(G.Group,{onChange:e=>s(t=>Object.assign(Object.assign({},t),{orientation:e.target.value})),children:[e(_,{title:p("All"),placement:"top",children:e(G.Button,{value:"",children:e(v,{})})}),e(_,{title:p("Landscape"),placement:"top",children:e(G.Button,{value:"landscape",children:e(y,{})})}),e(_,{title:p("Portrait"),placement:"top",children:e(G.Button,{value:"portrait",children:e(w,{})})}),e(_,{title:p("Squarish"),placement:"top",children:e(G.Button,{value:"squarish",children:e(C,{})})})]})})}),e(k,{children:e(b.Item,{name:"color",children:t(G.Group,{className:Wl.stockColorFilter,onChange:e=>s(t=>Object.assign(Object.assign({},t),{color:e.target.value})),children:[e(_,{title:p("All"),placement:"top",children:e(G.Button,{className:Wl.allColors,value:"",children:"All"})}),e(_,{title:p("Black"),placement:"top",children:e(G.Button,{className:Wl.blackColor,value:"black",children:"B"})}),e(_,{title:p("Black and White"),placement:"top",children:e(G.Button,{className:Wl.bwColor,value:"black_and_white",children:"B&W"})}),e(_,{title:p("White"),placement:"top",children:e(G.Button,{className:Wl.whiteColor,value:"white",children:"W"})}),e(_,{title:p("Orange"),placement:"top",children:e(G.Button,{className:Wl.orangeColor,value:"orange",children:"O"})}),e(_,{title:p("Red"),placement:"top",children:e(G.Button,{className:Wl.redColor,value:"red",children:"R"})}),e(_,{title:p("Purple"),placement:"top",children:e(G.Button,{className:Wl.purpleColor,value:"purple",children:"P"})}),e(_,{title:p("Magenta"),placement:"top",children:e(G.Button,{className:Wl.magentaColor,value:"magenta",children:"M"})}),e(_,{title:p("Green"),placement:"top",children:e(G.Button,{className:Wl.greenColor,value:"green",children:"G"})}),e(_,{title:p("Teal"),placement:"top",children:e(G.Button,{className:Wl.tealColor,value:"teal",children:"T"})}),e(_,{title:p("Blue"),placement:"top",children:e(G.Button,{className:Wl.blueColor,value:"blue",children:"B"})})]})})})]})]}),r.length>0&&!E&&e("div",{className:`ant-divider ${Wl.divider}`,role:"separator"})]}),!r.length&&!E&&e(o,{children:l.keywords?e(Cn,{}):t("div",{className:Wl.resultsContainer,children:[e("div",{className:Wl.videoIcon,children:e(g,{className:Wl.playButton})}),e("h1",{className:Wl.title,children:p("Millions of free stock images")}),e("p",{className:Wl.subtitle,children:p("Enter a search query and we'll find the perfect image for you")})]})}),!r.length&&E&&e(ja,{}),r.length>0&&t(o,{children:[e("div",{className:Wl.virtualCanvas,style:{height:ae},children:ie.map(({row:o,layout:r})=>{const n=o.item,i=j.has(n.id),a=r.bottom>=se.scrollTop-240&&r.top<=se.scrollTop+se.viewportHeight+240;return t("div",{className:`${Wl.listItem} ${i?Wl.loaded:""}`,onClick:()=>he(n.urls,n.links,n.id,n.description),style:{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height,minHeight:r.height,maxHeight:"none",marginBottom:0},children:[e(jl,{imageId:n.id,sourceUrl:n.urls.small,shouldLoad:a,loader:S,className:L===n.id?Wl.loadedImage:"",width:"100%",height:"100%",alt:n.description,decoding:"async",onLoad:()=>{D(e=>{if(e.has(n.id))return e;const t=new Set(e);return t.add(n.id),t})}}),t("p",{className:Wl.creatorInfo,onClick:e=>e.stopPropagation(),children:[p("Photo by")," ",e("a",{target:"_blank",href:`${n.user.links.html}?utm_source=${null==A?void 0:A.APP_NAME_UNSPLASH}&utm_medium=referral`,rel:"noreferrer",children:n.user.name})," ",p("on")," ",e("a",{target:"_blank",href:`https://unsplash.com/?utm_source=${null==A?void 0:A.APP_NAME_UNSPLASH}&utm_medium=referral`,rel:"noreferrer",children:"Unsplash"})]}),L===n.id&&e(U,{className:Wl.antSpin})]},n.id)})}),P&&e(ja,{})]})]})})})},Gl=()=>{const{options:e}=mn(),t=e.config;return d((e,o)=>{!1!==(null==t?void 0:t.pushToGTM)&&((e,t)=>{const o=()=>{try{const t=Object.assign(Object.assign({},e),{appLabel:"blocks_app"});window.dataLayer&&"function"==typeof window.dataLayer.push&&window.dataLayer.push(t)}catch(e){console.error("Ошибка при вызове GTM:",e)}};t?setTimeout(o,t):o()})(e,o)},[null==t?void 0:t.pushToGTM])};var Kl="slideshowContainer",Ql="slideshowImage";const Jl=({images:t,transitionDuration:o=1e3,frameHeight:r})=>{const[n,l]=i([]),[s,d]=i(r);a(()=>{const e=()=>{if("undefined"==typeof window)return void d(r);const e=window.innerHeight,t=Math.max(e-260,130);if("number"==typeof r){const e=Math.min(r,t);d(e)}else d(t)};if(e(),"undefined"!=typeof window)return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[r]);const c=()=>{l(e=>e.map((t,o)=>o===e.length-1?Object.assign(Object.assign({},t),{opacity:1}):t))};return a(()=>{if(t.length>0){const e=t[t.length-1];l(t=>[...t,{src:e,opacity:0}]),setTimeout(c,1e3)}else l([])},[t]),e("div",{className:Kl,style:{height:s,minHeight:130},children:n.map((t,r)=>e("img",{src:`data:image/jpeg;base64, ${t.src}`,alt:`Slide ${r+1}`,className:Ql,style:{opacity:t.opacity,transition:`opacity ${o}ms linear`,display:"block"}},r))})},Yl=t=>{var{className:o,style:r,color:n,text:i,variant:a}=t,l=Rn(t,["className","style","color","text","variant"]);const s=i||"";return e(K,Object.assign({style:r,color:n,variant:a,className:o},l,{children:s}))},Zl=({text:o,counter:r,limits:n,wrapperStyles:i})=>{const{t:a}=dr(),{options:l}=mn(),s=l.config,{token:d}=y.useToken(),c=+n>0,u=!c||r<+n,f=(null==s?void 0:s.billingPageUrl)||"/billing",h=r+" "+a("of")+" "+(c?n:"∞")+" "+(o||a("tests",{count:n}))+" "+a("was used",{count:r});return t("div",{className:"limits-couter-wrapper",style:i,children:[e(Yl,{variant:"filled",text:h,className:"limit-counter",style:{color:u?d.colorText:"white"},color:u?d.colorFillSecondary:"rgb(255, 77, 79)"}),c&&e("div",{style:{fontSize:14,textDecoration:"underline",cursor:"pointer"},onClick:()=>window.location.assign(f),children:a("Need more?")})]})};var Xl={imageAi:"imageAi",imageAiExample:"imageAiExample",imageItem:"imageItem",textAreaInputHybrid:"textAreaInputHybrid",loading:"loading",carousel:"carousel",arrow:"arrow",arrowNext:"arrowNext",arrowPrev:"arrowPrev",arrowBtn:"arrowBtn",arrowBtnNext:"arrowBtnNext",arrowBtnPrev:"arrowBtnPrev",row:"row",inputAffixWrapper:"inputAffixWrapper",textarea:"textarea",inputIcon:"inputIcon"};const es=h(({className:t,onClick:o})=>e("div",{className:`${Xl.arrow} ${Xl.arrowNext} ${t||""}`,onClick:o,children:e(S,{className:`${Xl.arrowBtn} ${Xl.arrowBtnNext}`,size:"large",icon:e(ge,{})})}));es.displayName="SampleNextArrow";const ts=h(({className:t,onClick:o})=>e("div",{className:`${Xl.arrow} ${Xl.arrowPrev} ${t||""}`,onClick:o,children:e(S,{className:`${Xl.arrowBtn} ${Xl.arrowBtnPrev}`,size:"large",icon:e(ve,{})})}));ts.displayName="SamplePrevArrow";const os=({customRequest:o,inputAiRef:r,isImageUploaded:l,setIsImageUploaded:s,aiImageRequest:f,setAiImageRequest:h,imageAiList:m,setImageAiList:p,isLoadingAi:g,setIsLoadingAi:v})=>{const{t:y}=dr(),{AiIcon_2:w}=gn(),C=n.useRef(null),[F,A]=i("auto"),{aiImageCounter:_,currentAiImgLimits:E,loadingDuringGeneration:x,requestStatus:P,handleGenerate:R,convertBase64ToFile:N,isShiftPressed:O,setIsShiftPressed:L,limitsInPlugin:M}=function({setFrameHeight:e,customRequest:t,aiTabRef:o,isImageUploaded:r,setIsImageUploaded:n,aiImageRequest:l,imageAiList:s,setImageAiList:f,isLoadingAi:h,setIsLoadingAi:m}){const{t:p}=dr(),{options:g}=mn(),v=g.config,y=On(),w=Gl(),{messages:b}=g.config,[C,I]=i([]),[F,A]=i(0),[_,S]=i(null),[E,x]=i(!1),[P,R]=i(p("Evaluating the task")),[N,k]=i(!1),O=c(new Set),T=c(new Set),L=c(new Set);a(()=>{I(b)},[b]),a(()=>{s.length||_||(I([]),O.current.clear(),T.current.clear(),L.current.clear(),j.current=-1)},[s,_]);const M=u(()=>v&&"function"==typeof(null==v?void 0:v.sendAIImageRequest)?null==v?void 0:v.sendAIImageRequest:()=>Promise.resolve({}),[v]),U=d(e=>{const t=`${_}-${e.progress}-${JSON.stringify(e.images||e.data)}`;if(!L.current.has(t))if(L.current.add(t),"error"!==e.status&&"Canceled"!==e.status){if(e.images){if(R(String(e.status)),100===e.progress){m(!1),f(e.images);const t=_,o=Array.isArray(e.images)?e.images:[];o.length>0&&t&&!O.current.has(t)&&(O.current.add(t),y.success({id:"AI_IMAGE_GENERERATION_SUCCESS",message:p("Images generated successfully"),placement:"bottomRight",data:{request:l,taskId:t,images:o}})),S(null),k(!1)}}else if(e.data&&(f([String(e.data)]),100===e.progress)){m(!1);const t=_,o=e.data?[String(e.data)]:[];o.length>0&&t&&!O.current.has(t)&&(O.current.add(t),y.success({id:"AI_IMAGE_GENERERATION_SUCCESS",message:p("Images generated successfully"),placement:"bottomRight",data:{request:l,taskId:t,images:o}})),S(null),k(!1)}}else m(!1),k(!1),_&&!T.current.has(_)&&(T.current.add(_),y.error({id:"AI_RESPONSE_INVALID",message:p("Something went wrong, please try again"),placement:"bottomRight",description:String(_)||void 0,data:{requestId:_,request:l,response:e},innerException:e}))},[l,f,R,p,m,_,y,k]),j=c(-1);a(()=>{if(C.length>0){const e=C.length-1;e>j.current&&(j.current=e,U(C[e]))}},[U,C]);const D=u(()=>{if(v&&"function"==typeof(null==v?void 0:v.sseQuery)){const e=null==v?void 0:v.sseQuery;return t=>e(t)}return e=>{}},[v]),B=u(()=>v&&"object"==typeof(null==v?void 0:v.handleLimitUsageEmitter)?null==v?void 0:v.handleLimitUsageEmitter:{fire:()=>{}},[v]),z=null==v?void 0:v.elementId,{projectId:q}=v,{limits:W}=(null==v?void 0:v.limits)?v:{limits:{ai_img_limit:0}},{ai_img_limit:V}=W,$=V>0&&F>=V,H=!(!(null==v?void 0:v.limits)||!v.counters)&&yt,G=d(()=>{B.fire({name:"AiImgCount",count:F+1})},[B,F]),K=u(()=>!$&&!H,[$,H,F,V]),Q=d(async()=>{R(p("Evaluating the task")),""===l||h||(m(!0),k(!0),f([]),I([]),w({event:"submit_form",action:"ai_image_generation",entity_id:z,project_id:q}),M({body:{project_id:q,request:"create-image",connection:"midjourney",message:l}}).then(e=>{var t,o,r,n,i,a,s,d,c;const{data:u,error:h}=e||{};if(h)throw h;const g=u;if(401===(null==g?void 0:g.status)||401===(null===(t=null==g?void 0:g.data)||void 0===t?void 0:t.status))throw new Error("ERROR");const v=null!==(o=null==g?void 0:g.data)&&void 0!==o?o:g;if((null==v?void 0:v._eventResult)&&Array.isArray(null===(r=v.task)||void 0===r?void 0:r.images)&&(null!==(i=null===(n=v.task.images)||void 0===n?void 0:n.length)&&void 0!==i?i:0)>0){const e=v.task.images;return f(e),m(!1),k(!1),void S(null)}const w=(null==g?void 0:g.task)||(null===(a=null==g?void 0:g.data)||void 0===a?void 0:a.task),b=null!==(d=null!==(s=null==w?void 0:w.id)&&void 0!==s?s:_)&&void 0!==d?d:void 0;200===(null==g?void 0:g.status)||200===(null===(c=null==g?void 0:g.data)||void 0===c?void 0:c.status)?((null==w?void 0:w.id)&&(R(w.message),S(w.id)),(null==g?void 0:g.message)&&y.success({id:"AI_IMAGE_GENERATION_STARTED",message:g.message,placement:"bottomRight",data:{request:l,taskId:b,response:null==g?void 0:g.data}}),D({task_id:null==w?void 0:w.id,entity_id:z})):(m(!1),k(!1),b&&!T.current.has(b)&&(T.current.add(b),y.error({id:"AI_IMAGE_GENERATION_FAILED",message:(null==g?void 0:g.message)||p("Something went wrong, please try again"),placement:"bottomRight",description:l,data:{request:l,taskId:b,response:g},innerException:g})))}).catch(e=>{m(!1),k(!1);const t=e;return((null==t?void 0:t.error)||(null==t?void 0:t.data))&&_&&!T.current.has(_)&&(T.current.add(_),null==y||y.error({id:"AI_IMAGE_GENERATION_FAILED",message:p("Something went wrong, please try again"),placement:"bottomRight",description:l,innerException:e,data:{request:l,taskId:_,response:null==t?void 0:t.data,error:Dn(null==t?void 0:t.error)}})),t}))},[l,h,m,k,f,w,z,q,M,y,D,p,_]),J=d(()=>{K&&Q()},[K,H,A,G,Q,y,p]);a(()=>{},[v,H]);const Y=d(e=>{if(r)return;const o=e.match(/^data:image\/([A-Za-z-+/]+);base64,(.+)$/);if(!o)return;const i=o[1],a=o[2],l=atob(a),s=new Array(l.length);for(let e=0;e<l.length;e++)s[e]=l.charCodeAt(e);const d=new Uint8Array(s),c=new Blob([d],{type:`image/${i}`}),u=new File([c],"image.jpeg",{type:c.type,lastModified:Date.now()});n(!0),(async()=>{try{"function"==typeof t&&await Promise.resolve(t({file:u}))}catch(e){console.error("FM AI: customRequest error",e)}finally{n(!1)}})()},[r,n,t]);return a(()=>{(h||s.length>0)&&setTimeout(()=>{var t,r;let n=350;if(o.current){const e=null===(t=o.current)||void 0===t?void 0:t.firstChild;e&&e instanceof HTMLElement&&(n=(null===(r=o.current.getBoundingClientRect())||void 0===r?void 0:r.height)-48-e.clientHeight)}e(n)},0)},[o,s.length,h,e]),{aiImageCounter:F,setAiImageCounter:A,currentAiImgLimits:V,isFieldsDisabled:$,canGenerateImage:K,aiImageRequest:l,imageAiList:s,setImageAiList:f,isLoadingAi:h,setIsLoadingAi:m,loadingDuringGeneration:N,setLoadingDuringGeneration:k,requestStatus:P,setRequestStatus:R,handleGenerate:J,handleLimitAiImgCount:G,convertBase64ToFile:Y,isShiftPressed:E,setIsShiftPressed:x,currentReqId:_,setCurrentReqId:S,limitsInPlugin:H}}({setFrameHeight:A,customRequest:o,aiTabRef:C,isImageUploaded:l,setIsImageUploaded:s,aiImageRequest:f,imageAiList:m,setImageAiList:p,isLoadingAi:g,setIsLoadingAi:v});a(()=>{},[l]);const[U,j]=i(!1),D=d(()=>j(!0),[]),B=d(()=>j(!1),[]),z=d(e=>h(e.target.value),[h]),q=d(e=>{"Shift"===e.key?L(!0):"Enter"!==e.key||O||(e.preventDefault(),R())},[O,R,L]),W=d(e=>{"Shift"===e.key&&L(!1)},[L]);return t("div",{className:Xl.imageAi,ref:C,children:[M&&e(Zl,{text:"images",counter:_,limits:E,wrapperStyles:{marginTop:-25}}),e(T,{gutter:24,className:Xl.row,children:t(k,{span:24,children:[e(b.Item,{children:t("span",{className:`ant-input-affix-wrapper ant-input-affix-wrapper-lg ${Xl.inputAffixWrapper}${U?" ant-input-affix-wrapper-focused":""}`,children:[e(I.TextArea,{ref:r,onKeyDown:q,onKeyUp:W,onFocus:D,onBlur:B,autoSize:!0,allowClear:!0,className:`${Xl.textAreaInputHybrid} ${Xl.textarea}`,placeholder:y("Generate image"),value:f,onChange:z,spellCheck:"false"}),e("span",{className:`ant-input-suffix ${Xl.inputSuffix}`,children:g||x?e(Z,{className:`${Xl.inputIcon} input-icon`,spin:!0}):e(w,{className:`${Xl.inputIcon} input-icon`,onClick:R})})]})}),t("div",{className:Xl.imageAiExample,children:[e("span",{children:y("For example:")})," ",y("A beautiful image of a sunset over a calm ocean.")]})]})}),(g||m.length>0)&&t(Q,{dotPlacement:"top",arrows:!0,nextArrow:e(es,{}),prevArrow:e(ts,{}),className:Xl.carousel,infinite:!1,children:[g&&!m.length&&e("div",{className:Xl.loading,children:t("div",{className:"spin",children:[e(Z,{style:{fontSize:48},spin:!0}),e("p",{className:"status",children:P})]})}),m.length>0&&m.map((o,r)=>t("div",{className:Xl.imageItem,children:[e(Jl,{images:m,frameHeight:F}),e("div",{className:"buttons",children:m.length>0&&!g&&e(S,{onClick:()=>N(`data:image/jpeg;base64, ${o}`),loading:l,icon:e(ye,{}),children:y("Use this variant")})})]},r))]})]})},rs=e=>{(null==e?void 0:e.customTheme)&&((e={})=>{const t=document.querySelector("head");if(!t)return;const o=document.createElement("style");if(o.type="text/css",o.dataset.themeVariablesFm="true",o.setAttribute("data-file-manager","true"),Object.entries(e).length){let r="";Object.entries(e).forEach(([e,t])=>{"object"!=typeof t&&(r+=`\t--${e}: ${t};\n`)}),r=`.em-filemanager {\n${r}}`,o.appendChild(document.createTextNode(r));const n=t.querySelector('[data-theme-variables-fm="true"]');n?t.replaceChild(o,n):t.insertBefore(o,t.firstChild)}})(null==e?void 0:e.customTheme)},{Sider:ns,Content:is}=H,as=n.lazy(()=>import("./file-manager-IconsTab-BHfR46Fs.js")),ls=n.lazy(()=>import("./file-manager-ImageCodeGenerator-BJBjgcM1.js")),ss={keywords:""},ds=()=>{var l,s,u;const f=Kn(),h=Di(),m=(()=>{var e,t;const{state:o,actions:r,options:n}=mn(),{selectedFolder:i,pathHistory:a,folders:l}=o,{t:s}=dr(),{setSelectedFolder:c,setPathHistory:u}=r,f=d(()=>{var e;return`em_fm:lastFolder:${(null===(e=null==n?void 0:n.config)||void 0===e?void 0:e.projectId)||"default"}`},[null===(e=null==n?void 0:n.config)||void 0===e?void 0:e.projectId]),h=d((e,t=new Set)=>{if(t.has(e))return console.warn(`Cycle detected in the path to the folder with id=${e}`),[];const o=(Array.isArray(l)?l:[]).find(t=>t.id===e);if(!o)return[];const r=new Set(t);return r.add(e),o.parentId?o.parentId===o.id?(console.warn(`Cycle detected: folder ${o.id} is a parent of itself`),[{id:o.id,name:o.name+" (ошибка)"}]):[...h(o.parentId,r),{id:o.id,name:o.name}]:[{id:o.id,name:o.name}]},[l]),m=d(e=>{var t;if("undefined"==typeof window)return;const o=!0===(null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.rememberLastFolder),r=f();try{if(!o)return void localStorage.removeItem(r);e?localStorage.setItem(r,e):localStorage.removeItem(r)}catch(e){}},[f,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.rememberLastFolder]),p=d(e=>{if("folders"===e){const e=[{id:"folders",name:s("Folders")}];return null==u||u(e),void(n.onPathChange&&n.onPathChange([]))}if(!(Array.isArray(l)?l:[]).find(t=>t.id===e))return void console.warn("⚠️ Folder not found:",e);const t=h(e),o=[{id:"folders",name:s("Folders")},...t];null==u||u(o),n.onPathChange&&n.onPathChange(o.map(e=>e.name))},[l,h,u,n,s]),g=d(e=>{const t="folders"===e?null:e;t!==i&&(null==c||c(t),m(t),p(e))},[m,i,c,p]),v=d(e=>{if(-1===e)null==c||c(null),null==u||u([{id:"folders",name:s("Folders")}]),n.onPathChange&&n.onPathChange([]);else{const t=a.slice(0,e+1),o=t[t.length-1],r="folders"===o.id?void 0:o.id;null==c||c(r||null),null==u||u(t),n.onPathChange&&n.onPathChange(t.map(e=>e.name))}},[n,a,u,c,s]),y=d(e=>{if(!e.isFolder)return;null==c||c(e.id);const t={id:e.id,name:e.name};if(u){const e=[...a,t];u(e)}if(n.onPathChange){const t=[...a.map(e=>e.name),e.name];n.onPathChange(t)}},[n,a,u,c]);return{state:{selectedFolder:i,pathHistory:a},actions:{handleFolderSelect:g,handleBreadcrumbClick:v,handleItemClick:y},selectedFolder:i,pathHistory:a,handleFolderSelect:g,handleBreadcrumbClick:v,handleItemClick:y}})(),p=(()=>{const{state:e,actions:t}=mn(),{pagination:o}=e,{setPagination:r}=t,n=d((e,t)=>{const n=t||o.pageSize;null==r||r({current:e,pageSize:n,total:o.total})},[o.pageSize,o.total,r]);return{state:{pagination:o},actions:{handlePaginationChange:n}}})(),v=(()=>{const[e,t]=i([]),[o,r]=i(!1),[n,a]=i(!1),l=c(0),s=c(new Map),u=d(()=>(l.current+=1,`upload_${l.current}_${Date.now()}`),[]),f=d(e=>Or(e.size),[]),h=d((e,o)=>{const n=o.map(t=>({id:u(),folderId:e,name:t.name,size:f(t),status:"uploading",progress:0}));return t(n),r(!0),a(!1),n.map(e=>e.id)},[u,f]),m=d((e,o)=>{const n={id:u(),folderId:e,name:o,size:void 0,status:"uploading",progress:0};return t(e=>[...e,n]),r(!0),a(!1),n.id},[u]),p=d((e,o)=>{t(t=>t.map(t=>t.id===e?Object.assign(Object.assign({},t),{progress:Math.min(100,Math.max(0,o))}):t))},[]),g=d((e,o)=>{o&&s.current.set(e,o),t(t=>t.map(t=>{if(t.id===e){const e=Object.assign(Object.assign({},t),{status:"success",progress:100});return(null==o?void 0:o.name)&&(e.name=o.name),(null==o?void 0:o.size)&&void 0===t.size&&(e.size=Or(o.size)),e}return t}))},[]),v=d((e,o)=>{t(t=>t.map(t=>t.id===e?Object.assign(Object.assign({},t),{status:"error",error:o}):t))},[]),y=d(()=>{r(!1),a(!1),setTimeout(()=>{t([]),s.current.clear()},300)},[]),w=d(()=>{a(e=>!e)},[]),b=d(e=>s.current.get(e),[]),C=e.length,I=e.filter(e=>"success"===e.status||"error"===e.status).length;return{uploadFiles:e,isUploadVisible:o,isUploadMinimized:n,totalFiles:C,completedFiles:I,startUpload:h,startUploadByUrl:m,updateProgress:p,markAsSuccess:g,markAsError:v,getUploadedFile:b,closeUpload:y,minimizeUpload:w}})(),y=Ai(),{deleteItems:w}=Qn(),b=On(),{t:C}=dr(),{options:I,state:F,actions:A}=mn(),_=I,S=null==_?void 0:_.onChangeSelection,E=F,x=null==_?void 0:_.config,{dataProviders:P}=_,{form:R,urlForm:N,renameForm:k,moveForm:O,renameFolderForm:T,copyForm:L,isModalVisible:M,isUrlModalVisible:j,isMoveModalVisible:D,isRenameFolderModalVisible:B,isCopyModalVisible:z,isDeleteConfirmVisible:q,folderToRename:V,activeLibraryItem:$}=F,{setIsUrlModalVisible:G,setActiveLibraryItem:K}=A,{config:Q}=I,{DropZoneFileIcon:J}=gn(),[Y,Z]=i(!1),[X,ee]=i(!1),[te,oe]=i(!1),re=c(0),ne=c(!1);ne.current=X;const ie=n.useRef(null),ae=n.useRef([]),[le,se]=i(!1),[de,ce]=i(!1),ue=Pi(e=>e.selectedFiles),fe=Pi(e=>e.clearSelection),he=Pi(e=>e.syncVisibleFiles),{folders:me,loading:pe}=f.state,{fetchFolders:ge,fetchChildFolders:ve,handleCreateFolder:ye,handleModalOk:we,handleModalCancel:Ce,generateMenuItems:Ie}=f.actions,Fe=(e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),{folders:l,folderToRename:s,renameFolderForm:c,isRenameFolderModalVisible:u}=o,{setFolderToRename:f,setIsRenameFolderModalVisible:h}=r,{apiEndpoints:m,dataProviders:p,config:g}=n,v=d(e=>{null==f||f(e),null==h||h(!0);const t=null==l?void 0:l.find(t=>t.id===e);t&&c&&c.setFieldsValue({newFolderName:t.name})},[f,h,l,c]),y=d(()=>{null==h||h(!1),null==f||f(null),null==c||c.resetFields()},[h,f,c]),w=d(async()=>{var t,o;if(s&&c)try{const n=await c.validateFields();if(!(null==n?void 0:n.newFolderName))return void a.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:i("Folder name cannot be empty"),placement:"bottomRight",data:{folderId:s,folderName:null==n?void 0:n.newFolderName,reason:"emptyName"}});if(!1===(null===(t=null==g?void 0:g.features)||void 0===t?void 0:t.enableRenameFolder))return void a.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:i("Folder rename is disabled by config"),placement:"bottomRight",data:{itemId:null!=s?s:void 0,itemName:null==n?void 0:n.newFolderName}});if(!(null==p?void 0:p.renameFolder))throw new Error(i("renameFolder is not implemented in dataProviders"));const l=await p.renameFolder(s,n.newFolderName.trim());if(!(null==l?void 0:l.id))return void a.error({id:"FOLDER_RENAME_FAILED",message:i("Unexpected response when renaming folder"),placement:"bottomRight",data:{itemId:null!=s?s:void 0,itemName:n.newFolderName,error:{message:"invalidResponse"}}});a.success({id:"FOLDER_RENAME_SUCCESS",message:i("Folder renamed"),placement:"bottomRight",data:{itemId:l.id,itemName:l.name,folderId:null!==(o=l.parentId)&&void 0!==o?o:null}}),y(),await e(),s!==l.id&&r.setSelectedFolder&&r.setSelectedFolder(l.id)}catch(e){console.error("Ошибка при переименовании папки:",e),a.error({id:"FOLDER_RENAME_FAILED",message:i("Failed to rename folder"),placement:"bottomRight",innerException:e,data:{itemId:null!=s?s:void 0,itemName:null==c?void 0:c.getFieldValue("newFolderName"),error:{message:e instanceof Error?e.message:String(e)}}})}},[s,c,m,y,e,i,null===(t=null==g?void 0:g.features)||void 0===t?void 0:t.enableRenameFolder,a]);return{state:{isRenamingFolder:u||!1,folderToRename:s},actions:{showRenameFolderModal:v,handleRenameFolderCancel:y,handleRenameFolderOk:w}}})(ge),{files:Ae,loading:_e,isRenamingFile:Se,fileToRename:Ee}=h.state,{fetchFiles:xe,handleDeleteFile:Pe,handleDeleteFolder:Re,handleAddFile:Ne,handleAddFileByUrl:ke,showRenameModal:Oe,handleRenameCancel:Te,handleRenameOk:Le,handleDroppedFiles:Me,showMoveModal:Ue,handleMoveCancel:je,handleMoveOk:De,handleCopyOk:Be,handleCopyCancel:ze,showDeleteConfirm:qe,handleDeleteConfirmCancel:We,handleDeleteConfirmOk:Ve}=h.actions,{selectedFolder:$e,pathHistory:He}=m.state,{handleFolderSelect:Ge,handleItemClick:Ke}=m.actions,{pagination:Qe}=p.state,Je=Pn(xe),{searchTerm:Ye,sortBy:Ze,sortOrder:Xe}=Je.state,{handleSearch:et,handleSort:tt,handlePaginationChange:ot}=Je.actions,rt=d(async()=>{const e=(e=>Vn(e))(He||[]);try{await Gn({options:_,pathFolder:e,dataProviders:null==_?void 0:_.dataProviders})}catch(e){console.error("Cache clear failed:",e)}await ge(),await xe({folderId:$e||"",page:Qe.current,limit:Qe.pageSize,search:Ye,sortBy:Ze,sortOrder:Xe,itemType:"all"})},[xe,ge,_,Qe,He,Ye,$e,Ze,Xe]),nt=(({files:e,fetchFiles:t,selectedFolder:o})=>{var n;const{t:i}=dr(),a=On(),{options:l,actions:s,state:d}=r.useContext(hn),{setActiveLibraryItem:c}=s,{activeLibraryItem:u}=d,f=Ai(),[h,m]=r.useState(!1),[p,g]=r.useState(null),v=r.useCallback(e=>{var t;if(e.type&&e.type.startsWith("image/"))return!0;if(e.extension){const t=e.extension.toLowerCase();return bt.includes(t)}const o=null===(t=e.name.split(".").pop())||void 0===t?void 0:t.toLowerCase();return!!o&&bt.includes(o)},[]),y=r.useCallback(async(e,t)=>{var o,r;const{dataProviders:n}=l;if(!1===(null===(r=null===(o=l.config)||void 0===o?void 0:o.features)||void 0===r?void 0:r.enableUpdateFile))throw new Jn(i("Updating files is disabled by configuration"),"UnsupportedOperation");if(!e.id||!e.thumbnail||!(null==n?void 0:n.updateFile))throw new Jn(i("Failed to save changes"),"UnsupportedOperation");const a=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),s=Tt(a),d=e.name.lastIndexOf("."),c=`${d>0?e.name.substring(0,d):e.name}.${s}`,u=(null==t?void 0:t.blob)||Bt(e.thumbnail,a);return n.updateFile(e.id,{name:c,type:a,data:u})},[l,i]),w=r.useCallback(async(e,t)=>{var o,r,n;if(!e.thumbnail)throw new Jn(i("Failed to save changes"),"ValidationError");const a=!(!0===(null===(o=l.config)||void 0===o?void 0:o.saveCopyToCurrentFolder))||(null!==(r=e.saveWithoutFolder)&&void 0!==r?r:!e.id),s=a?void 0:null!==(n=e.folderId)&&void 0!==n?n:void 0,d=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),c=(null==t?void 0:t.blob)||Bt(e.thumbnail,d),u=new File([c],e.name,{type:d,lastModified:Date.now()}),h=await f.uploadFileWithProvider(u,s,void 0,a);if(!h)throw new Jn(i("Failed to save image copy"),"FileWriteError");return h},[f,null===(n=l.config)||void 0===n?void 0:n.saveCopyToCurrentFolder,i]),b=r.useCallback(t=>{let o;if(t)o=t;else{const t=Pi.getState().selectedFiles;if(1!==t.size)return;const r=Array.from(t)[0];if(o=e.find(e=>e.id===r),!o||o.isFolder||!v(o))return}c&&c(ft),g(o),m(!0)},[e,v,m,c]),C=r.useCallback(()=>{c&&u===ft&&c(at),m(!1),g(null)},[u,c]),I=r.useCallback(async(e,r)=>{var n,s,d,c,u,f;try{const d=await y(e,r);return a.success({id:"IMAGE_UPDATE_SUCCESS",message:i("Success"),description:i("Image updated successfully"),placement:"bottomRight",data:{itemId:null!==(n=null==d?void 0:d.id)&&void 0!==n?n:void 0,itemName:null==d?void 0:d.name,folderId:null!==(s=null==d?void 0:d.folderId)&&void 0!==s?s:null,thumbnail:null==d?void 0:d.thumbnail}}),d&&l.onEditorOk&&l.onEditorOk(d,{mode:r.mode}),await t({folderId:o||""}),C(),null!=d?d:void 0}catch(t){const o=Dn(t),r=null!==(c=null!==(d=Un(null==o?void 0:o.code,i))&&void 0!==d?d:null==o?void 0:o.message)&&void 0!==c?c:i("Failed to save changes");throw a.error({id:"IMAGE_SAVE_FAILED",message:r,innerException:t,placement:"bottomRight",data:{itemId:null!==(u=e.id)&&void 0!==u?u:void 0,itemName:e.name,folderId:null!==(f=e.folderId)&&void 0!==f?f:null,thumbnail:e.thumbnail}}),t.notificationShown=!0,t}},[y,l,t,o,a,C,i]),F=r.useCallback(async(e,r)=>{var n,s,d,c,u,f;try{const d=await w(e,r);return a.success({id:"IMAGE_SAVE_COPY_SUCCESS",message:i("Success"),description:i("Image copy saved successfully"),placement:"bottomRight",data:{itemId:null!==(n=null==d?void 0:d.id)&&void 0!==n?n:void 0,itemName:null==d?void 0:d.name,folderId:null!==(s=null==d?void 0:d.folderId)&&void 0!==s?s:null,thumbnail:null==d?void 0:d.thumbnail}}),d&&l.onEditorOk&&l.onEditorOk(d,{mode:r.mode}),await t({folderId:o||""}),C(),null!=d?d:void 0}catch(t){const o=Dn(t),r=null!==(c=null!==(d=Un(null==o?void 0:o.code,i))&&void 0!==d?d:null==o?void 0:o.message)&&void 0!==c?c:i("Failed to save image copy");throw a.error({id:"IMAGE_SAVE_COPY_FAILED",message:r,innerException:t,placement:"bottomRight",data:{itemId:null!==(u=e.id)&&void 0!==u?u:void 0,itemName:e.name,folderId:null!==(f=e.folderId)&&void 0!==f?f:null,thumbnail:e.thumbnail}}),t.notificationShown=!0,t}},[w,l,t,o,a,C,i]);return{isPixieEditorVisible:h,editingFile:p,handleEdit:b,handlePixieEditorSave:I,handlePixieEditorSaveCopy:F,handlePixieEditorClose:C}})({files:Ae||[],fetchFiles:xe,selectedFolder:$e||null}),[it,mt]=i(!1),pt=d(e=>{if(e.preventDefault(),e.stopPropagation(),!e.dataTransfer||!e.dataTransfer.types||!e.dataTransfer.types.includes("Files"))return;e.dataTransfer.dropEffect="copy";const t=e.relatedTarget,o=e.currentTarget;t&&o.contains(t)||(re.current+=1,re.current>0&&Z(!0))},[]),gt=d(e=>{e.preventDefault(),e.stopPropagation();const t=e.relatedTarget,o=e.currentTarget;if(t&&!o.contains(t))re.current=Math.max(0,re.current-1),re.current<=0&&Z(!1);else if(t){const e=t.closest('[class*="dragOverlay"]');if(e&&o.contains(e))return}},[]),vt=d(e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")},[]),yt=d(e=>{e.preventDefault(),e.stopPropagation(),Z(!1),re.current=0;const t=(()=>{var t;const o=e.dataTransfer;if(!o)return[];if(null===(t=o.files)||void 0===t?void 0:t.length)return Array.from(o.files);const r=[];if(o.items)for(let e=0;e<o.items.length;e++){const t=o.items[e].getAsFile();t&&r.push(t)}return r})();t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error("Ошибка при загрузке файлов:",e)}).finally(()=>{mt(!1)}))},[Me]),wt=d(()=>{Z(!1),re.current=0,document.body.removeAttribute("data-fm-dragging"),oe(!1),ee(!1)},[]);n.useEffect(()=>{ae.current=Ae||[]},[Ae]);const Ct=null==E?void 0:E.activeLibraryItem;a(()=>{const e=e=>{e?document.body.setAttribute("data-fm-dragging","true"):document.body.removeAttribute("data-fm-dragging")};let t=!1;const o=o=>{var r,n;!t&&(null===(n=null===(r=o.dataTransfer)||void 0===r?void 0:r.types)||void 0===n?void 0:n.includes("Files"))&&(t=!0,oe(!0),e(!0),Ct===at&&ee(!0))},r=o=>{const r=o.relatedTarget;(!r||!document.documentElement.contains(r))&&t&&(t=!1,oe(!1),ee(!1),e(!1))};return window.addEventListener("dragenter",o,!0),window.addEventListener("dragleave",r,!0),()=>{window.removeEventListener("dragenter",o,!0),window.removeEventListener("dragleave",r,!0),document.body.removeAttribute("data-fm-dragging")}},[Ct]),a(()=>{const e=e=>{var t,o;if(document.body.removeAttribute("data-fm-dragging"),oe(!1),!(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files")))return;e.preventDefault();const r=(e=>{var t;if(!e)return[];if(null===(t=e.files)||void 0===t?void 0:t.length)return Array.from(e.files);const o=[];if(e.items)for(let t=0;t<e.items.length;t++){const r=e.items[t].getAsFile();r&&o.push(r)}return o})(e.dataTransfer);if(!r.length)return;const n=e.target,i=n.closest(`.${ta.filesContainer.replace(/\s+/g,".")}`)||n.closest("[data-files-container]"),a=n.closest(".em-filemanager")||n.closest(".file-manager__layout")||n.closest("[data-drop-overlay]")||n.closest("[data-drag-capture]");(ne.current||Y||i||a)&&(e.preventDefault(),e.stopPropagation(),ee(!1),Z(!1),re.current=0,mt(!0),Me(r).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error("Ошибка при загрузке файлов:",e)}).finally(()=>mt(!1)))},t=e=>{var t,o;(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",document.body.hasAttribute("data-fm-dragging")||(document.body.setAttribute("data-fm-dragging","true"),oe(!0)),Ct!==at||ne.current||ee(!0))},o=e=>{var t,o;(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",document.body.setAttribute("data-fm-dragging","true"),oe(!0))},r={capture:!0,passive:!1};return window.addEventListener("drop",e,r),window.addEventListener("dragover",t,r),window.addEventListener("dragenter",o,r),()=>{window.removeEventListener("drop",e,r),window.removeEventListener("dragover",t,r),window.removeEventListener("dragenter",o,r)}},[Y,Me,Ct]),a(()=>{const e=e=>{Y&&wt(),ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging")};return window.addEventListener("dragend",e,!0),()=>window.removeEventListener("dragend",e,!0)},[Y,wt]),a(()=>{let e=null;const t=t=>{Y&&(e=setTimeout(()=>{Y&&wt()},200))};return document.addEventListener("mouseup",t,!0),()=>{document.removeEventListener("mouseup",t,!0),e&&clearTimeout(e)}},[Y,wt]),a(()=>{const e=e=>{"Escape"===e.key&&Y&&wt()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[Y,wt]),a(()=>{const e=e=>{Y&&setTimeout(()=>{Y&&wt()},100)};return document.addEventListener("click",e,!0),()=>{document.removeEventListener("click",e,!0)}},[Y,wt]);const Ft=n.useCallback(async()=>{await Ve(),await ge(),$e===ht&&ve&&await ve(ht),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var e,t;return null===(t=null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts)||void 0===t?void 0:t.call(e)})})},[ge,ve,Ve,$e]),At=n.useCallback(()=>{ce(!0)},[]),_t=n.useCallback(async()=>{var e,t;if($e!==ht)return console.error("Clear trash called outside of trash folder"),void ce(!1);try{if(null==P?void 0:P.cleanTrash){const t=await P.cleanTrash();await xe({folderId:ht}),await(null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts()),t.success?b.success({id:"TRASH_CLEARED_SUCCESS",message:C("Trash cleared successfully"),description:C("{{count}} items permanently deleted",{count:t.deletedCount||0}),placement:"bottomRight"}):b.error({id:"TRASH_CLEAR_FAILED",message:C("Failed to clear trash"),placement:"bottomRight"})}else{const e=ae.current||[];if(0===e.length)return void ce(!1);const o=e.map(e=>({id:e.id,isFolder:e.isFolder})),r=await w({items:o,selectedFolder:ht,getItemNameById:t=>{var o;return(null===(o=e.find(e=>e.id===t))||void 0===o?void 0:o.name)||t||""},showNotifications:!1});await xe({folderId:ht}),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts());const{successCount:n,failCount:i}=r;0===i?b.success({id:"TRASH_CLEARED_SUCCESS",message:C("Trash cleared successfully"),description:C("{{count}} items permanently deleted",{count:n}),placement:"bottomRight"}):n>0?b.warning({id:"TRASH_CLEARED_PARTIAL",message:C("Trash partially cleared"),description:C("{{succeeded}} items deleted, {{failed}} items failed",{succeeded:n,failed:i}),placement:"bottomRight"}):b.error({id:"TRASH_CLEAR_FAILED",message:C("Failed to clear trash"),placement:"bottomRight"})}ce(!1)}catch(e){console.error("Error clearing trash:",e),b.error({id:"TRASH_CLEAR_ERROR",message:C("Error clearing trash"),placement:"bottomRight"}),ce(!1)}},[$e,P,xe,b,C,w]),St=n.useCallback(()=>{ce(!1)},[]),Et=n.useCallback(async e=>{var t;await De(e),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[De]),xt=n.useCallback(async e=>{var t;await Be(e),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[Be]),Rt=n.useCallback(async()=>{let e=[],t=new Map;const o=null==_?void 0:_.config;await Ne({onStartBatch:r=>{e=v.startUpload($e||void 0,r),t=new Map,r.forEach((r,n)=>{const i=e[n];i&&(t.set(r.name,i),t.set(Yt(r.name,o),i))})},onStart:r=>{if(0===e.length){e=v.startUpload($e||void 0,[r]);const n=e[0];n&&(t.set(r.name,n),t.set(Yt(r.name,o),n))}},onProgress:(e,o)=>{const r=t.get(e);r&&v.updateProgress(r,o)},onComplete:async e=>{var o;const r=t.get(e);if(r){await new Promise(e=>setTimeout(e,100));const t=null==Ae?void 0:Ae.find(t=>t.name===e&&!t.isFolder);v.markAsSuccess(r,t)}await(null===(o=ie.current)||void 0===o?void 0:o.refreshFileCounts())},onError:(o,r,n)=>{var i;const a=null!==(i=t.get(o))&&void 0!==i?i:null!=n&&n<e.length?e[n]:void 0;a&&v.markAsError(a,r)},onBatchComplete:async o=>{var r,n,i,a,l,s,d,c;for(let c=0;c<o.successes.length;c++){const u=o.successes[c],f=null===(r=o.uploadedFiles)||void 0===r?void 0:r.get(u),h=null!==(a=null!==(i=null!==(n=t.get(u))&&void 0!==n?n:(null==f?void 0:f.originalFileName)?t.get(f.originalFileName):void 0)&&void 0!==i?i:null!=(null==f?void 0:f.originalIndex)&&f.originalIndex<e.length?e[f.originalIndex]:void 0)&&void 0!==a?a:c<e.length?e[c]:void 0;if(h){let e;if(null==f?void 0:f.id){const t=f;e={id:t.id,name:null!==(l=t.name)&&void 0!==l?l:u,folderId:null!==(d=null!==(s=t.folderId)&&void 0!==s?s:$e)&&void 0!==d?d:null,isFolder:!1,size:t.size}}else await new Promise(e=>setTimeout(e,100)),e=null==Ae?void 0:Ae.find(e=>e.name===u&&!e.isFolder);v.updateProgress(h,100),v.markAsSuccess(h,e)}}o.errors.forEach(({fileName:e,error:o})=>{const r=t.get(e);r&&v.markAsError(r,o)}),await(null===(c=ie.current)||void 0===c?void 0:c.refreshFileCounts())}})},[Ne,v,Ae,$e,null==_?void 0:_.config]),Nt=n.useCallback(async(e,t,o,r)=>{var n,i;try{se(!0);let a=o||"uploaded-file";if(!o&&e){const t=e.split("?")[0].split("#")[0].split("/");a=t[t.length-1]||"uploaded-file";a.includes(".")&&(null===(n=a.split(".").pop())||void 0===n?void 0:n.length)&&a.split(".").pop().length<=5||(a+=".jpg")}const l=v.startUploadByUrl($e||void 0,a);try{const o=await ke(e,t,!0,null!=r?r:"uploadByUrl");if(v.updateProgress(l,100),o){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===o.id&&!e.isFolder))||o;v.markAsSuccess(l,e)}else v.markAsSuccess(l);await(null===(i=ie.current)||void 0===i?void 0:i.refreshFileCounts())}catch(e){const t=Dn(e),o=Wn(t,C);v.markAsError(l,o)}}finally{se(!1)}},[ke,v,$e,Ae,C]),kt=n.useCallback(async({file:e})=>{var t;const o=v.startUpload($e||void 0,[e])[0];let r=0;const n=setInterval(()=>{r=Math.min(r+10+Math.floor(Date.now()%10),90),v.updateProgress(o,r)},200);try{const r=await y.uploadFileWithProvider(e,void 0,!0);if(clearInterval(n),v.updateProgress(o,100),r){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===r.id&&!e.isFolder))||r;v.markAsSuccess(o,e)}else v.markAsSuccess(o);const i=r&&r.folderId||$e||null;return Ge&&Ge(i&&"folders"!==i?i:"folders"),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts()),r}catch(e){clearInterval(n);const t=e instanceof Error?e.message:String(e);throw v.markAsError(o,t),e}},[y,v,$e,Ae,Ge]),Lt=n.useCallback(async e=>{var t;if(Me){const o=v.startUpload($e||void 0,e);e.forEach(async(e,t)=>{const r=o[t];if(!r)return;let n=0;const i=setInterval(()=>{n=Math.min(n+10+Math.floor(Date.now()%10),85),v.updateProgress(r,n)},200);setTimeout(()=>{clearInterval(i)},2e3)}),await Me(e),o.forEach(e=>{v.updateProgress(e,100),v.markAsSuccess(e)}),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())}},[Me,v,$e]),Mt=n.useCallback(async e=>{var t;await Re(e),await ge(),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[Re,ge]),Ut=(({files:e,clearSelection:t,showRenameModal:o,showMoveModal:n,showCopyModal:i,handleDeleteFile:a,handleDeleteFolder:l,showDeleteConfirm:s,onEdit:d})=>{const c=r.useCallback(()=>{t()},[t]),u=r.useCallback(e=>{const t=Pi.getState().selectedFiles;if(t&&1===t.size||e){const r=e||Array.from(t)[0];o(r)}},[o]),f=r.useCallback(t=>{const o=Pi.getState().selectedFiles;if(o&&o.size>0||(null==t?void 0:t.id)){if(s)return void s();(t?[t.id]:o).forEach(t=>{const o=e.find(e=>e.id===t);o?o.isFolder?l(t):a(t):console.warn(`Объект с ID ${t} не найден в списке файлов`)})}},[e,a,l,s]);return{handleClearSelection:c,handleRename:u,handleDeleteSelected:f,handleCopy:r.useCallback(()=>{i()},[i]),handleMove:r.useCallback(()=>{n()},[n]),handleEdit:r.useCallback(()=>{d()},[d])}})({files:Ae||[],clearSelection:fe,showRenameModal:Oe,showMoveModal:Ue,showCopyModal:h.actions.showCopyModal||(()=>{}),handleDeleteFile:Pe,handleDeleteFolder:Mt,showDeleteConfirm:qe,onEdit:nt.handleEdit}),jt=pe||_e||it;a(()=>{Pt()},[]),g(()=>{$!==at?fe():he(Ae||[])},[$,Ae,he,fe]),a(()=>{if(!S||$!==at)return;if(!vo.current)return void(vo.current=!0);const e=(Array.isArray(Ae)?Ae:[]).filter(e=>ue.has(e.id));S(e)},[$,Ae,ue,S]),n.useEffect(()=>{if(!Ge||0===me.length)return;const e=!1!==(null==x?void 0:x.rememberLastFolder),t=`em_fm:lastFolder:${(null==x?void 0:x.projectId)||"default"}`;if(e&&"undefined"!=typeof window)try{const e=localStorage.getItem(t);if(e&&me.some(t=>t.id===e))return void Ge(e)}catch(e){}$e||Ge("folders")},[$e,Ge,me,null==x?void 0:x.rememberLastFolder,null==x?void 0:x.projectId]);const{handleRenameFolderCancel:Dt,handleRenameFolderOk:zt}=Fe.actions;a(()=>{const e=async e=>{if($!==at)return;const t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||"true"===(null==t?void 0:t.getAttribute("contenteditable")))return;const o=e.clipboardData;if(!o)return;const r=Array.from(o.items),n=r.filter(e=>e.type.startsWith("image/"));if(n.length>0){const t=n.map(e=>e.getAsFile()).filter(e=>null!==e);return void(t.length>0&&(e.preventDefault(),await Lt(t)))}const i=r.find(e=>"text/plain"===e.type);i&&i.getAsString(async t=>{const o=t.trim();if(o.startsWith("http://")||o.startsWith("https://"))e.preventDefault(),await Nt(o);else if(o.includes("<meta")||o.includes("http")){const t=o.match(/https?:\/\/[^\s"']+/);t&&(e.preventDefault(),await Nt(t[0]))}})};return document.addEventListener("paste",e),()=>{document.removeEventListener("paste",e)}},[$,Nt,Lt]);const qt=c(Qe);a(()=>{qt.current=Qe},[Qe]);const Wt=d(e=>{ot(e.current||qt.current.current,e.pageSize||qt.current.pageSize)},[ot]),Vt=d(e=>{null==Ke||Ke(e)},[Ke]),$t=n.useCallback(e=>{const{sortBy:t,sortOrder:o}=(e=>{const[t,o]=e.split("-");return{sortBy:t,sortOrder:o}})(e);tt(t,o)},[tt]),[Ht,Gt]=i(ss),[Kt,Qt]=i([]),Jt=c(null),[Zt,Xt]=i(It),[eo,to]=i([]),oo=c(null),[ro,no]=i(""),io=c(null),[ao,lo]=i(""),[so,co]=i([]),uo=n.useRef(void 0),[fo,ho]=i(!1),[mo,po]=i(!1),go=n.useRef(null),vo=n.useRef(!1),[yo,wo]=i({mode:"qr",rawText:"",foregroundHex:"#000000",backgroundHex:"#ffffff",transparentBackground:!1,qrSidePx:200,barcodeBarHeightPx:60}),bo=n.useRef($),Co=n.useCallback(e=>{const t=e.indexOf(",");if(-1===t)return null;const o=e.substring(0,t),r=o.match(/^data:([^;]+)/),n=r&&r[1]||"image/svg+xml";let i,a="svg";if(n.includes("png")?a="png":(n.includes("jpeg")||n.includes("jpg"))&&(a="jpg"),/;base64/i.test(o)){const o=e.substring(t+1),r=atob(o),a=new Uint8Array(r.length);for(let e=0;e<r.length;e+=1)a[e]=r.charCodeAt(e);i=new Blob([a],{type:n})}else{const o=decodeURIComponent(e.substring(t+1));i=new Blob([o],{type:n})}return new File([i],`icon_${Date.now()}.${a}`,{type:n})},[]),Io=n.useCallback(async e=>{var t;const o=v.startUpload($e||void 0,[e])[0];let r=0;const n=setInterval(()=>{r=Math.min(r+10+Math.floor(Date.now()%10),90),v.updateProgress(o,r)},200);try{const r=await y.uploadFileWithProvider(e,void 0,!0);if(clearInterval(n),v.updateProgress(o,100),r){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===r.id&&!e.isFolder))||r;v.markAsSuccess(o,e)}else v.markAsSuccess(o);await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())}catch(e){clearInterval(n);const t=e instanceof Error?e.message:String(e);throw v.markAsError(o,t),e}},[v,Ae,y,$e]),Fo=d(async e=>{if(Boolean(e&&e.startsWith("data:"))){const t=Co(e);if(!t)return;return void await Io(t)}e&&await Nt(e,void 0,void 0,"iconStock")},[Co,Nt,Io]),Ao=d(async()=>{const e=null==Q?void 0:Q.fileForEdit;if(uo.current===e)return;if($===ft&&e&&!nt.editingFile){uo.current=e;try{if("string"==typeof e){if(e.startsWith("data:"))return void(null==nt||nt.handleEdit({thumbnail:e,saveWithoutFolder:!0}));const t=await y.resolveFileForEditByUrl(e);uo.current===e&&(null==nt||nt.handleEdit(t))}}catch(t){uo.current===e&&(uo.current=null),console.error("Failed to open file in editor:",t),null==nt||nt.handlePixieEditorClose()}}},[null==Q?void 0:Q.fileForEdit,$,nt,y]);a(()=>{Ao()},[Ao]),a(()=>{var e,t,o,r;const n=bo.current;bo.current=$,$===at?(Qt([]),Gt(ss),to([]),Xt(It),co([]),lo(""),po(!1),ho(!1),n===at||n!==st&&n!==lt&&n!==ct||et("")):$===ct?null===(e=go.current)||void 0===e||e.focus():$===lt?null===(t=Jt.current)||void 0===t||t.focus():$===st?null===(o=oo.current)||void 0===o||o.focus():$===dt&&(null===(r=io.current)||void 0===r||r.focus())},[$,et]);const _o=n.useCallback(async()=>{var e;await zt(),await(null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts())},[zt]),So=d(e=>{var t;return e?(null===(t=e.files)||void 0===t?void 0:t.length)?Array.from(e.files):e.items?Array.from(e.items).map(e=>e.getAsFile()).filter(e=>Boolean(e)):[]:[]},[]);return t(o,{children:[te&&Ct===at&&be(e("div",{className:ta.dragCaptureLayer,"data-drag-capture":"true",onDragOver:e=>{var t,o;e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy"),(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&!ne.current&&ee(!0)},onDragEnter:e=>{var t,o;e.preventDefault(),e.stopPropagation(),(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&ee(!0)},onDragLeave:e=>{const t=e.relatedTarget;t&&document.documentElement.contains(t)||(ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging"))},onDrop:e=>{e.preventDefault(),e.stopPropagation(),oe(!1),ee(!1),document.body.removeAttribute("data-fm-dragging");const t=So(e.dataTransfer);t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error(e)}).finally(()=>mt(!1)))},"aria-hidden":"true"}),document.body),X&&be(e("div",{className:ta.dragOverlayGlobal,"data-drop-overlay":"true",onDragOver:e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")},onDragEnter:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.stopPropagation(),ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging");const t=So(e.dataTransfer);t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error(e)}).finally(()=>mt(!1)))},"aria-hidden":"true",children:t("div",{className:ta.dragOverlayInner,children:[e("div",{className:ta.uploadIcon,children:e(J,{})}),e("div",{className:ta.textTitle,children:C("Drop files here to upload")}),e("div",{className:ta.textDescription,children:C("Supported files:")+" .jpg, .jpeg, .svg, .png"})]})}),document.body),e(H,{className:"file-manager__layout",children:t("div",{className:ta.filesContainer,"data-files-container":"true",onDragOver:vt,onDragLeave:gt,onDragEnter:pt,onDrop:yt,children:[Y&&e("div",{className:ta.dragOverlay,children:t("div",{className:ta.dragOverlayInner,children:[e("div",{className:ta.uploadIcon,children:e(J,{})}),e("div",{className:ta.textTitle,children:C("Drop files here to upload")}),e("div",{className:ta.textDescription,children:C("Supported files:")+" .jpg, .jpeg, .svg, .png"})]})}),t(H,{className:"file-manager__content",children:[e(ns,{width:320,theme:"light",className:"file-manager-sider",children:e($a,{ref:ie,selectedFolder:$e||"folders",generateMenuItems:Ie,onFolderSelect:e=>null==Ge?void 0:Ge(e),folders:me||[],fetchFolders:ge,fetchChildFolders:ve,handleAddFile:Rt,setIsUrlModalVisible:e=>null==G?void 0:G(e),handleDeleteFolder:Mt,handleCreateFolder:ye,activeLibraryItem:$,setActiveLibraryItem:e=>null==K?void 0:K(e)})}),t(H,{className:"file-manager__main-content",children:[it&&e(ja,{style:{position:"absolute",width:"100%",height:"100%",top:0,left:0,zIndex:100,background:"var(--colorBgLayout)"}}),t(is,{className:"main-content",children:[e(Tl,{activeLibraryItem:$,selectedFolder:(null===(l=null==me?void 0:me.find(e=>(null==e?void 0:e.id)===$e))||void 0===l?void 0:l.name)||C("Folders"),isTrashFolder:"Trash"===$e,onClearTrash:At,files:Ae||[],loading:jt,onRefresh:rt,refreshDisabled:_e||pe,showRefresh:!(!(null===(s=null==_?void 0:_.apiEndpoints)||void 0===s?void 0:s.clearCache)&&!(null===(u=null==_?void 0:_.dataProviders)||void 0===u?void 0:u.clearCache))}),e(W,{className:"zero-divider"}),$===at&&e(Ea,{searchTerm:Ye,handleAddFile:Rt,files:Ae||[],handleSearch:et,sortBy:Ze,sortOrder:Xe,handleSortOptionChange:$t,pagination:Qe,setPagination:Wt,loading:jt,handleItemClick:Vt,onClearSelection:Ut.handleClearSelection,onRename:Ut.handleRename,onCopy:Ut.handleCopy,onMove:Ut.handleMove,onDelete:Ut.handleDeleteSelected,showRenameModal:Oe,showDeleteConfirm:qe,showCopyModal:h.actions.showCopyModal||(()=>{}),showMoveModal:Ue,onEdit:nt.handleEdit,getFileData:y.getFileData}),$===lt&&e(ql,{imageGifList:Kt,setImageGifList:Qt,currentReqGif:Ht,setCurrentReqGif:Gt,inputRef:Jt,customRequest:(e,t)=>Nt(e,void 0,t,"gif")}),$===st&&e(Hl,{imageStockList:eo,setImageStockList:to,currentReq:Zt,setCurrentReq:Xt,inputRef:oo,customRequest:(e,t)=>Nt(e,void 0,t,"imageStock")}),$===dt&&e(n.Suspense,{fallback:e("div",{style:{display:"flex",justifyContent:"center",padding:"48px 0"},children:e(U,{size:"large"})}),children:e(as,{customRequest:Fo,query:ro,setQuery:no,inputRef:io})}),$===ut&&e(n.Suspense,{fallback:e("div",{style:{display:"flex",justifyContent:"center",padding:"48px 0"},children:e(U,{size:"large"})}),children:e(ls,{customRequest:kt,state:yo,setState:wo})}),$===ct&&!!(null==Q?void 0:Q.sseQuery)&&e(os,{imageAiList:so,setImageAiList:co,aiImageRequest:ao,setAiImageRequest:lo,inputAiRef:go,customRequest:kt,isLoadingAi:fo,setIsLoadingAi:ho,isImageUploaded:mo,setIsImageUploaded:po}),$===ft&&e(o,{})]})]})]}),le&&!v.isUploadVisible&&e("div",{style:{position:"fixed",inset:0,zIndex:1500,backgroundColor:"rgba(255, 255, 255, 0.5)",pointerEvents:"all",display:"flex",alignItems:"center",justifyContent:"center"},children:e(U,{size:"large"})}),e(Wa,{isModalVisible:M,handleModalOk:we,handleModalCancel:Ce,form:R,selectedFolder:$e||null,folders:me||[],isUrlModalVisible:j,setIsUrlModalVisible:e=>null==G?void 0:G(e),handleAddFileByUrl:Nt,urlForm:N,isRenameModalVisible:Se,handleRenameOk:()=>null==Le?void 0:Le(),handleRenameCancel:()=>null==Te?void 0:Te(),renameForm:k,fileToRename:Ee,files:Ae||[],isMoveModalVisible:D,handleMoveOk:Et,handleMoveCancel:je,moveForm:O,selectedFiles:ue||new Set,isRenameFolderModalVisible:B,handleRenameFolderOk:_o,handleRenameFolderCancel:Dt,renameFolderForm:T,folderToRename:V,isCopyModalVisible:z,handleCopyOk:xt,handleCopyCancel:ze,copyForm:L,isDeleteConfirmVisible:q,handleDeleteConfirmOk:Ft,handleDeleteConfirmCancel:()=>null==We?void 0:We(),isClearTrashConfirmVisible:de,handleClearTrashConfirm:_t,handleClearTrashCancel:St,fetchChildFolders:ve}),e(ol,{visible:nt.isPixieEditorVisible,onClose:nt.handlePixieEditorClose,file:nt.editingFile,onSave:nt.handlePixieEditorSave,onSaveCopy:nt.handlePixieEditorSaveCopy}),e(Nl,{files:v.uploadFiles,visible:v.isUploadVisible,minimized:v.isUploadMinimized,totalFiles:v.totalFiles,completedFiles:v.completedFiles,onClose:v.closeUpload,onMinimize:v.minimizeUpload,onInsert:e=>{var t;const o=v.getUploadedFile(e.id)||e;null===(t=I.onEditorOk)||void 0===t||t.call(I,o)}})]})})]})},cs=h(({config:r={},onPathChange:i,onChangeSelection:l,onEditorOk:s,searchQuery:u="",sortBySize:f="name",apiEndpoints:h={},customIcons:m,dragDropIcon:p,dataProviders:g,handleNotify:v,handleError:y,handleSuccess:b})=>{const I=n.useMemo(()=>Object.assign({folderTreeLoading:"lazy",expandAllFoldersOnInit:!1,expandRootFolderOnInit:!1,iconStrokeWidth:1.4,availableImageExtensions:["jpg","jpeg","png","gif"],fileNameProcessing:Object.assign(Object.assign({},{transliterate:!0,replaceSpaces:!0,removeForbiddenChars:!0,toLowerCase:!0}),r.fileNameProcessing),folderNameProcessing:Object.assign(Object.assign({},{transliterate:!0,replaceSpaces:!0,removeForbiddenChars:!0,toLowerCase:!0}),r.folderNameProcessing)},r),[r]);n.useEffect(()=>{I.theme&&(e=>{if("system"===e){const t=matchMedia(vt).matches?pt:mt;e=e===gt?t:e}document.documentElement.setAttribute("data-theme",e)})(I.theme),rs(I)},[I]),a(()=>{I.locale&&I.locale!==Vo.language&&Vo.changeLanguage(I.locale),I.customLocale&&I.locale&&Vo.addResourceBundle(I.locale,"translation",I.customLocale,!0,!0)},[I.locale,I.customLocale]);const F=c(null),A=d(()=>{var e;return null!==(e=F.current)&&void 0!==e?e:document.body},[]),_=n.useMemo(()=>({apiEndpoints:h,searchQuery:u,sortBySize:f,onPathChange:i,onChangeSelection:l,onEditorOk:s,config:I,customIcons:m,dragDropIcon:p,dataProviders:g,handleNotify:v,handleError:y,handleSuccess:b,getModalContainer:A}),[h,u,f,i,l,s,I,m,p,g,v,y,b,A]);return e(C,{className:"em-filemanager",children:t(o,{children:[e(w,{getPopupContainer:()=>F.current||document.body,children:e(pn,{options:_,children:e(ds,{})})}),e("div",{ref:F,className:"file-manager-modal-root"})]})})});cs.displayName="FileManagerApp";const us=J.ErrorBoundary,fs=t=>{var o,r,n;return e(cr,{i18n:Vo,children:e(_t,{externalTheme:null!==(r=null===(o=t.config)||void 0===o?void 0:o.theme)&&void 0!==r?r:"light",customThemeToken:null===(n=t.config)||void 0===n?void 0:n.customTheme,children:e(us,{children:e(cs,Object.assign({},t))})})})},hs=new Map,ms=(t,o)=>{var r;let n;Pt();let i={};const a=e=>{const t=!e||"fileManager"!==e.mode&&"imageCenter"!==e.mode&&"plugin"!==e.mode?void 0:e.mode;return"imageCenter"===t?Et("imageCenter",e):Et(t)};if(t instanceof HTMLElement){n=t;i={config:a(o),apiEndpoints:null==o?void 0:o.apiEndpoints}}else{n=t.element;const e=a(t.config),o=Object.assign(Object.assign({},null===(r=t.config)||void 0===r?void 0:r.apiEndpoints),t.apiEndpoints);i={config:e,currentPath:t.currentPath,onPathChange:t.onPathChange,onChangeSelection:t.onChangeSelection,searchQuery:t.searchQuery,sortBySize:t.sortBySize,apiEndpoints:o,dataProviders:t.dataProviders,customIcons:t.customIcons,dragDropIcon:t.dragDropIcon,handleNotify:t.handleNotify,handleError:t.handleError,handleSuccess:t.handleSuccess}}const l=v(n);l.render(e(fs,Object.assign({},i))),hs.set(n.id||`container_${Date.now()}`,l)},ps=e=>{const t=e.id||Object.keys(hs).find(e=>e.startsWith("container_"));if(t&&hs.has(t)){const e=hs.get(t);null==e||e.unmount(),hs.delete(t)}else{console.warn("Couldn t find the root to unmount");try{v(e).unmount()}catch(e){console.error("Error unmounting the component:",e)}}},gs=new Map,vs=r=>{const{onClose:i,onSave:l,dataProviders:s,theme:u,locale:f,hasPagination:h,disablePagination:m,paginationAvailable:p,dedupeUploadNamesOnClient:g,saveCopyToCurrentFolder:v}=r,y=n.useMemo(()=>{var e,t;return{theme:null!=u?u:"light",locale:f,baseUrl:r.baseUrl,assetsUrl:r.assetsUrl,compressMaxSize:r.compressMaxSize,compressMaxWidthOrHeight:r.compressMaxWidthOrHeight,compessorUrl:null!==(e=r.compessorUrl)&&void 0!==e?e:r.compressorUrl,compressorUrl:null!==(t=r.compressorUrl)&&void 0!==t?t:r.compessorUrl,showNotifications:r.showNotifications,fetchWithProxy:r.fetchWithProxy,handleFileProxy:r.handleFileProxy,hasPagination:h,disablePagination:m,paginationAvailable:p,dedupeUploadNamesOnClient:g,saveCopyToCurrentFolder:v}},[u,f,r.baseUrl,r.assetsUrl,r.compressMaxSize,r.compressMaxWidthOrHeight,r.compessorUrl,r.compressorUrl,r.showNotifications,r.fetchWithProxy,r.handleFileProxy,h,m,p,g,v]),b=n.useCallback(async(e,t,o,r)=>{if(!e&&!t||!(null==s?void 0:s.getFiles))return null;try{const n=await s.getFiles({folderId:r?void 0:null!=o?o:void 0,noFolder:r,search:t||void 0,itemType:"file",page:1,limit:1}),[i]=n.files;return i?e&&i.id!==e?null:i:null}catch(e){return console.warn("Standalone Pixie: failed to resolve uploaded file from provider",e),null}},[s]),I=n.useMemo(()=>{if(r.file)return r.file;const e=r.name||"edited-image",t=r.extension||(r.type?r.type.split("/")[1]:"png"),o=r.type||`image/${t}`;return{thumbnail:r.imageDataUrl||"",name:e,id:void 0,type:o,extension:t,saveWithoutFolder:!0}},[r.file,r.imageDataUrl,r.name,r.extension,r.type]),F=n.useCallback(async(e,t)=>{if((null==s?void 0:s.updateFile)&&e.thumbnail)try{const o=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),r=Tt(o),n=e.name.substring(0,e.name.lastIndexOf("."))+"."+r,i=(null==t?void 0:t.blob)||Bt(e.thumbnail,o);return await s.updateFile(e.id,{name:n,type:o,data:i})}catch(e){return console.error("Error updating the file through updateFile:",e),null}return console.warn("DataProvider for updating files is not configured"),null},[s]),A=n.useCallback(async(e,t)=>{var o,r,n,i,a,l;if(!e.thumbnail)return null;try{const d=!0!==y.saveCopyToCurrentFolder||(null!==(o=e.saveWithoutFolder)&&void 0!==o?o:!e.id),c=d?"":e.folderId||"",u=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),f=(null==t?void 0:t.blob)||Bt(e.thumbnail,u),h=Yt(e.name,y),m=await Lr(s,h,c,d,Xt(y)),p=new File([f],m,{type:u,lastModified:Date.now()});if(null==s?void 0:s.uploadFiles){const t=await s.uploadFiles({items:[{name:p.name,size:p.size,type:p.type,folderId:c,noFolder:d,data:p,extension:Tt(u)}],folderId:c}),o=null===(r=t.detailed)||void 0===r?void 0:r[0];if(t.success&&(null==o?void 0:o.success)&&o.data){const t=o.data;if(t.url||t.thumbnailUrl||t.thumbnail)return{id:t.id||e.id||"",name:t.name||e.name,folderId:null!==(n=t.folderId)&&void 0!==n?n:c,type:t.type||p.type,size:null!==(i=t.size)&&void 0!==i?i:p.size,extension:t.extension||Tt(u),url:t.url,thumbnailUrl:t.thumbnailUrl,thumbnail:t.thumbnail,date:t.date,dimensions:t.dimensions,aspectRatio:t.aspectRatio,sourceUrl:t.sourceUrl,isFolder:!1,selected:!1};const r=await b(o.data.id,o.data.name||p.name,null!==(a=o.data.folderId)&&void 0!==a?a:c,d);return r||{id:o.data.id||e.id||"",name:o.data.name||e.name,folderId:null!==(l=o.data.folderId)&&void 0!==l?l:c,type:p.type,size:p.size,extension:Tt(u),url:o.data.url,thumbnailUrl:o.data.thumbnailUrl,thumbnail:o.data.thumbnail,isFolder:!1,selected:!1}}}return(null==s?void 0:s.uploadFile)?await s.uploadFile({name:p.name,size:p.size,type:p.type,folderId:c,noFolder:d,data:p,extension:Tt(u)}):null}catch(e){return console.error("Error saving file copy:",e),null}},[s,b,y]),_=n.useCallback(async(e,t)=>{if((null==s?void 0:s.updateFile)&&e.id&&e.thumbnail)try{const o=await F(e,t);o&&(e=o)}catch(e){console.error("Standalone Pixie: saveFileToServer error",e)}return l&&await l(e,t),i&&i(),e},[s,l,i,F]),S=n.useCallback(async(e,t)=>{let o=e;if(e.thumbnail)try{const r=await A(e,t);r&&(o=r)}catch(e){console.error("Standalone Pixie: saveFileCopyToServer error",e)}return l&&await l(o,t),i&&i(),o},[i,l,A]),E=c(null),x=d(()=>{var e;return null!==(e=E.current)&&void 0!==e?e:document.body},[]);return a(()=>{f&&f!==Vo.language&&Vo.changeLanguage(f)},[f]),e(C,{className:"em-filemanager",children:t(o,{children:[e(w,{getPopupContainer:()=>E.current||document.body,children:e(cr,{i18n:Vo,children:e(_t,{externalTheme:null!=u?u:"light",children:e(us,{children:e(pn,{options:{dataProviders:s,handleNotify:r.handleNotify,handleError:r.handleError,handleSuccess:r.handleSuccess,config:y,getModalContainer:x},children:e(ol,{visible:!0,onClose:i,file:I,onSave:_,onSaveCopy:S})})})})})}),e("div",{ref:E,className:"file-manager-modal-root"})]})})},ys=t=>{Pt();const o=t.element,r=v(o);r.render(e(vs,Object.assign({},t))),gs.set(o.id||`pixie_container_${Date.now()}`,r)},ws=e=>{const t=Array.from(gs.keys()).find(e=>e.startsWith("pixie_container_")),o=e.id||t;if(o&&gs.has(o)){const e=gs.get(o);null==e||e.unmount(),gs.delete(o)}else{console.warn("Couldn t find the root to unmount Pixie");try{v(e).unmount()}catch(e){console.error("Error unmounting Pixie:",e)}}},bs=e=>{var t,o;const{mode:r,element:n,fileManager:i,pixieEditor:a,theme:l,dataProviders:s}=e;let d,c;const u={unmount:()=>{d&&ps(d),c&&ws(c)},unmountFileManager:void 0,unmountPixieEditor:void 0};switch(r){case"fileManager":d=n,ms(n,Object.assign(Object.assign({},null==i?void 0:i.config),{theme:l||(null===(t=null==i?void 0:i.config)||void 0===t?void 0:t.theme),apiEndpoints:null==i?void 0:i.apiEndpoints})),u.unmountFileManager=()=>ps(d);break;case"pixieEditor":c=n,ys(Object.assign({element:n,theme:l||(null==a?void 0:a.theme),dataProviders:s||(null==a?void 0:a.dataProviders)},a)),u.unmountPixieEditor=()=>ws(c);break;case"both":{const e=document.createElement("div");e.id="file-manager-container",e.style.cssText="height: 50%; border-bottom: 1px solid #d9d9d9;";const t=document.createElement("div");t.id="pixie-editor-container",t.style.cssText="height: 50%;",n.appendChild(e),n.appendChild(t),d=e,c=t,ms(d,Object.assign(Object.assign({},null==i?void 0:i.config),{theme:l||(null===(o=null==i?void 0:i.config)||void 0===o?void 0:o.theme),apiEndpoints:null==i?void 0:i.apiEndpoints})),ys(Object.assign({element:c,theme:l||(null==a?void 0:a.theme),dataProviders:s||(null==a?void 0:a.dataProviders)},a)),u.unmountFileManager=()=>ps(d),u.unmountPixieEditor=()=>ws(c);break}}return u};function Cs(e,t="BackendError"){switch(e){case 400:return"ValidationError";case 401:return"AuthenticationFailed";case 403:return"AuthorizationFailed";case 404:return"FileNotFound";case 413:return"PayloadTooLarge";case 415:return"UnsupportedMediaType";case 429:return"RateLimitExceeded";case 500:return"BackendError";case 503:return"ServiceUnavailable";case 504:return"Timeout";default:return t}}const Is="";class Fs{constructor(){this.map=new Map}static childrenViewKey(e,t){return`v${Is}${e}${Is}${t}`}static childrenCountKey(e){return`c${Is}${e}`}getFreshError(e,t){const o=this.map.get(e);return o?t!==1/0&&Date.now()-o.updatedAt>t?(this.map.delete(e),null):o.error:null}setError(e,t){this.map.set(e,{error:t,updatedAt:Date.now()})}delete(e){this.map.delete(e)}clearChildrenViewErrorsForParent(e){const t=`v${Is}${e}${Is}`;for(const e of[...this.map.keys()])e.startsWith(t)&&this.map.delete(e)}clearAll(){this.map.clear()}}class As{constructor(){this.deletingIds=new Set}beginDeleting(e){for(const t of e)t&&this.deletingIds.add(t)}endDeleting(e){for(const t of e)t&&this.deletingIds.delete(t)}isDeleting(e){return!!e&&this.deletingIds.has(e)}}const _s=18e5;function Ss(e){return null==e||""===e?"":e}function Es(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function xs(e){if(!e)return null;const t=e.folderId;return null==t?null:String(t)}function Ps(e){return!!e&&!!e.isFolder}function Rs(){var e;if("function"==typeof(null===(e=null===globalThis||void 0===globalThis?void 0:globalThis.crypto)||void 0===e?void 0:e.randomUUID))return globalThis.crypto.randomUUID();try{const e=globalThis.crypto||globalThis.msCrypto;if(e&&"function"==typeof e.getRandomValues){const t=new Uint8Array(16);e.getRandomValues(t);let o="";for(let e=0;e<t.length;e++)o+=t[e].toString(16).padStart(2,"0");return`id_${o}`}}catch(e){}return`id_fallback_${Date.now().toString(36)}_${Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(36).slice(0,8)}`}function Ns(e){var t,o,r,n;if(!e||"object"!=typeof e)return!1;const i=e;return"path_folder_not_found"===i.code||"folder_not_found"===i.code||"FolderNotFound"===i.code||"path_folder_not_found"===(null===(t=i.data)||void 0===t?void 0:t.code)||"folder_not_found"===(null===(o=i.data)||void 0===o?void 0:o.code)||404===i.status||404===(null===(n=null===(r=i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status)}function ks(e){if(!e||"object"!=typeof e)return String(null!=e?e:"");const t=e,o=[],r={},n=["page","pageSize","sortBy","sortOrder","search","itemType","limit"];for(const e of Object.keys(t).sort()){const i=t[e];n.includes(e)?o.push(`${e}=${String(null!=i?i:"")}`):r[e]=i}const i=Object.keys(r).length?JSON.stringify(r):"",a=o.join("|"),l=i?function(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(36)}(i):"";return`${a}${l?`|${l}`:""}`}class Os{constructor(){this.entities=new Map,this.childrenByParent=new Map,this.maxCacheSize=1e4}now(){return Date.now()}checkCacheSize(){if(this.entities.size>this.maxCacheSize){const e=Array.from(this.entities.entries()).sort((e,t)=>e[1].updatedAt-t[1].updatedAt),t=Math.floor(.1*this.maxCacheSize);for(let o=0;o<t&&o<e.length;o++){const[t,r]=e[o];this.deleteEntityById(t)}}}getEntity(e){var t;return null===(t=this.entities.get(e))||void 0===t?void 0:t.value}getRecord(e){return this.entities.get(e)}getFileSystemItem(e){const t=this.getEntity(e);return t&&!Ps(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&Ps(t)?t:void 0}getChildrenIds(e,t={}){const o=Ss(e),r=this.childrenByParent.get(o);return r?t.onlyFileSystemItems?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}searchByUrl(e){for(const t of this.entities.values())if(t.value.url===e)return t.value;return null}upsertEntity(e){var t;const o=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=o?o.value:null,n=r?xs(r):null,i=xs(e),a=!!r&&Ps(r),l=Ps(e);let s;if(r&&Ps(r)&&l){const t=r.childrenCount,o=e.childrenCount;void 0!==t&&void 0===o&&(s=t)}if(r&&(n!==i||a!==l)){const t=Ss(n),o=this.childrenByParent.get(t);o&&(a?o.folders.delete(e.id):o.files.delete(e.id),0===o.files.size&&0===o.folders.size&&this.childrenByParent.delete(t))}let d=e;void 0!==s&&(d=Object.assign(Object.assign({},e),{childrenCount:s})),this.entities.set(e.id,{value:Object.assign({},d),updatedAt:this.now()}),this.checkCacheSize();const c=Ss(i);let u=this.childrenByParent.get(c);u||(u={files:new Set,folders:new Set},this.childrenByParent.set(c,u)),l?u.folders.add(e.id):u.files.add(e.id)}updateServerChildrenCount(e,t){if(null==e||null==t||Number.isNaN(t))return;const o=this.entities.get(e);if(!o||!Ps(o.value))return;const r=Object.assign(Object.assign({},o.value),{childrenCount:t});this.entities.set(e,{value:r,updatedAt:this.now()})}deleteEntityById(e){var t;const o=null!==(t=this.entities.get(e))&&void 0!==t?t:null;if(!o)return{entity:null,parentId:null};const r=o.value,n=xs(r),i=Ss(n),a=this.childrenByParent.get(i);return a&&(Ps(r)?a.folders.delete(e):a.files.delete(e),0===a.files.size&&0===a.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(e),{entity:Object.assign({},r),parentId:n}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!Ps(t.value))return{deletedFolderRecords:[],deletedFileSystemItemRecords:[]};const o=[{id:e,parentId:xs(t.value)}],r=[],n=[];for(;o.length;){const e=o.shift();r.push(e);const t=this.childrenByParent.get(Ss(e.id));if(t){for(const e of Array.from(t.folders)){const t=this.entities.get(e);t&&o.push({id:e,parentId:xs(t.value)})}for(const e of Array.from(t.files))n.push(e)}}const i=[];for(const e of n){const t=this.entities.get(e);if(!t)continue;const o=t.value,r=Ss(xs(o)),n=this.childrenByParent.get(r);n&&(n.files.delete(e),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(r)),this.entities.delete(e),i.push(Object.assign({},o))}const a=[];for(let e=r.length-1;e>=0;e--){const{id:t,parentId:o}=r[e],n=this.entities.get(t);if(!n)continue;const i=n.value,l=Ss(i.id);this.childrenByParent.delete(l);const s=Ss(o),d=this.childrenByParent.get(s);d&&(d.folders.delete(t),0===d.files.size&&0===d.folders.size&&this.childrenByParent.delete(s)),this.entities.delete(t),a.push(Object.assign({},i))}return{deletedFolderRecords:a,deletedFileSystemItemRecords:i}}moveEntityById(e,t){var o;const r=null!==(o=this.entities.get(e))&&void 0!==o?o:null;if(!r)return null;const n=r.value,i=Ss(xs(n)),a=this.childrenByParent.get(i);a&&(Ps(n)?a.folders.delete(e):a.files.delete(e),0===a.files.size&&0===a.folders.size&&this.childrenByParent.delete(i));const l=Object.assign(Object.assign({},n),{folderId:t});if(Ps(n)&&Ps(l)){const e=n.childrenCount;void 0!==e&&(l.childrenCount=e)}this.entities.set(e,{value:l,updatedAt:this.now()});const s=Ss(t);let d=this.childrenByParent.get(s);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(s,d)),Ps(l)?d.folders.add(e):d.files.add(e),Object.assign({},l)}copyFileSystemItem(e,t,o){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||Ps(n.value))return null;const i=n.value,a=Object.assign(Object.assign({},i),{id:t,folderId:o});return this.upsertEntity(a),Object.assign({},a)}copyFolderShallow(e,t,o){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||!Ps(n.value))return null;const i=n.value,a=Object.assign(Object.assign({},i),{id:t,folderId:o});return this.upsertEntity(a),Object.assign({},a)}isEntityStale(e,t){var o;const r=null!==(o=this.entities.get(e))&&void 0!==o?o:null;return!r||t!==1/0&&this.now()-r.updatedAt>t}touch(e,t){const o=this.entities.get(e);o&&(o.updatedAt=null!=t?t:this.now())}getEntitiesByIds(e){return e.map(e=>{var t,o;return null!==(o=null===(t=this.entities.get(e))||void 0===t?void 0:t.value)&&void 0!==o?o:null})}searchByName(e,t){var o,r,n,i,a;if(!e||""===e.trim())return[];const l=null==t?void 0:t.parentId,s=null!==(o=null==t?void 0:t.recursive)&&void 0!==o&&o,d=null!==(r=null==t?void 0:t.itemType)&&void 0!==r?r:"all",c=null!==(n=null==t?void 0:t.caseSensitive)&&void 0!==n&&n,u=null!==(i=null==t?void 0:t.limit)&&void 0!==i?i:1/0,f=c?e.trim():e.trim().toLowerCase(),h=[];let m=null;if(void 0!==l){m=new Set;const e=Ss(l);if(m.add(e),s){const t=[e],o=new Set;for(;t.length>0;){const e=t.shift();if(o.has(e))continue;o.add(e);const r=this.childrenByParent.get(e);if(r)for(const e of r.folders)m.add(e),t.push(e)}}}for(const[,e]of this.entities){if(h.length>=u)break;const t=e.value;if(null!==m){const e=Ss(xs(t));if(!m.has(e))continue}if("file"===d&&Ps(t))continue;if("folder"===d&&!Ps(t))continue;const o=null!==(a=t.name)&&void 0!==a?a:"";(c?o:o.toLowerCase()).includes(f)&&h.push(Object.assign({},t))}return h}toJSON(){return{entities:Array.from(this.entities.entries()),childrenByParent:Array.from(this.childrenByParent.entries()).map(([e,t])=>[e,{files:Array.from(t.files),folders:Array.from(t.folders)}])}}static fromJSON(e){var t,o;const r=new Os;for(const[o,n]of null!==(t=e.entities)&&void 0!==t?t:[])r.entities.set(o,{value:n.value,updatedAt:n.updatedAt});for(const[t,n]of null!==(o=e.childrenByParent)&&void 0!==o?o:[])r.childrenByParent.set(t,{files:new Set(n.files),folders:new Set(n.folders)});return r}}class Ts{constructor(e={},t=18e5,o,r,n=new Fs,i=Ns){var a,l,s,d,c;this.views=new Map,this.maxViewsPerParent=50,this.strategy={allowSortedInsert:null===(a=e.allowSortedInsert)||void 0===a||a,allowSearchInsert:null===(l=e.allowSearchInsert)||void 0===l||l,invalidateOnPaginationFull:null===(s=e.invalidateOnPaginationFull)||void 0===s||s,preloadPagesBefore:null!==(d=e.preloadPagesBefore)&&void 0!==d?d:0,preloadPagesAfter:null!==(c=e.preloadPagesAfter)&&void 0!==c?c:1,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=null!=o?o:t,this.entityTtl=null!=r?r:t,this.failedRequests=n,this.isFolderNotFoundError=i}setServerChildrenCountHandler(e){this.serverChildrenCountHandler=e}setChildrenCountInvalidator(e){this.childrenCountInvalidator=e}now(){return Date.now()}parentKey(e){return Ss(null!=e?e:null)}isExpired(e){return null==e||this.ttl!==1/0&&this.now()-e>this.ttl}areEntitiesStale(e,t){return!e||e.some(e=>!t.getEntity(e)||t.isEntityStale(e,this.entityTtl))}isEntityTypeCompatible(e,t){return!t||"all"===t||("file"===t&&!Ps(e)||!("folder"!==t||!Ps(e)))}cleanupOldViews(e){if(e.size<=this.maxViewsPerParent)return;const t=Array.from(e.entries()).sort((e,t)=>(t[1].view.updatedAt||0)-(e[1].view.updatedAt||0));for(;e.size>this.maxViewsPerParent&&t.length>0;){const[o]=t.pop();e.delete(o)}}async getOrCreateChildren(e,t,o,r){var n,i,a;const l=this.parentKey(e),s=ks(null!=t?t:{});let d=this.views.get(l);d||(d=new Map,this.views.set(l,d));const c=Fs.childrenViewKey(l,s);let u=d.get(s);if(!u){u={params:t,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:null}},d.set(s,u),this.cleanupOldViews(d)}const f=this.failedRequests.getFreshError(c,this.errorTtl);if(null!=f)throw f;if(u.view.value&&!this.isExpired(u.view.updatedAt)&&!this.areEntitiesStale(u.view.value,r)&&!(null===(n=u.view.meta)||void 0===n?void 0:n.stale)){const e=u.view.value.map(e=>r.getEntity(e)).filter(Boolean),t=(null===(i=u.params)||void 0===i?void 0:i.itemType)||"all",o=e.filter(e=>this.isEntityTypeCompatible(e,t));return Object.assign({items:o},null!==(a=u.view.meta)&&void 0!==a?a:{})}if(u.view.promise)return u.view.promise;const h=Rs();u.view.loadId=h;const m=(async()=>{var n,i,a,s;try{const d=await o(e,t),f=function(e){return!!e&&"string"==typeof e.search&&e.search.trim().length>0}(t),m=f?Object.assign(Object.assign({},d),{total:void 0}):d,p=null===(n=this.views.get(l))||void 0===n?void 0:n.get(ks(t));if(!p||p.view.loadId!==h){const e=new Error("StaleLoad");throw e.name="StaleLoad",e}for(const e of m.items)r.upsertEntity(e);u.view.value=m.items.map(e=>e.id);const{items:g}=m,v=Rn(m,["items"]),y=Object.assign({},v);u.view.meta=y,u.view.meta&&(u.view.meta.stale=!1),this.failedRequests.delete(c),u.view.updatedAt=this.now(),f||"number"!=typeof y.total||(this.serverChildrenCountHandler?this.serverChildrenCountHandler(null!=e?e:null,y.total,r):r.updateServerChildrenCount(e,y.total));const w=null!==(i=this.strategy.preloadPagesAfter)&&void 0!==i?i:0,b=null!==(a=this.strategy.preloadPagesBefore)&&void 0!==a?a:0,C=Es(null==t?void 0:t.pageSize),I=Number.isFinite(C);if((w>0||b>0)&&I){const n=e,i=Object.assign({},t),a="number"==typeof y.totalPages?y.totalPages:1,l=null!==(s=null==t?void 0:t.page)&&void 0!==s?s:1,d=C,c=o,u=h;setTimeout(()=>{this.preloadPagesAsync(n,i,l,a,d,w,b,r,y,c,u)},0)}return m}catch(e){if("StaleLoad"===(null==e?void 0:e.name))throw this.failedRequests.delete(c),u.view.value=void 0,u.view.updatedAt=this.now(),e;if(this.isFolderNotFoundError(e))return this.failedRequests.delete(c),u.view.value=[],u.view.meta={total:0,totalPages:0},u.view.updatedAt=this.now(),{items:[],total:0,totalPages:0};throw this.failedRequests.setError(c,e),u.view.value=void 0,u.view.updatedAt=this.now(),e}finally{u.view.promise=null}})();return u.view.promise=m,m}async preloadPagesAsync(e,t,o,r,n,i,a,l,s,d,c){try{const n=this.parentKey(e),s=this.views.get(n);if(!s)return;const u=s.get(ks(t));if(!u)return;if(null!=c&&u.view.loadId!==c)return;const f=s.get(ks(t));if(!(null==f?void 0:f.view.meta))return;const h="number"==typeof f.view.meta.totalPages?f.view.meta.totalPages:1;if(h!==r)return;const m=async o=>{const r=Object.assign(Object.assign({},t),{page:o});try{const i=await d(e,r),a=this.views.get(n);if(!a)return;const s=a.get(ks(t));if(!s)return;if(null!=c&&s.view.loadId!==c)return;if(s.view.loadId!==c)return;for(const e of i.items)l.upsertEntity(e);const u=ks(r);let f=a.get(u);if(!f){f={params:r,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:s.view.loadId}},a.set(u,f),this.cleanupOldViews(a)}if(!f.view.value||this.isExpired(f.view.updatedAt)){f.view.value=i.items.map(e=>e.id);const{items:e}=i,t=Rn(i,["items"]);f.view.meta=Object.assign(Object.assign({},t),{page:o,totalPages:h}),f.view.updatedAt=this.now()}}catch(e){console.debug("Preload failed silently:",e)}};if(i>0&&o<h)for(let e=1;e<=Math.min(i,h-o);e++){const r=o+e,n=ks(Object.assign(Object.assign({},t),{page:r})),i=s.get(n);(null==i?void 0:i.view.value)&&!this.isExpired(i.view.updatedAt)||m(r)}if(a>0&&o>1)for(let e=1;e<=Math.min(a,o-1);e++){const r=o-e,n=ks(Object.assign(Object.assign({},t),{page:r})),i=s.get(n);(null==i?void 0:i.view.value)&&!this.isExpired(i.view.updatedAt)||m(r)}}catch(e){console.debug("Preload process failed:",e)}}removeEmptyPageIfNeeded(e,t,o,r,n){if(t.view.value&&0===t.view.value.length&&o<r){const t=ks(Object.assign(Object.assign({},n),{page:o}));e.delete(t)}}updateTotalPagesForAllViews(e,t){for(const[,o]of e)o.view.meta&&(o.view.meta.totalPages=t)}isParamsSame(e,t){const o=Object.keys(null!=e?e:{}).filter(e=>"page"!==e).sort(),r=Object.keys(null!=t?t:{}).filter(e=>"page"!==e).sort();if(o.length!==r.length)return!1;for(let n=0;n<o.length;n++){const i=o[n];if(i!==r[n])return!1;if(e[i]!==t[i])return!1}return!0}syncTotalsInSameViews(e,t){var o,r,n;const i=t.view.meta;if(!i||"number"!=typeof i.total)return;const a=Number(i.total),l=Es(null===(o=t.params)||void 0===o?void 0:o.pageSize),s=Number.isFinite(l)&&l>0?Math.max(1,Math.ceil(a/l)):void 0;for(const[,o]of e)this.isParamsSame(null!==(r=o.params)&&void 0!==r?r:{},null!==(n=t.params)&&void 0!==n?n:{})&&(o.view.meta||(o.view.meta={}),o.view.meta.total=a,void 0!==s&&(o.view.meta.totalPages=s))}canSafelyModifySortedView(e){return!e.sortBy&&!e.sortOrder||!!this.strategy.comparator}cascadeShiftPages(e,t,o,r,n,i,a){var l,s,d;let c=t,u=o,f=!1;let h=0;for(;c.view.value&&c.view.value.length<r&&u<n&&h<100;){h++;const t=ks(Object.assign(Object.assign({},a),{page:u+1})),o=e.get(t);if(!(null==o?void 0:o.view.value)||this.isExpired(o.view.updatedAt)){c.view.meta=Object.assign(Object.assign({},null!==(l=c.view.meta)&&void 0!==l?l:{}),{stale:!0});break}const n=r-c.view.value.length,d=o.view.value.slice(0,n).filter(e=>i.getEntity(e));if(0===d.length){c.view.meta=Object.assign(Object.assign({},null!==(s=c.view.meta)&&void 0!==s?s:{}),{stale:!0});break}if(c.view.value=[...c.view.value,...d],c.view.updatedAt=Date.now(),o.view.value=o.view.value.slice(d.length),o.view.updatedAt=Date.now(),0===o.view.value.length){const t=u+1,r=o.view.meta;if(t<(r&&"number"==typeof r.totalPages?r.totalPages:1)){const o=ks(Object.assign(Object.assign({},a),{page:t}));e.delete(o),f=!0}break}c=o,u++}return(!c.view.value||c.view.value.length<r)&&u>=n&&(c.view.meta=Object.assign(Object.assign({},null!==(d=c.view.meta)&&void 0!==d?d:{}),{stale:!0})),f}cascadeShiftToNextPage(e,t,o,r,n,i,a){var l,s,d;if(!t.view.value||t.view.value.length<=r)return!1;if(o-(a.page||1)>=10)return t.view.meta=Object.assign(Object.assign({},null!==(l=t.view.meta)&&void 0!==l?l:{}),{stale:!0}),!1;const c=Object.assign(Object.assign({},a),{page:o+1}),u=ks(c);let f=e.get(u),h=!1;if(!(null==f?void 0:f.view.value)||this.isExpired(f.view.updatedAt)){if(!(o>=n))return t.view.meta=Object.assign(Object.assign({},null!==(s=t.view.meta)&&void 0!==s?s:{}),{stale:!0}),!1;{f={params:c,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:null}},e.set(u,f),this.cleanupOldViews(e);const r=t.view.meta;r&&(f.view.meta=Object.assign(Object.assign({},r),{page:o+1})),h=!0}}const m=t.view.value.slice(r).filter(e=>i.getEntity(e));if(0===m.length)return h&&e.delete(u),!1;t.view.value=t.view.value.slice(0,r),t.view.updatedAt=Date.now(),f.view.value=[...m,...null!==(d=f.view.value)&&void 0!==d?d:[]],f.view.updatedAt=Date.now();const p=f.view.meta&&"number"==typeof f.view.meta.totalPages?f.view.meta.totalPages:n;if(!h){if(this.cascadeShiftToNextPage(e,f,o+1,r,p,i,a))return!0}if(!f.view.value||0===f.view.value.length){const t=o+1,r=f.view.meta,n=r&&"number"==typeof r.totalPages?r.totalPages:1;this.removeEmptyPageIfNeeded(e,f,t,n,a)}return h}tryInsertSorted(e,t,o){var r;const n=this.strategy.comparator;if(!n)return!1;if(!e.view.value)return!1;const i=(null===(r=e.params)||void 0===r?void 0:r.itemType)||"all";if(!this.isEntityTypeCompatible(t,i))return!1;const a=e.view.value.map(e=>o.getEntity(e));if(a.some(e=>!e))return!1;let l=0,s=a.length;for(;l<s;){const o=Math.floor((l+s)/2),r=n(t,a[o],e.params);if("number"!=typeof r||Number.isNaN(r))return!1;r>=0?l=o+1:s=o}return e.view.value.includes(t.id)?(e.view.updatedAt=this.now(),!0):(e.view.value=[...e.view.value.slice(0,l),t.id,...e.view.value.slice(l)],e.view.updatedAt=this.now(),e.view.meta&&"number"==typeof e.view.meta.total&&(e.view.meta.total=Number(e.view.meta.total)+1),!0)}updateChildrenCountForOperation(e,t,o,r){var n,i,a,l;const s=xs(t);switch(e){case"delete":this.adjustChildrenCount(r,s,-1),null===(n=this.childrenCountInvalidator)||void 0===n||n.call(this,s);break;case"insert":case"copy":this.adjustChildrenCount(r,s,1),null===(i=this.childrenCountInvalidator)||void 0===i||i.call(this,s);break;case"move":this.adjustChildrenCount(r,null!=o?o:null,-1),this.adjustChildrenCount(r,s,1),null===(a=this.childrenCountInvalidator)||void 0===a||a.call(this,null!=o?o:null),null===(l=this.childrenCountInvalidator)||void 0===l||l.call(this,s)}}adjustChildrenCount(e,t,o){if(!t)return;const r=e.getFolder(t);if(r&&"number"==typeof r.childrenCount){const n=Math.max(0,r.childrenCount+o);e.updateServerChildrenCount(t,n)}}smartInvalidateChildrenViews(e,t,o,r,n,i){var a,l,s,d;if(!t)return;this.updateChildrenCountForOperation(o,t,n,r);const c=this.parentKey(e),u=this.views.get(c);if(u)for(const[,e]of u){const i=null!==(a=e.params)&&void 0!==a?a:{},c=null!==(l=null==i?void 0:i.page)&&void 0!==l?l:1,f=Es(null==i?void 0:i.pageSize),h=Number.isFinite(f),m=!(!(null==i?void 0:i.sortBy)&&!(null==i?void 0:i.sortOrder)),p=!!(null==i?void 0:i.search),g=(null==i?void 0:i.itemType)||"all";if(!this.isEntityTypeCompatible(t,g))continue;if(p&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,e.params)){(null===(s=e.view.value)||void 0===s?void 0:s.includes(t.id))&&(e.view.value=e.view.value.filter(e=>e!==t.id),e.view.meta&&"number"==typeof e.view.meta.total&&(e.view.meta.total=Math.max(0,e.view.meta.total-1)),e.view.updatedAt=Date.now());continue}if(!e.view.value){e.view.meta&&(e.view.meta.stale=!0),e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0);continue}e.view.value.includes(t.id);if(this.shouldInvalidateCompletely(e,o,t,m,h,c))e.view.meta=Object.assign(Object.assign({},null!==(d=e.view.meta)&&void 0!==d?d:{}),{stale:!0}),e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0);else switch(o){case"delete":this.handleDelete(u,e,c,f,h,t,r);break;case"insert":case"copy":this.handleInsert(u,e,c,f,h,m,t,r);break;case"update":this.handleUpdate(u,e,c,f,h,m,p,t,r);break;case"move":this.handleMove(u,e,c,f,h,m,t,n,r)}}}shouldInvalidateCompletely(e,t,o,r,n,i){return!(!(n&&i>1)||"insert"!==t&&"delete"!==t&&"move"!==t)||(!(!r||this.strategy.comparator||"insert"!==t&&"move"!==t)||!!this.isExpired(e.view.updatedAt))}tryReinsertEntity(e,t,o,r,n){var i,a;const l=(null===(i=e.params)||void 0===i?void 0:i.itemType)||"all";if(!this.isEntityTypeCompatible(t,l))return!1;if(this.strategy.comparator&&this.strategy.filterMatch){if(!this.strategy.filterMatch(t,e.params))return!1;if(this.tryInsertSorted(e,t,o))return!0}const s=null!==(a=e.params)&&void 0!==a?a:{};return!!(!s.sortBy&&!s.sortOrder||this.canSafelyModifySortedView(s))&&((!r||e.view.value.length<n)&&(e.view.value.push(t.id),!0))}handleDelete(e,t,o,r,n,i,a){var l;const s=t.view.value.includes(i.id);if(s&&(t.view.value=t.view.value.filter(e=>e!==i.id)),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(t.view.updatedAt=Date.now(),s&&n&&t.view.value.length<r&&a){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,a,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}handleInsert(e,t,o,r,n,i,a,l){var s,d,c,u;if(!t.view.value.includes(a.id)){if(i&&this.strategy.allowSortedInsert&&this.strategy.comparator&&l){if(this.tryInsertSorted(t,a,l)&&t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(n&&(null!==(d=null===(s=t.view.value)||void 0===s?void 0:s.length)&&void 0!==d?d:0)>r&&l){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftToNextPage(e,t,o,r,i,l,null!==(c=t.params)&&void 0!==c?c:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=t.view.meta.totalPages+1;t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}}else if(!n||t.view.value.length<r){if(t.view.value.push(a.id),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else t.view.meta=Object.assign(Object.assign({},null!==(u=t.view.meta)&&void 0!==u?u:{}),{stale:!0});t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleUpdate(e,t,o,r,n,i,a,l,s){var d,c,u,f;const h=t.view.value.includes(l.id),m=this.isEntityTypeCompatible(l,(null===(d=t.params)||void 0===d?void 0:d.itemType)||"all");if(h&&!m){if(t.view.value=t.view.value.filter(e=>e!==l.id),t.view.meta&&"number"==typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(c=t.params)&&void 0!==c?c:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}return t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h&&(i||a)){t.view.value=t.view.value.filter(e=>e!==l.id);if(this.tryReinsertEntity(t,l,s,n,r)){if(t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else{if(t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(u=t.params)&&void 0!==u?u:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}}return t.view.updatedAt=Date.now(),t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h)return t.view.updatedAt=Date.now(),t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0));if(m&&!a){if(i&&this.strategy.allowSortedInsert&&this.strategy.comparator&&s){if(this.tryInsertSorted(t,l,s)&&t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else if(!n||t.view.value.length<r){if(t.view.value.push(l.id),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else t.view.meta=Object.assign(Object.assign({},null!==(f=t.view.meta)&&void 0!==f?f:{}),{stale:!0});t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleMove(e,t,o,r,n,i,a,l,s){var d;if(t.view.value.includes(a.id)){if(t.view.value=t.view.value.filter(e=>e!==a.id),t.view.meta&&"number"==typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(d=t.params)&&void 0!==d?d:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}this.syncTotalsInSameViews(e,t)}t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}forceInvalidateChildrenViews(e){const t=this.parentKey(null!=e?e:null);this.failedRequests.clearChildrenViewErrorsForParent(t);const o=this.views.get(t);if(o)for(const[,e]of o)e.view.value=void 0,e.view.meta=void 0,e.view.promise=null,e.view.updatedAt=0,e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0)}getKnownTotal(e){var t,o;const r=this.parentKey(null!=e?e:null),n=this.views.get(r);if(!n)return;let i=null;for(const[,e]of n){const r=e.view.meta;r&&"number"==typeof r.total&&(!i||(null!==(t=e.view.updatedAt)&&void 0!==t?t:0)>i.updatedAt)&&(i={total:Number(r.total),updatedAt:null!==(o=e.view.updatedAt)&&void 0!==o?o:0})}return i?i.total:void 0}toJSON(){return{views:Array.from(this.views.entries()).map(([e,t])=>[e,Array.from(t.entries())]),ttl:this.ttl,errorTtl:this.errorTtl,entityTtl:this.entityTtl,strategy:{allowSortedInsert:this.strategy.allowSortedInsert,allowSearchInsert:this.strategy.allowSearchInsert,invalidateOnPaginationFull:this.strategy.invalidateOnPaginationFull,preloadPagesBefore:this.strategy.preloadPagesBefore,preloadPagesAfter:this.strategy.preloadPagesAfter}}}static fromJSON(e,t){var o,r,n,i,a,l;const s=null!==(r=null!==(o=null==t?void 0:t.ttl)&&void 0!==o?o:null==e?void 0:e.ttl)&&void 0!==r?r:_s,d=null!==(i=null!==(n=null==t?void 0:t.errorTtl)&&void 0!==n?n:null==e?void 0:e.errorTtl)&&void 0!==i?i:s,c=null!==(a=null==t?void 0:t.failedRequests)&&void 0!==a?a:new Fs,u=new Ts({},s,d,void 0,c,null==t?void 0:t.isFolderNotFoundError);for(const[t,o]of null!==(l=e.views)&&void 0!==l?l:[]){const e=new Map;for(const[t,r]of o){const o=r;(null==o?void 0:o.view)&&"error"in o.view&&delete o.view.error,e.set(t,o)}u.views.set(t,e)}return u}}class Ls{invalidateChildrenCountCache(e){const t=Ss(null!=e?e:"");this.childrenCountPromises.delete(t),this.failedRequests.delete(Fs.childrenCountKey(t))}constructor(e={},t=18e5,o,r){var n,i,a,l;this.childrenCountPromises=new Map,this.isFolderNotFoundError=null!==(n=null==r?void 0:r.isFolderNotFoundError)&&void 0!==n?n:Ns,this.failedRequests=new Fs,this.ttl=null!==(i=null==r?void 0:r.ttl)&&void 0!==i?i:t,this.errorTtl=null!==(l=null!==(a=null==r?void 0:r.errorTtl)&&void 0!==a?a:o)&&void 0!==l?l:this.ttl,this.entities=new Os,this.views=new Ts(e,this.ttl,this.errorTtl,void 0,this.failedRequests,this.isFolderNotFoundError),this.views.setServerChildrenCountHandler((e,t,o)=>{this.handleServerReportedChildrenCount(e,t,null!=o?o:this.entities)}),this.views.setChildrenCountInvalidator(e=>{this.invalidateChildrenCountCache(e)})}getEntity(e){var t;return null!==(t=this.entities.getEntity(e))&&void 0!==t?t:null}getFileSystemItem(e){var t;return null!==(t=this.entities.getFileSystemItem(e))&&void 0!==t?t:null}getFolder(e){var t;return null!==(t=this.entities.getFolder(e))&&void 0!==t?t:null}async getOrCreateChildren(e,t,o){return this.views.getOrCreateChildren(e,t,o,this.entities)}upsertEntity(e){const t=this.entities.getEntity(e.id),o=t?xs(t):null,r=xs(e),n=!!t&&Ps(t),i=Ps(e);if(this.entities.upsertEntity(e),t){if(o!==r||n!==i)return this.views.smartInvalidateChildrenViews(o,t,"delete",this.entities),void this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities);this.views.smartInvalidateChildrenViews(r,e,"update",this.entities,void 0,t)}else this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities)}isAncestor(e,t){let o=t;const r=new Set;for(;o&&!r.has(o);){r.add(o);if(Ss(o)===Ss(e))return!0;const t=this.entities.getEntity(o);if(!t)break;o=xs(t),null===o&&(o="")}return!1}moveEntity(e,t){const o=this.entities.getEntity(e);if(!o)return null;if(Ps(o)&&null!==t&&this.isAncestor(e,t))return null;const r=xs(o),n=this.entities.moveEntityById(e,t);return n?(this.views.smartInvalidateChildrenViews(r,o,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,n,"insert",this.entities),n):null}copyEntity(e,t,o,r){var n,i,a,l,s;const d=this.entities.getEntity(e);if(!d)return null;let c=null;if(Ps(d)){const o=[e],n=[];for(;o.length;){const e=o.shift();n.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const e of t)o.push(e)}const i=new Map;for(const e of n)i.set(e,Rs());for(const o of n){const n=this.entities.getFolder(o),s=i.get(o),d=xs(n),c=null===d?t:null!==(a=i.get(d))&&void 0!==a?a:null,u=Object.assign(Object.assign(Object.assign({},n),o===e?r:void 0),{id:s,folderId:null!==(l=o===e?null==r?void 0:r.folderId:void 0)&&void 0!==l?l:c});this.entities.upsertEntity(u)}for(const e of n){const t=i.get(e),o=this.entities.getChildrenIds(e,{onlyFileSystemItems:!0});for(const e of o){const o=this.entities.getFileSystemItem(e);if(!o)continue;const r=Rs(),n=Object.assign(Object.assign({},o),{id:r,folderId:t});this.entities.upsertEntity(n)}}c=null!==(s=this.entities.getEntity(i.get(e)))&&void 0!==s?s:null}else{const a=null!=o?o:Rs();if(c=this.entities.copyFileSystemItem(e,a,null!=t?t:null),c&&r){const e=Object.assign(Object.assign(Object.assign({},c),r),{id:a,folderId:null!==(i=null!==(n=r.folderId)&&void 0!==n?n:t)&&void 0!==i?i:null});this.entities.upsertEntity(e),c=e}}return c&&this.views.smartInvalidateChildrenViews(t,c,"copy",this.entities),c}searchByUrl(e){var t;return null!==(t=this.entities.searchByUrl(e))&&void 0!==t?t:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(Ps(t)){const{deletedFolderRecords:o,deletedFileSystemItemRecords:r}=this.entities.deleteFolderRecursive(e);for(const e of r)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of o)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of o)this.views.forceInvalidateChildrenViews(e.id);return t}{const{entity:t,parentId:o}=this.entities.deleteEntityById(e);return t&&this.views.smartInvalidateChildrenViews(o,t,"delete",this.entities),t}}deleteFolderRecursive(e){const{deletedFolderRecords:t,deletedFileSystemItemRecords:o}=this.entities.deleteFolderRecursive(e);for(const e of o)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of t)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of t)this.views.forceInvalidateChildrenViews(e.id);return{deletedFileSystemItemIds:o.map(e=>e.id),deletedFolderIds:t.map(e=>e.id)}}forceInvalidate(e){var t;const o=this.entities.getEntity(e);if(!o)return;const r=new Set;if(Ps(o)){const t=[e];for(;t.length;){const e=t.pop();if(r.has(e))continue;r.add(e),this.views.forceInvalidateChildrenViews(e),this.invalidateChildrenCountCache(e);const o=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const e of o)t.push(e)}}else{const e=null!==(t=o.folderId)&&void 0!==t?t:null;this.views.forceInvalidateChildrenViews(e),this.invalidateChildrenCountCache(e)}}getChildrenIds(e){return this.entities.getChildrenIds(e)}searchByName(e,t){return this.entities.searchByName(e,t)}async getChildrenCount(e="",t){const o=Ss(e),r=Fs.childrenCountKey(o),n=this.failedRequests.getFreshError(r,this.errorTtl);if(null!=n)return Promise.reject(n);const i=this.childrenCountPromises.get(o);if(i)return i;const a=(async()=>{try{const o=this.entities.getFolder(e);if(o&&"number"==typeof o.childrenCount)return this.failedRequests.delete(r),o.childrenCount;const n=this.views.getKnownTotal(e);if("number"==typeof n)return o&&this.handleServerReportedChildrenCount(e,n,this.entities),this.failedRequests.delete(r),n;if(t){const o=await t(e);return this.entities.getFolder(e)&&this.handleServerReportedChildrenCount(e,o,this.entities),this.failedRequests.delete(r),o}return this.failedRequests.delete(r),this.entities.getChildrenIds(e).length}catch(e){if(this.childrenCountPromises.delete(o),this.isFolderNotFoundError(e))return this.failedRequests.delete(r),0;throw this.failedRequests.setError(r,e),e}finally{this.childrenCountPromises.delete(o)}})();return this.childrenCountPromises.set(o,a),a}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t,o){var r,n,i,a,l,s,d,c,u,f,h;const m=null!==(n=null!==(r=null==o?void 0:o.ttl)&&void 0!==r?r:null==e?void 0:e.ttl)&&void 0!==n?n:_s,p=null!==(a=null!==(i=null==o?void 0:o.errorTtl)&&void 0!==i?i:null==e?void 0:e.errorTtl)&&void 0!==a?a:m,g=new Ls(null!=t?t:{},m,p,o),v=Os.fromJSON(null!==(l=null==e?void 0:e.entities)&&void 0!==l?l:{}),y=Ts.fromJSON(null!==(s=null==e?void 0:e.views)&&void 0!==s?s:{},{failedRequests:g.failedRequests,ttl:m,errorTtl:p,isFolderNotFoundError:null==o?void 0:o.isFolderNotFoundError});return t&&(y.strategy={allowSortedInsert:null===(d=t.allowSortedInsert)||void 0===d||d,allowSearchInsert:null===(c=t.allowSearchInsert)||void 0===c||c,invalidateOnPaginationFull:null===(u=t.invalidateOnPaginationFull)||void 0===u||u,preloadPagesBefore:null!==(f=t.preloadPagesBefore)&&void 0!==f?f:0,preloadPagesAfter:null!==(h=t.preloadPagesAfter)&&void 0!==h?h:1,comparator:t.comparator,filterMatch:t.filterMatch}),g.entities=v,g.views=y,y.setServerChildrenCountHandler((e,t,o)=>{g.handleServerReportedChildrenCount(e,t,null!=o?o:v)}),y.setChildrenCountInvalidator(e=>{g.invalidateChildrenCountCache(e)}),g}handleServerReportedChildrenCount(e,t,o){this.checkAndResolveChildrenCountConflict(e,t,o),this.invalidateChildrenCountCache(e)}checkAndResolveChildrenCountConflict(e,t,o){if(!o||void 0===t)return;const r=null!=e?e:null;if(!r)return void o.updateServerChildrenCount(r,t);const n=o.getFolder(r),i=null==n?void 0:n.childrenCount;void 0!==i&&i!==t&&(console.warn(`Conflict: folder "${r}" has childrenCount=${i} but server says total=${t}`),this.views.forceInvalidateChildrenViews(r)),o.updateServerChildrenCount(r,t)}}function Ms(e,t){const o=null!=e?e:{},r=Array.isArray(o.detailed)?o.detailed.map(e=>{var o;return{requestId:null!==(o=e.requestId)&&void 0!==o?o:e.id,success:!!e.success,data:t(e.data),error:e.error}}):void 0;return{success:!!o.success,error:o.error,detailed:r}}function Us(e){return null==e?"":String(e)}function js(e){return Object.assign(Object.assign({},e),{name:Us(e.name)})}function Ds(e){return e&&"object"==typeof e&&"name"in e?Object.assign(Object.assign({},e),{name:Us(e.name)}):e}class Bs{async _findOrCreateFolderByPath(e){const t=(o=e)?o.replaceAll("\\","/").split("/").filter(Boolean):[];var o;if(t.length>10){const e="Path depth exceeds maximum limit of %s".replace("%s",String(10));throw new Jn(e,"ValidationError")}let r;for(const o of t){const{files:t}=await this.getFiles({folderId:(null==r?void 0:r.id)||"",itemType:"folder"}),n=t.find(e=>e.name===o);if(n){if(!n.isFolder){const t="Path component '%s' in '%s' is not a folder".replace("%s",o).replace("%s",e);throw new Jn(t,"ValidationError")}r={id:n.id,name:n.name,parentId:n.folderId}}else{if("function"!=typeof this._dataProvider.createFolder)throw new Jn("Create folder operation is not supported by data provider","UnsupportedOperation");r=await this.createFolder({name:o,parentId:null==r?void 0:r.id})}}return r}getTrashFolder(){return this._findOrCreateFolderByPath(this._pathOptions.trashPath||"Trash")}getTempFolder(){return this._findOrCreateFolderByPath(this._pathOptions.tempPath||"Edited")}constructor(e,t={},o,r={}){var n,i;this._dataProvider=e,this._options=t,this._pathOptions=o,this._blobFetchForceReloadOnceIds=new Set,this._mutationRegistry=new As,this._mapItem=async e=>{var{childrenCount:t}=e;const o=js(Rn(e,["childrenCount"]));if(o.isFolder)return Object.assign(Object.assign({},o),{childCount:t,url:"",thumbnailUrl:""});const[r,n]=await Promise.all([this._getUrl(o),this._getThumbnailUrl(o)]);return Object.assign(Object.assign({},o),{childCount:0,url:r,thumbnailUrl:n})},this._config=r,this._useSoftDelete=this._pathOptions.useSoftDelete,this._rootId=this._pathOptions.rootId||"",this._enableTrash=void 0===this._options.enableTrash||this._options.enableTrash,this._validateDuplicates=this._dataProvider.validateDuplicates,this._cache=new Ls(t.cacheStrategy||{},null===(n=t.cacheStrategy)||void 0===n?void 0:n.ttl,null===(i=t.cacheStrategy)||void 0===i?void 0:i.errorTtl),this.setController({invalidateItemCache:e=>{this._cache.forceInvalidate(e)},getCachedItem:e=>this._cache.getEntity(e)}),"function"!=typeof this._dataProvider.clearCache&&(this.clearCache=void 0);const a=Object.getPrototypeOf(this);for(const e of Object.getOwnPropertyNames(a)){const t=Object.getOwnPropertyDescriptor(a,e);"constructor"!==e&&"function"==typeof(null==t?void 0:t.value)&&(this[e]=t.value.bind(this))}}setController(e){"function"==typeof this._dataProvider.setController&&this._dataProvider.setController(e)}async clearCache(e){if("function"!=typeof this._dataProvider.clearCache)throw new Jn("Clear cache is not supported by data provider","UnsupportedOperation");this._cache.forceInvalidate(this._rootId),await this._dataProvider.clearCache(e)}markNextFileBlobFetchBypassHttpCache(e){this._blobFetchForceReloadOnceIds.add(this.normalizeId(e))}normalizeId(e){return e?"root"===e||"folders"===e?this._rootId:e:this._rootId}_isDeletingId(e){return this._mutationRegistry.isDeleting(this.normalizeId(e))}_collectDeletingIds(e){const t=this.normalizeId(e),o=new Set([t]),r=this._cache.getEntity(t);if(!(null==r?void 0:r.isFolder))return Array.from(o);const n=[t];for(;n.length>0;){const e=n.pop(),t=this._cache.getChildrenIds(e);for(const e of t){if(o.has(e))continue;o.add(e);const t=this._cache.getEntity(e);(null==t?void 0:t.isFolder)&&n.push(e)}}return Array.from(o)}_emptyFilesResult(e,t){return{files:[],pagination:Object.assign(Object.assign(Object.assign({},"number"==typeof e?{page:e}:{}),"number"==typeof t?{limit:t}:{}),{total:0,totalPages:1,hasNext:!1,hasPrev:!1})}}_validateName(e,t=!1){if(!e||0===e.trim().length){throw new Jn(t?"Folder name cannot be empty":"File name cannot be empty",t?"FolderInvalidName":"FileInvalidName")}if(/[\/\\:*?"<>|]/.test(e)){const o=t?"FolderInvalidName":"FileInvalidName",r=t?"Folder name contains invalid characters: %s".replace("%s",e):"File name contains invalid characters: %s".replace("%s",e);throw new Jn(r,o)}}_validateTargetFolderType(e){const t=this.normalizeId(e);if(t===this._rootId)return;const o=this._cache.getEntity(t);if(o&&!o.isFolder){const t="Target item with id '%s' is not a folder".replace("%s",e);throw new Jn(t,"ValidationError")}}_checkNameExistsInCache(e,t,o,r){const n=this.normalizeId(e),i=this._cache.getChildrenIds(n);for(const e of i){const n=this._cache.getEntity(e);if(n&&n.name===t&&!!n.isFolder===o&&(!r||n.id!==r))return!0}return!1}async _getUrl(e){var t;if(e.url)return e.url;try{return"function"==typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getUrl)&&this._dataProvider.getUrl(e)||""}catch(e){console.log(e)}return""}async _getThumbnailUrl(e){var t;if(e.thumbnailUrl)return e.thumbnailUrl;try{return"function"==typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getThumbnailUrl)&&this._dataProvider.getThumbnailUrl(e)||""}catch(e){console.log(e)}return""}_isAncestor(e,t){if(!t)return!1;const o=this.normalizeId(t),r=this.normalizeId(e);if(o===r)return!0;let n=this._cache.getEntity(o);const i=new Set;for(;n&&n.folderId&&!i.has(n.id);){i.add(n.id);const e=this.normalizeId(n.folderId);if(e===r)return!0;if(n=this._cache.getEntity(e),!n||!n.isFolder)break}return!1}async getFile(e,t){return this._isDeletingId(e)?null:this._cache.searchByName(t,{parentId:this.normalizeId(e),caseSensitive:!0,recursive:!1,itemType:"file"})[0]||(await this.getFiles({folderId:e,itemType:"file",search:t})).files[0]}async getFileById(e){const t=this.normalizeId(e);if(this._isDeletingId(t))return null;const o=this._cache.getFileSystemItem(t);if(o&&!o.isFolder)return await this._mapItem(o);if(!this._dataProvider.pathMode)return null;const r=await this._getFileByPathStyleId(t);if(r&&!r.isFolder){const e=js(r);return this._cache.upsertEntity(e),await this._mapItem(e)}return null}async _getFileByPathStyleId(e){const t=e.replace(/\\/g,"/").replace(/^\/+/,""),o=t.lastIndexOf("/"),r=o<0?"":t.slice(0,o),n=o<0?t:t.slice(o+1);return n?this.getFile(r,n):null}async getFileUrl(e,t){const o=await this.getFile(e,t);return await this._getUrl(o)||await this._getThumbnailUrl(o)||o.thumbnail}async getFiles({folderId:e,search:t,sortBy:o,sortOrder:r,page:n,limit:i,itemType:a="all",noFolder:l=!1}){var s,d;l&&(e=null===(s=await this.getTempFolder())||void 0===s?void 0:s.id);const c=this.normalizeId(null!=e?e:this._rootId),u=!1===this._options.enablePagination,f=u?1:n,h=u?1e4:i,m=this._options.clientSideFilter,p=this._options.clientSideSorting,g=this._options.clientSidePaging,v=g?Math.max(1,null!=n?n:1):void 0,y=g?"number"==typeof i&&Number.isFinite(i)&&i>0?i:25:void 0,w=this._emptyFilesResult(g?v:f,g?y:h);if(this._isDeletingId(c))return w;const b=!1!==this._options.unifiedCatalogFetch&&u&&("folder"===a||"file"===a),C=b?"all":a,I={};m||(I.search=t),p||(I.sortBy=null!=o?o:"folder"!==C?"date":void 0,I.sortOrder=null!=r?r:"folder"!==C?"desc":void 0),g||(I.page=f,I.limit=b?1e4:h);const F=b?1e4:g?void 0:h,A={folderId:c,itemType:C,search:m?void 0:t,sortBy:p?void 0:I.sortBy,sortOrder:p?void 0:I.sortOrder,page:g?void 0:f,pageSize:F};let _;try{_=await this._cache.getOrCreateChildren(c,A,async(e,t)=>{var o;const r=t.pageSize,n=null!=r&&Number.isFinite(Number(r))?Number(r):1e4,i=await this._dataProvider.getItems(Object.assign(Object.assign({},t),{folderId:e,limit:n})),a=function(e){return(null!=e?e:[]).map(js)}(i.items);return g?{items:a,total:"number"==typeof(null===(o=i.pagination)||void 0===o?void 0:o.total)?i.pagination.total:a.length}:Object.assign({items:a},i.pagination)})}catch(e){if(this._isDeletingId(c))return w;throw e}let S,E=_.items;if(b&&("folder"===a?E=E.filter(e=>e.isFolder):"file"===a&&(E=E.filter(e=>!e.isFolder))),m)if("function"==typeof this._options.clientSideFilter)E=this._options.clientSideFilter(E,t);else if(t){const e=t.toLowerCase();E=E.filter(t=>{var o;return null===(o=t.name)||void 0===o?void 0:o.toLowerCase().includes(e)})}p&&(E="function"==typeof this._options.clientSideSorting?this._options.clientSideSorting(E,o,r):this._defaultClientSideSort(E,o,r)),S=g||m||b?E.length:null!==(d=_.total)&&void 0!==d?d:E.length;let x=E;if(g)if("function"==typeof this._options.clientSidePaging)x=this._options.clientSidePaging(E,v,y);else{const e=(v-1)*y,t=e+y;x=E.slice(e,t)}if("function"==typeof this._dataProvider.getUrl||"function"==typeof this._dataProvider.getThumbnailUrl){const e=x.map(async e=>{if(e.isFolder)return e;const[t,o]=await Promise.all([e.url?Promise.resolve(e.url):"function"==typeof this._dataProvider.getUrl?this._dataProvider.getUrl(e):Promise.resolve(void 0),e.thumbnailUrl?Promise.resolve(e.thumbnailUrl):"function"==typeof this._dataProvider.getThumbnailUrl?this._dataProvider.getThumbnailUrl(e):Promise.resolve(void 0)]);return Object.assign(Object.assign({},e),{url:t,thumbnailUrl:o})});x=await Promise.all(e)}const P=g?{page:v,limit:y,total:S,totalPages:Math.max(1,Math.ceil(S/y)),hasNext:v*y<S,hasPrev:v>1}:Object.assign(Object.assign({page:f,limit:h,total:S},!g&&_.totalPages&&{totalPages:_.totalPages}),!g&&_.hasNextPage&&{hasNextPage:_.hasNextPage});return{files:await Promise.all(x.map(this._mapItem)),pagination:P}}_defaultClientSideSort(e,t,o){return e.sort((e,r)=>{let n=0;switch(t){case"name":default:n=(e.name||"").localeCompare(r.name||"");break;case"date":n=new Date(e.date||0).getTime()-new Date(r.date||0).getTime();break;case"size":n=(Number(e.size)||0)-(Number(r.size)||0)}return"desc"===o?-n:n})}async getFileData(e,t){var o;const r=this.normalizeId("string"==typeof e?e:e.id);let n=t;this._blobFetchForceReloadOnceIds.delete(r)&&(n=Object.assign(Object.assign({},t),{forceReload:!0}));const i=this._cache.getEntity(r)||("string"==typeof e?{id:r,name:"",folderId:this._rootId,isFolder:!1}:Object.assign(Object.assign({},e),{childrenCount:e.childCount}));if("function"==typeof this._dataProvider.getFileData)return await this._dataProvider.getFileData(i,n);if(!i.url&&"function"!=typeof this._dataProvider.getUrl)throw new Jn("Cannot read file","FileReadError");const a=i.url||("function"==typeof this._dataProvider.getUrl?await this._dataProvider.getUrl(i):"");if(a){const e=null!==(o=this._config.fetchWithProxy)&&void 0!==o?o:fetch;return(await e(a,(null==n?void 0:n.forceReload)?{cache:"no-store"}:void 0)).blob()}throw new Jn("Unable to get file data","FileReadError")}async findFileByUrl(e){const t=this._cache.searchByUrl(e);if(t)return t;if("function"==typeof this._dataProvider.findFileByUrl)try{const t=await this._dataProvider.findFileByUrl(e);if(t){const e=js(t);return this._cache.upsertEntity(e),e}}catch(e){console.log(e)}return null}async getChildrenCount(e){if(!e)return 0;const t=this.normalizeId(null!=e?e:this._rootId);return this._isDeletingId(t)?0:this._cache.getChildrenCount(t,async()=>{var e;try{if(this._options.clientSidePaging){const o=await this.getFiles({folderId:t,itemType:"all",page:1,limit:25});return null!==(e=o.pagination.total)&&void 0!==e?e:o.files.length}const o=await this._dataProvider.getItems({folderId:t,limit:0,itemType:"all"});return void 0!==o.pagination?o.pagination.total||0:!1===this._options.enablePagination?o.items.length:0}catch(e){if(this._isDeletingId(t))return 0;if(this._isPathFolderNotFoundError(e))return 0;throw e}})}_isPathFolderNotFoundError(e){var t,o,r;if(!e||"object"!=typeof e)return!1;const n=e;return"path_folder_not_found"===n.code||"path_folder_not_found"===(null===(t=n.data)||void 0===t?void 0:t.code)||404===n.status||404===(null===(r=null===(o=n.data)||void 0===o?void 0:o.data)||void 0===r?void 0:r.status)}async _uploadFile(e){var t;const o=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);if("function"!=typeof this._dataProvider.uploadFile)throw new Jn("Upload file operation is not supported by data provider","UnsupportedOperation");if(this._validateName(e.name,!1),this._validateDuplicates){if(this._checkNameExistsInCache(o,e.name,!1)){const t="File '%s' already exists in target folder".replace("%s",e.name);throw new Jn(t,"FileAlreadyExists")}}const r=await this._dataProvider.uploadFile(Object.assign(Object.assign({},e),{folderId:o})),n=js(Object.assign(Object.assign({name:e.name,size:e.size},r),{folderId:o}));return this._cache.upsertEntity(n),n}async uploadFiles(e){var t,o,r,n,i;const a=e.items.some(e=>e.noFolder)?await this.getTempFolder():null;e=Object.assign(Object.assign({},e),{items:null===(t=e.items)||void 0===t?void 0:t.map(e=>Object.assign(Object.assign({},e),{folderId:e.noFolder?null==a?void 0:a.id:e.folderId}))});for(const t of e.items)t.folderId&&(e.folderId=t.folderId);const l=e.items||[],s=null!==(o=e.folderId)&&void 0!==o?o:this._rootId,d=this.normalizeId(s);if(this._validateDuplicates)for(const e of l)if(e.name){this._validateName(e.name,!1);const t=this.normalizeId(null!==(r=e.folderId)&&void 0!==r?r:d);if(this._checkNameExistsInCache(t,e.name,!1)){const t="File '%s' already exists in target folder".replace("%s",e.name);throw new Jn(t,"FileAlreadyExists")}}const c=this._cache.getEntity(d);let u={detailed:new Array(l.length),success:!0};if("function"==typeof this._dataProvider.uploadFiles){const e=l.map(e=>{var t;return Object.assign(Object.assign({},e),{folderId:this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:d)})});if(u=Ms(await this._dataProvider.uploadFiles({folderId:d,items:e}),e=>{if(e)return{id:e.id,name:Us(e.name),folderId:e.folderId}}),u.detailed&&u.detailed.length){for(let e=0;e<u.detailed.length;e++){const t=u.detailed[e];if(t&&t.success){const e=t.data,o=null!==(n=null==e?void 0:e.id)&&void 0!==n?n:t.requestId,r=js(Object.assign(Object.assign(Object.assign({},c),e),{folderId:null!==(i=null==e?void 0:e.folderId)&&void 0!==i?i:d}));this._cache.upsertEntity(r),t.requestId=o}}void 0===u.success&&(u.success=!u.detailed.some(e=>!e.success))}else u.success=!u.error&&!!u.success}else{if("function"!=typeof this._dataProvider.uploadFile)throw new Jn("Upload files is not supported by data provider","UnsupportedOperation");u.detailed=await Promise.all(l.map(async e=>{var t;const o=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:d);try{const t=await this._uploadFile(Object.assign(Object.assign({},e),{folderId:o}));return{requestId:t.id,data:t,success:!0}}catch(t){return{requestId:null==e?void 0:e.id,success:!1,error:t}}})),u.success=!u.detailed.some(e=>!e.success)}if(u.success&&this._enableTrash)try{this._cache.forceInvalidate(d)}catch(e){}return u}async deleteFile(e){const t=this.normalizeId(e),o=[t];this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash){const e=await this.getTrashFolder();return await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!1})}return await this.hardDeleteItem(t)}finally{this._mutationRegistry.endDeleting(o)}}async deleteItems(e,t){const o=Array.from(new Set(e.flatMap(e=>this._collectDeletingIds(this.normalizeId(e)))));this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash&&!0!==t.permanent){const t=await this.getTrashFolder();return await this.moveItems(t.id,e)}return await this.hardDeleteItems(e,t)}finally{this._mutationRegistry.endDeleting(o)}}async hardDeleteItems(e,t){let o={success:!0,detailed:[]};const r=t.permanent?null:await this.getTrashFolder();if("function"==typeof this._dataProvider.deleteItems){if(o=Ms(await this._dataProvider.deleteItems(e.map(e=>this._cache.getEntity(e)),t),e=>e),o.success){const t=o.detailed||e.map(e=>({requestId:e,success:!0,error:void 0}));for(const e of t)e.success&&(r?this._cache.moveEntity(e.requestId,r.id):this._cache.deleteEntity(e.requestId))}}else"function"==typeof this._dataProvider.deleteItem&&(o.detailed=await Promise.all(e.map(async e=>{const o=this._cache.getEntity(e);if(!o){const t="FileNotFound",o="Item with id '%s' not found".replace("%s",e);return{requestId:e,success:!1,error:new Jn(o,t)}}try{return await this._dataProvider.deleteItem(o,t),r?this._cache.moveEntity(e,r.id):this._cache.deleteEntity(e),{requestId:e,success:!0}}catch(t){return{requestId:e,error:t,success:!1}}})),o.success=!o.detailed.some(e=>!e.success));if(o.success&&r)try{this._cache.forceInvalidate(r.id)}catch(e){}return o}async hardDeleteItem(e){const t=this._cache.getEntity(e);if(!t){const t="Item with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}if("function"!=typeof this._dataProvider.deleteItem)throw new Jn("Delete item operation is not supported by data provider","DeleteNotAllowed");if(await this._dataProvider.deleteItem(t,{permanent:!0}),this._cache.deleteEntity(e),this._enableTrash)try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(e){}return!0}async cleanTrash(){if(!this._enableTrash)throw new Jn("Trash is not enabled","UnsupportedOperation");if("function"==typeof this._dataProvider.cleanTrash){const e=await this._dataProvider.cleanTrash();try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(e){}return e}throw new Jn("Clean trash is not supported by data provider","UnsupportedOperation")}async createFolder({name:e,parentId:t,is_force_create:o}){const r=this.normalizeId(null!=t?t:this._rootId);if(this._validateName(e,!0),this._validateDuplicates){if(this._checkNameExistsInCache(r,e,!0)){const t="Folder '%s' already exists in parent folder".replace("%s",e);throw new Jn(t,"FolderAlreadyExists")}}const n=await this._dataProvider.createFolder(e,r,o),i=js({id:n.id,folderId:r,name:n.name,isFolder:!0,childrenCount:n.childrenCount});return this._cache.upsertEntity(i),Object.assign(Object.assign({},n),{name:i.name})}async deleteFolder(e){const t=this.normalizeId(e),o=this._collectDeletingIds(t);this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash)try{const e=await this.getTrashFolder();return!!await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!0})&&(this._cache.deleteFolderRecursive(t),!0)}catch(e){return console.error("Error moving folder to trash:",e),await this.hardDeleteItem(t)}return await this.hardDeleteItem(t)}finally{this._mutationRegistry.endDeleting(o)}}async renameFolder(e,t){if("function"!=typeof this._dataProvider.renameItem)throw new Jn("Rename folder is not supported","RenameNotAllowed");const o=this.normalizeId(e),r=this._cache.getEntity(o);if(!r){const t="Folder with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FolderNotFound")}if(this._validateName(t,!0),this._validateDuplicates){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t,!0,o)){const e="Folder '%s' already exists in parent folder".replace("%s",t);throw new Jn(e,"FolderAlreadyExists")}}const n=Ds(await this._dataProvider.renameItem(r,t));return this._cache.upsertEntity(js(Object.assign(Object.assign({},this._cache.getEntity(n.id)),n))),this._cache.getEntity(n.id)}async renameFile(e,t){if("function"!=typeof this._dataProvider.renameItem)throw new Jn("Rename file is not supported","RenameNotAllowed");const o=this._cache.getEntity(e);if(!o){const t="File with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}const r=this.normalizeId(e);if(this._validateName(t,!1),this._validateDuplicates){const e=this.normalizeId(o.folderId);if(this._checkNameExistsInCache(e,t,!1,r)){const e="File '%s' already exists in parent folder".replace("%s",t);throw new Jn(e,"FileAlreadyExists")}}const n=Ds(await this._dataProvider.renameItem(o,t));return n&&this._cache.upsertEntity(js(Object.assign(Object.assign({},this._cache.getEntity(r)),n))),this._cache.getEntity(r)}async moveItem({itemId:e,targetFolderId:t,isFolder:o}){if("function"!=typeof this._dataProvider.moveItem)throw new Jn("Move item operation is not supported by data provider","MoveNotAllowed");const r=this.normalizeId(t);this._validateTargetFolderType(t);const n=this._cache.getEntity(e);if(!n){const t=Ds(await this._dataProvider.moveItem({id:e,folderId:r,isFolder:o},r));if(t.id===e)this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:r})));else{try{this._cache.deleteEntity(e)}catch(e){}this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:r})))}return!0}if(n.isFolder){if(e===r)throw new Jn("Cannot move folder into itself","MoveIntoSelf");if(this._isAncestor(e,r))throw new Jn("Cannot move folder into its descendant","MoveIntoDescendant")}if(this._validateDuplicates){if(r!==this.normalizeId(n.folderId)&&n.name){if(this._checkNameExistsInCache(r,n.name,!!n.isFolder,e)){const e=n.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${n.isFolder?"Folder":"File"} '${n.name}' already exists in target folder`,e)}}}const i=Ds(await this._dataProvider.moveItem(n,r));if(i.id===e){const t=this._cache.moveEntity(e,r);return this._cache.upsertEntity(js(Object.assign(Object.assign({},t),i))),!0}{const t=this._cache.deleteEntity(e);return this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},t),i),{folderId:r}))),!0}}async moveItems(e,t){const o=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>this._cache.getEntity(e));for(const e of r)if(e){if(e.isFolder){if(e.id===o){const t="Cannot move folder '%s' into itself".replace("%s",e.name);throw new Jn(t,"MoveIntoSelf")}if(this._isAncestor(e.id,o)){const t="Cannot move folder '%s' into its descendant".replace("%s",e.name);throw new Jn(t,"MoveIntoDescendant")}}if(this._validateDuplicates){const t=this.normalizeId(e.folderId);if(o!==t&&e.name){if(this._checkNameExistsInCache(o,e.name,!!e.isFolder,e.id)){const t=e.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${e.isFolder?"Folder":"File"} '${e.name}' already exists in target folder`,t)}}}}let n={detailed:new Array(r.length),success:!0};if("function"==typeof this._dataProvider.moveItems){n=Ms(await this._dataProvider.moveItems(r,o),e=>e)}else{if("function"!=typeof this._dataProvider.moveItem)throw new Jn("Move items is not supported","MoveNotAllowed");n.detailed=await Promise.all(t.map(async(e,t)=>{const n=r[t]||{id:e,folderId:null,isFolder:!1,name:e};try{return{requestId:e,data:Ds(await this._dataProvider.moveItem(n,o)),success:!0}}catch(t){return{requestId:e,success:!1,error:t}}}))}if(n.success){const e=n.detailed||t.map(e=>({requestId:e,success:!0,data:void 0}));for(const t of e)if(t.success)if(t.data&&t.data.id!==t.requestId){const e=this._cache.deleteEntity(t.requestId);this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},e),t.data),{folderId:o})))}else this._cache.moveEntity(t.requestId,o),t.data&&this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},this._cache.getEntity(t.requestId)),t.data),{folderId:o})));return n}return{success:!1,error:n.error||new Jn("Move items failed","MoveNotAllowed")}}async copyItem({itemId:e,targetFolderId:t}){if("function"!=typeof this._dataProvider.copyItem)throw new Jn("Copy item is not supported","CopyNotAllowed");const o=this.normalizeId(t);this._validateTargetFolderType(t);const r=this._cache.getEntity(e);if(!r){const t=Ds(await this._dataProvider.copyItem({id:e,folderId:o},o));return this._cache.copyEntity(e,o,t.id),this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:o}))),!0}if(this._validateDuplicates&&r.name){const t=o===this.normalizeId(r.folderId)?e:void 0;if(this._checkNameExistsInCache(o,r.name,!!r.isFolder,t)){const e=r.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${r.isFolder?"Folder":"File"} '${r.name}' already exists in target folder`,e)}}const n=Ds(await this._dataProvider.copyItem(r,o));return this._cache.copyEntity(e,o,n.id,Object.assign(Object.assign({},n),{folderId:o}))||this._cache.upsertEntity(js(Object.assign(Object.assign({},n),{folderId:o}))),!0}async copyItems(e,t){var o;const r=this.normalizeId(e);this._validateTargetFolderType(e);const n=t.map(e=>"string"==typeof e?{id:e}:e),i=n.map(e=>e.id),a=i.map((e,t)=>{var o;const r=this._cache.getEntity(e),i=null===(o=n[t])||void 0===o?void 0:o.newName;return r?i?Object.assign(Object.assign({},r),{name:i}):r:void 0});if(this._validateDuplicates)for(let e=0;e<a.length;e++){const t=a[e];if(t&&t.name){const o=this.normalizeId(t.folderId),n=r===o?i[e]:void 0;if(this._checkNameExistsInCache(r,t.name,!!t.isFolder,n)){const e=t.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${t.isFolder?"Folder":"File"} '${t.name}' already exists in target folder`,e)}}}let l={detailed:new Array(a.length),success:!0};if("function"==typeof this._dataProvider.copyItems){l=Ms(await this._dataProvider.copyItems(a,r),e=>e)}else{if("function"!=typeof this._dataProvider.copyItem)throw new Jn("Copy items is not supported","CopyNotAllowed");l.detailed=await Promise.all(i.map(async(e,t)=>{const o=a[t]||{id:e,folderId:null,isFolder:!1};try{return{requestId:e,data:Ds(await this._dataProvider.copyItem(o,r)),success:!0}}catch(t){return{requestId:e,success:!1,error:t}}}))}if(l.success&&l.detailed)for(let e=0,t=l.detailed.length;e<t;e++){const t=l.detailed[e];if(t.success)if(null===(o=t.data)||void 0===o?void 0:o.id){const e=t.data.folderId||r;!this._cache.copyEntity(t.requestId,e,t.data.id,Object.assign(Object.assign({},t.data),{folderId:e}))&&t.data&&this._cache.upsertEntity(js(Object.assign(Object.assign({},t.data),{folderId:e})))}else console.error("batchResult in copy method must have ids")}else if(!l.detailed)throw new Jn("batchResult in copy method must have detailed results","ValidationError");return l}async uploadFileByUrl(e){var t;if(e.noFolder){const t=await this.getTempFolder();e=Object.assign(Object.assign({},e),{folderId:t.id})}const o=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);try{const t=await this._dataProvider.uploadFileByUrl(e.url,o,{eventSource:e.eventSource}),r=js(Object.assign(Object.assign({},t),{folderId:o}));return this._cache.upsertEntity(r),r}catch(e){throw console.error("uploadFileByUrl error:",e),e}}async updateFile(e,t){if("function"!=typeof this._dataProvider.updateFile)throw new Jn("Update file is not supported","UnsupportedOperation");const o=this.normalizeId(e),r=this._cache.getEntity(o);if(!r){const t="File with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}if(t.name&&t.name!==r.name&&this._validateName(t.name,!1),this._validateDuplicates&&t.name&&t.name!==r.name){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t.name,!1,o)){const e="File '%s' already exists in parent folder".replace("%s",t.name);throw new Jn(e,"FileAlreadyExists")}}const n=Ds(await this._dataProvider.updateFile(r,Object.assign({},t)));return this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},this._cache.getEntity(o)),n),t))),this._cache.getEntity(o)}}var zs,qs=new Uint8Array(16);function Ws(){if(!zs&&!(zs="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return zs(qs)}var Vs=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var $s=[],Hs=0;Hs<256;++Hs)$s.push((Hs+256).toString(16).substr(1));function Gs(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=($s[e[t+0]]+$s[e[t+1]]+$s[e[t+2]]+$s[e[t+3]]+"-"+$s[e[t+4]]+$s[e[t+5]]+"-"+$s[e[t+6]]+$s[e[t+7]]+"-"+$s[e[t+8]]+$s[e[t+9]]+"-"+$s[e[t+10]]+$s[e[t+11]]+$s[e[t+12]]+$s[e[t+13]]+$s[e[t+14]]+$s[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Vs.test(e)}(o))throw TypeError("Stringified UUID is invalid");return o}function Ks(e,t,o){var r=(e=e||{}).random||(e.rng||Ws)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,Gs(r)}class Qs{constructor(e,t="",o="Trash",r="Trash",n=!0){var i;this._inner=e,this.rootPath=t,this.trashId=o,this.trashPath=r,this.ensureFolderTrailingSlash=n,this._pathToId=new Map,this._idToPath=new Map,this.validateDuplicates=null!==(i=this._inner.validateDuplicates)&&void 0!==i&&i,"function"==typeof e.getUrl&&(this.getUrl=t=>e.getUrl(Object.assign(Object.assign({},t),{id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath}))),"function"==typeof e.getThumbnailUrl&&(this.getThumbnailUrl=t=>e.getThumbnailUrl(Object.assign(Object.assign({},t),{id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})));const a=this;"function"!=typeof this._inner.deleteItems&&(a.deleteItems=void 0),"function"!=typeof this._inner.deleteItem&&(a.deleteItem=void 0),"function"!=typeof this._inner.moveItems?a.moveItems=void 0:a.moveItem=void 0,"function"!=typeof this._inner.copyItems?a.copyItems=void 0:a.copyItem=void 0,"function"!=typeof this._inner.uploadFiles?a.uploadFiles=void 0:a.uploadFile=void 0,"function"!=typeof this._inner.clearCache&&(a.clearCache=void 0),this._getOrGenerateId(this.rootPath)}setController(e){"function"==typeof this._inner.setController&&this._inner.setController({invalidateItemCache:t=>{const o=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(o);r&&e.invalidateItemCache(r)},getCachedItem:t=>{var o,r,n;const i=t.replace(/^\/+|\/+$/g,""),a=this._pathToId.get(i);if(a){const t=e.getCachedItem(a);if(t)return Object.assign(Object.assign({},t),{id:this.pathForId(t.id,null!==(o=t.isFolder)&&void 0!==o&&o),folderId:this.pathForId(null!==(r=t.folderId)&&void 0!==r?r:"",null!==(n=t.isFolder)&&void 0!==n&&n)})}}})}clearCache(e){if("function"==typeof this._inner.clearCache)return this._inner.clearCache(e)}_getOrGenerateId(e){if(e===this.rootPath)return"";const t=e.replaceAll(/^\/+|\/+$/g,"");if(t===this.trashPath.replaceAll(/^\/+|\/+$/g,""))return this.trashId;if(this._pathToId.has(t))return this._pathToId.get(t);const o=Ks();return this._pathToId.set(t,o),this._idToPath.set(o,t),o}pathForId(e,t,o){if(""===e||void 0===e)return this.rootPath;if(e===this.trashId)return this.trashPath;let r=this._idToPath.get(e);if(!r){if(o)return`unknown folder ${e}`;throw new Jn(`Path for id '${e}' not found in mapping`,"FileNotFound")}let n=0;for(;n<this.rootPath.length&&"/"===this.rootPath[n];)n++;if(n){let e=0;for(;e<r.length&&"/"===r[e];)e++;const t=r.slice(e);r="/".repeat(n)+t}return t&&this.ensureFolderTrailingSlash&&!r.endsWith("/")&&(r+="/"),r}_updateIdMapping(e,t){const o=t.replace(/^\/+|\/+$/g,""),r=this._idToPath.get(e);r&&this._pathToId.delete(r),this._idToPath.set(e,o),this._pathToId.set(o,e)}async getItems(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,o=await this._inner.getItems(Object.assign(Object.assign({},e),{folderId:t})),r=o.items.map(e=>{const t=this._getOrGenerateId(e.id),o=e.folderId?this._getOrGenerateId(e.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},e),{id:t,folderId:o})});return Object.assign(Object.assign({},o),{items:r})}async createFolder(e,t,o){const r=t?this.pathForId(t,!0):this.rootPath,n=await this._inner.createFolder(e,r,o),i=this._getOrGenerateId(n.id),a=n.folderId?this._getOrGenerateId(n.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},n),{id:i,folderId:a})}async renameItem(e,t){var o,r;if("function"!=typeof this._inner.renameItem){throw new Jn("Rename item is not supported by inner storage","RenameNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=n;let a=Rn(await this._inner.renameItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),t),[]);return this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,i,a.id),a.folderId&&(a=Object.assign(Object.assign({},a),{folderId:this._getOrGenerateId(a.folderId)})),Object.assign(Object.assign({},a),{id:this._getOrGenerateId(a.id)})}async deleteItem(e,t){var o,r;if("function"!=typeof this._inner.deleteItem){throw new Jn("Delete item is not supported by inner storage","DeleteNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o);await this._inner.deleteItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),t),this.recursivelyRemoveMappings(e.id,n)}async uploadFile(e){if("function"!=typeof this._inner.uploadFile){throw new Jn("Upload file is not supported by inner storage","UnsupportedOperation")}const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,o=await this._inner.uploadFile(Object.assign(Object.assign({},e),{folderId:t})),r=this._getOrGenerateId(o.id),n=o.folderId?this._getOrGenerateId(o.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},o),{id:r,folderId:n})}async uploadFiles(e){var t,o,r,n,i;const a=e.folderId,l=null!==(o=null===(t=e.items)||void 0===t?void 0:t.map(e=>e.folderId))&&void 0!==o?o:[],s=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,d=Object.assign(Object.assign({},e),{folderId:s,items:null!==(n=null===(r=e.items)||void 0===r?void 0:r.map(e=>{var t;return Object.assign(Object.assign({},e),{folderId:e.folderId?this.pathForId(null!==(t=e.folderId)&&void 0!==t?t:"",!0):s})}))&&void 0!==n?n:[]}),c=await this._inner.uploadFiles(d);return Object.assign(Object.assign({},c),{detailed:null===(i=c.detailed)||void 0===i?void 0:i.map((e,t)=>{var o,r;if(!(null==e?void 0:e.data))return e;const n=e.data.id?this._getOrGenerateId(e.data.id):"",i=e.data.folderId?this._getOrGenerateId(e.data.folderId):null!==(r=null!==(o=l[t])&&void 0!==o?o:a)&&void 0!==r?r:this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},e),{data:Object.assign(Object.assign({},e.data),{id:n,folderId:i})})})})}async findFileByUrl(e,t){const o=t?this.pathForId(t,!0):this.rootPath;if("function"==typeof this._inner.findFileByUrl){const t=await this._inner.findFileByUrl(e,o);if(!t)return;const r=this._getOrGenerateId(t.id),n=t.folderId?this._getOrGenerateId(t.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},t),{id:r,folderId:n})}}async uploadFileByUrl(e,t,o){const r=t?this.pathForId(t,!0):this.rootPath,n=await this._inner.uploadFileByUrl(e,r,o),i=this._getOrGenerateId(n.id),a=n.folderId?this._getOrGenerateId(n.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},n),{id:i,folderId:a})}async moveItem(e,t){var o,r;if("function"!=typeof this._inner.moveItem){throw new Jn("Move item is not supported by inner storage","MoveNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.moveItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),i);this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,n,a.id);const l=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return Object.assign(Object.assign({},a),{id:l,folderId:s})}async moveItems(e,t){var o;if("function"!=typeof this._inner.moveItems){throw new Jn("Move items is not supported by inner storage","MoveNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,n=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),i=await this._inner.moveItems(n,r),a=[];if(i.detailed&&i.detailed.length>0){const r=new Map;for(let t=0;t<i.detailed.length;t++){const o=i.detailed[t],n=o.requestId||(t<e.length?e[t].id:void 0);n&&r.set(n,o)}for(const n of e){const l=r.get(n.id)||(i.detailed.length===e.length?i.detailed[e.indexOf(n)]:void 0);if((null==l?void 0:l.success)&&l.data){if(this._updateIdMapping(n.id,l.data.id),n.isFolder){const e=this.pathForId(n.id,null!==(o=n.isFolder)&&void 0!==o&&o);this.remapCachedFolderContents(n.id,e,l.data.id)}a.push({requestId:n.id,success:!0,data:Object.assign(Object.assign({},l.data),{id:this._getOrGenerateId(l.data.id),folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)})})}else{const e="Move operation failed - no detailed result";a.push({requestId:n.id,success:!1,error:(null==l?void 0:l.error)||{message:e,code:"MoveNotAllowed"}})}}}else for(const t of e){const e="Move operation failed - no detailed results";a.push({requestId:t.id,success:!1,error:{message:e,code:"MoveNotAllowed"}})}return{success:i.success,detailed:a,error:i.error}}async copyItems(e,t){var o;if("function"!=typeof this._inner.copyItems){throw new Jn("Copy items is not supported by inner storage","CopyNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,n=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),i=await this._inner.copyItems(n,r),a=[];if(i.detailed&&i.detailed.length>0){const r=new Map;for(let t=0;t<i.detailed.length;t++){const o=i.detailed[t],n=o.requestId||(t<e.length?e[t].id:void 0);n&&r.set(n,o)}for(const n of e){const l=r.get(n.id)||(i.detailed.length===e.length?i.detailed[e.indexOf(n)]:void 0);if((null==l?void 0:l.success)&&(null===(o=l.data)||void 0===o?void 0:o.id)){const e=this._getOrGenerateId(l.data.id);a.push({requestId:n.id,success:!0,data:Object.assign(Object.assign({},l.data),{id:e,folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)})})}else{const e=l?l.success?l.data?l.data.id?{message:"Unknown copy error",code:"CopyNotAllowed"}:{message:"No ID in copied item data",code:"CopyNotAllowed"}:{message:"No data returned from copy operation",code:"CopyNotAllowed"}:l.error||{message:"Copy operation failed",code:"CopyNotAllowed"}:{message:"No detailed result from copy operation",code:"CopyNotAllowed"};a.push({requestId:n.id,success:!1,error:e})}}}else for(const t of e){const e="No detailed results from copy operation";a.push({requestId:t.id,success:!1,error:{message:e,code:"CopyNotAllowed"}})}const l=a.every(e=>e.success);return{success:l,detailed:a,error:l?void 0:i.error||{message:"Copy operation completed with errors",code:"CopyNotAllowed"}}}async deleteItems(e,t){var o,r,n,i;if("function"!=typeof this._inner.deleteItems){throw new Jn("Delete items is not supported by inner storage","DeleteNotAllowed")}const a=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),l=await this._inner.deleteItems(a,t),s=[];if(l.detailed&&l.detailed.length>0){const n=new Map;for(let t=0;t<l.detailed.length;t++){const o=l.detailed[t],r=o.requestId||(t<e.length?e[t].id:void 0);r&&n.set(r,o)}for(const i of e){const a=n.get(i.id)||(l.detailed.length===e.length?l.detailed[e.indexOf(i)]:void 0);if(null==a?void 0:a.success){const e=this.pathForId(i.id,null!==(o=i.isFolder)&&void 0!==o&&o);if(t.permanent)this.recursivelyRemoveMappings(i.id,e);else if(this._updateIdMapping(i.id,this.trashPath+"/"+e+(i.isFolder?"/":"")),i.isFolder){const t=this.pathForId(i.id,null!==(r=i.isFolder)&&void 0!==r&&r);this.remapCachedFolderContents(i.id,t,this.trashPath+"/"+e+(i.isFolder?"/":""))}s.push({requestId:i.id,success:!0})}else{const e="Delete operation failed";s.push({requestId:i.id,success:!1,error:(null==a?void 0:a.error)||{message:e,code:"DeleteNotAllowed"}})}}}else for(const o of e)if(l.success){const e=this.pathForId(o.id,null!==(n=o.isFolder)&&void 0!==n&&n);if(t.permanent)this.recursivelyRemoveMappings(o.id,e);else if(this._updateIdMapping(o.id,this.trashPath+"/"+e+(o.isFolder?"/":"")),o.isFolder){const t=this.pathForId(o.id,null!==(i=o.isFolder)&&void 0!==i&&i);this.remapCachedFolderContents(o.id,t,this.trashPath+"/"+e+(o.isFolder?"/":""))}s.push({requestId:o.id,success:!0})}else{const e="Delete operation failed";s.push({requestId:o.id,success:!1,error:l.error||{message:e,code:"DeleteNotAllowed"}})}const d=s.every(e=>e.success);return{success:d,detailed:s,error:d?void 0:l.error||{message:"Some items failed to delete",code:"DeleteNotAllowed"}}}remapCachedFolderContents(e,t,o){const r=t.replace(/\/+$/,""),n=o.replace(/\/+$/,""),i=[];for(const[e,t]of this._idToPath.entries()){const o=t.replace(/\/+$/,"");o!==r&&o.startsWith(r+"/")&&i.push({id:e,oldPath:o})}for(const{id:e,oldPath:t}of i){const o=n+t.substring(r.length);this._updateIdMapping(e,o)}}recursivelyRemoveMappings(e,t){const o=t.replace(/\/+$/,""),r=[],n=[];for(const[e,t]of this._idToPath.entries()){const i=t.replace(/\/+$/,"");(i===o||i.startsWith(o+"/"))&&(r.push(e),n.push(i))}for(let e=0;e<r.length;e++)this._idToPath.delete(r[e]),this._pathToId.delete(n[e])}async copyItem(e,t){var o,r;if("function"!=typeof this._inner.copyItem){throw new Jn("Copy item is not supported by inner storage","CopyNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.copyItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),i),l=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):null!=t?t:"";return Object.assign(Object.assign({},a),{id:l,folderId:s})}async updateFile(e,t){var o;if("function"!=typeof this._inner.updateFile){throw new Jn("Update file is not supported by inner storage","UnsupportedOperation")}const r=this.pathForId(e.id,!1);let n=Rn(await this._inner.updateFile(Object.assign(Object.assign({},e),{id:r,folderId:this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0)}),t),[]);return this._updateIdMapping(e.id,n.id),n.folderId&&(n=Object.assign(Object.assign({},n),{folderId:this._getOrGenerateId(n.folderId)})),Object.assign(Object.assign({},n),{id:this._getOrGenerateId(n.id)})}async getFileData(e,t){var o;const r=this.pathForId(e.id,!1);if("function"==typeof this._inner.getFileData)return this._inner.getFileData(Object.assign(Object.assign({},e),{id:r,folderId:this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0)}),t);const n=e.url||("function"==typeof this.getUrl?await this.getUrl(e):void 0);if(!n){throw new Jn("Cannot get file data: no url and no inner.getFileData","FileReadError")}return fetch(n,(null==t?void 0:t.forceReload)?{cache:"no-store"}:void 0).then(e=>e.blob())}async cleanTrash(){if("function"!=typeof this._inner.cleanTrash){throw new Jn("Clean trash is not supported by inner storage","UnsupportedOperation")}return await this._inner.cleanTrash()}}var Js={init:ms,unmount:ps,initPixieEditor:ys,unmountPixieEditor:ws,initFileManager:bs};export{Ea as A,Wa as B,$a as C,Pt as D,Rt as E,Ua as F,Jn as G,Cs as H,Ya as I,Qa as J,Ja as K,Fs as L,As as M,Cn as N,_s as O,vs as P,Ns as Q,Bs as R,Qs as S,Ls as T,gi as U,Ts as V,mn as a,gn as b,Ul as c,Zi as d,On as e,Kn as f,za as g,Tn as h,Xt as i,ri as j,ni as k,si as l,Da as m,Yt as n,Sn as o,Ho as p,ms as q,Lr as r,ps as s,fs as t,dr as u,ys as v,ws as w,bs as x,Js as y,cs as z};
10
- //# sourceMappingURL=file-manager-index-DrkEBKW2.js.map
9
+ */var An,_n,Sn=(In||(In=1,An=Fn,_n=Fn.exports,function(){var e,t="Expected a function",o="__lodash_hash_undefined__",r="__lodash_placeholder__",n=32,i=128,a=256,l=1/0,s=9007199254740991,d=NaN,c=4294967295,u=[["ary",i],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",n],["partialRight",64],["rearg",a]],f="[object Arguments]",h="[object Array]",m="[object Boolean]",p="[object Date]",g="[object Error]",v="[object Function]",y="[object GeneratorFunction]",w="[object Map]",b="[object Number]",C="[object Object]",I="[object Promise]",F="[object RegExp]",A="[object Set]",_="[object String]",S="[object Symbol]",E="[object WeakMap]",x="[object ArrayBuffer]",P="[object DataView]",R="[object Float32Array]",N="[object Float64Array]",k="[object Int8Array]",O="[object Int16Array]",T="[object Int32Array]",L="[object Uint8Array]",M="[object Uint8ClampedArray]",U="[object Uint16Array]",j="[object Uint32Array]",D=/\b__p \+= '';/g,B=/\b(__p \+=) '' \+/g,z=/(__e\(.*?\)|\b__t\)) \+\n'';/g,q=/&(?:amp|lt|gt|quot|#39);/g,W=/[&<>"']/g,V=RegExp(q.source),$=RegExp(W.source),H=/<%-([\s\S]+?)%>/g,G=/<%([\s\S]+?)%>/g,K=/<%=([\s\S]+?)%>/g,Q=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,J=/^\w*$/,Y=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/[\\^$.*+?()[\]{}|]/g,X=RegExp(Z.source),ee=/^\s+/,te=/\s/,oe=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,re=/\{\n\/\* \[wrapped with (.+)\] \*/,ne=/,? & /,ie=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ae=/[()=,{}\[\]\/\s]/,le=/\\(\\)?/g,se=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,de=/\w*$/,ce=/^[-+]0x[0-9a-f]+$/i,ue=/^0b[01]+$/i,fe=/^\[object .+?Constructor\]$/,he=/^0o[0-7]+$/i,me=/^(?:0|[1-9]\d*)$/,pe=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,ge=/($^)/,ve=/['\n\r\u2028\u2029\\]/g,ye="\\ud800-\\udfff",we="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",be="\\u2700-\\u27bf",Ce="a-z\\xdf-\\xf6\\xf8-\\xff",Ie="A-Z\\xc0-\\xd6\\xd8-\\xde",Fe="\\ufe0e\\ufe0f",Ae="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",_e="['’]",Se="["+ye+"]",Ee="["+Ae+"]",xe="["+we+"]",Pe="\\d+",Re="["+be+"]",Ne="["+Ce+"]",ke="[^"+ye+Ae+Pe+be+Ce+Ie+"]",Oe="\\ud83c[\\udffb-\\udfff]",Te="[^"+ye+"]",Le="(?:\\ud83c[\\udde6-\\uddff]){2}",Me="[\\ud800-\\udbff][\\udc00-\\udfff]",Ue="["+Ie+"]",je="\\u200d",De="(?:"+Ne+"|"+ke+")",Be="(?:"+Ue+"|"+ke+")",ze="(?:['’](?:d|ll|m|re|s|t|ve))?",qe="(?:['’](?:D|LL|M|RE|S|T|VE))?",We="(?:"+xe+"|"+Oe+")?",Ve="["+Fe+"]?",$e=Ve+We+"(?:"+je+"(?:"+[Te,Le,Me].join("|")+")"+Ve+We+")*",He="(?:"+[Re,Le,Me].join("|")+")"+$e,Ge="(?:"+[Te+xe+"?",xe,Le,Me,Se].join("|")+")",Ke=RegExp(_e,"g"),Qe=RegExp(xe,"g"),Je=RegExp(Oe+"(?="+Oe+")|"+Ge+$e,"g"),Ye=RegExp([Ue+"?"+Ne+"+"+ze+"(?="+[Ee,Ue,"$"].join("|")+")",Be+"+"+qe+"(?="+[Ee,Ue+De,"$"].join("|")+")",Ue+"?"+De+"+"+ze,Ue+"+"+qe,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Pe,He].join("|"),"g"),Ze=RegExp("["+je+ye+we+Fe+"]"),Xe=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,et=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],tt=-1,ot={};ot[R]=ot[N]=ot[k]=ot[O]=ot[T]=ot[L]=ot[M]=ot[U]=ot[j]=!0,ot[f]=ot[h]=ot[x]=ot[m]=ot[P]=ot[p]=ot[g]=ot[v]=ot[w]=ot[b]=ot[C]=ot[F]=ot[A]=ot[_]=ot[E]=!1;var rt={};rt[f]=rt[h]=rt[x]=rt[P]=rt[m]=rt[p]=rt[R]=rt[N]=rt[k]=rt[O]=rt[T]=rt[w]=rt[b]=rt[C]=rt[F]=rt[A]=rt[_]=rt[S]=rt[L]=rt[M]=rt[U]=rt[j]=!0,rt[g]=rt[v]=rt[E]=!1;var nt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},it=parseFloat,at=parseInt,lt="object"==typeof $o&&$o&&$o.Object===Object&&$o,st="object"==typeof self&&self&&self.Object===Object&&self,dt=lt||st||Function("return this")(),ct=_n&&!_n.nodeType&&_n,ut=ct&&An&&!An.nodeType&&An,ft=ut&&ut.exports===ct,ht=ft&&lt.process,mt=function(){try{var e=ut&&ut.require&&ut.require("util").types;return e||ht&&ht.binding&&ht.binding("util")}catch(e){}}(),pt=mt&&mt.isArrayBuffer,gt=mt&&mt.isDate,vt=mt&&mt.isMap,yt=mt&&mt.isRegExp,wt=mt&&mt.isSet,bt=mt&&mt.isTypedArray;function Ct(e,t,o){switch(o.length){case 0:return e.call(t);case 1:return e.call(t,o[0]);case 2:return e.call(t,o[0],o[1]);case 3:return e.call(t,o[0],o[1],o[2])}return e.apply(t,o)}function It(e,t,o,r){for(var n=-1,i=null==e?0:e.length;++n<i;){var a=e[n];t(r,a,o(a),e)}return r}function Ft(e,t){for(var o=-1,r=null==e?0:e.length;++o<r&&!1!==t(e[o],o,e););return e}function At(e,t){for(var o=null==e?0:e.length;o--&&!1!==t(e[o],o,e););return e}function _t(e,t){for(var o=-1,r=null==e?0:e.length;++o<r;)if(!t(e[o],o,e))return!1;return!0}function St(e,t){for(var o=-1,r=null==e?0:e.length,n=0,i=[];++o<r;){var a=e[o];t(a,o,e)&&(i[n++]=a)}return i}function Et(e,t){return!(null==e||!e.length)&&Ut(e,t,0)>-1}function xt(e,t,o){for(var r=-1,n=null==e?0:e.length;++r<n;)if(o(t,e[r]))return!0;return!1}function Pt(e,t){for(var o=-1,r=null==e?0:e.length,n=Array(r);++o<r;)n[o]=t(e[o],o,e);return n}function Rt(e,t){for(var o=-1,r=t.length,n=e.length;++o<r;)e[n+o]=t[o];return e}function Nt(e,t,o,r){var n=-1,i=null==e?0:e.length;for(r&&i&&(o=e[++n]);++n<i;)o=t(o,e[n],n,e);return o}function kt(e,t,o,r){var n=null==e?0:e.length;for(r&&n&&(o=e[--n]);n--;)o=t(o,e[n],n,e);return o}function Ot(e,t){for(var o=-1,r=null==e?0:e.length;++o<r;)if(t(e[o],o,e))return!0;return!1}var Tt=zt("length");function Lt(e,t,o){var r;return o(e,function(e,o,n){if(t(e,o,n))return r=o,!1}),r}function Mt(e,t,o,r){for(var n=e.length,i=o+(r?1:-1);r?i--:++i<n;)if(t(e[i],i,e))return i;return-1}function Ut(e,t,o){return t==t?function(e,t,o){for(var r=o-1,n=e.length;++r<n;)if(e[r]===t)return r;return-1}(e,t,o):Mt(e,Dt,o)}function jt(e,t,o,r){for(var n=o-1,i=e.length;++n<i;)if(r(e[n],t))return n;return-1}function Dt(e){return e!=e}function Bt(e,t){var o=null==e?0:e.length;return o?Vt(e,t)/o:d}function zt(t){return function(o){return null==o?e:o[t]}}function qt(t){return function(o){return null==t?e:t[o]}}function Wt(e,t,o,r,n){return n(e,function(e,n,i){o=r?(r=!1,e):t(o,e,n,i)}),o}function Vt(t,o){for(var r,n=-1,i=t.length;++n<i;){var a=o(t[n]);a!==e&&(r=r===e?a:r+a)}return r}function $t(e,t){for(var o=-1,r=Array(e);++o<e;)r[o]=t(o);return r}function Ht(e){return e?e.slice(0,co(e)+1).replace(ee,""):e}function Gt(e){return function(t){return e(t)}}function Kt(e,t){return Pt(t,function(t){return e[t]})}function Qt(e,t){return e.has(t)}function Jt(e,t){for(var o=-1,r=e.length;++o<r&&Ut(t,e[o],0)>-1;);return o}function Yt(e,t){for(var o=e.length;o--&&Ut(t,e[o],0)>-1;);return o}var Zt=qt({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"}),Xt=qt({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function eo(e){return"\\"+nt[e]}function to(e){return Ze.test(e)}function oo(e){var t=-1,o=Array(e.size);return e.forEach(function(e,r){o[++t]=[r,e]}),o}function ro(e,t){return function(o){return e(t(o))}}function no(e,t){for(var o=-1,n=e.length,i=0,a=[];++o<n;){var l=e[o];l!==t&&l!==r||(e[o]=r,a[i++]=o)}return a}function io(e){var t=-1,o=Array(e.size);return e.forEach(function(e){o[++t]=e}),o}function ao(e){var t=-1,o=Array(e.size);return e.forEach(function(e){o[++t]=[e,e]}),o}function lo(e){return to(e)?function(e){for(var t=Je.lastIndex=0;Je.test(e);)++t;return t}(e):Tt(e)}function so(e){return to(e)?function(e){return e.match(Je)||[]}(e):function(e){return e.split("")}(e)}function co(e){for(var t=e.length;t--&&te.test(e.charAt(t)););return t}var uo=qt({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),fo=function te(ye){var we,be=(ye=null==ye?dt:fo.defaults(dt.Object(),ye,fo.pick(dt,et))).Array,Ce=ye.Date,Ie=ye.Error,Fe=ye.Function,Ae=ye.Math,_e=ye.Object,Se=ye.RegExp,Ee=ye.String,xe=ye.TypeError,Pe=be.prototype,Re=Fe.prototype,Ne=_e.prototype,ke=ye["__core-js_shared__"],Oe=Re.toString,Te=Ne.hasOwnProperty,Le=0,Me=(we=/[^.]+$/.exec(ke&&ke.keys&&ke.keys.IE_PROTO||""))?"Symbol(src)_1."+we:"",Ue=Ne.toString,je=Oe.call(_e),De=dt._,Be=Se("^"+Oe.call(Te).replace(Z,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ze=ft?ye.Buffer:e,qe=ye.Symbol,We=ye.Uint8Array,Ve=ze?ze.allocUnsafe:e,$e=ro(_e.getPrototypeOf,_e),He=_e.create,Ge=Ne.propertyIsEnumerable,Je=Pe.splice,Ze=qe?qe.isConcatSpreadable:e,nt=qe?qe.iterator:e,lt=qe?qe.toStringTag:e,st=function(){try{var e=ui(_e,"defineProperty");return e({},"",{}),e}catch(e){}}(),ct=ye.clearTimeout!==dt.clearTimeout&&ye.clearTimeout,ut=Ce&&Ce.now!==dt.Date.now&&Ce.now,ht=ye.setTimeout!==dt.setTimeout&&ye.setTimeout,mt=Ae.ceil,Tt=Ae.floor,qt=_e.getOwnPropertySymbols,ho=ze?ze.isBuffer:e,mo=ye.isFinite,po=Pe.join,go=ro(_e.keys,_e),vo=Ae.max,yo=Ae.min,wo=Ce.now,bo=ye.parseInt,Co=Ae.random,Io=Pe.reverse,Fo=ui(ye,"DataView"),Ao=ui(ye,"Map"),_o=ui(ye,"Promise"),So=ui(ye,"Set"),Eo=ui(ye,"WeakMap"),xo=ui(_e,"create"),Po=Eo&&new Eo,Ro={},No=Ui(Fo),ko=Ui(Ao),Oo=Ui(_o),To=Ui(So),Lo=Ui(Eo),Mo=qe?qe.prototype:e,Uo=Mo?Mo.valueOf:e,jo=Mo?Mo.toString:e;function Do(e){if(el(e)&&!Wa(e)&&!(e instanceof Wo)){if(e instanceof qo)return e;if(Te.call(e,"__wrapped__"))return ji(e)}return new qo(e)}var Bo=function(){function t(){}return function(o){if(!Xa(o))return{};if(He)return He(o);t.prototype=o;var r=new t;return t.prototype=e,r}}();function zo(){}function qo(t,o){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!o,this.__index__=0,this.__values__=e}function Wo(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=c,this.__views__=[]}function Vo(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function $o(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function Ho(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var r=e[t];this.set(r[0],r[1])}}function Go(e){var t=-1,o=null==e?0:e.length;for(this.__data__=new Ho;++t<o;)this.add(e[t])}function Ko(e){var t=this.__data__=new $o(e);this.size=t.size}function Qo(e,t){var o=Wa(e),r=!o&&qa(e),n=!o&&!r&&Ga(e),i=!o&&!r&&!n&&sl(e),a=o||r||n||i,l=a?$t(e.length,Ee):[],s=l.length;for(var d in e)!t&&!Te.call(e,d)||a&&("length"==d||n&&("offset"==d||"parent"==d)||i&&("buffer"==d||"byteLength"==d||"byteOffset"==d)||yi(d,s))||l.push(d);return l}function Jo(t){var o=t.length;return o?t[Gr(0,o-1)]:e}function Yo(e,t){return Ti(Pn(e),ar(t,0,e.length))}function Zo(e){return Ti(Pn(e))}function Xo(t,o,r){(r!==e&&!Da(t[o],r)||r===e&&!(o in t))&&nr(t,o,r)}function er(t,o,r){var n=t[o];Te.call(t,o)&&Da(n,r)&&(r!==e||o in t)||nr(t,o,r)}function tr(e,t){for(var o=e.length;o--;)if(Da(e[o][0],t))return o;return-1}function or(e,t,o,r){return ur(e,function(e,n,i){t(r,e,o(e),i)}),r}function rr(e,t){return e&&Rn(t,Rl(t),e)}function nr(e,t,o){"__proto__"==t&&st?st(e,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):e[t]=o}function ir(t,o){for(var r=-1,n=o.length,i=be(n),a=null==t;++r<n;)i[r]=a?e:_l(t,o[r]);return i}function ar(t,o,r){return t==t&&(r!==e&&(t=t<=r?t:r),o!==e&&(t=t>=o?t:o)),t}function lr(t,o,r,n,i,a){var l,s=1&o,d=2&o,c=4&o;if(r&&(l=i?r(t,n,i,a):r(t)),l!==e)return l;if(!Xa(t))return t;var u=Wa(t);if(u){if(l=function(e){var t=e.length,o=new e.constructor(t);return t&&"string"==typeof e[0]&&Te.call(e,"index")&&(o.index=e.index,o.input=e.input),o}(t),!s)return Pn(t,l)}else{var h=mi(t),g=h==v||h==y;if(Ga(t))return Fn(t,s);if(h==C||h==f||g&&!i){if(l=d||g?{}:gi(t),!s)return d?function(e,t){return Rn(e,hi(e),t)}(t,function(e,t){return e&&Rn(t,Nl(t),e)}(l,t)):function(e,t){return Rn(e,fi(e),t)}(t,rr(l,t))}else{if(!rt[h])return i?t:{};l=function(e,t,o){var r,n=e.constructor;switch(t){case x:return An(e);case m:case p:return new n(+e);case P:return function(e,t){var o=t?An(e.buffer):e.buffer;return new e.constructor(o,e.byteOffset,e.byteLength)}(e,o);case R:case N:case k:case O:case T:case L:case M:case U:case j:return _n(e,o);case w:return new n;case b:case _:return new n(e);case F:return function(e){var t=new e.constructor(e.source,de.exec(e));return t.lastIndex=e.lastIndex,t}(e);case A:return new n;case S:return r=e,Uo?_e(Uo.call(r)):{}}}(t,h,s)}}a||(a=new Ko);var I=a.get(t);if(I)return I;a.set(t,l),il(t)?t.forEach(function(e){l.add(lr(e,o,r,e,t,a))}):tl(t)&&t.forEach(function(e,n){l.set(n,lr(e,o,r,n,t,a))});var E=u?e:(c?d?ni:ri:d?Nl:Rl)(t);return Ft(E||t,function(e,n){E&&(e=t[n=e]),er(l,n,lr(e,o,r,n,t,a))}),l}function sr(t,o,r){var n=r.length;if(null==t)return!n;for(t=_e(t);n--;){var i=r[n],a=o[i],l=t[i];if(l===e&&!(i in t)||!a(l))return!1}return!0}function dr(o,r,n){if("function"!=typeof o)throw new xe(t);return Ri(function(){o.apply(e,n)},r)}function cr(e,t,o,r){var n=-1,i=Et,a=!0,l=e.length,s=[],d=t.length;if(!l)return s;o&&(t=Pt(t,Gt(o))),r?(i=xt,a=!1):t.length>=200&&(i=Qt,a=!1,t=new Go(t));e:for(;++n<l;){var c=e[n],u=null==o?c:o(c);if(c=r||0!==c?c:0,a&&u==u){for(var f=d;f--;)if(t[f]===u)continue e;s.push(c)}else i(t,u,r)||s.push(c)}return s}Do.templateSettings={escape:H,evaluate:G,interpolate:K,variable:"",imports:{_:Do}},Do.prototype=zo.prototype,Do.prototype.constructor=Do,qo.prototype=Bo(zo.prototype),qo.prototype.constructor=qo,Wo.prototype=Bo(zo.prototype),Wo.prototype.constructor=Wo,Vo.prototype.clear=function(){this.__data__=xo?xo(null):{},this.size=0},Vo.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Vo.prototype.get=function(t){var r=this.__data__;if(xo){var n=r[t];return n===o?e:n}return Te.call(r,t)?r[t]:e},Vo.prototype.has=function(t){var o=this.__data__;return xo?o[t]!==e:Te.call(o,t)},Vo.prototype.set=function(t,r){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=xo&&r===e?o:r,this},$o.prototype.clear=function(){this.__data__=[],this.size=0},$o.prototype.delete=function(e){var t=this.__data__,o=tr(t,e);return!(o<0||(o==t.length-1?t.pop():Je.call(t,o,1),--this.size,0))},$o.prototype.get=function(t){var o=this.__data__,r=tr(o,t);return r<0?e:o[r][1]},$o.prototype.has=function(e){return tr(this.__data__,e)>-1},$o.prototype.set=function(e,t){var o=this.__data__,r=tr(o,e);return r<0?(++this.size,o.push([e,t])):o[r][1]=t,this},Ho.prototype.clear=function(){this.size=0,this.__data__={hash:new Vo,map:new(Ao||$o),string:new Vo}},Ho.prototype.delete=function(e){var t=di(this,e).delete(e);return this.size-=t?1:0,t},Ho.prototype.get=function(e){return di(this,e).get(e)},Ho.prototype.has=function(e){return di(this,e).has(e)},Ho.prototype.set=function(e,t){var o=di(this,e),r=o.size;return o.set(e,t),this.size+=o.size==r?0:1,this},Go.prototype.add=Go.prototype.push=function(e){return this.__data__.set(e,o),this},Go.prototype.has=function(e){return this.__data__.has(e)},Ko.prototype.clear=function(){this.__data__=new $o,this.size=0},Ko.prototype.delete=function(e){var t=this.__data__,o=t.delete(e);return this.size=t.size,o},Ko.prototype.get=function(e){return this.__data__.get(e)},Ko.prototype.has=function(e){return this.__data__.has(e)},Ko.prototype.set=function(e,t){var o=this.__data__;if(o instanceof $o){var r=o.__data__;if(!Ao||r.length<199)return r.push([e,t]),this.size=++o.size,this;o=this.__data__=new Ho(r)}return o.set(e,t),this.size=o.size,this};var ur=On(wr),fr=On(br,!0);function hr(e,t){var o=!0;return ur(e,function(e,r,n){return o=!!t(e,r,n)}),o}function mr(t,o,r){for(var n=-1,i=t.length;++n<i;){var a=t[n],l=o(a);if(null!=l&&(s===e?l==l&&!ll(l):r(l,s)))var s=l,d=a}return d}function pr(e,t){var o=[];return ur(e,function(e,r,n){t(e,r,n)&&o.push(e)}),o}function gr(e,t,o,r,n){var i=-1,a=e.length;for(o||(o=vi),n||(n=[]);++i<a;){var l=e[i];t>0&&o(l)?t>1?gr(l,t-1,o,r,n):Rt(n,l):r||(n[n.length]=l)}return n}var vr=Tn(),yr=Tn(!0);function wr(e,t){return e&&vr(e,t,Rl)}function br(e,t){return e&&yr(e,t,Rl)}function Cr(e,t){return St(t,function(t){return Ja(e[t])})}function Ir(t,o){for(var r=0,n=(o=wn(o,t)).length;null!=t&&r<n;)t=t[Mi(o[r++])];return r&&r==n?t:e}function Fr(e,t,o){var r=t(e);return Wa(e)?r:Rt(r,o(e))}function Ar(t){return null==t?t===e?"[object Undefined]":"[object Null]":lt&&lt in _e(t)?function(t){var o=Te.call(t,lt),r=t[lt];try{t[lt]=e;var n=!0}catch(e){}var i=Ue.call(t);return n&&(o?t[lt]=r:delete t[lt]),i}(t):function(e){return Ue.call(e)}(t)}function _r(e,t){return e>t}function Sr(e,t){return null!=e&&Te.call(e,t)}function Er(e,t){return null!=e&&t in _e(e)}function xr(t,o,r){for(var n=r?xt:Et,i=t[0].length,a=t.length,l=a,s=be(a),d=1/0,c=[];l--;){var u=t[l];l&&o&&(u=Pt(u,Gt(o))),d=yo(u.length,d),s[l]=!r&&(o||i>=120&&u.length>=120)?new Go(l&&u):e}u=t[0];var f=-1,h=s[0];e:for(;++f<i&&c.length<d;){var m=u[f],p=o?o(m):m;if(m=r||0!==m?m:0,!(h?Qt(h,p):n(c,p,r))){for(l=a;--l;){var g=s[l];if(!(g?Qt(g,p):n(t[l],p,r)))continue e}h&&h.push(p),c.push(m)}}return c}function Pr(t,o,r){var n=null==(t=Ei(t,o=wn(o,t)))?t:t[Mi(Qi(o))];return null==n?e:Ct(n,t,r)}function Rr(e){return el(e)&&Ar(e)==f}function Nr(t,o,r,n,i){return t===o||(null==t||null==o||!el(t)&&!el(o)?t!=t&&o!=o:function(t,o,r,n,i,a){var l=Wa(t),s=Wa(o),d=l?h:mi(t),c=s?h:mi(o),u=(d=d==f?C:d)==C,v=(c=c==f?C:c)==C,y=d==c;if(y&&Ga(t)){if(!Ga(o))return!1;l=!0,u=!1}if(y&&!u)return a||(a=new Ko),l||sl(t)?ti(t,o,r,n,i,a):function(e,t,o,r,n,i,a){switch(o){case P:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case x:return!(e.byteLength!=t.byteLength||!i(new We(e),new We(t)));case m:case p:case b:return Da(+e,+t);case g:return e.name==t.name&&e.message==t.message;case F:case _:return e==t+"";case w:var l=oo;case A:var s=1&r;if(l||(l=io),e.size!=t.size&&!s)return!1;var d=a.get(e);if(d)return d==t;r|=2,a.set(e,t);var c=ti(l(e),l(t),r,n,i,a);return a.delete(e),c;case S:if(Uo)return Uo.call(e)==Uo.call(t)}return!1}(t,o,d,r,n,i,a);if(!(1&r)){var I=u&&Te.call(t,"__wrapped__"),E=v&&Te.call(o,"__wrapped__");if(I||E){var R=I?t.value():t,N=E?o.value():o;return a||(a=new Ko),i(R,N,r,n,a)}}return!!y&&(a||(a=new Ko),function(t,o,r,n,i,a){var l=1&r,s=ri(t),d=s.length,c=ri(o),u=c.length;if(d!=u&&!l)return!1;for(var f=d;f--;){var h=s[f];if(!(l?h in o:Te.call(o,h)))return!1}var m=a.get(t),p=a.get(o);if(m&&p)return m==o&&p==t;var g=!0;a.set(t,o),a.set(o,t);for(var v=l;++f<d;){var y=t[h=s[f]],w=o[h];if(n)var b=l?n(w,y,h,o,t,a):n(y,w,h,t,o,a);if(!(b===e?y===w||i(y,w,r,n,a):b)){g=!1;break}v||(v="constructor"==h)}if(g&&!v){var C=t.constructor,I=o.constructor;C==I||!("constructor"in t)||!("constructor"in o)||"function"==typeof C&&C instanceof C&&"function"==typeof I&&I instanceof I||(g=!1)}return a.delete(t),a.delete(o),g}(t,o,r,n,i,a))}(t,o,r,n,Nr,i))}function kr(t,o,r,n){var i=r.length,a=i,l=!n;if(null==t)return!a;for(t=_e(t);i--;){var s=r[i];if(l&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++i<a;){var d=(s=r[i])[0],c=t[d],u=s[1];if(l&&s[2]){if(c===e&&!(d in t))return!1}else{var f=new Ko;if(n)var h=n(c,u,d,t,o,f);if(!(h===e?Nr(u,c,3,n,f):h))return!1}}return!0}function Or(e){return!(!Xa(e)||(t=e,Me&&Me in t))&&(Ja(e)?Be:fe).test(Ui(e));var t}function Tr(e){return"function"==typeof e?e:null==e?os:"object"==typeof e?Wa(e)?Br(e[0],e[1]):Dr(e):us(e)}function Lr(e){if(!Fi(e))return go(e);var t=[];for(var o in _e(e))Te.call(e,o)&&"constructor"!=o&&t.push(o);return t}function Mr(e){if(!Xa(e))return function(e){var t=[];if(null!=e)for(var o in _e(e))t.push(o);return t}(e);var t=Fi(e),o=[];for(var r in e)("constructor"!=r||!t&&Te.call(e,r))&&o.push(r);return o}function Ur(e,t){return e<t}function jr(e,t){var o=-1,r=$a(e)?be(e.length):[];return ur(e,function(e,n,i){r[++o]=t(e,n,i)}),r}function Dr(e){var t=ci(e);return 1==t.length&&t[0][2]?_i(t[0][0],t[0][1]):function(o){return o===e||kr(o,e,t)}}function Br(t,o){return bi(t)&&Ai(o)?_i(Mi(t),o):function(r){var n=_l(r,t);return n===e&&n===o?Sl(r,t):Nr(o,n,3)}}function zr(t,o,r,n,i){t!==o&&vr(o,function(a,l){if(i||(i=new Ko),Xa(a))!function(t,o,r,n,i,a,l){var s=xi(t,r),d=xi(o,r),c=l.get(d);if(c)Xo(t,r,c);else{var u=a?a(s,d,r+"",t,o,l):e,f=u===e;if(f){var h=Wa(d),m=!h&&Ga(d),p=!h&&!m&&sl(d);u=d,h||m||p?Wa(s)?u=s:Ha(s)?u=Pn(s):m?(f=!1,u=Fn(d,!0)):p?(f=!1,u=_n(d,!0)):u=[]:rl(d)||qa(d)?(u=s,qa(s)?u=gl(s):Xa(s)&&!Ja(s)||(u=gi(d))):f=!1}f&&(l.set(d,u),i(u,d,n,a,l),l.delete(d)),Xo(t,r,u)}}(t,o,l,r,zr,n,i);else{var s=n?n(xi(t,l),a,l+"",t,o,i):e;s===e&&(s=a),Xo(t,l,s)}},Nl)}function qr(t,o){var r=t.length;if(r)return yi(o+=o<0?r:0,r)?t[o]:e}function Wr(e,t,o){t=t.length?Pt(t,function(e){return Wa(e)?function(t){return Ir(t,1===e.length?e[0]:e)}:e}):[os];var r=-1;t=Pt(t,Gt(si()));var n=jr(e,function(e,o,n){var i=Pt(t,function(t){return t(e)});return{criteria:i,index:++r,value:e}});return function(e,t){var o=e.length;for(e.sort(t);o--;)e[o]=e[o].value;return e}(n,function(e,t){return function(e,t,o){for(var r=-1,n=e.criteria,i=t.criteria,a=n.length,l=o.length;++r<a;){var s=Sn(n[r],i[r]);if(s)return r>=l?s:s*("desc"==o[r]?-1:1)}return e.index-t.index}(e,t,o)})}function Vr(e,t,o){for(var r=-1,n=t.length,i={};++r<n;){var a=t[r],l=Ir(e,a);o(l,a)&&Zr(i,wn(a,e),l)}return i}function $r(e,t,o,r){var n=r?jt:Ut,i=-1,a=t.length,l=e;for(e===t&&(t=Pn(t)),o&&(l=Pt(e,Gt(o)));++i<a;)for(var s=0,d=t[i],c=o?o(d):d;(s=n(l,c,s,r))>-1;)l!==e&&Je.call(l,s,1),Je.call(e,s,1);return e}function Hr(e,t){for(var o=e?t.length:0,r=o-1;o--;){var n=t[o];if(o==r||n!==i){var i=n;yi(n)?Je.call(e,n,1):un(e,n)}}return e}function Gr(e,t){return e+Tt(Co()*(t-e+1))}function Kr(e,t){var o="";if(!e||t<1||t>s)return o;do{t%2&&(o+=e),(t=Tt(t/2))&&(e+=e)}while(t);return o}function Qr(e,t){return Ni(Si(e,t,os),e+"")}function Jr(e){return Jo(Dl(e))}function Yr(e,t){var o=Dl(e);return Ti(o,ar(t,0,o.length))}function Zr(t,o,r,n){if(!Xa(t))return t;for(var i=-1,a=(o=wn(o,t)).length,l=a-1,s=t;null!=s&&++i<a;){var d=Mi(o[i]),c=r;if("__proto__"===d||"constructor"===d||"prototype"===d)return t;if(i!=l){var u=s[d];(c=n?n(u,d,s):e)===e&&(c=Xa(u)?u:yi(o[i+1])?[]:{})}er(s,d,c),s=s[d]}return t}var Xr=Po?function(e,t){return Po.set(e,t),e}:os,en=st?function(e,t){return st(e,"toString",{configurable:!0,enumerable:!1,value:Xl(t),writable:!0})}:os;function tn(e){return Ti(Dl(e))}function on(e,t,o){var r=-1,n=e.length;t<0&&(t=-t>n?0:n+t),(o=o>n?n:o)<0&&(o+=n),n=t>o?0:o-t>>>0,t>>>=0;for(var i=be(n);++r<n;)i[r]=e[r+t];return i}function rn(e,t){var o;return ur(e,function(e,r,n){return!(o=t(e,r,n))}),!!o}function nn(e,t,o){var r=0,n=null==e?r:e.length;if("number"==typeof t&&t==t&&n<=2147483647){for(;r<n;){var i=r+n>>>1,a=e[i];null!==a&&!ll(a)&&(o?a<=t:a<t)?r=i+1:n=i}return n}return an(e,t,os,o)}function an(t,o,r,n){var i=0,a=null==t?0:t.length;if(0===a)return 0;for(var l=(o=r(o))!=o,s=null===o,d=ll(o),c=o===e;i<a;){var u=Tt((i+a)/2),f=r(t[u]),h=f!==e,m=null===f,p=f==f,g=ll(f);if(l)var v=n||p;else v=c?p&&(n||h):s?p&&h&&(n||!m):d?p&&h&&!m&&(n||!g):!m&&!g&&(n?f<=o:f<o);v?i=u+1:a=u}return yo(a,4294967294)}function ln(e,t){for(var o=-1,r=e.length,n=0,i=[];++o<r;){var a=e[o],l=t?t(a):a;if(!o||!Da(l,s)){var s=l;i[n++]=0===a?0:a}}return i}function sn(e){return"number"==typeof e?e:ll(e)?d:+e}function dn(e){if("string"==typeof e)return e;if(Wa(e))return Pt(e,dn)+"";if(ll(e))return jo?jo.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function cn(e,t,o){var r=-1,n=Et,i=e.length,a=!0,l=[],s=l;if(o)a=!1,n=xt;else if(i>=200){var d=t?null:Qn(e);if(d)return io(d);a=!1,n=Qt,s=new Go}else s=t?[]:l;e:for(;++r<i;){var c=e[r],u=t?t(c):c;if(c=o||0!==c?c:0,a&&u==u){for(var f=s.length;f--;)if(s[f]===u)continue e;t&&s.push(u),l.push(c)}else n(s,u,o)||(s!==l&&s.push(u),l.push(c))}return l}function un(e,t){return null==(e=Ei(e,t=wn(t,e)))||delete e[Mi(Qi(t))]}function fn(e,t,o,r){return Zr(e,t,o(Ir(e,t)),r)}function hn(e,t,o,r){for(var n=e.length,i=r?n:-1;(r?i--:++i<n)&&t(e[i],i,e););return o?on(e,r?0:i,r?i+1:n):on(e,r?i+1:0,r?n:i)}function mn(e,t){var o=e;return o instanceof Wo&&(o=o.value()),Nt(t,function(e,t){return t.func.apply(t.thisArg,Rt([e],t.args))},o)}function pn(e,t,o){var r=e.length;if(r<2)return r?cn(e[0]):[];for(var n=-1,i=be(r);++n<r;)for(var a=e[n],l=-1;++l<r;)l!=n&&(i[n]=cr(i[n]||a,e[l],t,o));return cn(gr(i,1),t,o)}function gn(t,o,r){for(var n=-1,i=t.length,a=o.length,l={};++n<i;){var s=n<a?o[n]:e;r(l,t[n],s)}return l}function vn(e){return Ha(e)?e:[]}function yn(e){return"function"==typeof e?e:os}function wn(e,t){return Wa(e)?e:bi(e,t)?[e]:Li(vl(e))}var bn=Qr;function Cn(t,o,r){var n=t.length;return r=r===e?n:r,!o&&r>=n?t:on(t,o,r)}var In=ct||function(e){return dt.clearTimeout(e)};function Fn(e,t){if(t)return e.slice();var o=e.length,r=Ve?Ve(o):new e.constructor(o);return e.copy(r),r}function An(e){var t=new e.constructor(e.byteLength);return new We(t).set(new We(e)),t}function _n(e,t){var o=t?An(e.buffer):e.buffer;return new e.constructor(o,e.byteOffset,e.length)}function Sn(t,o){if(t!==o){var r=t!==e,n=null===t,i=t==t,a=ll(t),l=o!==e,s=null===o,d=o==o,c=ll(o);if(!s&&!c&&!a&&t>o||a&&l&&d&&!s&&!c||n&&l&&d||!r&&d||!i)return 1;if(!n&&!a&&!c&&t<o||c&&r&&i&&!n&&!a||s&&r&&i||!l&&i||!d)return-1}return 0}function En(e,t,o,r){for(var n=-1,i=e.length,a=o.length,l=-1,s=t.length,d=vo(i-a,0),c=be(s+d),u=!r;++l<s;)c[l]=t[l];for(;++n<a;)(u||n<i)&&(c[o[n]]=e[n]);for(;d--;)c[l++]=e[n++];return c}function xn(e,t,o,r){for(var n=-1,i=e.length,a=-1,l=o.length,s=-1,d=t.length,c=vo(i-l,0),u=be(c+d),f=!r;++n<c;)u[n]=e[n];for(var h=n;++s<d;)u[h+s]=t[s];for(;++a<l;)(f||n<i)&&(u[h+o[a]]=e[n++]);return u}function Pn(e,t){var o=-1,r=e.length;for(t||(t=be(r));++o<r;)t[o]=e[o];return t}function Rn(t,o,r,n){var i=!r;r||(r={});for(var a=-1,l=o.length;++a<l;){var s=o[a],d=n?n(r[s],t[s],s,r,t):e;d===e&&(d=t[s]),i?nr(r,s,d):er(r,s,d)}return r}function Nn(e,t){return function(o,r){var n=Wa(o)?It:or,i=t?t():{};return n(o,e,si(r,2),i)}}function kn(t){return Qr(function(o,r){var n=-1,i=r.length,a=i>1?r[i-1]:e,l=i>2?r[2]:e;for(a=t.length>3&&"function"==typeof a?(i--,a):e,l&&wi(r[0],r[1],l)&&(a=i<3?e:a,i=1),o=_e(o);++n<i;){var s=r[n];s&&t(o,s,n,a)}return o})}function On(e,t){return function(o,r){if(null==o)return o;if(!$a(o))return e(o,r);for(var n=o.length,i=t?n:-1,a=_e(o);(t?i--:++i<n)&&!1!==r(a[i],i,a););return o}}function Tn(e){return function(t,o,r){for(var n=-1,i=_e(t),a=r(t),l=a.length;l--;){var s=a[e?l:++n];if(!1===o(i[s],s,i))break}return t}}function Ln(t){return function(o){var r=to(o=vl(o))?so(o):e,n=r?r[0]:o.charAt(0),i=r?Cn(r,1).join(""):o.slice(1);return n[t]()+i}}function Mn(e){return function(t){return Nt(Jl(ql(t).replace(Ke,"")),e,"")}}function Un(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var o=Bo(e.prototype),r=e.apply(o,t);return Xa(r)?r:o}}function jn(t){return function(o,r,n){var i=_e(o);if(!$a(o)){var a=si(r,3);o=Rl(o),r=function(e){return a(i[e],e,i)}}var l=t(o,r,n);return l>-1?i[a?o[l]:l]:e}}function Dn(o){return oi(function(r){var n=r.length,i=n,a=qo.prototype.thru;for(o&&r.reverse();i--;){var l=r[i];if("function"!=typeof l)throw new xe(t);if(a&&!s&&"wrapper"==ai(l))var s=new qo([],!0)}for(i=s?i:n;++i<n;){var d=ai(l=r[i]),c="wrapper"==d?ii(l):e;s=c&&Ci(c[0])&&424==c[1]&&!c[4].length&&1==c[9]?s[ai(c[0])].apply(s,c[3]):1==l.length&&Ci(l)?s[d]():s.thru(l)}return function(){var e=arguments,t=e[0];if(s&&1==e.length&&Wa(t))return s.plant(t).value();for(var o=0,i=n?r[o].apply(this,e):t;++o<n;)i=r[o].call(this,i);return i}})}function Bn(t,o,r,n,a,l,s,d,c,u){var f=o&i,h=1&o,m=2&o,p=24&o,g=512&o,v=m?e:Un(t);return function i(){for(var y=arguments.length,w=be(y),b=y;b--;)w[b]=arguments[b];if(p)var C=li(i),I=function(e,t){for(var o=e.length,r=0;o--;)e[o]===t&&++r;return r}(w,C);if(n&&(w=En(w,n,a,p)),l&&(w=xn(w,l,s,p)),y-=I,p&&y<u){var F=no(w,C);return Gn(t,o,Bn,i.placeholder,r,w,F,d,c,u-y)}var A=h?r:this,_=m?A[t]:t;return y=w.length,d?w=function(t,o){for(var r=t.length,n=yo(o.length,r),i=Pn(t);n--;){var a=o[n];t[n]=yi(a,r)?i[a]:e}return t}(w,d):g&&y>1&&w.reverse(),f&&c<y&&(w.length=c),this&&this!==dt&&this instanceof i&&(_=v||Un(_)),_.apply(A,w)}}function zn(e,t){return function(o,r){return function(e,t,o,r){return wr(e,function(e,n,i){t(r,o(e),n,i)}),r}(o,e,t(r),{})}}function qn(t,o){return function(r,n){var i;if(r===e&&n===e)return o;if(r!==e&&(i=r),n!==e){if(i===e)return n;"string"==typeof r||"string"==typeof n?(r=dn(r),n=dn(n)):(r=sn(r),n=sn(n)),i=t(r,n)}return i}}function Wn(e){return oi(function(t){return t=Pt(t,Gt(si())),Qr(function(o){var r=this;return e(t,function(e){return Ct(e,r,o)})})})}function Vn(t,o){var r=(o=o===e?" ":dn(o)).length;if(r<2)return r?Kr(o,t):o;var n=Kr(o,mt(t/lo(o)));return to(o)?Cn(so(n),0,t).join(""):n.slice(0,t)}function $n(t){return function(o,r,n){return n&&"number"!=typeof n&&wi(o,r,n)&&(r=n=e),o=fl(o),r===e?(r=o,o=0):r=fl(r),function(e,t,o,r){for(var n=-1,i=vo(mt((t-e)/(o||1)),0),a=be(i);i--;)a[r?i:++n]=e,e+=o;return a}(o,r,n=n===e?o<r?1:-1:fl(n),t)}}function Hn(e){return function(t,o){return"string"==typeof t&&"string"==typeof o||(t=pl(t),o=pl(o)),e(t,o)}}function Gn(t,o,r,i,a,l,s,d,c,u){var f=8&o;o|=f?n:64,4&(o&=~(f?64:n))||(o&=-4);var h=[t,o,a,f?l:e,f?s:e,f?e:l,f?e:s,d,c,u],m=r.apply(e,h);return Ci(t)&&Pi(m,h),m.placeholder=i,ki(m,t,o)}function Kn(e){var t=Ae[e];return function(e,o){if(e=pl(e),(o=null==o?0:yo(hl(o),292))&&mo(e)){var r=(vl(e)+"e").split("e");return+((r=(vl(t(r[0]+"e"+(+r[1]+o)))+"e").split("e"))[0]+"e"+(+r[1]-o))}return t(e)}}var Qn=So&&1/io(new So([,-0]))[1]==l?function(e){return new So(e)}:ls;function Jn(e){return function(t){var o=mi(t);return o==w?oo(t):o==A?ao(t):function(e,t){return Pt(t,function(t){return[t,e[t]]})}(t,e(t))}}function Yn(o,l,s,d,c,u,f,h){var m=2&l;if(!m&&"function"!=typeof o)throw new xe(t);var p=d?d.length:0;if(p||(l&=-97,d=c=e),f=f===e?f:vo(hl(f),0),h=h===e?h:hl(h),p-=c?c.length:0,64&l){var g=d,v=c;d=c=e}var y=m?e:ii(o),w=[o,l,s,d,c,g,v,u,f,h];if(y&&function(e,t){var o=e[1],n=t[1],l=o|n,s=l<131,d=n==i&&8==o||n==i&&o==a&&e[7].length<=t[8]||384==n&&t[7].length<=t[8]&&8==o;if(!s&&!d)return e;1&n&&(e[2]=t[2],l|=1&o?0:4);var c=t[3];if(c){var u=e[3];e[3]=u?En(u,c,t[4]):c,e[4]=u?no(e[3],r):t[4]}(c=t[5])&&(u=e[5],e[5]=u?xn(u,c,t[6]):c,e[6]=u?no(e[5],r):t[6]),(c=t[7])&&(e[7]=c),n&i&&(e[8]=null==e[8]?t[8]:yo(e[8],t[8])),null==e[9]&&(e[9]=t[9]),e[0]=t[0],e[1]=l}(w,y),o=w[0],l=w[1],s=w[2],d=w[3],c=w[4],!(h=w[9]=w[9]===e?m?0:o.length:vo(w[9]-p,0))&&24&l&&(l&=-25),l&&1!=l)b=8==l||16==l?function(t,o,r){var n=Un(t);return function i(){for(var a=arguments.length,l=be(a),s=a,d=li(i);s--;)l[s]=arguments[s];var c=a<3&&l[0]!==d&&l[a-1]!==d?[]:no(l,d);return(a-=c.length)<r?Gn(t,o,Bn,i.placeholder,e,l,c,e,e,r-a):Ct(this&&this!==dt&&this instanceof i?n:t,this,l)}}(o,l,h):l!=n&&33!=l||c.length?Bn.apply(e,w):function(e,t,o,r){var n=1&t,i=Un(e);return function t(){for(var a=-1,l=arguments.length,s=-1,d=r.length,c=be(d+l),u=this&&this!==dt&&this instanceof t?i:e;++s<d;)c[s]=r[s];for(;l--;)c[s++]=arguments[++a];return Ct(u,n?o:this,c)}}(o,l,s,d);else var b=function(e,t,o){var r=1&t,n=Un(e);return function t(){return(this&&this!==dt&&this instanceof t?n:e).apply(r?o:this,arguments)}}(o,l,s);return ki((y?Xr:Pi)(b,w),o,l)}function Zn(t,o,r,n){return t===e||Da(t,Ne[r])&&!Te.call(n,r)?o:t}function Xn(t,o,r,n,i,a){return Xa(t)&&Xa(o)&&(a.set(o,t),zr(t,o,e,Xn,a),a.delete(o)),t}function ei(t){return rl(t)?e:t}function ti(t,o,r,n,i,a){var l=1&r,s=t.length,d=o.length;if(s!=d&&!(l&&d>s))return!1;var c=a.get(t),u=a.get(o);if(c&&u)return c==o&&u==t;var f=-1,h=!0,m=2&r?new Go:e;for(a.set(t,o),a.set(o,t);++f<s;){var p=t[f],g=o[f];if(n)var v=l?n(g,p,f,o,t,a):n(p,g,f,t,o,a);if(v!==e){if(v)continue;h=!1;break}if(m){if(!Ot(o,function(e,t){if(!Qt(m,t)&&(p===e||i(p,e,r,n,a)))return m.push(t)})){h=!1;break}}else if(p!==g&&!i(p,g,r,n,a)){h=!1;break}}return a.delete(t),a.delete(o),h}function oi(t){return Ni(Si(t,e,Vi),t+"")}function ri(e){return Fr(e,Rl,fi)}function ni(e){return Fr(e,Nl,hi)}var ii=Po?function(e){return Po.get(e)}:ls;function ai(e){for(var t=e.name+"",o=Ro[t],r=Te.call(Ro,t)?o.length:0;r--;){var n=o[r],i=n.func;if(null==i||i==e)return n.name}return t}function li(e){return(Te.call(Do,"placeholder")?Do:e).placeholder}function si(){var e=Do.iteratee||rs;return e=e===rs?Tr:e,arguments.length?e(arguments[0],arguments[1]):e}function di(e,t){var o,r,n=e.__data__;return("string"==(r=typeof(o=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==o:null===o)?n["string"==typeof t?"string":"hash"]:n.map}function ci(e){for(var t=Rl(e),o=t.length;o--;){var r=t[o],n=e[r];t[o]=[r,n,Ai(n)]}return t}function ui(t,o){var r=function(t,o){return null==t?e:t[o]}(t,o);return Or(r)?r:e}var fi=qt?function(e){return null==e?[]:(e=_e(e),St(qt(e),function(t){return Ge.call(e,t)}))}:ms,hi=qt?function(e){for(var t=[];e;)Rt(t,fi(e)),e=$e(e);return t}:ms,mi=Ar;function pi(e,t,o){for(var r=-1,n=(t=wn(t,e)).length,i=!1;++r<n;){var a=Mi(t[r]);if(!(i=null!=e&&o(e,a)))break;e=e[a]}return i||++r!=n?i:!!(n=null==e?0:e.length)&&Za(n)&&yi(a,n)&&(Wa(e)||qa(e))}function gi(e){return"function"!=typeof e.constructor||Fi(e)?{}:Bo($e(e))}function vi(e){return Wa(e)||qa(e)||!!(Ze&&e&&e[Ze])}function yi(e,t){var o=typeof e;return!!(t=null==t?s:t)&&("number"==o||"symbol"!=o&&me.test(e))&&e>-1&&e%1==0&&e<t}function wi(e,t,o){if(!Xa(o))return!1;var r=typeof t;return!!("number"==r?$a(o)&&yi(t,o.length):"string"==r&&t in o)&&Da(o[t],e)}function bi(e,t){if(Wa(e))return!1;var o=typeof e;return!("number"!=o&&"symbol"!=o&&"boolean"!=o&&null!=e&&!ll(e))||J.test(e)||!Q.test(e)||null!=t&&e in _e(t)}function Ci(e){var t=ai(e),o=Do[t];if("function"!=typeof o||!(t in Wo.prototype))return!1;if(e===o)return!0;var r=ii(o);return!!r&&e===r[0]}(Fo&&mi(new Fo(new ArrayBuffer(1)))!=P||Ao&&mi(new Ao)!=w||_o&&mi(_o.resolve())!=I||So&&mi(new So)!=A||Eo&&mi(new Eo)!=E)&&(mi=function(t){var o=Ar(t),r=o==C?t.constructor:e,n=r?Ui(r):"";if(n)switch(n){case No:return P;case ko:return w;case Oo:return I;case To:return A;case Lo:return E}return o});var Ii=ke?Ja:ps;function Fi(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Ne)}function Ai(e){return e==e&&!Xa(e)}function _i(t,o){return function(r){return null!=r&&r[t]===o&&(o!==e||t in _e(r))}}function Si(t,o,r){return o=vo(o===e?t.length-1:o,0),function(){for(var e=arguments,n=-1,i=vo(e.length-o,0),a=be(i);++n<i;)a[n]=e[o+n];n=-1;for(var l=be(o+1);++n<o;)l[n]=e[n];return l[o]=r(a),Ct(t,this,l)}}function Ei(e,t){return t.length<2?e:Ir(e,on(t,0,-1))}function xi(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var Pi=Oi(Xr),Ri=ht||function(e,t){return dt.setTimeout(e,t)},Ni=Oi(en);function ki(e,t,o){var r=t+"";return Ni(e,function(e,t){var o=t.length;if(!o)return e;var r=o-1;return t[r]=(o>1?"& ":"")+t[r],t=t.join(o>2?", ":" "),e.replace(oe,"{\n/* [wrapped with "+t+"] */\n")}(r,function(e,t){return Ft(u,function(o){var r="_."+o[0];t&o[1]&&!Et(e,r)&&e.push(r)}),e.sort()}(function(e){var t=e.match(re);return t?t[1].split(ne):[]}(r),o)))}function Oi(t){var o=0,r=0;return function(){var n=wo(),i=16-(n-r);if(r=n,i>0){if(++o>=800)return arguments[0]}else o=0;return t.apply(e,arguments)}}function Ti(t,o){var r=-1,n=t.length,i=n-1;for(o=o===e?n:o;++r<o;){var a=Gr(r,i),l=t[a];t[a]=t[r],t[r]=l}return t.length=o,t}var Li=function(e){var t=Oa(e,function(e){return 500===o.size&&o.clear(),e}),o=t.cache;return t}(function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(Y,function(e,o,r,n){t.push(r?n.replace(le,"$1"):o||e)}),t});function Mi(e){if("string"==typeof e||ll(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Ui(e){if(null!=e){try{return Oe.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function ji(e){if(e instanceof Wo)return e.clone();var t=new qo(e.__wrapped__,e.__chain__);return t.__actions__=Pn(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}var Di=Qr(function(e,t){return Ha(e)?cr(e,gr(t,1,Ha,!0)):[]}),Bi=Qr(function(t,o){var r=Qi(o);return Ha(r)&&(r=e),Ha(t)?cr(t,gr(o,1,Ha,!0),si(r,2)):[]}),zi=Qr(function(t,o){var r=Qi(o);return Ha(r)&&(r=e),Ha(t)?cr(t,gr(o,1,Ha,!0),e,r):[]});function qi(e,t,o){var r=null==e?0:e.length;if(!r)return-1;var n=null==o?0:hl(o);return n<0&&(n=vo(r+n,0)),Mt(e,si(t,3),n)}function Wi(t,o,r){var n=null==t?0:t.length;if(!n)return-1;var i=n-1;return r!==e&&(i=hl(r),i=r<0?vo(n+i,0):yo(i,n-1)),Mt(t,si(o,3),i,!0)}function Vi(e){return null!=e&&e.length?gr(e,1):[]}function $i(t){return t&&t.length?t[0]:e}var Hi=Qr(function(e){var t=Pt(e,vn);return t.length&&t[0]===e[0]?xr(t):[]}),Gi=Qr(function(t){var o=Qi(t),r=Pt(t,vn);return o===Qi(r)?o=e:r.pop(),r.length&&r[0]===t[0]?xr(r,si(o,2)):[]}),Ki=Qr(function(t){var o=Qi(t),r=Pt(t,vn);return(o="function"==typeof o?o:e)&&r.pop(),r.length&&r[0]===t[0]?xr(r,e,o):[]});function Qi(t){var o=null==t?0:t.length;return o?t[o-1]:e}var Ji=Qr(Yi);function Yi(e,t){return e&&e.length&&t&&t.length?$r(e,t):e}var Zi=oi(function(e,t){var o=null==e?0:e.length,r=ir(e,t);return Hr(e,Pt(t,function(e){return yi(e,o)?+e:e}).sort(Sn)),r});function Xi(e){return null==e?e:Io.call(e)}var ea=Qr(function(e){return cn(gr(e,1,Ha,!0))}),ta=Qr(function(t){var o=Qi(t);return Ha(o)&&(o=e),cn(gr(t,1,Ha,!0),si(o,2))}),oa=Qr(function(t){var o=Qi(t);return o="function"==typeof o?o:e,cn(gr(t,1,Ha,!0),e,o)});function ra(e){if(!e||!e.length)return[];var t=0;return e=St(e,function(e){if(Ha(e))return t=vo(e.length,t),!0}),$t(t,function(t){return Pt(e,zt(t))})}function na(t,o){if(!t||!t.length)return[];var r=ra(t);return null==o?r:Pt(r,function(t){return Ct(o,e,t)})}var ia=Qr(function(e,t){return Ha(e)?cr(e,t):[]}),aa=Qr(function(e){return pn(St(e,Ha))}),la=Qr(function(t){var o=Qi(t);return Ha(o)&&(o=e),pn(St(t,Ha),si(o,2))}),sa=Qr(function(t){var o=Qi(t);return o="function"==typeof o?o:e,pn(St(t,Ha),e,o)}),da=Qr(ra),ca=Qr(function(t){var o=t.length,r=o>1?t[o-1]:e;return r="function"==typeof r?(t.pop(),r):e,na(t,r)});function ua(e){var t=Do(e);return t.__chain__=!0,t}function fa(e,t){return t(e)}var ha=oi(function(t){var o=t.length,r=o?t[0]:0,n=this.__wrapped__,i=function(e){return ir(e,t)};return!(o>1||this.__actions__.length)&&n instanceof Wo&&yi(r)?((n=n.slice(r,+r+(o?1:0))).__actions__.push({func:fa,args:[i],thisArg:e}),new qo(n,this.__chain__).thru(function(t){return o&&!t.length&&t.push(e),t})):this.thru(i)}),ma=Nn(function(e,t,o){Te.call(e,o)?++e[o]:nr(e,o,1)}),pa=jn(qi),ga=jn(Wi);function va(e,t){return(Wa(e)?Ft:ur)(e,si(t,3))}function ya(e,t){return(Wa(e)?At:fr)(e,si(t,3))}var wa=Nn(function(e,t,o){Te.call(e,o)?e[o].push(t):nr(e,o,[t])}),ba=Qr(function(e,t,o){var r=-1,n="function"==typeof t,i=$a(e)?be(e.length):[];return ur(e,function(e){i[++r]=n?Ct(t,e,o):Pr(e,t,o)}),i}),Ca=Nn(function(e,t,o){nr(e,o,t)});function Ia(e,t){return(Wa(e)?Pt:jr)(e,si(t,3))}var Fa=Nn(function(e,t,o){e[o?0:1].push(t)},function(){return[[],[]]}),Aa=Qr(function(e,t){if(null==e)return[];var o=t.length;return o>1&&wi(e,t[0],t[1])?t=[]:o>2&&wi(t[0],t[1],t[2])&&(t=[t[0]]),Wr(e,gr(t,1),[])}),_a=ut||function(){return dt.Date.now()};function Sa(t,o,r){return o=r?e:o,o=t&&null==o?t.length:o,Yn(t,i,e,e,e,e,o)}function Ea(o,r){var n;if("function"!=typeof r)throw new xe(t);return o=hl(o),function(){return--o>0&&(n=r.apply(this,arguments)),o<=1&&(r=e),n}}var xa=Qr(function(e,t,o){var r=1;if(o.length){var i=no(o,li(xa));r|=n}return Yn(e,r,t,o,i)}),Pa=Qr(function(e,t,o){var r=3;if(o.length){var i=no(o,li(Pa));r|=n}return Yn(t,r,e,o,i)});function Ra(o,r,n){var i,a,l,s,d,c,u=0,f=!1,h=!1,m=!0;if("function"!=typeof o)throw new xe(t);function p(t){var r=i,n=a;return i=a=e,u=t,s=o.apply(n,r)}function g(t){var o=t-c;return c===e||o>=r||o<0||h&&t-u>=l}function v(){var e=_a();if(g(e))return y(e);d=Ri(v,function(e){var t=r-(e-c);return h?yo(t,l-(e-u)):t}(e))}function y(t){return d=e,m&&i?p(t):(i=a=e,s)}function w(){var t=_a(),o=g(t);if(i=arguments,a=this,c=t,o){if(d===e)return function(e){return u=e,d=Ri(v,r),f?p(e):s}(c);if(h)return In(d),d=Ri(v,r),p(c)}return d===e&&(d=Ri(v,r)),s}return r=pl(r)||0,Xa(n)&&(f=!!n.leading,l=(h="maxWait"in n)?vo(pl(n.maxWait)||0,r):l,m="trailing"in n?!!n.trailing:m),w.cancel=function(){d!==e&&In(d),u=0,i=c=a=d=e},w.flush=function(){return d===e?s:y(_a())},w}var Na=Qr(function(e,t){return dr(e,1,t)}),ka=Qr(function(e,t,o){return dr(e,pl(t)||0,o)});function Oa(e,o){if("function"!=typeof e||null!=o&&"function"!=typeof o)throw new xe(t);var r=function(){var t=arguments,n=o?o.apply(this,t):t[0],i=r.cache;if(i.has(n))return i.get(n);var a=e.apply(this,t);return r.cache=i.set(n,a)||i,a};return r.cache=new(Oa.Cache||Ho),r}function Ta(e){if("function"!=typeof e)throw new xe(t);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}Oa.Cache=Ho;var La=bn(function(e,t){var o=(t=1==t.length&&Wa(t[0])?Pt(t[0],Gt(si())):Pt(gr(t,1),Gt(si()))).length;return Qr(function(r){for(var n=-1,i=yo(r.length,o);++n<i;)r[n]=t[n].call(this,r[n]);return Ct(e,this,r)})}),Ma=Qr(function(t,o){var r=no(o,li(Ma));return Yn(t,n,e,o,r)}),Ua=Qr(function(t,o){var r=no(o,li(Ua));return Yn(t,64,e,o,r)}),ja=oi(function(t,o){return Yn(t,a,e,e,e,o)});function Da(e,t){return e===t||e!=e&&t!=t}var Ba=Hn(_r),za=Hn(function(e,t){return e>=t}),qa=Rr(function(){return arguments}())?Rr:function(e){return el(e)&&Te.call(e,"callee")&&!Ge.call(e,"callee")},Wa=be.isArray,Va=pt?Gt(pt):function(e){return el(e)&&Ar(e)==x};function $a(e){return null!=e&&Za(e.length)&&!Ja(e)}function Ha(e){return el(e)&&$a(e)}var Ga=ho||ps,Ka=gt?Gt(gt):function(e){return el(e)&&Ar(e)==p};function Qa(e){if(!el(e))return!1;var t=Ar(e);return t==g||"[object DOMException]"==t||"string"==typeof e.message&&"string"==typeof e.name&&!rl(e)}function Ja(e){if(!Xa(e))return!1;var t=Ar(e);return t==v||t==y||"[object AsyncFunction]"==t||"[object Proxy]"==t}function Ya(e){return"number"==typeof e&&e==hl(e)}function Za(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=s}function Xa(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function el(e){return null!=e&&"object"==typeof e}var tl=vt?Gt(vt):function(e){return el(e)&&mi(e)==w};function ol(e){return"number"==typeof e||el(e)&&Ar(e)==b}function rl(e){if(!el(e)||Ar(e)!=C)return!1;var t=$e(e);if(null===t)return!0;var o=Te.call(t,"constructor")&&t.constructor;return"function"==typeof o&&o instanceof o&&Oe.call(o)==je}var nl=yt?Gt(yt):function(e){return el(e)&&Ar(e)==F},il=wt?Gt(wt):function(e){return el(e)&&mi(e)==A};function al(e){return"string"==typeof e||!Wa(e)&&el(e)&&Ar(e)==_}function ll(e){return"symbol"==typeof e||el(e)&&Ar(e)==S}var sl=bt?Gt(bt):function(e){return el(e)&&Za(e.length)&&!!ot[Ar(e)]},dl=Hn(Ur),cl=Hn(function(e,t){return e<=t});function ul(e){if(!e)return[];if($a(e))return al(e)?so(e):Pn(e);if(nt&&e[nt])return function(e){for(var t,o=[];!(t=e.next()).done;)o.push(t.value);return o}(e[nt]());var t=mi(e);return(t==w?oo:t==A?io:Dl)(e)}function fl(e){return e?(e=pl(e))===l||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}function hl(e){var t=fl(e),o=t%1;return t==t?o?t-o:t:0}function ml(e){return e?ar(hl(e),0,c):0}function pl(e){if("number"==typeof e)return e;if(ll(e))return d;if(Xa(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=Xa(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=Ht(e);var o=ue.test(e);return o||he.test(e)?at(e.slice(2),o?2:8):ce.test(e)?d:+e}function gl(e){return Rn(e,Nl(e))}function vl(e){return null==e?"":dn(e)}var yl=kn(function(e,t){if(Fi(t)||$a(t))Rn(t,Rl(t),e);else for(var o in t)Te.call(t,o)&&er(e,o,t[o])}),wl=kn(function(e,t){Rn(t,Nl(t),e)}),bl=kn(function(e,t,o,r){Rn(t,Nl(t),e,r)}),Cl=kn(function(e,t,o,r){Rn(t,Rl(t),e,r)}),Il=oi(ir),Fl=Qr(function(t,o){t=_e(t);var r=-1,n=o.length,i=n>2?o[2]:e;for(i&&wi(o[0],o[1],i)&&(n=1);++r<n;)for(var a=o[r],l=Nl(a),s=-1,d=l.length;++s<d;){var c=l[s],u=t[c];(u===e||Da(u,Ne[c])&&!Te.call(t,c))&&(t[c]=a[c])}return t}),Al=Qr(function(t){return t.push(e,Xn),Ct(Ol,e,t)});function _l(t,o,r){var n=null==t?e:Ir(t,o);return n===e?r:n}function Sl(e,t){return null!=e&&pi(e,t,Er)}var El=zn(function(e,t,o){null!=t&&"function"!=typeof t.toString&&(t=Ue.call(t)),e[t]=o},Xl(os)),xl=zn(function(e,t,o){null!=t&&"function"!=typeof t.toString&&(t=Ue.call(t)),Te.call(e,t)?e[t].push(o):e[t]=[o]},si),Pl=Qr(Pr);function Rl(e){return $a(e)?Qo(e):Lr(e)}function Nl(e){return $a(e)?Qo(e,!0):Mr(e)}var kl=kn(function(e,t,o){zr(e,t,o)}),Ol=kn(function(e,t,o,r){zr(e,t,o,r)}),Tl=oi(function(e,t){var o={};if(null==e)return o;var r=!1;t=Pt(t,function(t){return t=wn(t,e),r||(r=t.length>1),t}),Rn(e,ni(e),o),r&&(o=lr(o,7,ei));for(var n=t.length;n--;)un(o,t[n]);return o}),Ll=oi(function(e,t){return null==e?{}:function(e,t){return Vr(e,t,function(t,o){return Sl(e,o)})}(e,t)});function Ml(e,t){if(null==e)return{};var o=Pt(ni(e),function(e){return[e]});return t=si(t),Vr(e,o,function(e,o){return t(e,o[0])})}var Ul=Jn(Rl),jl=Jn(Nl);function Dl(e){return null==e?[]:Kt(e,Rl(e))}var Bl=Mn(function(e,t,o){return t=t.toLowerCase(),e+(o?zl(t):t)});function zl(e){return Ql(vl(e).toLowerCase())}function ql(e){return(e=vl(e))&&e.replace(pe,Zt).replace(Qe,"")}var Wl=Mn(function(e,t,o){return e+(o?"-":"")+t.toLowerCase()}),Vl=Mn(function(e,t,o){return e+(o?" ":"")+t.toLowerCase()}),$l=Ln("toLowerCase"),Hl=Mn(function(e,t,o){return e+(o?"_":"")+t.toLowerCase()}),Gl=Mn(function(e,t,o){return e+(o?" ":"")+Ql(t)}),Kl=Mn(function(e,t,o){return e+(o?" ":"")+t.toUpperCase()}),Ql=Ln("toUpperCase");function Jl(t,o,r){return t=vl(t),(o=r?e:o)===e?function(e){return Xe.test(e)}(t)?function(e){return e.match(Ye)||[]}(t):function(e){return e.match(ie)||[]}(t):t.match(o)||[]}var Yl=Qr(function(t,o){try{return Ct(t,e,o)}catch(e){return Qa(e)?e:new Ie(e)}}),Zl=oi(function(e,t){return Ft(t,function(t){t=Mi(t),nr(e,t,xa(e[t],e))}),e});function Xl(e){return function(){return e}}var es=Dn(),ts=Dn(!0);function os(e){return e}function rs(e){return Tr("function"==typeof e?e:lr(e,1))}var ns=Qr(function(e,t){return function(o){return Pr(o,e,t)}}),is=Qr(function(e,t){return function(o){return Pr(e,o,t)}});function as(e,t,o){var r=Rl(t),n=Cr(t,r);null!=o||Xa(t)&&(n.length||!r.length)||(o=t,t=e,e=this,n=Cr(t,Rl(t)));var i=!(Xa(o)&&"chain"in o&&!o.chain),a=Ja(e);return Ft(n,function(o){var r=t[o];e[o]=r,a&&(e.prototype[o]=function(){var t=this.__chain__;if(i||t){var o=e(this.__wrapped__);return(o.__actions__=Pn(this.__actions__)).push({func:r,args:arguments,thisArg:e}),o.__chain__=t,o}return r.apply(e,Rt([this.value()],arguments))})}),e}function ls(){}var ss=Wn(Pt),ds=Wn(_t),cs=Wn(Ot);function us(e){return bi(e)?zt(Mi(e)):function(e){return function(t){return Ir(t,e)}}(e)}var fs=$n(),hs=$n(!0);function ms(){return[]}function ps(){return!1}var gs,vs=qn(function(e,t){return e+t},0),ys=Kn("ceil"),ws=qn(function(e,t){return e/t},1),bs=Kn("floor"),Cs=qn(function(e,t){return e*t},1),Is=Kn("round"),Fs=qn(function(e,t){return e-t},0);return Do.after=function(e,o){if("function"!=typeof o)throw new xe(t);return e=hl(e),function(){if(--e<1)return o.apply(this,arguments)}},Do.ary=Sa,Do.assign=yl,Do.assignIn=wl,Do.assignInWith=bl,Do.assignWith=Cl,Do.at=Il,Do.before=Ea,Do.bind=xa,Do.bindAll=Zl,Do.bindKey=Pa,Do.castArray=function(){if(!arguments.length)return[];var e=arguments[0];return Wa(e)?e:[e]},Do.chain=ua,Do.chunk=function(t,o,r){o=(r?wi(t,o,r):o===e)?1:vo(hl(o),0);var n=null==t?0:t.length;if(!n||o<1)return[];for(var i=0,a=0,l=be(mt(n/o));i<n;)l[a++]=on(t,i,i+=o);return l},Do.compact=function(e){for(var t=-1,o=null==e?0:e.length,r=0,n=[];++t<o;){var i=e[t];i&&(n[r++]=i)}return n},Do.concat=function(){var e=arguments.length;if(!e)return[];for(var t=be(e-1),o=arguments[0],r=e;r--;)t[r-1]=arguments[r];return Rt(Wa(o)?Pn(o):[o],gr(t,1))},Do.cond=function(e){var o=null==e?0:e.length,r=si();return e=o?Pt(e,function(e){if("function"!=typeof e[1])throw new xe(t);return[r(e[0]),e[1]]}):[],Qr(function(t){for(var r=-1;++r<o;){var n=e[r];if(Ct(n[0],this,t))return Ct(n[1],this,t)}})},Do.conforms=function(e){return function(e){var t=Rl(e);return function(o){return sr(o,e,t)}}(lr(e,1))},Do.constant=Xl,Do.countBy=ma,Do.create=function(e,t){var o=Bo(e);return null==t?o:rr(o,t)},Do.curry=function t(o,r,n){var i=Yn(o,8,e,e,e,e,e,r=n?e:r);return i.placeholder=t.placeholder,i},Do.curryRight=function t(o,r,n){var i=Yn(o,16,e,e,e,e,e,r=n?e:r);return i.placeholder=t.placeholder,i},Do.debounce=Ra,Do.defaults=Fl,Do.defaultsDeep=Al,Do.defer=Na,Do.delay=ka,Do.difference=Di,Do.differenceBy=Bi,Do.differenceWith=zi,Do.drop=function(t,o,r){var n=null==t?0:t.length;return n?on(t,(o=r||o===e?1:hl(o))<0?0:o,n):[]},Do.dropRight=function(t,o,r){var n=null==t?0:t.length;return n?on(t,0,(o=n-(o=r||o===e?1:hl(o)))<0?0:o):[]},Do.dropRightWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!0,!0):[]},Do.dropWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!0):[]},Do.fill=function(t,o,r,n){var i=null==t?0:t.length;return i?(r&&"number"!=typeof r&&wi(t,o,r)&&(r=0,n=i),function(t,o,r,n){var i=t.length;for((r=hl(r))<0&&(r=-r>i?0:i+r),(n=n===e||n>i?i:hl(n))<0&&(n+=i),n=r>n?0:ml(n);r<n;)t[r++]=o;return t}(t,o,r,n)):[]},Do.filter=function(e,t){return(Wa(e)?St:pr)(e,si(t,3))},Do.flatMap=function(e,t){return gr(Ia(e,t),1)},Do.flatMapDeep=function(e,t){return gr(Ia(e,t),l)},Do.flatMapDepth=function(t,o,r){return r=r===e?1:hl(r),gr(Ia(t,o),r)},Do.flatten=Vi,Do.flattenDeep=function(e){return null!=e&&e.length?gr(e,l):[]},Do.flattenDepth=function(t,o){return null!=t&&t.length?gr(t,o=o===e?1:hl(o)):[]},Do.flip=function(e){return Yn(e,512)},Do.flow=es,Do.flowRight=ts,Do.fromPairs=function(e){for(var t=-1,o=null==e?0:e.length,r={};++t<o;){var n=e[t];r[n[0]]=n[1]}return r},Do.functions=function(e){return null==e?[]:Cr(e,Rl(e))},Do.functionsIn=function(e){return null==e?[]:Cr(e,Nl(e))},Do.groupBy=wa,Do.initial=function(e){return null!=e&&e.length?on(e,0,-1):[]},Do.intersection=Hi,Do.intersectionBy=Gi,Do.intersectionWith=Ki,Do.invert=El,Do.invertBy=xl,Do.invokeMap=ba,Do.iteratee=rs,Do.keyBy=Ca,Do.keys=Rl,Do.keysIn=Nl,Do.map=Ia,Do.mapKeys=function(e,t){var o={};return t=si(t,3),wr(e,function(e,r,n){nr(o,t(e,r,n),e)}),o},Do.mapValues=function(e,t){var o={};return t=si(t,3),wr(e,function(e,r,n){nr(o,r,t(e,r,n))}),o},Do.matches=function(e){return Dr(lr(e,1))},Do.matchesProperty=function(e,t){return Br(e,lr(t,1))},Do.memoize=Oa,Do.merge=kl,Do.mergeWith=Ol,Do.method=ns,Do.methodOf=is,Do.mixin=as,Do.negate=Ta,Do.nthArg=function(e){return e=hl(e),Qr(function(t){return qr(t,e)})},Do.omit=Tl,Do.omitBy=function(e,t){return Ml(e,Ta(si(t)))},Do.once=function(e){return Ea(2,e)},Do.orderBy=function(t,o,r,n){return null==t?[]:(Wa(o)||(o=null==o?[]:[o]),Wa(r=n?e:r)||(r=null==r?[]:[r]),Wr(t,o,r))},Do.over=ss,Do.overArgs=La,Do.overEvery=ds,Do.overSome=cs,Do.partial=Ma,Do.partialRight=Ua,Do.partition=Fa,Do.pick=Ll,Do.pickBy=Ml,Do.property=us,Do.propertyOf=function(t){return function(o){return null==t?e:Ir(t,o)}},Do.pull=Ji,Do.pullAll=Yi,Do.pullAllBy=function(e,t,o){return e&&e.length&&t&&t.length?$r(e,t,si(o,2)):e},Do.pullAllWith=function(t,o,r){return t&&t.length&&o&&o.length?$r(t,o,e,r):t},Do.pullAt=Zi,Do.range=fs,Do.rangeRight=hs,Do.rearg=ja,Do.reject=function(e,t){return(Wa(e)?St:pr)(e,Ta(si(t,3)))},Do.remove=function(e,t){var o=[];if(!e||!e.length)return o;var r=-1,n=[],i=e.length;for(t=si(t,3);++r<i;){var a=e[r];t(a,r,e)&&(o.push(a),n.push(r))}return Hr(e,n),o},Do.rest=function(o,r){if("function"!=typeof o)throw new xe(t);return Qr(o,r=r===e?r:hl(r))},Do.reverse=Xi,Do.sampleSize=function(t,o,r){return o=(r?wi(t,o,r):o===e)?1:hl(o),(Wa(t)?Yo:Yr)(t,o)},Do.set=function(e,t,o){return null==e?e:Zr(e,t,o)},Do.setWith=function(t,o,r,n){return n="function"==typeof n?n:e,null==t?t:Zr(t,o,r,n)},Do.shuffle=function(e){return(Wa(e)?Zo:tn)(e)},Do.slice=function(t,o,r){var n=null==t?0:t.length;return n?(r&&"number"!=typeof r&&wi(t,o,r)?(o=0,r=n):(o=null==o?0:hl(o),r=r===e?n:hl(r)),on(t,o,r)):[]},Do.sortBy=Aa,Do.sortedUniq=function(e){return e&&e.length?ln(e):[]},Do.sortedUniqBy=function(e,t){return e&&e.length?ln(e,si(t,2)):[]},Do.split=function(t,o,r){return r&&"number"!=typeof r&&wi(t,o,r)&&(o=r=e),(r=r===e?c:r>>>0)?(t=vl(t))&&("string"==typeof o||null!=o&&!nl(o))&&!(o=dn(o))&&to(t)?Cn(so(t),0,r):t.split(o,r):[]},Do.spread=function(e,o){if("function"!=typeof e)throw new xe(t);return o=null==o?0:vo(hl(o),0),Qr(function(t){var r=t[o],n=Cn(t,0,o);return r&&Rt(n,r),Ct(e,this,n)})},Do.tail=function(e){var t=null==e?0:e.length;return t?on(e,1,t):[]},Do.take=function(t,o,r){return t&&t.length?on(t,0,(o=r||o===e?1:hl(o))<0?0:o):[]},Do.takeRight=function(t,o,r){var n=null==t?0:t.length;return n?on(t,(o=n-(o=r||o===e?1:hl(o)))<0?0:o,n):[]},Do.takeRightWhile=function(e,t){return e&&e.length?hn(e,si(t,3),!1,!0):[]},Do.takeWhile=function(e,t){return e&&e.length?hn(e,si(t,3)):[]},Do.tap=function(e,t){return t(e),e},Do.throttle=function(e,o,r){var n=!0,i=!0;if("function"!=typeof e)throw new xe(t);return Xa(r)&&(n="leading"in r?!!r.leading:n,i="trailing"in r?!!r.trailing:i),Ra(e,o,{leading:n,maxWait:o,trailing:i})},Do.thru=fa,Do.toArray=ul,Do.toPairs=Ul,Do.toPairsIn=jl,Do.toPath=function(e){return Wa(e)?Pt(e,Mi):ll(e)?[e]:Pn(Li(vl(e)))},Do.toPlainObject=gl,Do.transform=function(e,t,o){var r=Wa(e),n=r||Ga(e)||sl(e);if(t=si(t,4),null==o){var i=e&&e.constructor;o=n?r?new i:[]:Xa(e)&&Ja(i)?Bo($e(e)):{}}return(n?Ft:wr)(e,function(e,r,n){return t(o,e,r,n)}),o},Do.unary=function(e){return Sa(e,1)},Do.union=ea,Do.unionBy=ta,Do.unionWith=oa,Do.uniq=function(e){return e&&e.length?cn(e):[]},Do.uniqBy=function(e,t){return e&&e.length?cn(e,si(t,2)):[]},Do.uniqWith=function(t,o){return o="function"==typeof o?o:e,t&&t.length?cn(t,e,o):[]},Do.unset=function(e,t){return null==e||un(e,t)},Do.unzip=ra,Do.unzipWith=na,Do.update=function(e,t,o){return null==e?e:fn(e,t,yn(o))},Do.updateWith=function(t,o,r,n){return n="function"==typeof n?n:e,null==t?t:fn(t,o,yn(r),n)},Do.values=Dl,Do.valuesIn=function(e){return null==e?[]:Kt(e,Nl(e))},Do.without=ia,Do.words=Jl,Do.wrap=function(e,t){return Ma(yn(t),e)},Do.xor=aa,Do.xorBy=la,Do.xorWith=sa,Do.zip=da,Do.zipObject=function(e,t){return gn(e||[],t||[],er)},Do.zipObjectDeep=function(e,t){return gn(e||[],t||[],Zr)},Do.zipWith=ca,Do.entries=Ul,Do.entriesIn=jl,Do.extend=wl,Do.extendWith=bl,as(Do,Do),Do.add=vs,Do.attempt=Yl,Do.camelCase=Bl,Do.capitalize=zl,Do.ceil=ys,Do.clamp=function(t,o,r){return r===e&&(r=o,o=e),r!==e&&(r=(r=pl(r))==r?r:0),o!==e&&(o=(o=pl(o))==o?o:0),ar(pl(t),o,r)},Do.clone=function(e){return lr(e,4)},Do.cloneDeep=function(e){return lr(e,5)},Do.cloneDeepWith=function(t,o){return lr(t,5,o="function"==typeof o?o:e)},Do.cloneWith=function(t,o){return lr(t,4,o="function"==typeof o?o:e)},Do.conformsTo=function(e,t){return null==t||sr(e,t,Rl(t))},Do.deburr=ql,Do.defaultTo=function(e,t){return null==e||e!=e?t:e},Do.divide=ws,Do.endsWith=function(t,o,r){t=vl(t),o=dn(o);var n=t.length,i=r=r===e?n:ar(hl(r),0,n);return(r-=o.length)>=0&&t.slice(r,i)==o},Do.eq=Da,Do.escape=function(e){return(e=vl(e))&&$.test(e)?e.replace(W,Xt):e},Do.escapeRegExp=function(e){return(e=vl(e))&&X.test(e)?e.replace(Z,"\\$&"):e},Do.every=function(t,o,r){var n=Wa(t)?_t:hr;return r&&wi(t,o,r)&&(o=e),n(t,si(o,3))},Do.find=pa,Do.findIndex=qi,Do.findKey=function(e,t){return Lt(e,si(t,3),wr)},Do.findLast=ga,Do.findLastIndex=Wi,Do.findLastKey=function(e,t){return Lt(e,si(t,3),br)},Do.floor=bs,Do.forEach=va,Do.forEachRight=ya,Do.forIn=function(e,t){return null==e?e:vr(e,si(t,3),Nl)},Do.forInRight=function(e,t){return null==e?e:yr(e,si(t,3),Nl)},Do.forOwn=function(e,t){return e&&wr(e,si(t,3))},Do.forOwnRight=function(e,t){return e&&br(e,si(t,3))},Do.get=_l,Do.gt=Ba,Do.gte=za,Do.has=function(e,t){return null!=e&&pi(e,t,Sr)},Do.hasIn=Sl,Do.head=$i,Do.identity=os,Do.includes=function(e,t,o,r){e=$a(e)?e:Dl(e),o=o&&!r?hl(o):0;var n=e.length;return o<0&&(o=vo(n+o,0)),al(e)?o<=n&&e.indexOf(t,o)>-1:!!n&&Ut(e,t,o)>-1},Do.indexOf=function(e,t,o){var r=null==e?0:e.length;if(!r)return-1;var n=null==o?0:hl(o);return n<0&&(n=vo(r+n,0)),Ut(e,t,n)},Do.inRange=function(t,o,r){return o=fl(o),r===e?(r=o,o=0):r=fl(r),function(e,t,o){return e>=yo(t,o)&&e<vo(t,o)}(t=pl(t),o,r)},Do.invoke=Pl,Do.isArguments=qa,Do.isArray=Wa,Do.isArrayBuffer=Va,Do.isArrayLike=$a,Do.isArrayLikeObject=Ha,Do.isBoolean=function(e){return!0===e||!1===e||el(e)&&Ar(e)==m},Do.isBuffer=Ga,Do.isDate=Ka,Do.isElement=function(e){return el(e)&&1===e.nodeType&&!rl(e)},Do.isEmpty=function(e){if(null==e)return!0;if($a(e)&&(Wa(e)||"string"==typeof e||"function"==typeof e.splice||Ga(e)||sl(e)||qa(e)))return!e.length;var t=mi(e);if(t==w||t==A)return!e.size;if(Fi(e))return!Lr(e).length;for(var o in e)if(Te.call(e,o))return!1;return!0},Do.isEqual=function(e,t){return Nr(e,t)},Do.isEqualWith=function(t,o,r){var n=(r="function"==typeof r?r:e)?r(t,o):e;return n===e?Nr(t,o,e,r):!!n},Do.isError=Qa,Do.isFinite=function(e){return"number"==typeof e&&mo(e)},Do.isFunction=Ja,Do.isInteger=Ya,Do.isLength=Za,Do.isMap=tl,Do.isMatch=function(e,t){return e===t||kr(e,t,ci(t))},Do.isMatchWith=function(t,o,r){return r="function"==typeof r?r:e,kr(t,o,ci(o),r)},Do.isNaN=function(e){return ol(e)&&e!=+e},Do.isNative=function(e){if(Ii(e))throw new Ie("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return Or(e)},Do.isNil=function(e){return null==e},Do.isNull=function(e){return null===e},Do.isNumber=ol,Do.isObject=Xa,Do.isObjectLike=el,Do.isPlainObject=rl,Do.isRegExp=nl,Do.isSafeInteger=function(e){return Ya(e)&&e>=-9007199254740991&&e<=s},Do.isSet=il,Do.isString=al,Do.isSymbol=ll,Do.isTypedArray=sl,Do.isUndefined=function(t){return t===e},Do.isWeakMap=function(e){return el(e)&&mi(e)==E},Do.isWeakSet=function(e){return el(e)&&"[object WeakSet]"==Ar(e)},Do.join=function(e,t){return null==e?"":po.call(e,t)},Do.kebabCase=Wl,Do.last=Qi,Do.lastIndexOf=function(t,o,r){var n=null==t?0:t.length;if(!n)return-1;var i=n;return r!==e&&(i=(i=hl(r))<0?vo(n+i,0):yo(i,n-1)),o==o?function(e,t,o){for(var r=o+1;r--;)if(e[r]===t)return r;return r}(t,o,i):Mt(t,Dt,i,!0)},Do.lowerCase=Vl,Do.lowerFirst=$l,Do.lt=dl,Do.lte=cl,Do.max=function(t){return t&&t.length?mr(t,os,_r):e},Do.maxBy=function(t,o){return t&&t.length?mr(t,si(o,2),_r):e},Do.mean=function(e){return Bt(e,os)},Do.meanBy=function(e,t){return Bt(e,si(t,2))},Do.min=function(t){return t&&t.length?mr(t,os,Ur):e},Do.minBy=function(t,o){return t&&t.length?mr(t,si(o,2),Ur):e},Do.stubArray=ms,Do.stubFalse=ps,Do.stubObject=function(){return{}},Do.stubString=function(){return""},Do.stubTrue=function(){return!0},Do.multiply=Cs,Do.nth=function(t,o){return t&&t.length?qr(t,hl(o)):e},Do.noConflict=function(){return dt._===this&&(dt._=De),this},Do.noop=ls,Do.now=_a,Do.pad=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;if(!t||r>=t)return e;var n=(t-r)/2;return Vn(Tt(n),o)+e+Vn(mt(n),o)},Do.padEnd=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;return t&&r<t?e+Vn(t-r,o):e},Do.padStart=function(e,t,o){e=vl(e);var r=(t=hl(t))?lo(e):0;return t&&r<t?Vn(t-r,o)+e:e},Do.parseInt=function(e,t,o){return o||null==t?t=0:t&&(t=+t),bo(vl(e).replace(ee,""),t||0)},Do.random=function(t,o,r){if(r&&"boolean"!=typeof r&&wi(t,o,r)&&(o=r=e),r===e&&("boolean"==typeof o?(r=o,o=e):"boolean"==typeof t&&(r=t,t=e)),t===e&&o===e?(t=0,o=1):(t=fl(t),o===e?(o=t,t=0):o=fl(o)),t>o){var n=t;t=o,o=n}if(r||t%1||o%1){var i=Co();return yo(t+i*(o-t+it("1e-"+((i+"").length-1))),o)}return Gr(t,o)},Do.reduce=function(e,t,o){var r=Wa(e)?Nt:Wt,n=arguments.length<3;return r(e,si(t,4),o,n,ur)},Do.reduceRight=function(e,t,o){var r=Wa(e)?kt:Wt,n=arguments.length<3;return r(e,si(t,4),o,n,fr)},Do.repeat=function(t,o,r){return o=(r?wi(t,o,r):o===e)?1:hl(o),Kr(vl(t),o)},Do.replace=function(){var e=arguments,t=vl(e[0]);return e.length<3?t:t.replace(e[1],e[2])},Do.result=function(t,o,r){var n=-1,i=(o=wn(o,t)).length;for(i||(i=1,t=e);++n<i;){var a=null==t?e:t[Mi(o[n])];a===e&&(n=i,a=r),t=Ja(a)?a.call(t):a}return t},Do.round=Is,Do.runInContext=te,Do.sample=function(e){return(Wa(e)?Jo:Jr)(e)},Do.size=function(e){if(null==e)return 0;if($a(e))return al(e)?lo(e):e.length;var t=mi(e);return t==w||t==A?e.size:Lr(e).length},Do.snakeCase=Hl,Do.some=function(t,o,r){var n=Wa(t)?Ot:rn;return r&&wi(t,o,r)&&(o=e),n(t,si(o,3))},Do.sortedIndex=function(e,t){return nn(e,t)},Do.sortedIndexBy=function(e,t,o){return an(e,t,si(o,2))},Do.sortedIndexOf=function(e,t){var o=null==e?0:e.length;if(o){var r=nn(e,t);if(r<o&&Da(e[r],t))return r}return-1},Do.sortedLastIndex=function(e,t){return nn(e,t,!0)},Do.sortedLastIndexBy=function(e,t,o){return an(e,t,si(o,2),!0)},Do.sortedLastIndexOf=function(e,t){if(null!=e&&e.length){var o=nn(e,t,!0)-1;if(Da(e[o],t))return o}return-1},Do.startCase=Gl,Do.startsWith=function(e,t,o){return e=vl(e),o=null==o?0:ar(hl(o),0,e.length),t=dn(t),e.slice(o,o+t.length)==t},Do.subtract=Fs,Do.sum=function(e){return e&&e.length?Vt(e,os):0},Do.sumBy=function(e,t){return e&&e.length?Vt(e,si(t,2)):0},Do.template=function(t,o,r){var n=Do.templateSettings;r&&wi(t,o,r)&&(o=e),t=vl(t),o=bl({},o,n,Zn);var i,a,l=bl({},o.imports,n.imports,Zn),s=Rl(l),d=Kt(l,s),c=0,u=o.interpolate||ge,f="__p += '",h=Se((o.escape||ge).source+"|"+u.source+"|"+(u===K?se:ge).source+"|"+(o.evaluate||ge).source+"|$","g"),m="//# sourceURL="+(Te.call(o,"sourceURL")?(o.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tt+"]")+"\n";t.replace(h,function(e,o,r,n,l,s){return r||(r=n),f+=t.slice(c,s).replace(ve,eo),o&&(i=!0,f+="' +\n__e("+o+") +\n'"),l&&(a=!0,f+="';\n"+l+";\n__p += '"),r&&(f+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),c=s+e.length,e}),f+="';\n";var p=Te.call(o,"variable")&&o.variable;if(p){if(ae.test(p))throw new Ie("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(a?f.replace(D,""):f).replace(B,"$1").replace(z,"$1;"),f="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(i?", __e = _.escape":"")+(a?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var g=Yl(function(){return Fe(s,m+"return "+f).apply(e,d)});if(g.source=f,Qa(g))throw g;return g},Do.times=function(e,t){if((e=hl(e))<1||e>s)return[];var o=c,r=yo(e,c);t=si(t),e-=c;for(var n=$t(r,t);++o<e;)t(o);return n},Do.toFinite=fl,Do.toInteger=hl,Do.toLength=ml,Do.toLower=function(e){return vl(e).toLowerCase()},Do.toNumber=pl,Do.toSafeInteger=function(e){return e?ar(hl(e),-9007199254740991,s):0===e?e:0},Do.toString=vl,Do.toUpper=function(e){return vl(e).toUpperCase()},Do.trim=function(t,o,r){if((t=vl(t))&&(r||o===e))return Ht(t);if(!t||!(o=dn(o)))return t;var n=so(t),i=so(o);return Cn(n,Jt(n,i),Yt(n,i)+1).join("")},Do.trimEnd=function(t,o,r){if((t=vl(t))&&(r||o===e))return t.slice(0,co(t)+1);if(!t||!(o=dn(o)))return t;var n=so(t);return Cn(n,0,Yt(n,so(o))+1).join("")},Do.trimStart=function(t,o,r){if((t=vl(t))&&(r||o===e))return t.replace(ee,"");if(!t||!(o=dn(o)))return t;var n=so(t);return Cn(n,Jt(n,so(o))).join("")},Do.truncate=function(t,o){var r=30,n="...";if(Xa(o)){var i="separator"in o?o.separator:i;r="length"in o?hl(o.length):r,n="omission"in o?dn(o.omission):n}var a=(t=vl(t)).length;if(to(t)){var l=so(t);a=l.length}if(r>=a)return t;var s=r-lo(n);if(s<1)return n;var d=l?Cn(l,0,s).join(""):t.slice(0,s);if(i===e)return d+n;if(l&&(s+=d.length-s),nl(i)){if(t.slice(s).search(i)){var c,u=d;for(i.global||(i=Se(i.source,vl(de.exec(i))+"g")),i.lastIndex=0;c=i.exec(u);)var f=c.index;d=d.slice(0,f===e?s:f)}}else if(t.indexOf(dn(i),s)!=s){var h=d.lastIndexOf(i);h>-1&&(d=d.slice(0,h))}return d+n},Do.unescape=function(e){return(e=vl(e))&&V.test(e)?e.replace(q,uo):e},Do.uniqueId=function(e){var t=++Le;return vl(e)+t},Do.upperCase=Kl,Do.upperFirst=Ql,Do.each=va,Do.eachRight=ya,Do.first=$i,as(Do,(gs={},wr(Do,function(e,t){Te.call(Do.prototype,t)||(gs[t]=e)}),gs),{chain:!1}),Do.VERSION="4.17.21",Ft(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){Do[e].placeholder=Do}),Ft(["drop","take"],function(t,o){Wo.prototype[t]=function(r){r=r===e?1:vo(hl(r),0);var n=this.__filtered__&&!o?new Wo(this):this.clone();return n.__filtered__?n.__takeCount__=yo(r,n.__takeCount__):n.__views__.push({size:yo(r,c),type:t+(n.__dir__<0?"Right":"")}),n},Wo.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}}),Ft(["filter","map","takeWhile"],function(e,t){var o=t+1,r=1==o||3==o;Wo.prototype[e]=function(e){var t=this.clone();return t.__iteratees__.push({iteratee:si(e,3),type:o}),t.__filtered__=t.__filtered__||r,t}}),Ft(["head","last"],function(e,t){var o="take"+(t?"Right":"");Wo.prototype[e]=function(){return this[o](1).value()[0]}}),Ft(["initial","tail"],function(e,t){var o="drop"+(t?"":"Right");Wo.prototype[e]=function(){return this.__filtered__?new Wo(this):this[o](1)}}),Wo.prototype.compact=function(){return this.filter(os)},Wo.prototype.find=function(e){return this.filter(e).head()},Wo.prototype.findLast=function(e){return this.reverse().find(e)},Wo.prototype.invokeMap=Qr(function(e,t){return"function"==typeof e?new Wo(this):this.map(function(o){return Pr(o,e,t)})}),Wo.prototype.reject=function(e){return this.filter(Ta(si(e)))},Wo.prototype.slice=function(t,o){t=hl(t);var r=this;return r.__filtered__&&(t>0||o<0)?new Wo(r):(t<0?r=r.takeRight(-t):t&&(r=r.drop(t)),o!==e&&(r=(o=hl(o))<0?r.dropRight(-o):r.take(o-t)),r)},Wo.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},Wo.prototype.toArray=function(){return this.take(c)},wr(Wo.prototype,function(t,o){var r=/^(?:filter|find|map|reject)|While$/.test(o),n=/^(?:head|last)$/.test(o),i=Do[n?"take"+("last"==o?"Right":""):o],a=n||/^find/.test(o);i&&(Do.prototype[o]=function(){var o=this.__wrapped__,l=n?[1]:arguments,s=o instanceof Wo,d=l[0],c=s||Wa(o),u=function(e){var t=i.apply(Do,Rt([e],l));return n&&f?t[0]:t};c&&r&&"function"==typeof d&&1!=d.length&&(s=c=!1);var f=this.__chain__,h=!!this.__actions__.length,m=a&&!f,p=s&&!h;if(!a&&c){o=p?o:new Wo(this);var g=t.apply(o,l);return g.__actions__.push({func:fa,args:[u],thisArg:e}),new qo(g,f)}return m&&p?t.apply(this,l):(g=this.thru(u),m?n?g.value()[0]:g.value():g)})}),Ft(["pop","push","shift","sort","splice","unshift"],function(e){var t=Pe[e],o=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:pop|shift)$/.test(e);Do.prototype[e]=function(){var e=arguments;if(r&&!this.__chain__){var n=this.value();return t.apply(Wa(n)?n:[],e)}return this[o](function(o){return t.apply(Wa(o)?o:[],e)})}}),wr(Wo.prototype,function(e,t){var o=Do[t];if(o){var r=o.name+"";Te.call(Ro,r)||(Ro[r]=[]),Ro[r].push({name:t,func:o})}}),Ro[Bn(e,2).name]=[{name:"wrapper",func:e}],Wo.prototype.clone=function(){var e=new Wo(this.__wrapped__);return e.__actions__=Pn(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=Pn(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=Pn(this.__views__),e},Wo.prototype.reverse=function(){if(this.__filtered__){var e=new Wo(this);e.__dir__=-1,e.__filtered__=!0}else(e=this.clone()).__dir__*=-1;return e},Wo.prototype.value=function(){var e=this.__wrapped__.value(),t=this.__dir__,o=Wa(e),r=t<0,n=o?e.length:0,i=function(e,t,o){for(var r=-1,n=o.length;++r<n;){var i=o[r],a=i.size;switch(i.type){case"drop":e+=a;break;case"dropRight":t-=a;break;case"take":t=yo(t,e+a);break;case"takeRight":e=vo(e,t-a)}}return{start:e,end:t}}(0,n,this.__views__),a=i.start,l=i.end,s=l-a,d=r?l:a-1,c=this.__iteratees__,u=c.length,f=0,h=yo(s,this.__takeCount__);if(!o||!r&&n==s&&h==s)return mn(e,this.__actions__);var m=[];e:for(;s--&&f<h;){for(var p=-1,g=e[d+=t];++p<u;){var v=c[p],y=v.iteratee,w=v.type,b=y(g);if(2==w)g=b;else if(!b){if(1==w)continue e;break e}}m[f++]=g}return m},Do.prototype.at=ha,Do.prototype.chain=function(){return ua(this)},Do.prototype.commit=function(){return new qo(this.value(),this.__chain__)},Do.prototype.next=function(){this.__values__===e&&(this.__values__=ul(this.value()));var t=this.__index__>=this.__values__.length;return{done:t,value:t?e:this.__values__[this.__index__++]}},Do.prototype.plant=function(t){for(var o,r=this;r instanceof zo;){var n=ji(r);n.__index__=0,n.__values__=e,o?i.__wrapped__=n:o=n;var i=n;r=r.__wrapped__}return i.__wrapped__=t,o},Do.prototype.reverse=function(){var t=this.__wrapped__;if(t instanceof Wo){var o=t;return this.__actions__.length&&(o=new Wo(this)),(o=o.reverse()).__actions__.push({func:fa,args:[Xi],thisArg:e}),new qo(o,this.__chain__)}return this.thru(Xi)},Do.prototype.toJSON=Do.prototype.valueOf=Do.prototype.value=function(){return mn(this.__wrapped__,this.__actions__)},Do.prototype.first=Do.prototype.head,nt&&(Do.prototype[nt]=function(){return this}),Do}();ut?((ut.exports=fo)._=fo,ct._=fo):dt._=fo}.call(Fn.exports)),Fn.exports);const En=e=>null===e.parentId||"null"===e.parentId||!e.parentId,xn=async(e,t,o)=>{var r;if("file"===(null==t?void 0:t.itemType))return e;let n=[];if(!o)return e;{const e=await o({parentId:t.folderId});n=Array.isArray(e)?e:[]}let i=((e,t)=>{const o=Array.isArray(e)?e:[];return(r=t.folderId)&&"root"!==r&&"folders"!==r&&"null"!==r&&null!==r?o.filter(e=>e.parentId===t.folderId):o.filter(En);var r})(n,t);if(null===(r=null==t?void 0:t.search)||void 0===r?void 0:r.trim()){const e=t.search.trim().toLowerCase();i=i.filter(t=>{var o;return null===(o=t.name)||void 0===o?void 0:o.toLowerCase().includes(e)})}if(0===i.length)return e;const a=i.map(e=>({id:e.id,name:e.name,size:void 0,date:"-",isFolder:!0,folderId:e.parentId||"",type:"",selected:!1,extension:"",childCount:e.childCount}));if("folder"===(null==t?void 0:t.itemType))return a;const l=e.filter(e=>!e.isFolder);return[...a,...l]},Pn=e=>{var t,o,r,n;const{state:i,actions:l,options:s}=mn(),{searchTerm:u,sortBy:f,sortOrder:h,selectedFolder:m,pagination:p,pathHistory:g}=i,{setSearchTerm:v,setSortBy:y,setSortOrder:w,setPagination:b}=l,C=e||l.fetchFiles,I=c(null),F=c(Sn.debounce(e=>{const t=JSON.stringify(e);I.current!==t&&(I.current=t,null==C||C(e))},150)).current,A=d(()=>{const e=m||"";if(!e)return;const t=[...Array.isArray(g)?g:[]].reverse().find(t=>t.id===e);return null==t?void 0:t.name},[m,g]),_=d(()=>{var e;const t=null===(e=null==s?void 0:s.config)||void 0===e?void 0:e.disablePagination;return{folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:t?void 0:p.current,limit:t?void 0:p.pageSize,sortBy:f,sortOrder:h,itemType:"all"}},[m,A,u,p.current,p.pageSize,f,h,null===(t=null==s?void 0:s.config)||void 0===t?void 0:t.disablePagination]),S=d(e=>{var t,o;if(v&&v(e),b&&b({current:1,pageSize:p.pageSize,total:0}),C){const r={folderId:m||"",folderName:A(),search:(null==e?void 0:e.trim())||void 0,page:(null===(t=null==s?void 0:s.config)||void 0===t?void 0:t.disablePagination)?void 0:1,limit:(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)?void 0:p.pageSize,sortBy:f,sortOrder:h,itemType:"all"};C(r)}else console.error("🔎 useSortAndFilter: fetchFiles НЕ ОПРЕДЕЛЕНА!")},[v,b,p.pageSize,C,m,A,f,h,null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination]),E=d((e,t)=>{var o,r;null==y||y(e),null==w||w(t),C&&F({folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)?void 0:p.current,limit:(null===(r=null==s?void 0:s.config)||void 0===r?void 0:r.disablePagination)?void 0:p.pageSize,sortBy:e,sortOrder:t,itemType:"all"})},[y,w,F,m,A,u,p.current,p.pageSize,null===(r=null==s?void 0:s.config)||void 0===r?void 0:r.disablePagination]),x=d((e,t)=>{var o;(null===(o=null==s?void 0:s.config)||void 0===o?void 0:o.disablePagination)||(b&&b({current:e,pageSize:t||p.pageSize,total:p.total}),C&&F({folderId:m||"",folderName:A(),search:(null==u?void 0:u.trim())||void 0,page:e,limit:t||p.pageSize,sortBy:f,sortOrder:h,itemType:"all"}))},[b,p.pageSize,p.total,F,m,A,u,f,h,null===(n=null==s?void 0:s.config)||void 0===n?void 0:n.disablePagination]);return a(()=>{if(C){const e=_();F(Object.assign(Object.assign({},e),{page:1}))}},[m]),a(()=>{C&&F(_())},[]),a(()=>()=>{var e;null===(e=F.cancel)||void 0===e||e.call(F)},[F]),{state:{searchTerm:u||"",sortBy:f||"name",sortOrder:h||"asc"},actions:{setSearchTerm:v||(()=>{}),setSortBy:y||(()=>{}),setSortOrder:w||(()=>{}),handleSearch:S,handleSort:E,handlePaginationChange:x,getCurrentQueryParams:_}}};function Rn(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(o[r[n]]=e[r[n]])}return o}"function"==typeof SuppressedError&&SuppressedError;const Nn=new Map;function kn(e){const t="id"in e&&void 0!==e.id?String(e.id):"unknown",o="data"in e?e.data:void 0;return`${e.type}:${t}:${function(e){if(null==e)return"";try{return JSON.stringify(e,Object.keys(e).sort())}catch(t){return String(e)}}(o)}`}const On=()=>{var e,t;const{notification:o}=C.useApp(),r=mn(),{options:n}=r,i=d(async e=>{let t;if(n.handleNotify){try{t=await n.handleNotify(e)}catch(e){console.error(e)}if(!1===t)return!1;"object"==typeof t&&t&&(e=t)}if("error"===e.type&&n.handleError){try{t=await n.handleError(e)}catch(e){console.error(e)}if(!1===t)return!1;"object"==typeof t&&t&&(e=t)}if("success"===e.type&&n.handleSuccess){try{t=await n.handleSuccess(e)}catch(e){console.error(e)}if(t)return!1}return t},[n]),a=d(async function(e,t=!1){var r,a,l,s,d;try{void 0===e.visibility&&(e.visibility=!t);const c=await i(e);"object"==typeof c&&(e=c);const u=null!==(a=null===(r=n.config)||void 0===r?void 0:r.notificationDedupeTtlMs)&&void 0!==a?a:12e3,f="error"===e.type&&!0===e.notificationDedupe;f&&function(e,t){if(t<=0)return;const o=kn(e),r=Date.now(),n=Nn.get(o);void 0!==n&&r-n<t&&(e.visibility=!1)}(e,u);if(!(!1!==e.visibility&&!1!==c&&!1!==(null===(l=n.config)||void 0===l?void 0:l.showNotifications)))return e;const h=o[e.type];if("function"==typeof h){const t=e,{message:o,btn:r}=t,n=Rn(t,["message","btn"]);h(Object.assign(Object.assign(Object.assign({},n),{title:null!==(s=n.title)&&void 0!==s?s:o}),void 0!==r?{actions:r}:{})),f&&(d=e,u<=0||Nn.set(kn(d),Date.now()))}else console.warn(`Unknown notification type: ${e.type}`,e)}catch(e){console.error(e)}return e},[o,i,null===(e=n.config)||void 0===e?void 0:e.notificationDedupeTtlMs,null===(t=n.config)||void 0===t?void 0:t.showNotifications]);return u(()=>({error:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"error"}),t),success:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"success"}),t),warning:(e,t=!1)=>a(Object.assign(Object.assign({},e),{type:"warning"}),t),notify:a}),[a])},Tn=()=>C.useApp().message,Ln={FileNotFound:"File not found or no longer available.",FileAlreadyExists:"File with this name already exists.",FileInvalidName:"File name is not valid. Allowed characters: {{allowedChars}}",FileAccessDenied:"You don't have permission to access this file.",FileReadError:"Failed to read the file.",FileWriteError:"Failed to write the file.",FileTooLarge:"File is too large ({{fileSize}}). Maximum allowed size: {{maxSize}}.",FileTypeNotAllowed:"This file type is not allowed.",FileCorrupted:"The file appears to be corrupted.",FileChecksumMismatch:"File integrity check failed.",FileStorageQuotaExceeded:"Storage quota exceeded. Please free up space.",FileLocked:"File is locked by another process or user.",FileVersionConflict:"File version conflict. Please refresh and try again.",FolderNotFound:"Folder not found or no longer available.",FolderAlreadyExists:"Folder with this name already exists.",FolderInvalidName:"Folder name is not valid. Allowed characters: {{allowedChars}}",FolderAccessDenied:"You don't have permission to access this folder.",FolderReadError:"Failed to read the folder contents.",FolderWriteError:"Failed to write to the folder.",FolderQuotaExceeded:"Folder storage quota exceeded.",FolderNotEmpty:"Folder is not empty.",FolderBackendError:"Server error while processing the folder.",FolderTimeout:"Folder operation took too long.",RenameNotAllowed:"Renaming is not allowed for this item.",MoveNotAllowed:"Moving is not allowed for this item.",CopyNotAllowed:"Copying is not allowed for this item.",DeleteNotAllowed:"Deleting is not allowed for this item.",MoveIntoSelf:"Cannot move an item into itself.",MoveIntoDescendant:"Cannot move an item into its descendant folder.",CopyIntoSelf:"Cannot copy an item into itself.",UnsupportedOperation:"This operation is not supported.",ConfigError:"Configuration error occurred.",FileUploadQuotaExceeded:"You have exceeded the upload quota.",FileUploadNetworkError:"Network error while uploading the file.",FileUploadTimeout:"File upload took too long.",FileUploadBackendError:"Server error while uploading the file.",UploadUrlInvalid:"The specified URL is not valid.",UploadUrlNotReachable:"The specified URL is not reachable.",UploadUrlContentTypeNotAllowed:"Content type at the URL is not allowed.",UploadUrlDownloadFailed:"Failed to download file from the URL.",FileLookupFailed:"Failed to find existing file by URL.",FileProxyFailed:"Failed to load file through proxy.",FileProxyNotConfigured:"File proxy is not configured.",FileDownloadNetworkError:"Network error while downloading the file.",FileDownloadTimeout:"File download took too long.",FileDownloadBackendError:"Server error while downloading the file.",BatchPartialFailure:"Some items could not be processed.",BatchAllFailed:"Failed to process all items in the batch.",BatchConflict:"Some items in the batch are in a conflicting state.",BatchValidationFailed:"Some items in the batch did not pass validation.",BatchItemLimitExceeded:"Batch operation exceeds the maximum number of items allowed.",ValidationError:"Some of the provided data is invalid.",PayloadTooLarge:"File is too large ({{fileSize}}). Maximum allowed size: {{maxSize}}.",UnsupportedMediaType:"This media type is not supported.",NetworkError:"Network error. Please check your connection and try again.",BackendError:"Server error. Please try again later.",Timeout:"The operation took too long. Please try again.",AuthenticationFailed:"Authentication failed. Please sign in again.",AuthorizationFailed:"You are not allowed to perform this action.",RateLimitExceeded:"Too many requests. Please try again a bit later.",ServiceUnavailable:"Service is temporarily unavailable. Please try again later.",AIResponseInvalid:"AI service returned an invalid response.",AIImageGenerationFailed:"Failed to generate image using AI.",AIImageGenerationLimitExceeded:"You have reached the AI image generation limit.",IntegrationError:"Error in external integration.",ThirdPartyError:"Error in a third-party service.",UnknownError:"An unknown error occurred."},Mn={FileTooLarge:"File is too large to upload.",PayloadTooLarge:"File is too large to upload."},Un=(e,t,o)=>{var r,n,i;if(!e)return;const a=Ln[e];if(!a)return;const l=null!==(r=null==o?void 0:o.fileSize)&&void 0!==r?r:"",s=null!==(n=null==o?void 0:o.maxSize)&&void 0!==n?n:"";if(("FileTooLarge"===e||"PayloadTooLarge"===e)&&!(!!l&&!!s)){const o=Mn[e];return o?t(o):t(a,{fileSize:"?",maxSize:"?"})}return t(a,{allowedChars:null!==(i=null==o?void 0:o.allowedChars)&&void 0!==i?i:"a-z A-Z 0-9 . _ -",fileSize:l,maxSize:s})},jn=e=>{if(!e||"string"!=typeof e)return;const t=e.toLowerCase();return(t.includes("maximum number of files")||t.includes("number of files exceeded"))&&(t.includes("allowed")||t.includes("received"))?"BatchItemLimitExceeded":t.includes("exceeds")||t.includes("maximum")||t.includes("too large")||t.includes("size limit")||t.includes("object size")||t.includes("размер")||t.includes("превышен")?"PayloadTooLarge":t.includes("403")||t.includes("forbidden")||t.includes("access denied")||t.includes("доступ запрещён")?"AuthorizationFailed":t.includes("404")||t.includes("not found")||t.includes("не найден")?"UploadUrlNotReachable":t.includes("already exists")||t.includes("уже существует")||t.includes("дубликат")?"FileAlreadyExists":t.includes("invalid")&&(t.includes("name")||t.includes("имя")||t.includes("назва"))?"FileInvalidName":t.includes("type")&&(t.includes("not allowed")||t.includes("не поддерживается"))?"FileTypeNotAllowed":void 0},Dn=e=>{var t,o,r,n,i,a,l,s,d,c,u,f,h,m,p,g,v,y;if(!e)return{message:"Unknown error",raw:e};if("string"==typeof e)return{message:e};if(e instanceof Error){const i=e;return{message:null!==(t=i.message)&&void 0!==t?t:e.message,code:i.code,status:null!==(o=i.status)&&void 0!==o?o:i.httpStatus,stack:null!==(r=i.stack)&&void 0!==r?r:e.stack,raw:null!==(n=i.raw)&&void 0!==n?n:e}}if("object"==typeof e){const t=e,o=null!==(i=t.data)&&void 0!==i?i:t,r=null!==(a=null==o?void 0:o.data)&&void 0!==a?a:o,n=null!==(d=null!==(s=null!==(l=t.message)&&void 0!==l?l:null==o?void 0:o.message)&&void 0!==s?s:t.error)&&void 0!==d?d:t.reason,w=null!==(f=null!==(u=null!==(c=t.status)&&void 0!==c?c:t.httpStatus)&&void 0!==u?u:null==r?void 0:r.status)&&void 0!==f?f:null==o?void 0:o.status,b=null!==(h=t.code)&&void 0!==h?h:null==o?void 0:o.code,C=t.stack,I=null!==(m=t.raw)&&void 0!==m?m:e,F=null!==(g=null!==(p=t.fileSize)&&void 0!==p?p:null==r?void 0:r.fileSize)&&void 0!==g?g:null==o?void 0:o.fileSize,A=null!==(y=null!==(v=t.maxSize)&&void 0!==v?v:null==r?void 0:r.maxSize)&&void 0!==y?y:null==o?void 0:o.maxSize;if(n||b||w||C||I)return Object.assign(Object.assign({message:n,code:b,status:w,stack:C,raw:I},null!=F&&{fileSize:F}),null!=A&&{maxSize:A})}return{message:String(e),raw:e}};const Bn=(e,t,o)=>{const r=Dn(e),n=null==r?void 0:r.code;if("FileTooLarge"===n&&null!=(null==o?void 0:o.fileSize)&&null!=(null==o?void 0:o.maxSize))return t("File too large ({{size}}). Maximum allowed size: {{maxSize}}",{size:Nr(o.fileSize),maxSize:Nr(o.maxSize)});if(("BatchItemLimitExceeded"===n||"exceeded_max_files"===n)&&(null==r?void 0:r.message)){const{allowed:e,received:o}=function(e){const t=e.match(/Allowed:\s*(\d+)/i),o=e.match(/received:\s*(\d+)/i);return{allowed:t?parseInt(t[1],10):void 0,received:o?parseInt(o[1],10):void 0}}(r.message);if(null!=e&&null!=o)return t("Maximum number of files exceeded. Allowed: {{allowed}}, received: {{received}}",{allowed:e,received:o})}if((null==r?void 0:r.message)&&"Unknown error"!==r.message)return r.message;const i=null!=(null==o?void 0:o.fileSize)&&null!=(null==o?void 0:o.maxSize)?{fileSize:Nr(o.fileSize),maxSize:Nr(o.maxSize)}:void 0,a=Un(n,t,i);return null!=a?a:t("Error uploading file")},zn=e=>{const t=Dn(e);return"path_folder_not_found"===(null==t?void 0:t.code)},qn=["file_get_contents","open stream","failed to open stream","http request failed","curl_error"];const Wn=(e,t,o)=>{var r;if(!e)return t("Error when downloading a file by URL");const n=null!==(r=(e=>{const t=jn(e);if("AuthorizationFailed"===t){const t=(e||"").toLowerCase();if(t.includes("download")||t.includes("url")||t.includes("file_get_contents")||t.includes("failed to download"))return"UploadUrlNotReachable"}return t})(null==e?void 0:e.message))&&void 0!==r?r:null==e?void 0:e.code,i=Un(n,t,o);if(i)return i;const a=(null==e?void 0:e.message)&&"string"==typeof e.message?e.message.trim():null;return a&&function(e){if(!e||e.length>200)return!1;const t=e.toLowerCase();return!qn.some(e=>t.includes(e))}(a)?a:t("Failed to download file from the URL.")},Vn=e=>Array.isArray(e)?e.filter(e=>(null==e?void 0:e.id)&&"folders"!==e.id).map(e=>e.name).filter(Boolean).join("/"):"",$n=e=>{const t=e.trim();if(!t)return"";const o=t.toLowerCase(),r=[o.indexOf(" and "),o.indexOf(" or "),t.indexOf(","),t.indexOf(";"),o.indexOf(". ")].filter(e=>e>=0);if(0===r.length)return t;const n=Math.min(...r);return t.slice(0,n).trim()||t},Hn=(e,t)=>{const o=(e=>{var t,o,r,n;if(e&&"object"==typeof e){const i=e,a=null!==(r=null===(o=null===(t=i.data)||void 0===t?void 0:t.data)||void 0===o?void 0:o.path_folder)&&void 0!==r?r:null===(n=i.data)||void 0===n?void 0:n.path_folder;if("string"==typeof a&&a.trim())return $n(a)||null}const i=Dn(e),a=null==i?void 0:i.message;if(!a)return null;const l=a.toLowerCase(),s=["не существует:","not exists:","not exist:","not found:"];for(const e of s){const t=l.indexOf(e);if(t>=0){const o=a.slice(t+e.length).trim();return $n(o)||null}}const d=["not exists ","not exist ","not found "];for(const e of d){const t=l.indexOf(e);if(t>=0){const o=a.slice(t+e.length).trim();return $n(o)||null}}return null})(e);return o?(e=>{const t=e.split("/").filter(Boolean);return t.length<=1?"":(t.pop(),t.join("/"))})(o):Vn(t)},Gn=async e=>{var t;const{options:o,pathFolder:r,dataProviders:n}=e;if(null==n?void 0:n.clearCache)return void await n.clearCache(r||null);const i=null===(t=null==o?void 0:o.apiEndpoints)||void 0===t?void 0:t.clearCache;if(!i)return;const a=i.includes("?");let l=i;r&&r.length>0&&(l=`${i}${a?"&":"?"}path_folder=${encodeURIComponent(r)}`);const s=await fetch(l,{method:"POST"});if(!s.ok)throw new Error(`Cache clear failed: ${s.status}`)},Kn=()=>{var e,t;const{state:o,actions:n,options:i}=mn(),{t:a}=dr(),l=On(),{folders:s,selectedFolder:c,pathHistory:u,form:f,loading:h,isModalVisible:m}=o,{setFolders:p,setLoading:g,setIsModalVisible:v}=n,{dataProviders:y,config:w}=i,b=d(e=>(Array.isArray(e)?e:[]).filter(e=>e&&e.id&&e.name).map(e=>({id:e.id,name:e.name,parentId:e.folderId?e.folderId:null})),[]),C=d(async(e=!1)=>{null==g||g(!0);try{let e=[];const t="lazy"===(null==w?void 0:w.folderTreeLoading);if(!(null==y?void 0:y.getFolders)){if(null==y?void 0:y.getFiles){const e=async o=>{const{files:r}=await y.getFiles({itemType:"folder",folderId:null!=o?o:void 0}),n=b(r);if(t)return n;const i=await Promise.all(n.map(t=>e(t.id)));return[...n,...i.flat()]},o=await e(null);return void(p&&p(e=>{const r=Array.isArray(e)?e:[];if(!t){const e=o,t=e.filter(e=>e.id===e.parentId);return t.length>0&&console.warn("Folders with cyclic dependencies detected:",t),e}const n=[...r.filter(e=>e.parentId),...o],i=n.filter(e=>e.id===e.parentId);return i.length>0&&console.warn("Folders with cyclic dependencies detected:",i),n}))}return void console.error("DataProvider for folders is not defined")}{const o=!t;e=await y.getFolders({parentId:null,deep:o})}const o=Array.isArray(e)?e:[];null==p||p(o);const r=o.filter(e=>e.id===e.parentId);r.length>0&&console.warn("Folders with cyclic dependencies detected:",r)}catch(t){console.error("Error loading folders:",t);const o=Dn(t);if(!e&&(404===(null==o?void 0:o.status)||"FileNotFound"===(null==o?void 0:o.code))){const e=Hn(t,u||[]);try{return await Gn({options:i,pathFolder:e,dataProviders:null==i?void 0:i.dataProviders}),void await C(!0)}catch(e){console.error("Cache clear failed:",e)}}const r=Un(null==o?void 0:o.code,a);l.error({id:"FOLDERS_FETCH_FAILED",message:null!=r?r:a("Failed to load folders"),description:a("Folders"),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{reason:t instanceof Error?t.message:String(t),folderId:null,folderName:a("Folders")}})}finally{null==g||g(!1)}},[null==y?void 0:y.getFiles,null==y?void 0:y.getFolders,p,g,null==w?void 0:w.folderTreeLoading,b,l,a,u,i]),I=d(()=>C(),[C]),F=d(async e=>{try{let t,o;if(null==y?void 0:y.getFolders){t=await y.getFolders({parentId:e,deep:!1});const r=Array.isArray(s)?s:[],n=new Set(t.map(e=>e.id)),i=r.filter(t=>t.parentId!==e||n.has(t.id));o=[...i,...t.filter(e=>!i.some(t=>t.id===e.id))]}else{if(!(null==y?void 0:y.getFiles))return[];{const{files:r}=await y.getFiles({itemType:"folder",folderId:null!=e?e:void 0});t=b(r);const n=Array.isArray(s)?s:[],i=new Set(t.map(e=>e.id)),a=n.filter(t=>t.parentId!==e||i.has(t.id));o=[...a,...t.filter(e=>!a.some(t=>t.id===e.id))]}}let r=o,n=0;for(;n!==r.length;){n=r.length;const e=new Set(r.map(e=>e.id));r=r.filter(t=>!t.parentId||e.has(t.parentId))}return null==p||p(r),t}catch(e){return console.error("Error loading child folders:",e),[]}},[y,s,p,b]),A=d(()=>{var e;const t=null!==(e=null==w?void 0:w.defaultFolderName)&&void 0!==e?e:a("New folder");f.setFieldsValue({folderName:t}),null==v||v(!0)},[f,v,a,null==w?void 0:w.defaultFolderName]),_=d(async(e,t)=>{const o=[...(Array.isArray(s)?s:[]).filter(t=>t.id!==e.id),e];if(null==p||p(o),e.parentId&&(await F(e.parentId),await new Promise(e=>setTimeout(e,50))),!(null==t?void 0:t.preserveSelection)&&n.setSelectedFolder&&n.setSelectedFolder(e.id),!(null==t?void 0:t.preserveSelection)&&n.setPathHistory){const t=Array.isArray(o)?o:[],r=(e,o=new Set)=>{if(o.has(e))return console.warn(`Cycle detected in the path to the folder with id=${e}`),[];const n=t.find(t=>t.id===e);if(!n)return[];const i=new Set(o);return i.add(e),n.parentId?[...r(n.parentId,i),{id:n.id,name:n.name}]:[{id:n.id,name:n.name}]},i=r(e.id),l=[{id:"folders",name:a("Folders")},...i];n.setPathHistory(l)}},[s,p,n,o.pathHistory,F,a]),S=d(async e=>{try{if(null==y?void 0:y.getFolders){const t=await y.getFolders(),o=Array.isArray(t)?t:[];return o.some(t=>t.id===e)}if(null==y?void 0:y.getFiles){const t=new Set,o=async r=>{const{files:n}=await y.getFiles({itemType:"folder",folderId:null!=r?r:void 0}),i=b(n);for(const r of i){if(t.has(r.id))continue;if(t.add(r.id),r.id===e)return!0;if(await o(r.id))return!0}return!1};return await o(null)}}catch(e){console.warn("⚠️ Error checking the folder:",e)}return!1},[null==y?void 0:y.getFolders,null==y?void 0:y.getFiles,b]),E=d(async e=>{var t;let o,r,n=null;try{const i=await(e?e.validateFields():f.validateFields());if(o=i.folderName.trim(),!o){const e=i.targetFolder||(c&&"folders"!==c?c:null);return void l.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:a("Folder name cannot be empty"),placement:"bottomRight",data:{folderName:o,folderId:null!=e?e:null,reason:"emptyName",is_force_create:!!i.is_force_create}})}r=Zt(o,w);const d=i.targetFolder;if(d)n="folders"!==d?d:null;else if(c&&"folders"!==c)n=c;else if(Array.isArray(u)&&u.length>1){const e=u[u.length-1];n=(null==e?void 0:e.id)&&"folders"!==e.id?e.id:null}if(Xt(w)&&(null==y?void 0:y.getFolders))try{const e=(await y.getFolders({parentId:n,deep:!1})||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean);if(e.includes(o.trim().toLowerCase()))return void l.error({id:"FOLDER_ALREADY_EXISTS",message:a("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,folderId:n}})}catch(e){}let h;if(!(null==y?void 0:y.createFolder))return void l.error({id:"FOLDER_CREATE_PROVIDER_NOT_CONFIGURED",message:a("Folder creation provider is not configured"),placement:"bottomRight",data:{folderName:r,folderId:null!=n?n:null,is_force_create:!!i.is_force_create}});h=await y.createFolder({name:r,parentId:n,is_force_create:!!i.is_force_create}),(e=>{if(!e||!e.id)throw new Error(a("Invalid server response: folder ID is missing"));if(e.id===e.parentId&&e.parentId)throw console.error("Circular dependency detected: folder cannot be its own parent"),new Error(a("Error: folder cannot be its own parent"))})(h);const m={id:h.id,name:h.name,parentId:null!=n?n:null,childCount:h.childCount},g=[...(Array.isArray(s)?s:[]).filter(e=>e.id!==m.id),m];if(null==p||p(g),l.success({id:"FOLDER_CREATE_SUCCESS",message:a("Folder created"),placement:"bottomRight",data:{itemIds:[m.id],folderId:null!==(t=m.parentId)&&void 0!==t?t:null,folderName:m.name}}),e||null==v||v(!1),(async()=>{try{await _(m,{preserveSelection:Boolean(e)}),await I(),await new Promise(e=>setTimeout(e,200));await S(h.id)||console.warn("⚠️ Could not confirm the creation of the folder on the server, but continuing...")}catch(e){console.error("Error performing background operations after creating the folder:",e)}})(),e)return h}catch(e){console.error("❌ Error creating the folder:",e);const t=Dn(e),i=Un(null==t?void 0:t.code,a);l.error({id:"FOLDER_CREATE_FAILED",message:null!=i?i:a("Failed to create folder"),placement:"bottomRight",innerException:e,data:{folderName:r||o,folderId:null!=n?n:null,reason:e instanceof Error?e.message:String(e)}})}},[f,c,y,_,I,S,v,l,a,s,p,w,u]),x=d(()=>{null==v||v(!1)},[v]),P=d((e,t=new Set)=>{const o=Array.isArray(s)?s:[];return e.map(e=>{if(t.has(e.id))return console.warn(`Cycle detected in the folder structure with id=${e.id}. Skipping child elements processing.`),{key:e.id,label:e.name+" "+a("(error)"),icon:r.createElement(se,{style:{color:"red"}})};const n=new Set(t);n.add(e.id);const i=o.filter(t=>t.parentId===e.id&&t.id!==e.id);return{key:e.id,label:e.name,children:i.length>0?P(i,n):void 0}})},[s]),R=d(()=>{const e=Array.isArray(s)?s:[],t={key:"folders",label:a("Folders"),children:[]},o=e.filter(e=>null===e.parentId||!e.parentId);return t.children=P(o),[t]},[s,a,P]),N=d(async(e,t)=>{var o,r,d,c;let u;try{const f=t.trim(),h=null==s?void 0:s.find(t=>t.id===e);if(!f)return void l.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:a("Folder name cannot be empty"),placement:"bottomRight",data:{folderId:e,folderName:t,reason:"emptyName"}});u=Zt(f,w);if(!(!1!==(null===(o=null==w?void 0:w.features)||void 0===o?void 0:o.enableRenameFolder)))return void l.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:a("Folder rename is disabled by config"),placement:"bottomRight",data:{itemId:e,itemName:null!==(r=null==h?void 0:h.name)&&void 0!==r?r:u}});if(!(null===(d=i.dataProviders)||void 0===d?void 0:d.renameFolder))return void l.error({id:"FOLDER_RENAME_FAILED",message:a("Folder rename provider is not configured"),placement:"bottomRight",data:{itemId:e,itemName:u,error:{message:"providerNotConfigured"}}});const m=await i.dataProviders.renameFolder(e,u);if(!(null==m?void 0:m.id))return void l.error({id:"FOLDER_RENAME_FAILED",message:a("Unexpected response when renaming folder"),placement:"bottomRight",data:{itemId:e,itemName:u,error:{message:"invalidResponse"}}});await I(),e!==m.id&&n.setSelectedFolder&&n.setSelectedFolder(m.id),l.success({id:"FOLDER_RENAME_SUCCESS",message:a("Folder renamed"),placement:"bottomRight",data:{itemId:m.id,itemName:m.name,folderId:null!==(c=m.parentId)&&void 0!==c?c:null}})}catch(o){console.error("Error renaming the folder:",o),l.error({id:"FOLDER_RENAME_FAILED",message:a("Failed to rename folder"),placement:"bottomRight",innerException:o,data:{itemId:e,itemName:u||t,error:{message:o instanceof Error?o.message:String(o)}}})}},[I,s,null===(e=i.dataProviders)||void 0===e?void 0:e.renameFolder,null===(t=null==w?void 0:w.features)||void 0===t?void 0:t.enableRenameFolder,w,n.setSelectedFolder,l,a]);return{state:{folders:s,isCreatingFolder:m,loading:h},actions:{fetchFolders:I,fetchChildFolders:F,handleCreateFolder:A,handleModalOk:E,handleModalCancel:x,generateMenuItems:R,renameFolder:N}}},Qn=()=>{const{options:e,actions:t}=mn(),{dataProviders:o,config:r}=e,{setUndoDeletion:n}=t,{t:i}=dr(),a=On(),l=d(async({items:e,selectedFolder:t,getItemNameById:l,showNotifications:s=!1})=>{let d=0,c=0;const u=[],f=async t=>{if(null==o?void 0:o.deleteItems)try{const r=await o.deleteItems(e.map(e=>e.id),{permanent:t}),n=r.detailed;if(n){const e=n.filter(e=>e.success),t=n.filter(e=>!e.success),o=t.filter(e=>{var t;const o=null!==(t=e.innerException)&&void 0!==t?t:e.error;return zn(o)}),r=t.filter(e=>{var t;const o=null!==(t=e.innerException)&&void 0!==t?t:e.error;return!zn(o)});return d+=e.length+o.length,c+=r.length,void r.forEach(e=>{var t;const o=(e=>{var t;return null!==(t=e.requestId)&&void 0!==t?t:e.id})(e),r=null!==(t=e.innerException)&&void 0!==t?t:e.error,n=Dn(r);u.push({itemId:o,itemName:l(o),error:n})})}if(r.success)d+=e.length;else{const t=r.error;if(zn(t))d+=e.length;else if(t){c+=e.length;const o=Dn(t);u.push({error:o})}else c+=e.length}return}catch(o){if(zn(o))d+=e.length;else{const r=t?"Ошибка при удалении":"Ошибка при перемещении в корзину";console.error(r,o),c+=e.length;const n=Dn(o);u.push({error:n})}}const r=t?"DataProvider для удаления файлов не настроен":"DataProvider для перемещения не настроен";console.warn(r)},h=(null==r?void 0:r.enableTrashFolder)&&"Trash"===t;return(null==r?void 0:r.enableTrashFolder)&&!h?await f(!1):await f(!0),d>0&&(null==r?void 0:r.enableTrashFolder)&&!h&&(null==n||n({itemIds:e.map(e=>e.id),sourceFolderId:t||"folders"})),s&&(d>0&&a.success({id:"FILES_DELETE_SUCCESS",message:i("Files deleted"),placement:"bottomRight",data:{successCount:d,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:t||null}}),c>0&&a.error({id:"FILES_DELETE_ERROR",message:i("Error when deleting a file"),placement:"bottomRight",data:{failCount:c,totalCount:e.length,itemIds:e.map(e=>e.id),itemNames:e.map(e=>l(e.id)),folderId:t||null,errors:u}})),{successCount:d,failCount:c,errorDetails:u}},[o,r,n,i,a]);return{deleteItems:l}};class Jn extends Error{constructor(e,t,o,r){super(e),this.code=t,this.status=o,this.details=r,this.name="FileManagerApiError",Error.captureStackTrace&&Error.captureStackTrace(this,Jn)}}const Yn=/^(localhost|127\.0\.0\.1|0\.0\.0\.0|::1)$/i,Zn=/^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)/;function Xn(e,t){const o=e.trim();if(!o)throw new Jn(t("Enter the URL of the image"),"UploadUrlInvalid");if(o.length>8192)throw new Jn(t("URL too long"),"UploadUrlInvalid");let r;try{r=new URL(o)}catch(e){throw new Jn(t("The specified URL is not valid."),"UploadUrlInvalid")}const n=r.protocol.toLowerCase();if("http:"!==n&&"https:"!==n)throw new Jn(t("Only http and https URLs are supported"),"UploadUrlInvalid");const i=r.hostname.toLowerCase();if(Yn.test(i)&&("undefined"==typeof window||!Yn.test(window.location.hostname.toLowerCase())))throw new Jn(t("Private and local URLs are not allowed"),"UploadUrlInvalid");if(Zn.test(i))throw new Jn(t("Private and local URLs are not allowed"),"UploadUrlInvalid")}function ei(e,t){var o;if(null==e?void 0:e.extension){const t=e.extension.toLowerCase(),o={jpg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},jpeg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},png:{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},gif:{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},webp:{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},svg:{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(o[t])return o[t]}if(null==e?void 0:e.type){const t=Nt(e.type),o={"image/jpeg":{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},"image/png":{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},"image/gif":{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},"image/webp":{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},"image/svg+xml":{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(o[t])return o[t]}if(null==e?void 0:e.name){const t=null===(o=e.name.split(".").pop())||void 0===o?void 0:o.toLowerCase();if(t){const e={jpg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},jpeg:{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"},png:{extension:"png",mimeType:"image/png",format:"png",pixieFormat:"png"},gif:{extension:"gif",mimeType:"image/gif",format:"gif",pixieFormat:"png"},webp:{extension:"webp",mimeType:"image/webp",format:"webp",pixieFormat:"png"},svg:{extension:"svg",mimeType:"image/svg+xml",format:"svg",pixieFormat:"svg"}};if(e[t])return e[t]}}if(t){const e=Nt(t),o=Tt(e);let r="jpeg";return"png"===o?r="png":"svg"===o?r="svg":"jpeg"===o&&(r="jpeg"),{extension:o,mimeType:e,format:o,pixieFormat:r}}return{extension:"jpeg",mimeType:"image/jpeg",format:"jpeg",pixieFormat:"jpeg"}}const ti={MAX_SIZE_MB:.48,MAX_WIDTH_OR_HEIGHT:2e3,QUALITY:.8},oi=["gif","svg"];function ri(e,t){const{colorHex:o,colorHex2:r,colorHex3:n}=t,i=[`--icon-grad-1: ${o}`,`--icon-grad-2: ${r}`,`--icon-stroke-1: ${o}`,`--icon-stroke-2: ${r}`,`--icon-stroke-3: ${n}`,`--icon-fill-1: ${o}`,`--icon-fill-2: ${r}`,`--icon-fill-3: ${n}`,`color: ${o}`].join(";");let a=e.replace(/<svg([^>]*)>/i,(e,t)=>{let o=t;return/style="/i.test(o)?o=o.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};${i}"`):o+=` style="${i}"`,`<svg${o}>`});return a=a.replace(/var\(--icon-color-1\)/g,o).replace(/var\(--icon-color-2\)/g,r).replace(/var\(--icon-color-3\)/g,n).replace(/var\(--icon-fill-1\)/g,o).replace(/var\(--icon-fill-2\)/g,r).replace(/var\(--icon-fill-3\)/g,n).replace(/var\(--icon-stroke-1\)/g,o).replace(/var\(--icon-stroke-2\)/g,r).replace(/var\(--icon-stroke-3\)/g,n).replace(/var\(--icon-grad-1\)/g,o).replace(/var\(--icon-grad-2\)/g,r).replace(/currentColor/g,o),a}function ni(e,t){const o=e.match(/\swidth="([0-9.]+)(px)?"/i),r=e.match(/\sheight="([0-9.]+)(px)?"/i);if(o&&r){const e=parseFloat(o[1]),n=parseFloat(r[1]);if(Number.isFinite(e)&&Number.isFinite(n)&&e>0&&n>0){const o=e/n;return o>=1?{width:t,height:Math.max(1,Math.round(t/o))}:{width:Math.max(1,Math.round(t*o)),height:t}}}const n=e.match(/viewBox="([^"]+)"/i);if(n){const e=n[1].trim().split(/\s+/);if(4===e.length){const o=parseFloat(e[2]),r=parseFloat(e[3]);if(Number.isFinite(o)&&Number.isFinite(r)&&o>0&&r>0){const e=o/r;return e>=1?{width:t,height:Math.max(1,Math.round(t/e))}:{width:Math.max(1,Math.round(t*e)),height:t}}}}return{width:t,height:t}}function ii(e){if(!e)return null;const t=e.trim();if(t.endsWith("%"))return null;const o=parseFloat(t.replace(/px$/i,""));return Number.isFinite(o)&&o>0?o:null}function ai(e,t=2,o=4096){const{width:r,height:n}=function(e){var t,o,r,n,i;const a=null!==(o=null===(t=e.match(/<\s*svg\b[\s\S]*?>/i))||void 0===t?void 0:t[0])&&void 0!==o?o:"",l=null===(r=a.match(/\bwidth\s*=\s*["']([^"']*)["']/i))||void 0===r?void 0:r[1],s=null===(n=a.match(/\bheight\s*=\s*["']([^"']*)["']/i))||void 0===n?void 0:n[1],d=ii(l),c=ii(s);if(null!=d&&null!=c)return{width:d,height:c};const u=null===(i=e.match(/viewBox\s*=\s*["']([^"']+)["']/i))||void 0===i?void 0:i[1];if(u){const e=u.trim().split(/[\s,]+/);if(4===e.length){const t=parseFloat(e[2]),o=parseFloat(e[3]);if(Number.isFinite(t)&&Number.isFinite(o)&&t>0&&o>0)return{width:t,height:o}}}return null!=d?{width:d,height:d}:null!=c?{width:c,height:c}:{width:300,height:300}}(e);let i=Math.max(1,Math.round(r*t)),a=Math.max(1,Math.round(n*t));const l=Math.max(64,o),s=Math.max(i,a);if(s>l){const e=l/s;i=Math.max(1,Math.round(i*e)),a=Math.max(1,Math.round(a*e))}return{width:i,height:a}}async function li(e,t,o,r,n){var i;const a=null!==(i=null==n?void 0:n.canvasScale)&&void 0!==i?i:2,l=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(l);try{const e=new Image;await new Promise((t,o)=>{e.onload=()=>t(),e.onerror=()=>o(new Error("Failed to load SVG image")),e.src=s});const r=document.createElement("canvas"),n=Math.max(1,Math.round(t*a)),i=Math.max(1,Math.round(o*a));r.width=n,r.height=i;const l=r.getContext("2d");if(!l)throw new Error("Canvas 2D context is not available");return l.clearRect(0,0,n,i),l.drawImage(e,0,0,n,i),function(e){return new Promise((t,o)=>{e.toBlob(e=>{e?t(e):o(new Error("canvas.toBlob returned null"))},"image/png")})}(r)}finally{URL.revokeObjectURL(s)}}async function si(e,t,o,r,n){const i=await li(e,t,o,0,n);return a=i,new Promise((e,t)=>{const o=new FileReader;o.onload=()=>e(o.result),o.onerror=()=>{var e;return t(null!==(e=o.error)&&void 0!==e?e:new Error("readAsDataURL failed"))},o.readAsDataURL(a)});var a}function di(e,t,o,r){return new File([e],t,{type:o,lastModified:r})}function ci(e,t){return t&&t!==e.name?di(e,t,e.type,e.lastModified):e}async function ui(e,t={}){const{maxSizeMB:o=ti.MAX_SIZE_MB,maxWidthOrHeight:r=ti.MAX_WIDTH_OR_HEIGHT,mimeType:n,fileName:i,libURL:a,enableCompression:l=!0,convertSvgToPng:s=!1}=t;if(!(e&&e instanceof File))return e;let d=e,c=!1;if(s){const t=(d.type||"").toLowerCase(),o=/\.svg$/i.test(d.name.trim()),n=t.includes("svg");let a=!1;if(!n&&!o)try{const e=await async function(e,t=24e3){const o=Math.min(t,Math.max(0,e.size));return e.slice(0,o).text()}(d);a=function(e){const t=e.trimStart().replace(/^\uFEFF/,"");return!!t.startsWith("<")&&/<\s*svg[\s>/]/i.test(t)}(e)}catch(e){a=!1}if(n||o||a)try{d=await async function(e,t={}){var o,r,n;const i=null!==(o=t.pixelScale)&&void 0!==o?o:2,a=null!==(r=t.maxLongEdge)&&void 0!==r?r:4096,l=await e.text(),{width:s,height:d}=ai(l,i,a),c=await li(l,s,d,0,{canvasScale:1}),u=null!==(n=t.outputFileName)&&void 0!==n?n:e.name,f=/\.svg$/i.test(u)?u.replace(/\.svg$/i,".png"):`${u}.png`;return new File([c],f,{type:"image/png",lastModified:e.lastModified})}(d,{maxLongEdge:r,outputFileName:null!=i?i:d.name}),c=!0}catch(t){console.warn("prepareImageForUpload: SVG to PNG conversion failed, using original",t),d=e}}if(c)return d;const u=(d.type&&""!==d.type.trim()?d.type:Lt(d.name))||n||"image/jpeg",f=Nt(u);if(!f.startsWith("image/"))return ci(d,i);const h="image/webp"===(m=f)?"image/jpeg":m;var m;const p=Tt(f),g=Tt(h),v=h!==f?function(e,t){const o=t.startsWith(".")?t.slice(1):t,r=e.lastIndexOf(".");return r>0?`${e.substring(0,r)}.${o}`:`${e}.${o}`}(null!=i?i:d.name,g):null!=i?i:d.name,y=l&&(w=p,!oi.includes(w));var w;if(!y&&!(h!==f))return ci(d,v);try{const t={libURL:a,useWebWorker:!0,fileType:h};y?(t.maxSizeMB=o,t.maxWidthOrHeight=r):(t.maxSizeMB=Math.max(e.size/1048576+1,1),t.initialQuality=1,t.alwaysKeepResolution=!0);const n=await $e(d,t);return function(e,t,o,r){const n=null!=r?r:t.name;return e instanceof File?e.type!==o||e.lastModified!==t.lastModified||e.name!==n?di(e,n,o,t.lastModified):e:di(e,n,o,t.lastModified)}(n,d,Nt(n.type||h),v)}catch(e){console.error("prepareImageForUpload failed",e);try{return ci(d,v)}catch(e){return console.error("Failed to create File with normalized name after image preparation error",e),d}}}async function fi(e){const{folderId:t,dataProviders:o,folders:r,pathHistory:n,t:i}=e,a=null==t?"":String(t);if(!a||"folders"===a)return i("Folders");if("Trash"===a)return i("Trash");const l=n||[],s=l[l.length-1];if((null==s?void 0:s.id)===a&&s.name)return s.name;const d=[...l].reverse().find(e=>e.id===a);if(null==d?void 0:d.name)return d.name;const c=null==o?void 0:o.getItem;if(c)try{const e=await Promise.resolve(c(a));if(null==e?void 0:e.name)return e.name}catch(e){}const u=null==r?void 0:r.find(e=>e.id===a);return(null==u?void 0:u.name)?u.name:a}const hi=/^(utm_[a-z0-9_]+|fbclid|gclid|igshid|mc_cid|mc_eid)$/i;function mi(e){const t=new URL(e.trim());t.hash="",t.hostname=t.hostname.toLowerCase(),("https:"===t.protocol&&"443"===t.port||"http:"===t.protocol&&"80"===t.port)&&(t.port="");const o=Array.from(t.searchParams.entries()).filter(([e])=>!hi.test(e)).sort(([e,t],[o,r])=>{const n=e.localeCompare(o);return 0!==n?n:t.localeCompare(r)});return t.search="",o.forEach(([e,o])=>t.searchParams.append(e,o)),t.toString()}function pi(e){if(function(e){return"object"==typeof e&&null!==e&&("name"in e&&"DirectResourceFetchError"===e.name?!("final"in e)||!1!==e.final:"final"in e&&!0===e.final)}(e)||e instanceof Jn)throw e}async function gi(e,t,o,r,n){const{fetchWithProxy:i,handleFileProxy:a,handleProxyUrl:l}=t,s=Object.assign({mode:"cors"},null==n?void 0:n.fetchInit);let d;if(a)try{const t=await Promise.resolve(a(e));if(t)return r(t)}catch(e){pi(e),d=e,console.warn("handleFileProxy failed, falling back to next strategy",e)}if(l)try{const t=await Promise.resolve(l(e));if(t&&t!==e){return r(await o(t))}}catch(e){pi(e),d=e,console.warn("handleProxyUrl fetch failed, falling back to next strategy",e)}if(i)try{const t=await Promise.resolve(i(e,s,{intent:"downloadBlob"}));if(!t.ok)throw new Error(`HTTP ${t.status}`);return r(await t.blob())}catch(e){pi(e),d=e,console.warn("fetchWithProxy failed",e)}if(!i)try{return r(await o(e))}catch(e){pi(e),d=e}throw d instanceof Error?d:new Error("Failed to download file from the URL")}function vi(e){return!!(null==e?void 0:e.startsWith("image/"))&&"image/gif"!==e}function yi(e,t){if(t===e.name)return e;try{return new File([e],t,{type:e.type,lastModified:e.lastModified})}catch(t){return console.warn("Failed to create normalized File:",t),e}}function wi(e){return new Promise((t,o)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>{var e;return o(null!==(e=r.error)&&void 0!==e?e:new Error("Failed to read proxied file"))},r.readAsDataURL(e)})}function bi(e){try{const t=new URL(e).pathname.split("/").pop();return t?decodeURIComponent(t):void 0}catch(e){return}}function Ci(e){return null==e||""===e||"folders"===e?null:e}async function Ii(e){const t=await fetch(e,{mode:"cors"});if(!t.ok)throw new Jn(`HTTP ${t.status}`,"UploadUrlDownloadFailed",t.status);return t.blob()}function Fi(e,t){var o,r;if(!(e instanceof Blob)||0===e.size)throw new Jn(t("Failed to download file from the URL."),"UploadUrlDownloadFailed");const n=(null===(r=null===(o=e.type)||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim())||"image/png";if(!n.startsWith("image/"))throw new Jn(t("Content type at the URL is not allowed."),"UploadUrlContentTypeNotAllowed");return{blob:e,mimeType:n}}const Ai=()=>{var e,t,o,r;const{state:i,actions:a,options:l}=mn(),s=Pn(),{sortBy:c,sortOrder:u}=s.state,{actions:{fetchFolders:f}}=Kn(),{t:h}=dr(),m=On(),{deleteItems:p}=Qn(),{selectedFolder:g,urlForm:v,pagination:y,files:w,pathHistory:b,folders:C}=i,I=n.useRef(null),F=n.useRef([]);I.current=y,F.current=Array.isArray(w)?w:[];const A=n.useRef(null),{setFiles:_,setLoading:S,setIsUrlModalVisible:E,setActiveLibraryItem:x,setPagination:P,setSelectedFolder:R,setPathHistory:N}=a,{dataProviders:k}=l,O=d(async e=>{var t,o,r,n,i;if(!(null==k?void 0:k.getFiles))return[];const a=null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.disablePagination,s=a?void 0:null!==(o=null==e?void 0:e.page)&&void 0!==o?o:1,d=a?void 0:null!==(r=null==e?void 0:e.limit)&&void 0!==r?r:20,{files:c,pagination:u}=await k.getFiles({folderId:"folders"!==(null==e?void 0:e.folderId)?null==e?void 0:e.folderId:void 0,noFolder:null==e?void 0:e.noFolder,search:(null===(n=null==e?void 0:e.search)||void 0===n?void 0:n.trim())||void 0,sortBy:null==e?void 0:e.sortBy,sortOrder:null==e?void 0:e.sortOrder,page:s,limit:d,itemType:(null==e?void 0:e.itemType)||"all"});return P&&((null===(i=null==l?void 0:l.config)||void 0===i?void 0:i.disablePagination)?P({current:1,pageSize:c.length||1,total:c.length||0}):u&&P({current:u.page,pageSize:u.limit,total:u.total})),c},[k,null===(e=null==l?void 0:l.config)||void 0===e?void 0:e.disablePagination,P]),T=d(async(e,t,o)=>Lr(k,e,t,o,Xt(null==l?void 0:l.config)),[k,null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient]),L=d(async(e,t=!1)=>{var o,r,n,i,a;try{null==S||S(!0);let t=[];if(!(null==k?void 0:k.getFiles))return void console.error("DataProvider for getting files is not defined");t=await O(e);const o=null!=e?e:{folderId:g||"",itemType:"all"};"file"!==o.itemType&&(t=await xn(t,o,null==k?void 0:k.getFolders)),"Trash"!==(g||"")&&(t=t.filter(e=>!(e.isFolder&&"Trash"===e.id))),null==_||_(t);const r=Ci(o.folderId);if(r===Ci(g)){const e=Array.isArray(b)?b:[];A.current={selectedFolder:null!=g?g:null,pathHistory:e.map(e=>Object.assign({},e))}}}catch(s){if("StaleLoad"===(null==s?void 0:s.name))return;const d=Dn(s),c=404===(null==d?void 0:d.status)||"FileNotFound"===(null==d?void 0:d.code)||"path_folder_not_found"===(null==d?void 0:d.code);if(c||console.error("Error loading files:",s),!t&&c){const t=Hn(s,b||[]);try{return await Gn({options:l,pathFolder:t,dataProviders:null==l?void 0:l.dataProviders}),void await L(e,!0)}catch(e){console.error("Cache clear failed:",e)}}if(c&&R&&N){const t=Array.isArray(b)?b:[];if(t.length>1){const r=t.slice(0,-1),n=r[r.length-1],i=null!==(o=null==n?void 0:n.id)&&void 0!==o?o:"folders";return N(r),R(i),await f(),m.success({id:"FOLDER_NOT_FOUND_NAVIGATE",message:h("Folder not found"),description:h("Navigated to parent folder"),placement:"bottomRight"}),void await L(Object.assign(Object.assign({},e),{folderId:i}),!1)}return N([{id:"folders",name:h("Folders")}]),R("folders"),await f(),m.success({id:"FOLDER_NOT_FOUND_NAVIGATE",message:h("Folder not found"),description:h("Navigated to root folder"),placement:"bottomRight"}),void await L(Object.assign(Object.assign({},e),{folderId:"folders"}),!1)}const u=A.current;if(u&&R&&N){const e=Array.isArray(b)?b:[],t=(null!==(r=u.selectedFolder)&&void 0!==r?r:null)===(null!=g?g:null),o=(i=u.pathHistory,a=e,i.length===a.length&&i.every((e,t)=>{var o;return e.id===(null===(o=a[t])||void 0===o?void 0:o.id)}));t&&o||(R(u.selectedFolder),N(u.pathHistory.map(e=>Object.assign({},e))),l.onPathChange&&l.onPathChange(u.pathHistory.map(e=>e.name)))}const p=Un(null==d?void 0:d.code,h),v=null!=e?e:{folderId:g||"",itemType:"all"},y=void 0!==v.folderId&&""!==v.folderId?v.folderId:g||"",w=Array.isArray(b)?b.map(e=>Object.assign({},e)):[],I=null===(n=v.folderName)||void 0===n?void 0:n.trim(),F=I&&I.length>0?I:await fi({folderId:y,dataProviders:k,folders:Array.isArray(C)?C:[],pathHistory:w,t:h}),_=h("Failed to load files"),S=h("Failed to load files in folder",{folderName:F}),E=p&&p!==_?p:void 0;m.error({id:"FILES_FETCH_FAILED",message:S,description:E,placement:"bottomRight",innerException:s,notificationDedupe:!0,data:{params:Object.assign(Object.assign({},v),{folderName:F}),folderName:F}})}finally{null==S||S(!1)}},[k,_,S,R,N,O,f,g,C,m,h,b,l]),M=d(e=>L(e),[L]),U=d(async(e,t)=>{var o;if(!(null==k?void 0:k.findFileByUrl))return null;const r=mi(e);try{return null!==(o=await k.findFileByUrl(r))&&void 0!==o?o:null}catch(e){return console.warn("findFileByUrl failed, falling back to direct loading",e),null}},[k]),j=d(async(e,t)=>{var o,r,n;Xn(e,h);const i=mi(e),a=await U(i,t);if(a)return{kind:"existing",file:a,normalizedUrl:i};let s,d;try{const e=await gi(i,{fetchWithProxy:null===(o=null==l?void 0:l.config)||void 0===o?void 0:o.fetchWithProxy,handleFileProxy:null===(r=null==l?void 0:l.config)||void 0===r?void 0:r.handleFileProxy,handleProxyUrl:null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.handleProxyUrl},Ii,e=>Fi(e,h));s=e.blob,d=e.mimeType}catch(e){if(e instanceof Jn)throw e;throw e instanceof Error?e:new Jn(h("Failed to download file from the URL."),"UploadUrlDownloadFailed")}const c=Tt(d),u=bi(i)||"uploaded-file",f=u.replace(/\.[^.]+$/,"")||"uploaded-file";return{kind:"blob",blob:s,normalizedUrl:i,mimeType:d,extension:c,fileName:Yt(u.includes(".")?u:`${f}.${c}`,null==l?void 0:l.config)}},[U,null==l?void 0:l.config,h]),D=d(async(e,t)=>{var o,r,n,i;Xn(e,h);const a=mi(e);try{const e=await j(a,t);if("existing"===e.kind)return e.file;return{thumbnail:await wi(e.blob),name:e.fileName,type:e.mimeType,extension:e.extension,size:e.blob.size,sourceUrl:e.normalizedUrl,saveWithoutFolder:!0}}catch(e){let c=e;if(null==k?void 0:k.uploadFileByUrl)try{const e=null!=g?g:"",t=Yt(bi(a)||"uploaded-file",null==l?void 0:l.config),n=await T(t,e,!1),i=await k.uploadFileByUrl({url:a,folderId:e,name:n,eventSource:"pixie"}),s=Fi(null!==(o=(null==i?void 0:i.id)&&k.getFileData?await k.getFileData(i.id):void 0)&&void 0!==o?o:(null==i?void 0:i.url)?await Ii(i.url):(null==i?void 0:i.thumbnailUrl)?await Ii(i.thumbnailUrl):(null==i?void 0:i.sourceUrl)?await Ii(i.sourceUrl):void 0,h),d=await wi(s.blob);return Object.assign(Object.assign({},i),{thumbnail:d,type:i.type||s.mimeType,extension:i.extension||Tt(s.mimeType),size:null!==(r=i.size)&&void 0!==r?r:s.blob.size,sourceUrl:i.sourceUrl||a})}catch(e){c=e,console.warn("Failed to prepare file for Pixie via uploadByUrl fallback",e)}const u=Dn(c),f=(s=null==u?void 0:u.code,d="UploadUrlDownloadFailed","string"==typeof s?s:d),p=c instanceof Jn?c:new Jn(null!==(i=null!==(n=Un(f,h))&&void 0!==n?n:null==u?void 0:u.message)&&void 0!==i?i:h("Failed to download file from the URL."),f,null==u?void 0:u.status);throw p.notificationShown=!0,await m.error({id:"EDITOR_PROXY_FILE_FAILED",message:p.message,placement:"bottomRight",data:{url:a,folderId:g||null,error:u,eventSource:"pixie"},innerException:c},t),p}var s,d},[k,m,null==l?void 0:l.config,j,T,g,h]),B=d(async e=>{const t=I.current;try{const o=F.current.find(t=>t.id===e),r=e=>{if(!e)return;const t=w.find(t=>t.id===e);return null==t?void 0:t.name};await p({items:[{id:e,isFolder:null==o?void 0:o.isFolder}],selectedFolder:g,getItemNameById:r,showNotifications:!0});const n=Object.assign({},t);let i=t.current;1===w.length&&(i=n.current>1?n.current-1:1),await M({folderId:g||"",page:i,limit:t.pageSize,sortBy:c,sortOrder:u})}catch(t){console.error("ОError when deleting a file:",t);const o=t;(null==o?void 0:o.notificationShown)||m.error({id:"FILES_DELETE_ERROR",message:h("Error when deleting a file"),placement:"bottomRight",innerException:t,data:{failCount:1,totalCount:1,itemIds:[e],folderId:g||null,errors:[{itemId:e,error:Dn(t)}]}})}},[p,M,g,h,m,w,c,u]),z=d(async e=>{try{const t=I.current;if(!(null==k?void 0:k.deleteFolder))return void m.error({id:"FOLDER_DELETE_ERROR",message:h("DataProvider for folder deletion is not configured"),placement:"bottomRight",data:{totalCount:1,failCount:1,itemIds:[e],folderId:e}});if(!await k.deleteFolder(e)){const e=new Error("Не удалось удалить папку");throw e.notificationShown=!1,e}m.success({id:"FOLDER_DELETE_SUCCESS",message:h("Folder deleted"),placement:"bottomRight",data:{successCount:1,totalCount:1,itemIds:[e],folderId:e}});g===e?await M({page:t.current,limit:t.pageSize,sortBy:c,sortOrder:u}):await M({folderId:g||"",sortBy:c,sortOrder:u,page:t.current,limit:t.pageSize})}catch(t){console.error("Error when deleting a folder:",t);const o=t;(null==o?void 0:o.notificationShown)||m.error({id:"FOLDER_DELETE_ERROR",message:h("Error when deleting a folder"),innerException:t,placement:"bottomRight",data:{totalCount:1,failCount:1,itemIds:[e],folderId:e,errors:[{itemId:e,error:Dn(t)}]}})}},[k,g,m,h,M,c,u]),q=d(async(e,t)=>{var o,r;try{if(null==k?void 0:k.getFileData){const t=await k.getFileData(e);if(t)return t;throw new Error(h("Failed to download file"))}{const t=await fetch(`/api/files/${e}/content`);if(!t.ok)throw new Error(h("Error loading image"));return await t.blob()}}catch(n){console.error("Error when loading a file:",n);const i=F.current.find(t=>t.id===e);t||m.error({id:"FILE_DOWNLOAD_FAILED",message:h("Failed to download file"),placement:"bottomRight",description:(null==i?void 0:i.name)||e,innerException:n,notificationDedupe:!1,data:{itemId:e,itemName:(null==i?void 0:i.name)||e,folderId:null!==(o=null==i?void 0:i.folderId)&&void 0!==o?o:null,thumbnail:null!==(r=null==i?void 0:i.thumbnail)&&void 0!==r?r:null}},t)}},[k,m,h]),W=d(async(e,t,o,r)=>{var n,a,s,d,c,u,f,p,v,y,w,b,C,I,F;if("Trash"===(r?"":null!=t?t:g||""))throw new Error(h("Upload to Trash is forbidden"));const A=Yt(e.name,null==l?void 0:l.config),_=A.split(".").pop()||"",S=r?"":null!=t?t:g||"";let E=e;try{if(Mt(e)){const t=null!==(a=null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.compressMaxSize)&&void 0!==a?a:ti.MAX_SIZE_MB,o=null!==(d=null===(s=null==l?void 0:l.config)||void 0===s?void 0:s.compressMaxWidthOrHeight)&&void 0!==d?d:2e3,r=null!==(u=null===(c=null==l?void 0:l.config)||void 0===c?void 0:c.compessorUrl)&&void 0!==u?u:null===(f=null==l?void 0:l.config)||void 0===f?void 0:f.compressorUrl,i=(null===(p=e.type)||void 0===p?void 0:p.trim())||Lt(e.name)||e.type;E=await ui(e,{maxSizeMB:t,maxWidthOrHeight:o,mimeType:i,fileName:A,libURL:r,enableCompression:vi(i),convertSvgToPng:!0})}else E=yi(e,A)}catch(t){console.warn("Image preparation failed, uploading original file",t),E=yi(e,A)}let P=E.name;const R=Xt(null==l?void 0:l.config);R&&(P=await T(P,S,r)),R&&(E=yi(E,P));try{if(null==k?void 0:k.uploadFiles)try{const t=await k.uploadFiles({items:[{name:P,size:E.size,type:E.type||e.type,folderId:S,data:E,extension:_,noFolder:r}],folderId:S});if(t.success&&t.detailed&&t.detailed.length>0){const n=t.detailed[0];if(!n.success||!n.data){if(!o){const e=(null==n?void 0:n.error)?String(n.error):h("Failed to upload file");m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:e,placement:"bottomRight",description:A,innerException:null==n?void 0:n.error,data:{itemName:A,folderId:S||null,eventSource:"upload"}})}return void(x&&x(at))}{const t=n.data;if(t.id){const o=(null!==(v=t.folderId)&&void 0!==v?v:S)||void 0,n=null!==(y=null!=o?o:g)&&void 0!==y?y:"";await M({folderId:n,noFolder:r});let a=i.files.find(e=>e.id===t.id);if(!a)try{a=(await O({folderId:o,noFolder:r,itemType:"all"})).find(e=>e.id===t.id)}catch(e){console.warn("uploadFileWithProvider: не удалось получить свежий список файлов",e)}return x&&x(at),a||Object.assign(Object.assign({},t),{id:t.id,name:t.name||A,folderId:null!==(b=null!==(w=t.folderId)&&void 0!==w?w:S)&&void 0!==b?b:null,type:E.type||e.type,size:E.size,extension:_||A.split(".").pop()||"",thumbnail:null!==(C=t.thumbnail)&&void 0!==C?C:void 0,url:null!==(I=t.url)&&void 0!==I?I:void 0,thumbnailUrl:null!==(F=t.thumbnailUrl)&&void 0!==F?F:void 0,isFolder:!1,selected:!1})}}}else if(!t.success){if(!o){const e=t.error?String(t.error):h("Failed to upload file");m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:e,placement:"bottomRight",description:A,innerException:t.error,data:{itemName:A,folderId:S||null,eventSource:"upload"}})}return void(x&&x(at))}return void(x&&x(at))}catch(e){throw e}if(null==k?void 0:k.uploadFile){const t=await k.uploadFile({name:P,size:E.size,type:E.type||e.type,folderId:S,noFolder:r,data:E,extension:_});return x&&x(at),t}return void(o||m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"}))}catch(e){const t=Dn(e),r=Un(null==t?void 0:t.code,h);return o?void 0:void m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:null!=r?r:h("Failed to upload file"),placement:"bottomRight",description:A,innerException:e,data:{itemName:A,folderId:S||null,error:Dn(e),eventSource:"upload"}})}},[k,g,x,i.files,M,O,m,h,null==l?void 0:l.config]),V=d(async(e,t)=>{var o;if(!(null==k?void 0:k.getFolders)||!(null==k?void 0:k.createFolder))return e||"";try{const r=await k.getFolders(),n=Array.isArray(r)?r:[],i=(e,t)=>n.find(o=>{var r;return(null!==(r=o.parentId)&&void 0!==r?r:null)===(null!=e?e:null)&&o.name===t});let a=null!=e?e:"";for(const e of t){if(!e)continue;let t=i(a,e);if(!t){const o=await k.createFolder({name:e,parentId:null!=a?a:null});n.push(o),t=o}a=t.id}return null!==(o=a)&&void 0!==o?o:e||""}catch(t){return console.warn("ensureFolderPath: unable to guarantee the path",t),e||""}},[k]),$=d(async(e,t)=>{var o,r,n,i;if(!(null===(r=null===(o=e.type)||void 0===o?void 0:o.startsWith)||void 0===r?void 0:r.call(o,"image/")))return null!=t?t:null;const a=null==e?void 0:e.webkitRelativePath;let l=t||"";if(a&&a.includes("/")){const e=a.split("/");e.pop();const o=e.filter(Boolean);o.length&&(l=await V(t||"",o)||t||"")}return null!==(i=null!==(n=l)&&void 0!==n?n:t)&&void 0!==i?i:null},[V]);d(async e=>{var t,o,r,n,i,a,l,s,d,c,u,f;const{file:h,selectedFolderId:m,uploadFn:p,progressCallbacks:g}=e;if(!(null===(o=null===(t=h.type)||void 0===t?void 0:t.startsWith)||void 0===o?void 0:o.call(t,"image/")))return{success:!0,fileName:h.name,folderId:null!=m?m:null};const v=null!==(n=null!==(r=await $(h,m))&&void 0!==r?r:m)&&void 0!==n?n:null,y=null!==(i=null!=v?v:m)&&void 0!==i?i:null;let w;null===(a=null==g?void 0:g.onStart)||void 0===a||a.call(g,h);try{if(null==g?void 0:g.onProgress){let e=0;w=window.setInterval(()=>{var t;e=Math.min(e+10+Math.floor(Date.now()%10),90),null===(t=null==g?void 0:g.onProgress)||void 0===t||t.call(g,h.name,e)},200)}const e=await p(h,null!=y?y:void 0);return(null==g?void 0:g.onProgress)&&(null===(l=null==g?void 0:g.onProgress)||void 0===l||l.call(g,h.name,100)),null===(s=null==g?void 0:g.onComplete)||void 0===s||s.call(g,h.name),{success:!0,fileName:h.name,fileId:null==e?void 0:e.id,folderId:null!==(c=null!==(d=null==e?void 0:e.folderId)&&void 0!==d?d:y)&&void 0!==c?c:null}}catch(e){const t=e instanceof Error?e.message:String(e);return null===(u=null==g?void 0:g.onError)||void 0===u||u.call(g,h.name,t),{success:!1,fileName:h.name,folderId:null!==(f=null!=y?y:m)&&void 0!==f?f:null,error:t}}finally{void 0!==w&&clearInterval(w)}},[$]);const H=d(async(e,t)=>{var o,r,n,i,a,s,d,c,u,f,p,v,y,w,b,C,I,F,A,_,S,E,P,R,N,O,T,L,M,U,j,D,B,z,q;if(0===e.length)return{successCount:0,failCount:0,successes:[],errors:[],totalCount:0};null===(o=null==t?void 0:t.onStartBatch)||void 0===o||o.call(t,e);const W=e=>{const t=e.filter(Boolean);return t.length>0&&t.length<=5?t.join(", "):null},V=[];for(let o=0;o<e.length;o++){const v=e[o];if(!Mt(v)){const e=await m.warning({id:"FILES_UPLOAD_UNSUPPORTED_TYPE",message:h("Unsupported file type"),placement:"bottomRight",data:{itemName:v.name,fileType:v.type,folderId:g||null}});null===(r=null==t?void 0:t.onError)||void 0===r||r.call(t,v.name,e.message);continue}const y=Yt(v.name,null==l?void 0:l.config);let w=v;try{if(Mt(v)){const e=null!==(i=null===(n=null==l?void 0:l.config)||void 0===n?void 0:n.compressMaxSize)&&void 0!==i?i:ti.MAX_SIZE_MB,t=null!==(s=null===(a=null==l?void 0:l.config)||void 0===a?void 0:a.compressMaxWidthOrHeight)&&void 0!==s?s:2e3,o=null!==(c=null===(d=null==l?void 0:l.config)||void 0===d?void 0:d.compessorUrl)&&void 0!==c?c:null===(u=null==l?void 0:l.config)||void 0===u?void 0:u.compressorUrl,r=(null===(f=v.type)||void 0===f?void 0:f.trim())||Lt(v.name)||v.type;w=await ui(v,{maxSizeMB:e,maxWidthOrHeight:t,mimeType:r,fileName:y,libURL:o,enableCompression:vi(r),convertSvgToPng:!0})}else w=yi(v,y)}catch(e){console.warn("Image preparation failed, uploading original file",e),w=yi(v,y)}const b=`${Date.now()}-${o}-${Math.random().toString(36).slice(2,8)}`,C=await $(w,g);null===(p=null==t?void 0:t.onStart)||void 0===p||p.call(t,w),V.push({file:w,targetFolderId:C,requestId:b,originalFileName:v.name,originalIndex:o})}const H=V.length;if(0===H)return{successCount:0,failCount:0,successes:[],errors:[],totalCount:0};const G=Xt(null==l?void 0:l.config),K=new Map;if(G&&(null==k?void 0:k.getFiles)){const e=[...new Set(V.map(e=>{var t,o;return null!==(o=null!==(t=e.targetFolderId)&&void 0!==t?t:g)&&void 0!==o?o:""}).filter(e=>null!=e))];for(const t of e)try{const{files:e}=await k.getFiles({folderId:""===t?"":null!=t?t:void 0,itemType:"all",page:1,limit:1e4});let o=(e||[]).map(e=>e.name).filter(e=>!!e);if(null==k?void 0:k.getFolders){const e=(await k.getFolders({parentId:t||null,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);o=[...o,...e]}K.set(t,o)}catch(e){console.warn("Could not fetch files for duplicate check:",e)}}const Q=new Map,J=V.map(e=>{const t=G?((e,t)=>{const o=null!=e?e:"";let r=K.get(o)||[],n=Q.get(o);n||(n=new Set(r.map(e=>e.toLowerCase())),Q.set(o,n));const i=Tr(t,Array.from(n));return n.add(i.toLowerCase()),i})(e.targetFolderId,e.file.name):e.file.name,o=G?yi(e.file,t):e.file;return Object.assign(Object.assign({},e),{resolvedUploadName:t,uploadFile:o})}),Y=!t,Z=1===H&&Y,X=[],ee=[],te=[],oe=[],re=new Map;let ne=0,ie=0;const ae=null!==(y=null===(v=null==l?void 0:l.config)||void 0===v?void 0:v.maxFileSize)&&void 0!==y?y:52428800,le=async(e,o,r,n)=>{var i,a;const{emitProgress:l=!0,emitNotification:s=!0}=null!=n?n:{};ne++,X.push(e),ee.push(null!=r?r:e),await((e,t,o,r)=>{var n;return m.success({id:"FILE_UPLOAD_ITEM_SUCCESS",message:`${h("File")} ${e} ${h("has been successfully uploaded")}`,placement:"bottomRight",data:{itemId:o,itemName:e,folderId:null!==(n=null!=t?t:g)&&void 0!==n?n:null,eventSource:"upload"}},r||!Y)})(e,o,r,!s),l&&(null===(i=null==t?void 0:t.onProgress)||void 0===i||i.call(t,e,100),null===(a=null==t?void 0:t.onComplete)||void 0===a||a.call(t,e))},se=async(e,o,r,n)=>{var i;const{emitProgress:a=!0,emitNotification:l=!0,fileSize:s,progressCallbackName:d,progressCallbackIndex:c}=null!=n?n:{};ie++;const u=null!=s?{fileSize:s,maxSize:ae}:void 0,f=await((e,t,o,r,n)=>{var i,a,l,s,d,c,u;const f=Dn(o),p=null!==(i=null==n?void 0:n.fileSize)&&void 0!==i?i:null==f?void 0:f.fileSize,v=null!==(l=null!==(a=null==n?void 0:n.maxSize)&&void 0!==a?a:null==f?void 0:f.maxSize)&&void 0!==l?l:ae,y={allowedChars:"a-z A-Z 0-9 . _ -",fileSize:null!=p?Nr(Number(p)):void 0,maxSize:null!=v?Nr(Number(v)):void 0},w=null==f?void 0:f.code,b="BatchItemLimitExceeded"===w||"exceeded_max_files"===w?w:null!==(s=jn(null==f?void 0:f.message))&&void 0!==s?s:w,C="BatchItemLimitExceeded"===b||"exceeded_max_files"===b?Bn(o,h):Un(b,h,y),I=(null==f?void 0:f.message)&&"string"==typeof f.message&&f.message.length>0?f.message:null,F=o instanceof Error?o.message:"string"==typeof o?o:null,A=F&&"[object Object]"!==F?F:null;return m.error({id:"FILE_UPLOAD_ITEM_FAILED",message:null!==(c=null!==(d=null!=I?I:C)&&void 0!==d?d:A)&&void 0!==c?c:h("Error uploading file {{fileName}}",{fileName:e}),placement:"bottomRight",data:{itemName:e,folderId:null!==(u=null!=t?t:g)&&void 0!==u?u:null,error:Dn(o),eventSource:"upload"},innerException:o},r||!Y)})(e,o,r,!l,u);a&&(null===(i=null==t?void 0:t.onError)||void 0===i||i.call(t,null!=d?d:e,f.message,c)),oe.push({itemId:void 0,itemName:e,error:Dn(r)}),te.push({fileName:e,error:f.message})};let de;if(!(null==k?void 0:k.uploadFiles))return m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"}),{successCount:0,failCount:H,successes:[],errors:[],totalCount:H};{const e=[];try{(null==t?void 0:t.onProgress)&&V.forEach(o=>{let r=0;const n=window.setInterval(()=>{var e;r=Math.min(r+10+Math.floor(Date.now()%10),90),null===(e=null==t?void 0:t.onProgress)||void 0===e||e.call(t,o.file.name,r)},200);e.push(n)}),de=await k.uploadFiles({items:J.map(e=>{var t,o;return{requestId:e.requestId,name:e.resolvedUploadName,size:e.uploadFile.size,type:e.uploadFile.type,folderId:null!==(o=null!==(t=e.targetFolderId)&&void 0!==t?t:g)&&void 0!==o?o:null,data:e.uploadFile,extension:e.uploadFile.name.split(".").pop()||""}}),folderId:null!=g?g:null}),e.forEach(e=>window.clearInterval(e)),e.length=0;const o=null!==(w=de.detailed)&&void 0!==w?w:[],r=new Map(o.filter(e=>e.requestId).map(e=>[e.requestId,e]));if(o.length>0)for(let e=0;e<J.length;e++){const t=J[e],n=null!==(b=t.requestId?r.get(t.requestId):void 0)&&void 0!==b?b:o[e];if(n&&n.success){const e=n.data,o=null!==(C=null==e?void 0:e.name)&&void 0!==C?C:t.resolvedUploadName,r=null!==(A=null!==(F=null!==(I=null==e?void 0:e.folderId)&&void 0!==I?I:t.targetFolderId)&&void 0!==F?F:g)&&void 0!==A?A:null,i=null==e?void 0:e.id;re.set(o,{id:i,name:o,folderId:r,size:null==e?void 0:e.size,originalFileName:t.originalFileName,originalIndex:t.originalIndex}),await le(o,r,i,{emitNotification:Z})}else{const e=null==n?void 0:n.data,o=null!==(_=null==e?void 0:e.name)&&void 0!==_?_:t.resolvedUploadName,r=null!==(P=null!==(E=null!==(S=null==e?void 0:e.folderId)&&void 0!==S?S:t.targetFolderId)&&void 0!==E?E:g)&&void 0!==P?P:null;await se(o,r,null!==(R=null==n?void 0:n.error)&&void 0!==R?R:new Error(h("Error uploading file")),{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}else if(de.success)for(const e of J){const t=e.resolvedUploadName,o=null!==(O=null!==(N=e.targetFolderId)&&void 0!==N?N:g)&&void 0!==O?O:null;await le(t,o,void 0,{emitNotification:Z})}else{const e=null!==(T=de.error)&&void 0!==T?T:new Error(h("Error uploading file"));for(const t of J){const o=t.resolvedUploadName,r=null!==(M=null!==(L=t.targetFolderId)&&void 0!==L?L:g)&&void 0!==M?M:null;await se(o,r,e,{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}}catch(e){for(const t of J){const o=t.resolvedUploadName,r=null!==(j=null!==(U=t.targetFolderId)&&void 0!==U?U:g)&&void 0!==j?j:null;await se(o,r,null!=e?e:new Error(h("Error uploading file")),{emitNotification:Z,fileSize:t.file.size,progressCallbackName:t.originalFileName,progressCallbackIndex:t.originalIndex})}}finally{e.forEach(e=>window.clearInterval(e))}}if(ne>0&&(x&&x(at),H>1&&Y)){const e=W(X),t=e?h("Uploaded",{names:e}):h("uploads_success_summary",{successCount:ne,totalCount:H});m.success({id:"FILES_UPLOAD_BATCH_SUCCESS",message:t,placement:"bottomRight",data:{successCount:ne,totalCount:H,itemIds:ee,itemNames:X,folderId:null!=g?g:null,eventSource:"upload"}})}if(ie>0&&Y&&!Z)if(H>1){const e=te.map(e=>e.fileName),t=W(e),o=t?h("Failed",{names:t}):h("uploads_fail_summary",{failCount:ie,totalCount:H});m.error({id:"FILES_UPLOAD_BATCH_FAILED",message:o,placement:"bottomRight",data:{failCount:ie,totalCount:H,itemNames:e,folderId:null!=g?g:null,errors:oe,eventSource:"upload"}})}else if(1===H&&oe.length>0&&(null===(D=oe[0].error)||void 0===D?void 0:D.code)){const e=Un(null===(B=oe[0].error)||void 0===B?void 0:B.code,h),t=null!==(q=null===(z=te[0])||void 0===z?void 0:z.fileName)&&void 0!==q?q:"",o=null!=e?e:t?`${h("Failed to upload files")}: ${t}`:h("Failed to upload files");m.error({id:"FILES_UPLOAD_BATCH_FAILED",message:o,placement:"bottomRight",data:{failCount:ie,totalCount:H,itemNames:[t],folderId:null!=g?g:null,errors:oe,eventSource:"upload"}})}return{successCount:ne,failCount:ie,successes:X,errors:te,totalCount:H,uploadedFiles:re.size>0?re:void 0}},[k,null===(o=null==l?void 0:l.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient,m,$,g,x,h,null==l?void 0:l.config]),G=d(async e=>{var t;if(!(null==k?void 0:k.uploadFiles))return void m.error({id:"FILES_UPLOAD_PROVIDER_NOT_CONFIGURED",message:h("DataProvider for file upload is not configured"),placement:"bottomRight"});if("Trash"===g)return void m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}});const o=I.current,r=document.createElement("input");r.type="file",r.accept="image/*",r.multiple=!0;try{!(!(null===(t=null==l?void 0:l.config)||void 0===t?void 0:t.features)||!l.config.features.enableDirectoryUpload)&&(r.webkitdirectory=!0)}catch(e){}r.onchange=async t=>{var r;const n=t.target.files;if(!n||0===n.length)return;const i=Array.from(n);try{null==S||S(!0);const{successes:t,errors:n,uploadedFiles:a}=await H(i,e);null===(r=null==e?void 0:e.onBatchComplete)||void 0===r||r.call(e,{files:i,successes:t,errors:n,uploadedFiles:a}),await f(),await M({folderId:g||"",sortBy:c,sortOrder:u,page:o.current,limit:o.pageSize})}catch(e){console.error("Error when loading files:",e)}finally{null==S||S(!1)}},r.click()},[null==k?void 0:k.uploadFiles,g,m,h,S,M,f,c,u,H,null===(r=null==l?void 0:l.config)||void 0===r?void 0:r.features]),K=d(async(e,t,o,r="uploadByUrl")=>{const n=I.current,i=Boolean(e&&String(e).trim());let a,s=null!=e?e:null;try{if(!t&&"Trash"===g)throw o||m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}}),new Jn(h("Cannot upload files to Trash"),"UploadUrlDownloadFailed");let e,d;if(!s&&v&&(e=await v.validateFields(),s=null==e?void 0:e.fileUrl),!s)throw o||m.error({id:"FILES_UPLOAD_URL_VALIDATION_FAILED",message:h("Please fill in all fields"),placement:"bottomRight",data:{url:null!=s?s:null,folderId:g||null,eventSource:r}}),new Jn(h("Please fill in all fields"),"UploadUrlInvalid");if(Xn(s,h),s=mi(s),null==S||S(!0),s){const e=s.split("?")[0].split("#")[0].split("/");d=e[e.length-1]||"uploaded-file",d=Yt(d,null==l?void 0:l.config)}const f=t?"":g||"",p=Boolean((null==k?void 0:k.uploadFiles)||(null==k?void 0:k.uploadFile)),y=Boolean(null==k?void 0:k.uploadFileByUrl);let w=d;w&&y&&(w=await T(w,f,t));try{const e=await j(s,o);if("existing"===e.kind)a=e.file;else if(p){const o=new File([e.blob],e.fileName,{type:e.mimeType,lastModified:Date.now()});try{a=await W(o,f,!0,t)}catch(e){throw e.uploadUrlStage="binaryUpload",e}if(!a){const e=new Jn(h("Failed to upload file"),"FileUploadBackendError");throw e.uploadUrlStage="binaryUpload",e}}else{if(!y)throw o||m.error({id:"FILES_UPLOAD_URL_NOT_SUPPORTED",message:h("Upload by URL is not supported"),placement:"bottomRight",data:{url:s,folderId:g||null,eventSource:r}}),new Jn(h("Upload by URL is not supported"),"UploadUrlDownloadFailed");a=await k.uploadFileByUrl({url:s,folderId:g||"",noFolder:t,name:w,eventSource:r})}}catch(e){const o=e;if("binaryUpload"===(null==o?void 0:o.uploadUrlStage)||!y)throw e;console.warn("Failed to fetch file by URL locally, falling back to uploadByUrl",e),a=await k.uploadFileByUrl({url:s,folderId:g||"",noFolder:t,name:w,eventSource:r})}const b=(null==e?void 0:e.name)||(null==a?void 0:a.name)||"unnamed file";return a&&m.success({id:"FILE_UPLOAD_ITEM_SUCCESS",message:`${h("File")} ${b} ${h("successfully uploaded")}`,placement:"bottomRight",data:{itemName:b,itemId:null==a?void 0:a.id,folderId:g||null,eventSource:r}},o),(e||i)&&(null==E||E(!1),null==v||v.resetFields()),x&&x(at),await M({folderId:g||"",noFolder:t,sortBy:c,sortOrder:u,page:n.current,limit:n.pageSize}),a}catch(e){if(console.error("Error when loading a file by URL:",e),!o){const t=Dn(e),o=t,n=e,i=Number(null==o?void 0:o.fileSize),a=Number(null==o?void 0:o.maxSize),l=Number.isFinite(i)&&Number.isFinite(a)?{fileSize:i,maxSize:a}:void 0,d="binaryUpload"===(null==n?void 0:n.uploadUrlStage)?Bn(t,h,l):Wn(t,h);m.error({id:"FILES_UPLOAD_BY_URL_FAILED",message:d,placement:"bottomRight",data:{url:null!=s?s:null,folderId:g||null,error:t,eventSource:r},innerException:e})}throw e}finally{null==S||S(!1)}},[v,S,k,m,h,E,x,M,g,c,u,T,j,W,null==l?void 0:l.config]),Q=d(async e=>{if(!e.length)return;const t=I.current;"Trash"!==g?(await H(e),await M({folderId:g||"",sortBy:c,sortOrder:u,page:t.current,limit:t.pageSize})):m.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:h("Cannot upload files to Trash"),placement:"bottomRight",data:{folderId:g||null,reason:"Upload to Trash is not allowed"}})},[M,g,c,u,H,m,h]);return{fetchFiles:M,handleDeleteFile:B,handleDeleteFolder:z,handleAddFile:G,handleAddFileByUrl:K,handleDroppedFiles:Q,getFileData:q,findFileByUrl:U,resolveFileForEditByUrl:D,uploadFileWithProvider:W}},_i=e=>{let t;const o=new Set,r=(e,r)=>{const n="function"==typeof e?e(t):e;if(!Object.is(n,t)){const e=t;t=(null!=r?r:"object"!=typeof n||null===n)?n:Object.assign({},t,n),o.forEach(o=>o(t,e))}},n=()=>t,i={setState:r,getState:n,getInitialState:()=>a,subscribe:e=>(o.add(e),()=>o.delete(e))},a=t=e(r,n,i);return i},Si=e=>e;const Ei=e=>{const t=(e=>e?_i(e):_i)(e),o=e=>function(e,t=Si){const o=n.useSyncExternalStore(e.subscribe,n.useCallback(()=>t(e.getState()),[e,t]),n.useCallback(()=>t(e.getInitialState()),[e,t]));return n.useDebugValue(o),o}(t,e);return Object.assign(o,t),o};function xi(e,t){if(e.size!==t.size)return!1;for(const o of e)if(!t.has(o))return!1;return!0}const Pi=(Ri=e=>({selectedFiles:new Set,visibleFileIds:[],anchorId:null,multiSelect:!0,setMultiSelect:t=>{e(e=>{var o;if(e.multiSelect===t)return e;if(t)return{multiSelect:!0};const r=null!==(o=Array.from(e.selectedFiles)[0])&&void 0!==o?o:null;return{multiSelect:!1,selectedFiles:r?new Set([r]):new Set,anchorId:r}})},syncVisibleFiles:t=>{const o=Array.isArray(t)?t.map(e=>e.id):[];e(e=>{const t=new Set(o),r=new Set(Array.from(e.selectedFiles).filter(e=>t.has(e))),n=e.anchorId&&t.has(e.anchorId)?e.anchorId:null,i=function(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o+=1)if(e[o]!==t[o])return!1;return!0}(e.visibleFileIds,o),a=xi(e.selectedFiles,r),l=e.anchorId===n;return i&&a&&l?e:{visibleFileIds:o,selectedFiles:r,anchorId:n}})},setSelectedFiles:t=>{e(e=>{var o;const r=new Set(e.visibleFileIds),n=new Set(Array.from(t).filter(e=>r.has(e)));return xi(e.selectedFiles,n)?e:{selectedFiles:n,anchorId:null!==(o=Array.from(n)[0])&&void 0!==o?o:null}})},clearSelection:()=>{e(e=>0===e.selectedFiles.size&&null===e.anchorId?e:{selectedFiles:new Set,anchorId:null})},selectAllVisible:()=>{e(e=>{var t;const o=new Set(e.visibleFileIds),r=null!==(t=e.visibleFileIds[0])&&void 0!==t?t:null;return xi(e.selectedFiles,o)&&e.anchorId===r?e:{selectedFiles:o,anchorId:r}})},toggleFileSelection:(t,o)=>{e(e=>{const r=!1!==e.multiSelect,n=Boolean(null==o?void 0:o.shiftKey)&&r,i=Boolean(null==o?void 0:o.metaKey)||Boolean(null==o?void 0:o.ctrlKey)||Boolean(null==o?void 0:o.forceToggle),a=e.visibleFileIds,l=new Set(a);if(a.length>0&&!l.has(t))return e;if(!r){const o=new Set([t]);return xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}if(n&&e.anchorId&&l.has(e.anchorId)){const o=a.indexOf(e.anchorId),r=a.indexOf(t);if(-1===o||-1===r)return e;const[n,l]=o<r?[o,r]:[r,o],s=a.slice(n,l+1),d=i?new Set(e.selectedFiles):new Set;return s.forEach(e=>{d.add(e)}),xi(e.selectedFiles,d)?e:{selectedFiles:d}}if(n&&!e.anchorId){const o=new Set([t]);return xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}if(i){const o=new Set(e.selectedFiles);return o.has(t)?o.delete(t):o.add(t),xi(e.selectedFiles,o)&&e.anchorId===t?e:{selectedFiles:o,anchorId:t}}const s=new Set([t]);return xi(e.selectedFiles,s)&&e.anchorId===t?e:{selectedFiles:s,anchorId:t}})}}),Ri?Ei(Ri):Ei);var Ri;const Ni=e=>{var t,o,r,n;const{state:i,actions:a,options:l}=mn(),{t:s}=dr(),c=Kn(),u=On(),{fetchFolders:f}=c.actions,{renameItem:h}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=d(async({itemId:r,newName:n,isFolder:i})=>{var a,l,s,d,c,u,f,h;try{if(i){if(!(null==t?void 0:t.renameFolder))throw new Error(o("renameFolder is not implemented in dataProviders"));const i=Zt(n.trim(),e.config),d=await t.renameFolder(r,i);return{success:!0,renamedItem:{id:d.id,name:null!==(a=d.name)&&void 0!==a?a:i,parentId:null!==(l=d.parentId)&&void 0!==l?l:null,folderId:null!==(s=d.parentId)&&void 0!==s?s:null}}}if(!(null==t?void 0:t.renameFile))throw new Error(o("renameFile is not implemented in dataProviders"));const m=Yt(n,e.config),p=await t.renameFile(r,m);return{success:!0,renamedItem:{id:null!==(d=null==p?void 0:p.id)&&void 0!==d?d:r,name:null!==(c=null==p?void 0:p.name)&&void 0!==c?c:m,folderId:null!==(u=null==p?void 0:p.folderId)&&void 0!==u?u:null,parentId:null!==(h=null!==(f=null==p?void 0:p.parentId)&&void 0!==f?f:null==p?void 0:p.folderId)&&void 0!==h?h:null}}}catch(e){return{success:!1,error:Dn(e)}}},[t,o,e.config]);return{renameItem:r}})(),{files:m,selectedFolder:p,fileToRename:g,renameForm:v,isRenameModalVisible:y,pagination:w}=i,{setFileToRename:b,setIsRenameModalVisible:C}=a,{dataProviders:I,config:F}=l,A=e=>{var t,o;if(!e)return null;const r=e;return null!==(o=null!==(t=r.folderId)&&void 0!==t?t:r.parentId)&&void 0!==o?o:null},_=(e,t)=>{var o;return{itemId:null!==(o=null==e?void 0:e.id)&&void 0!==o?o:t,itemName:null==e?void 0:e.name,folderId:A(e)}},S=d(e=>{var t,o;const r=null==m?void 0:m.find(t=>t.id===e);if((null==r?void 0:r.isFolder)||e.startsWith("folder_")){if(!(!1!==(null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder)))return void u.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:s("Folder rename is disabled by config"),placement:"bottomRight",data:_(r,e)});if(!(null==I?void 0:I.renameFolder))throw new Error(s("renameFolder is not implemented in dataProviders"))}else{if(!(!1!==(null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile)))return void u.error({id:"FILE_RENAME_DISABLED_BY_CONFIG",message:s("File rename is disabled by config"),placement:"bottomRight",data:_(r,e)});if(!(null==I?void 0:I.renameFile))throw new Error(s("renameFile is not implemented in dataProviders"))}null==b||b(e),null==C||C(!0),r&&v&&v.setFieldsValue({newFileName:r.name})},[m,b,C,v,null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder,null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile,null==I?void 0:I.renameFolder,null==I?void 0:I.renameFile,u,s]),E=d(()=>{null==C||C(!1),null==b||b(null),null==v||v.resetFields()},[C,b,v]),x=d(async()=>{var t,o,r,n,i,l,d,c,y,b,C,I;if(!g||!v)return;const A=null==m?void 0:m.find(e=>e.id===g);try{const m=await v.validateFields();if(!(null==m?void 0:m.newFileName))return;const S=(null==A?void 0:A.isFolder)||g.startsWith("folder_");if(S){if(!(!1!==(null===(t=null==F?void 0:F.features)||void 0===t?void 0:t.enableRenameFolder)))return void u.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:s("Folder rename is disabled by config"),placement:"bottomRight",data:_(A,g)})}else{if(!(!1!==(null===(o=null==F?void 0:F.features)||void 0===o?void 0:o.enableRenameFile)))return void u.error({id:"FILE_RENAME_DISABLED_BY_CONFIG",message:s("File rename is disabled by config"),placement:"bottomRight",data:_(A,g)})}const x=await h({itemId:g,newName:m.newFileName,isFolder:S});if(!x.success){const e=Un(null===(r=x.error)||void 0===r?void 0:r.code,s);return void u.error({id:"ITEM_RENAME_FAILED",message:null!==(i=null!=e?e:null===(n=x.error)||void 0===n?void 0:n.message)&&void 0!==i?i:s("Error renaming"),placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{error:x.error}),innerException:x.error})}const P=x.renamedItem;S?(u.success({id:"FOLDER_RENAME_SUCCESS",message:s(`${s("Folder renamed to")} ${null!==(l=null==P?void 0:P.name)&&void 0!==l?l:m.newFileName}`),placement:"bottomRight",data:{itemId:null!==(d=null==P?void 0:P.id)&&void 0!==d?d:g,itemName:null!==(c=null==P?void 0:P.name)&&void 0!==c?c:m.newFileName,folderId:null!==(b=null!==(y=null==P?void 0:P.parentId)&&void 0!==y?y:null==P?void 0:P.folderId)&&void 0!==b?b:null}}),await f(),(null==P?void 0:P.id)&&P.id!==g&&a.setSelectedFolder&&a.setSelectedFolder(P.id)):u.success({id:"FILE_RENAME_SUCCESS",message:`${s("File renamed to")} ${null!==(C=null==P?void 0:P.name)&&void 0!==C?C:m.newFileName}`,placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{itemName:null!==(I=null==P?void 0:P.name)&&void 0!==I?I:m.newFileName})}),E(),await e({folderId:p||"",page:w.current,limit:w.pageSize})}catch(e){console.error("Error when renaming:",e);const t=Dn(e),o=Un(null==t?void 0:t.code,s);u.error({id:"ITEM_RENAME_FAILED",message:null!=o?o:e instanceof Error?e.message:s("Error renaming"),placement:"bottomRight",data:Object.assign(Object.assign({},_(A,g)),{error:t}),innerException:e})}},[g,v,m,a,E,e,p,s,w,null===(r=null==F?void 0:F.features)||void 0===r?void 0:r.enableRenameFolder,null===(n=null==F?void 0:F.features)||void 0===n?void 0:n.enableRenameFile,u,f,h]);return{state:{isRenamingFile:y||!1,fileToRename:g},actions:{showRenameModal:S,handleRenameCancel:E,handleRenameOk:x}}},ki=e=>{const t=t=>{if(!t)return;const o=e.find(e=>e.id===t);return null==o?void 0:o.name};return{getItemNameById:t,getItemNamesByIds:e=>e.map(t).filter(e=>Boolean(e)),getNamesPreview:e=>e.length>0&&e.length<=5?e.join(", "):null}},Oi=(e,t,o,r,n)=>({itemIds:e,itemNames:n&&n.length?n:void 0,successCount:t,totalCount:o,folderId:null!=r?r:null}),Ti=(e,t,o,r,n,i)=>({itemIds:e,itemNames:i&&i.length?i:void 0,failCount:t,totalCount:o,folderId:null!=r?r:null,errors:n}),Li=()=>{const e=On(),{t:t}=dr(),{state:o,options:r}=mn(),{folders:n,pathHistory:i}=o,{dataProviders:a}=r,{actions:{fetchFolders:l,fetchChildFolders:s}}=Kn();return{refreshFolders:d(async({parentIds:o,selectedFolder:r})=>{try{if(await l(),o&&s)for(const e of o)e&&await s(e)}catch(o){console.error("Error when updating the folder tree:",o);const r=t("Folders");e.error({id:"FOLDERS_FETCH_FAILED",message:t("Failed to refresh folder tree"),description:r,placement:"bottomRight",innerException:o,notificationDedupe:!0,data:{folderId:null,folderName:r,reason:o instanceof Error?o.message:String(o)}})}},[e,t,l,s]),refreshFiles:d(async({fetchFiles:o,selectedFolder:r,page:l,limit:s})=>{try{await o({folderId:r||"",page:l,limit:s})}catch(o){console.error("Ошибка при обновлении списка файлов:",o);const d=await fi({folderId:r||"",dataProviders:a,folders:Array.isArray(n)?n:[],pathHistory:i,t:t}),c=t("Failed to load files"),u=o instanceof Error?o.message:String(o);e.error({id:"FILES_FETCH_FAILED",message:t("Failed to load files in folder",{folderName:d}),description:u&&u!==c?u:void 0,placement:"bottomRight",innerException:o,notificationDedupe:!0,data:{params:{folderId:r||void 0,page:l,limit:s,folderName:d},folderName:d}})}},[e,t,a,n,i])}},Mi=e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),l=Pi(e=>e.selectedFiles),s=Pi(e=>e.clearSelection),{files:c,selectedFolder:u,moveForm:f,pagination:h,currentMenuFile:m}=o,{setIsMoveModalVisible:p,setPagination:g}=r,{dataProviders:v}=n,{moveItems:y}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=On(),n=d(async({items:e,targetFolderId:n,getItemNameById:i,showNotifications:a=!1})=>{let l=0,s=0;const d=[];if(null==t?void 0:t.moveItems)try{const o=await t.moveItems("folders"===n?"":n,e.map(e=>e.id)),r=o.detailed;if(r){const e=r.filter(e=>e.success),t=r.filter(e=>!e.success);l+=e.length,s+=t.length,t.forEach(e=>{const t=null!==(r=(o=e).requestId)&&void 0!==r?r:o.id;var o,r;const n=e.error,a=Dn(n);d.push({itemId:t,itemName:i(t),error:a})})}else if(o.success)l+=e.length;else{const t=o.error;if(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length}}catch(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length,d.push({error:{message:"Move provider is not configured"}});return a&&(l>0&&r.success({id:"FILES_MOVE_SUCCESS",message:o("Files moved"),placement:"bottomRight",data:{successCount:l,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:"folders"===n?null:n}}),s>0&&r.error({id:"FILES_MOVE_ERROR",message:o("Errors occurred while moving"),placement:"bottomRight",innerException:d.length?d:void 0,data:{failCount:s,totalCount:e.length,itemIds:e.map(e=>e.id),errors:d.length?d:void 0}})),{successCount:l,failCount:s,errorDetails:d}},[t,r,o]);return{moveItems:n}})(),{refreshFolders:w,refreshFiles:b}=Li(),{getItemNameById:C,getItemNamesByIds:I,getNamesPreview:F}=ki(c),A=d(()=>{null==p||p(!0)},[p]),_=d(()=>{null==p||p(!1),null==f||f.resetFields()},[p,f]),S=d(async t=>{var o,r,d,p,A,S,E,x;if(!((null==m?void 0:m.length)||l&&0!==l.size))return;const P=c.length,R=Object.assign({},h),N=Array.from((null==m?void 0:m.length)?[m]:l),k=N.length;let O=0,T=0;const L=[],M=N.map(e=>c.find(t=>t.id===e)).filter(e=>Boolean(e)),U=M.some(e=>(null==e?void 0:e.isFolder)||e.id.startsWith("folder_"));try{let l=t;if(!t){const e=await f.validateFields();l=null==e?void 0:e.targetFolder}if(!l)return void a.error({id:"FILES_MOVE_DIRECTORY_NOT_SELECTED",message:i("Select destination folder"),placement:"bottomRight"});const c="folders"===l?null:l,h=null!=c?c:u,m=!0===(null===(o=null==n?void 0:n.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient);if(m&&(null==v?void 0:v.getFolders))try{const e=await v.getFolders({parentId:c,deep:!1}),t=new Set((e||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean));for(const e of M){if(!e.isFolder&&!(null===(d=(r=e.id).startsWith)||void 0===d?void 0:d.call(r,"folder_")))continue;const o=e.name||C(e.id)||"";if(o&&t.has(o.toLowerCase()))return void a.error({id:"FOLDER_ALREADY_EXISTS_MOVE",message:i("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,targetFolderId:l}})}}catch(e){console.warn("Could not check folder duplicates for move:",e)}if(m&&(null==v?void 0:v.getFiles)&&(null==v?void 0:v.renameFile))try{let e=[];if(null==v?void 0:v.getFiles){const{files:t}=await v.getFiles({folderId:null!=c?c:void 0,itemType:"all",page:1,limit:1e4});e=(t||[]).map(e=>e.name).filter(e=>!!e)}if(null==v?void 0:v.getFolders){const t=(await v.getFolders({parentId:c,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);e=[...e,...t]}const t=new Set(e.map(e=>null==e?void 0:e.toLowerCase()).filter(Boolean));for(const e of M){if(e.isFolder||(null===(A=(p=e.id).startsWith)||void 0===A?void 0:A.call(p,"folder_")))continue;const o=e.name||C(e.id)||"";if(!o||!t.has(o.toLowerCase())){t.add(o.toLowerCase());continue}const r=Tr(o,Array.from(t));await v.renameFile(e.id,r),t.add(r.toLowerCase())}}catch(e){console.warn("Could not check duplicates for move:",e)}const j=await y({items:M,targetFolderId:l,getItemNameById:C,showNotifications:!1});if(O=j.successCount,T=j.failCount,L.push(...j.errorDetails),O>0){const e=I(N),t=F(e),o=t?i("Moved",{names:t}):i("move_success_summary",{successCount:O,totalCount:k});a.success({id:"FILES_MOVE_SUCCESS",message:o,placement:"bottomRight",data:Oi(N,O,k,c,e)})}if(T>0){const e=I(N),t=F(e);let o;if(1===k&&L.length>0&&(null===(S=L[0].error)||void 0===S?void 0:S.code)){const e=Un(null===(E=L[0].error)||void 0===E?void 0:E.code,i);o=null!=e?e:t?i("Failed",{names:t}):i("move_fail_summary",{failCount:T,totalCount:k})}else o=t?i("Failed",{names:t}):i("move_fail_summary",{failCount:T,totalCount:k});a.error({id:"FILES_MOVE_ERROR",message:o,placement:"bottomRight",innerException:L.length?L:void 0,data:Ti(N,T,k,c,L.length?L:void 0,e)})}_(),s();let D=R.current;if(O>0&&P>0&&O>=P&&R.current>1&&(D=R.current-1),O>0&&R.total>=O){const e=Math.max(0,(null!==(x=R.total)&&void 0!==x?x:0)-O);null==g||g({current:D,pageSize:R.pageSize,total:e})}U&&await w({parentIds:void 0,selectedFolder:h}),await b({fetchFiles:e,selectedFolder:u,page:D,limit:R.pageSize})}catch(e){console.error("Error when moving:",e);const t=Un(Dn(e).code,i);a.error({id:"FILES_MOVE_ERROR",innerException:e,message:null!=t?t:i("Error moving"),placement:"bottomRight",data:Ti(N,k,k,u||null,[{error:Dn(e)}],I(N))})}},[m,l,f,e,u,h,c,a,g,i,y,s,p,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient,null==v?void 0:v.getFiles,null==v?void 0:v.renameFile,C]);return{actions:{showMoveModal:A,handleMoveCancel:_,handleMoveOk:S}}},Ui=e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),l=Pi(e=>e.selectedFiles),s=Pi(e=>e.clearSelection),{files:c,selectedFolder:u,copyForm:f,pagination:h,currentMenuFile:m}=o,{setIsCopyModalVisible:p}=r,{dataProviders:g}=n,{copyItems:v}=(()=>{const{options:e}=mn(),{dataProviders:t}=e,{t:o}=dr(),r=On(),n=d(async({items:e,targetFolderId:n,getItemNameById:i,showNotifications:a=!1})=>{let l=0,s=0;const d=[],c="folders"===n?"":n;if(null==t?void 0:t.copyItems)try{const o=await t.copyItems(c,e.map(e=>({id:e.id,newName:e.newName}))),r=o.detailed;if(r){const e=r.filter(e=>e.success),t=r.filter(e=>!e.success);l+=e.length,s+=t.length,t.forEach(e=>{const t=null!==(r=(o=e).requestId)&&void 0!==r?r:o.id;var o,r;const n=e.error,a=Dn(n);d.push({itemId:t,itemName:i(t),error:a})})}else if(o.success)l+=e.length;else{const t=o.error;if(t){s+=e.length;const o=Dn(t);d.push({error:o})}else s+=e.length}}catch(t){s+=e.length;const o=Dn(t);d.push({error:o})}else if(null==t?void 0:t.copyItem)for(const o of e)try{const e=(null==o?void 0:o.isFolder)||o.id.startsWith("folder_");await t.copyItem({itemId:o.id,targetFolderId:c,isFolder:e,newName:o.newName})?l++:s++}catch(e){s++;const t=Dn(e);d.push({itemId:o.id,itemName:i(o.id),error:t})}else s+=e.length,d.push({error:{message:"Copy provider is not configured"}});return a&&(l>0&&r.success({id:"FILES_COPY_SUCCESS",message:o("Files copied"),placement:"bottomRight",data:{successCount:l,totalCount:e.length,itemIds:e.map(e=>e.id),folderId:"folders"===n?null:n}}),s>0&&r.error({id:"FILES_COPY_ERROR",message:o("Errors occurred while copying"),placement:"bottomRight",innerException:d.length?d:void 0,data:{failCount:s,totalCount:e.length,itemIds:e.map(e=>e.id),errors:d.length?d:void 0}})),{successCount:l,failCount:s,errorDetails:d}},[t,r,o]);return{copyItems:n}})(),{refreshFolders:y,refreshFiles:w}=Li(),{getItemNameById:b,getItemNamesByIds:C,getNamesPreview:I}=ki(c),F=d(()=>{null==p||p(!0)},[p]),A=d(()=>{null==p||p(!1),null==f||f.resetFields()},[p,f]),_=d(async t=>{var o,r,d,p,F;if(!((null==m?void 0:m.length)||l&&0!==l.size))return;const _=Array.from((null==m?void 0:m.length)?[m]:l),S=_.length;let E=0,x=0;const P=[],R=_.map(e=>c.find(t=>t.id===e)).filter(e=>Boolean(e)),N=R.some(e=>(null==e?void 0:e.isFolder)||e.id.startsWith("folder_"));try{let l=t;if(!t){const e=await f.validateFields();l=null==e?void 0:e.targetFolder}if(!l)return void a.error({id:"FILES_COPY_DIRECTORY_NOT_SELECTED",message:i("Select destination folder"),placement:"bottomRight"});const c="folders"===l?null:l,m=null!=c?c:u;let k=R.map(e=>({id:e.id,isFolder:(null==e?void 0:e.isFolder)||e.id.startsWith("folder_")}));const O=!0===(null===(o=null==n?void 0:n.config)||void 0===o?void 0:o.dedupeUploadNamesOnClient);if(O&&(null==g?void 0:g.getFolders))try{const e=await g.getFolders({parentId:c,deep:!1}),t=new Set((e||[]).map(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase()}).filter(Boolean));for(const e of R){if(!e.isFolder&&!(null===(d=(r=e.id).startsWith)||void 0===d?void 0:d.call(r,"folder_")))continue;const o=e.name||b(e.id)||"";if(o&&t.has(o.toLowerCase()))return void a.error({id:"FOLDER_ALREADY_EXISTS_COPY",message:i("A folder with that name already exists. Please enter a different folder name."),placement:"bottomRight",data:{folderName:o,targetFolderId:l}})}}catch(e){console.warn("Could not check folder duplicates for copy:",e)}if(O&&(null==g?void 0:g.getFiles))try{let e=[];const{files:t}=await g.getFiles({folderId:null!=c?c:void 0,itemType:"all",page:1,limit:1e4});if(e=(t||[]).map(e=>e.name).filter(e=>!!e),null==g?void 0:g.getFolders){const t=(await g.getFolders({parentId:c,deep:!1})||[]).map(e=>e.name).filter(e=>!!e);e=[...e,...t]}const o=[...e];k=R.map(e=>{var t,r;if(e.isFolder||(null===(r=(t=e.id).startsWith)||void 0===r?void 0:r.call(t,"folder_")))return{id:e.id,isFolder:!0};const n=R.find(t=>t.id===e.id),i=(null==n?void 0:n.name)||b(e.id)||"",a=Tr(i,o);return o.push(a),{id:e.id,isFolder:!1,newName:a!==i?a:void 0}})}catch(e){console.warn("Could not check duplicates for copy:",e)}else k=R.map(e=>({id:e.id,isFolder:(null==e?void 0:e.isFolder)||e.id.startsWith("folder_")}));const T=await v({items:k,targetFolderId:l,getItemNameById:b,showNotifications:!1});if(E=T.successCount,x=T.failCount,P.push(...T.errorDetails),E>0){const e=C(_),t=I(e),o=t?i("Copied",{names:t}):i("copy_success_summary",{successCount:E,totalCount:S});a.success({id:"FILES_COPY_SUCCESS",message:o,placement:"bottomRight",data:Oi(_,E,S,c,e)})}if(x>0){const e=C(_),t=I(e);let o;if(1===S&&P.length>0&&(null===(p=P[0].error)||void 0===p?void 0:p.code)){const e=Un(null===(F=P[0].error)||void 0===F?void 0:F.code,i);o=null!=e?e:t?i("Failed",{names:t}):i("copy_fail_summary",{failCount:x,totalCount:S})}else o=t?i("Failed",{names:t}):i("copy_fail_summary",{failCount:x,totalCount:S});a.error({id:"FILES_COPY_ERROR",message:o,placement:"bottomRight",innerException:P.length?P:void 0,data:Ti(_,x,S,c,P.length?P:void 0,e)})}A(),s(),N&&await y({parentIds:void 0,selectedFolder:m}),await w({fetchFiles:e,selectedFolder:u,page:h.current,limit:h.pageSize})}catch(e){console.error("Error when copying:",e);const t=Un(Dn(e).code,i);a.error({id:"FILES_COPY_ERROR",message:null!=t?t:i("Error copying"),innerException:e,placement:"bottomRight",data:Ti(_,S,S,u||null,[{error:Dn(e)}],C(_))})}},[m,l,f,e,u,h,c,a,i,v,s,p,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.dedupeUploadNamesOnClient,null==g?void 0:g.getFiles,b]);return{actions:{showCopyModal:F,handleCopyCancel:A,handleCopyOk:_}}},ji=e=>{const t=Ni(e),o=Mi(e),r=Ui(e),n=(e=>{const{state:t,actions:o,options:r}=mn(),{t:n}=dr(),i=On(),a=Pi(e=>e.selectedFiles),l=Pi(e=>e.clearSelection),{files:s,selectedFolder:c,pagination:u,currentMenuFile:f}=t,{setIsDeleteConfirmVisible:h,setUndoDeletion:m,setPagination:p}=o,{config:g}=r,{deleteItems:v}=Qn(),{refreshFolders:y,refreshFiles:w}=Li(),{getItemNameById:b,getItemNamesByIds:C,getNamesPreview:I}=ki(s),F=d(()=>{null==h||h(!0)},[h]),A=d(()=>{null==h||h(!1)},[h]),_=d(async()=>{var t,o,r;if(!((null==f?void 0:f.length)||a&&0!==a.size))return void(null==h||h(!1));const d=s.length,F=Object.assign({},u),A=Array.from(f?[f]:a),_=A.map(e=>s.find(t=>t.id===e)).filter(e=>Boolean(e)),S=new Set;_.forEach(e=>{(null==e?void 0:e.isFolder)&&S.add((e=>{var t,o;if(!e)return null;const r=e;return null!==(o=null!==(t=r.folderId)&&void 0!==t?t:r.parentId)&&void 0!==o?o:null})(e))});let E=0,x=0;const P=[];try{const a=await v({items:_,selectedFolder:c,getItemNameById:b,showNotifications:!1});E=a.successCount,x=a.failCount,P.push(...a.errorDetails);const s=(null==g?void 0:g.enableTrashFolder)&&"Trash"===c;if(E>0&&(null==g?void 0:g.enableTrashFolder)&&!s&&(null==m||m({itemIds:A,sourceFolderId:c||"folders"})),E>0){const e=A.length;(null==g?void 0:g.enableTrashFolder)&&!s?await i.success({id:"FILES_DELETE_SUCCESS",message:n("moved_to_trash",{count:E}),placement:"bottomRight",data:{successCount:E,totalCount:e,itemIds:A,folderId:c||null}}):await i.success({id:"FILES_DELETE_SUCCESS",message:n("Files deleted"),placement:"bottomRight",data:{successCount:E,totalCount:e,itemIds:A,folderId:c||null}})}if(x>0){const e=C(A),r=I(e),a=A.length,l=1===a&&P.length>0&&(null===(t=P[0].error)||void 0===t?void 0:t.code),d=(null==g?void 0:g.enableTrashFolder)&&!s,c=n(d?"При перемещении в корзину произошли ошибки":"При удалении произошли ошибки"),u=l?Un(null===(o=P[0].error)||void 0===o?void 0:o.code,n):void 0,f=null!=u?u:r?n("Failed",{names:r}):c;i.error({id:"FILES_DELETE_ERROR",message:f,placement:"bottomRight",innerException:P.length?P:void 0,data:{failCount:x,isTrashMove:d,totalCount:a,itemNames:e,errors:P.length?P:void 0}})}l(),null==h||h(!1),await y({parentIds:Array.from(S),selectedFolder:c});let u=F.current;if(E>0&&d>0&&E>=d&&F.current>1&&(u=F.current-1),E>0&&F.total>=E){const e=Math.max(0,(null!==(r=F.total)&&void 0!==r?r:0)-E);null==p||p({current:u,pageSize:F.pageSize,total:e})}await w({fetchFiles:e,selectedFolder:c,page:u,limit:F.pageSize})}catch(e){console.error("Error when deleting:",e),i.error({id:"FILES_DELETE_ERROR",message:n("Error deleting"),placement:"bottomRight",innerException:e,data:{failCount:x,totalCount:_.length}})}},[f,a,h,e,c,u,m,p,s,n,i,v,l,null==g?void 0:g.enableTrashFolder]);return{actions:{showDeleteConfirm:F,handleDeleteConfirmCancel:A,handleDeleteConfirmOk:_}}})(e);return{state:t.state,actions:Object.assign(Object.assign(Object.assign(Object.assign({},t.actions),o.actions),r.actions),n.actions)}},Di=()=>{const{state:e}=mn(),{files:t,loading:o,isUrlModalVisible:r}=e,n=Ai(),i=(()=>{const{state:e}=mn(),t=e.multiSelect,o=Pi(e=>e.selectedFiles),r=Pi(e=>e.toggleFileSelection),n=Pi(e=>e.setMultiSelect);return a(()=>{n(!1!==t)},[t,n]),{state:{selectedFiles:o},actions:{toggleFileSelection:r}}})(),l=ji(n.fetchFiles);return{state:{files:t||[],selectedFiles:i.state.selectedFiles,loading:o||!1,isAddingFileByUrl:r||!1,isRenamingFile:l.state.isRenamingFile,fileToRename:l.state.fileToRename},actions:{fetchFiles:n.fetchFiles,handleDeleteFile:n.handleDeleteFile,handleDeleteFolder:n.handleDeleteFolder,handleAddFile:n.handleAddFile,handleAddFileByUrl:n.handleAddFileByUrl,handleDroppedFiles:n.handleDroppedFiles,uploadFileWithProvider:n.uploadFileWithProvider,toggleFileSelection:i.actions.toggleFileSelection,showRenameModal:l.actions.showRenameModal,handleRenameCancel:l.actions.handleRenameCancel,handleRenameOk:l.actions.handleRenameOk,showMoveModal:l.actions.showMoveModal,handleMoveCancel:l.actions.handleMoveCancel,handleMoveOk:l.actions.handleMoveOk,showCopyModal:l.actions.showCopyModal,handleCopyCancel:l.actions.handleCopyCancel,handleCopyOk:l.actions.handleCopyOk,showDeleteConfirm:l.actions.showDeleteConfirm,handleDeleteConfirmCancel:l.actions.handleDeleteConfirmCancel,handleDeleteConfirmOk:l.actions.handleDeleteConfirmOk}}};function Bi({maxConcurrent:e=6}={}){const t=c(new Map),o=c([]),r=c(0),n=u(()=>{const n=e=>({status:e.status,shouldLoad:"loading"===e.status||"loaded"===e.status||"error"===e.status}),i=e=>{const t=n(e);e.listeners.forEach(e=>e(t))},a=e=>{0!==o.current.length&&(o.current=o.current.filter(t=>t!==e))},l=(e,o)=>{const r=t.current.get(e);if(!r){const r={id:e,src:o,status:"idle",listeners:new Set,active:!1};return t.current.set(e,r),r}return r.src!==o&&(a(e),r.src=o,r.status="idle"),r},s=()=>{for(;r.current<e&&o.current.length>0;){const e=o.current.shift();if(!e)break;const n=t.current.get(e);n&&n.active&&"queued"===n.status&&(n.status="loading",r.current+=1,i(n))}},d=(e,t)=>{"loading"===e.status&&(e.status=t,r.current=Math.max(0,r.current-1),i(e),s())};return{getSnapshot:(e,t)=>n(l(e,t)),subscribe:(e,o,r)=>{const i=l(e,o);return i.listeners.add(r),r(n(i)),()=>{const o=t.current.get(e);o&&(o.listeners.delete(r),o.active||0!==o.listeners.size||"loading"===o.status||t.current.delete(e))}},setActive:(e,t,n)=>{const d=l(e,t);d.active=n,n?"loaded"!==d.status&&"loading"!==d.status&&"queued"!==d.status?(d.status="queued",i(d),o.current.includes(e)||o.current.push(e),s()):i(d):"queued"===d.status?(a(e),d.status="idle",i(d)):"loading"===d.status&&(r.current=Math.max(0,r.current-1),d.status="idle",i(d),s())},markLoaded:e=>{const o=t.current.get(e);o&&d(o,"loaded")},markError:e=>{const o=t.current.get(e);o&&d(o,"error")},release:e=>{const o=t.current.get(e);o&&(o.active=!1,"queued"===o.status?(a(e),o.status="idle"):"loading"===o.status&&(r.current=Math.max(0,r.current-1),o.status="idle",s()),0===o.listeners.size&&t.current.delete(e))}}},[e]);return a(()=>()=>{o.current=[],t.current.clear(),r.current=0},[]),n}function zi(e){var t;if(e&&"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQABLAEsAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAAEsAAAAAQAAASwAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAQOgAwAEAAAAAQAAAMoAAAAA/+EJ2Wh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8APD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1wTU06RG9jdW1lbnRJRD0iYWRvYmU6ZG9jaWQ6c3RvY2s6Mzk2MmU4NTQtNjA1NC00MGZmLWEwYzMtYjJkNjcwMzQ2OWFhIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOmE5M2NiZTgyLWI5NjEtNGUzNS1iYmQ0LWJjZWE1Zjc1YTQwZiIvPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDw/eHBhY2tldCBlbmQ9InciPz4A/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIAMoBAwMBIgACEQADEQD/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/3QAEABH/2gAMAwEAAhEDEQA/APsuiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoqG7uIbWB55nCooyTS208VxCssLh0boRQBLRRRQAUUUUAFFFFAH/9D7LooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAqG7uIrWBppnCoo5Jou7iK1gaaZwqKM5NcRq2oXOsXqxQq2wnEcYPX3NABq2oXOr3qwxK3l5xHGO/ua6nw7pzadZ7ZJGaR+WBPA9hUfh7R49Pi82TDXDDkkfd9hWxQAUUUUAFFFFABRRRQB//9H7LooooAKKKKACiiuOv/EOpQX88KNDsSQqMp6H60AdjRXD/wDCTapn70P/AH7/APr0f8JPqn96H/v3/wDXoA7iiuH/AOEn1T+9D/37/wDr0f8ACT6p/eh/79//AF6AO4orh/8AhJ9U/vQ/9+//AK9H/CT6p/eh/wC/f/16AO4orh/+En1T+9D/AN+//r0f8JPqn96H/v3/APXoA7iiuH/4SfVP70P/AH7/APr0f8JPqn96H/v3/wDXoA7iiuH/AOEn1T+9D/37/wDr0f8ACT6p/eh/79//AF6AO4orh/8AhJ9U/vQ/9+//AK9H/CT6p/eh/wC/f/16AO4orh/+En1T+9D/AN+//r0f8JPqn96H/v3/APXoA7iobq4itYHmncIijJJrE0jUdQlt2v8AUJIYrNVyMJgv9Oaw9X1C51e8WGJWMecRxr39zQAatqNzq94kUasELYjjB6/Wul8P6NHp8Qlkw1ww5P8Ad9hWRmDw9bfwTajIv4Riqw8Tap6wf98f/XoA7elrh/8AhJtU/vQ/9+//AK9avhnWL3UL94bgx7BGWG1cdwPX3oA6OiiigAooooAKKKKAP//S+y6KKKACiiigArgHAbxSVYAg3mCD3+eu/rgT/wAjV/2+f+z0Adt9jtMf8esH/fsUfY7T/n1g/wC/Yqeh2CIWY4AGSaAK7WlmqktbQADkkxr/AIVUe50JJPLZ7EN6YWuX17WJr+dkRylurYVQfve5rKJoA9Ghh0+Zd0MVtIvqqKaf9jtP+fWD/v2K89sry4sphLbyFD3HY/Wu+0e9TULFLhQATww9DQBJ9jtP+fWD/v2KattZM7ILe3LL94bF4p99cx2lpJcS/dRc/X2rjdG1eSLWmuZ2Oy4bEnoPQ/hQB2P2O0/59YP+/Yo+x2n/AD6wf9+xU4IPSloAr/Y7T/n1g/79ij7Haf8APrB/37FWKKAK/wBjtP8An1g/79ij7Haf8+sH/fsVYooAr/Y7T/n1g/79ioruPTrWBppoLdUUckxj/Cp7u4itYGnmcKijJJriNX1C61i9EUKtsziOMHr7mgBNVv7jVrxYII/3YOIYl/ma6bw9o8enxCSTD3DDkn+H2FHh/R49Pi8yTDXDDkkfd9hWxQBC9rbOxZ7eJmPUlATTfsdp/wA+sH/fsVYooAztXtbVdLumW3hBELkEIOPlNc74H/5Csv8A1xP8xXUaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5igDs6KKKACiiigAooooA//0/suiiigAooooAK4E/8AI1f9vn/s9d9XAn/kav8At8/9noA72s/xI7R6HdMpwdmPzODWhUN/ALqymt26SIVoA816UlS3ML207wSrtdCQai+lAC11HgN2xdx4+XKH6Hn/AArl++K6jSv+JN4flvJhiWfBRe/Tj+ZNAEHjLUfOnFjEw2R/NJju3Yfl/Oudp0jtJIzucsxJJ96bQB2/hLUftdkLeRh50OF+q9jW3XnOkXrWF/HcDJUHDjPUV6HDIssSSIQVYAg0APooooAKhu7iK1gaeZwqKM5NF3cQ2sDTTOFRRk5riNW1C51i9WKJW8vOI4x39zQAavqF1rF6IYVbZnEcYPX3NdL4e0ePT4hLIA1w45JH3fYUeHtHj0+LzJcNcMOTj7vsK2KACiiigAooooAqaz/yCbz/AK4v/wCgmuX8D/8AIWl/64n+YrqNZ/5BN5/1xf8A9BNcv4H/AOQtL/1xP8xQB2dFFFABRRRQAUUUUAf/1PsuiiigAooooAK4E/8AI1f9vn/s9d9XAn/kav8At8/9noA72lpKWgDO1bSLXUQDKCsg6OvX/wCvWFJ4Tn3fJdxFc8FkOa66igDC0zw3a2riadzPIOeRhR+FYXinUPtl+Yoz+5h+VcdCe5/p+FdH4n1H7DYFYziaX5U9vU1wn40AFFFFABXW+DNR3xtp8x+ZPmjyeo7j/PrXJVNZzva3UdxG2HjbP/1qAPTKhu7iK2gaaZwqKOSahTULf+zFv3bZEybsmuP1XULnV70QxK3l7sRxr39zQAmrahc6xerFEreXnEcY7+5rpfD2jx6fF5suGuGHJx932FHh7R49PiEkuGuGHJ/u+wrYoAKKKKACiiigAooooAqaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5iuo1n/AJBN5/1xf/0E1y/gf/kLS/8AXE/zFAHZ0UUUAFFFFABRRRQB/9X7LooooAKKKKACuBP/ACNX/b5/7PXfVwJ/5Gr/ALfP/Z6AO9paSloAKazBVZicBRkmnVz3jHUfs9qLOJsSy/ex2XvQBzuu351DUXlDfu1+WMewqhRRQAUUUv40AFbGi6ZG8TahqB8uzTkA9ZP/AK1Gi6ZG8TajqJ2WcfIB/wCWn/1qi1W+uNWu0hhQiIHbFEv86ADU7+fVbpIIU2xZ2xRL/M103h7R00+LzZcPcMOTj7vsKyCYfD9sQNsupSr+EY/z+ddDot8uoWCTj7/Rx6N3oAvUUUUAFZ17rFta6jDZydZPvNnhPTNSaxqEWn2bTv8AM3RF9TXntxLJPK8sp3O5yx9TQB6dmlrA8Kar9qg+yzt+/jHBP8QrfoAKKKKAKms/8gm8/wCuL/8AoJrl/A//ACFpf+uJ/mK6jWf+QTef9cX/APQTXL+B/wDkLS/9cT/MUAdnRRRQAUUUUAFFFFAH/9b7LooooAKKKKACuBP/ACNX/b5/7PXfVwJ/5Gr/ALfP/Z6AO9paSloAjuZo7eB5pThEGSa851G6e9vJLl+rngeg7Ct/xpqOWXT4m6fNLj9B/X8q5mgBKKKO9AADzWzoumRvEdQ1A7LOPkA/8tP/AK1JoulxvE2oagQlnHyAf+Wn/wBaotVv59WukhhjIizthiX+dABql/catdJBDGRHnbDEv86vkweH7bHyy6jKv4Rj/P8An0UmDw/bEfLLqMq/hGP8/n/Ln5JHlkaSRi7scsx70AEkjySNLIxd2OWY961fCuo/Y78RSNiGY7T7Hsax6WgD1EGmyuscbSOwVVBJPoKy/DGofbrABzmaLCvk9fQ1k+MNU3MdPgY4X/WkevpQBla7qLajel84iTiMe3rWdS0lAEtrPJbXMdxC2HQ5HvXoWlXsd/ZpPGevDD0PevOK0/D2pHTr0FiTBJgOP60Ad/RTUYOoZSCCMg06gCprP/IJvP8Ari//AKCa5fwP/wAhaX/rif5iuo1n/kE3n/XF/wD0E1y/gf8A5C0v/XE/zFAHZ0UUUAFFFFABRRRQB//X+y6KKKACiiigArgT/wAjV/2+f+z131cCf+Rq/wC3z/2egDvarapeJY2Mlw/8I+UZ6nsKs1xni7UftN39ljb91Eecd2/z/WgDFnlknmeaRsu5JJqOigdeKAFrX0XS43iOoagQlnHyAf8Alp/9al0XTI3ibUNQISzj5Ab/AJaf/WqHVb+41a6SGGMrEDtiiX+dAC6rfT6tdJBChEWdsMS/zq+TB4ftj92XUZV/CMf5/P8AkhMPh+2x8suoyr+EY/z+f8sCSR5ZGlkYu7HLMe9ABJI8sjSSMXdjlmPemUUUAFLSUUAWtOvp7CZ5YD8zIVOenNVmJZixJJPUmkooAKKKKAClFJRQB1Pg/VOBp87Dj/VEn9K6jPFeYRs0bh0JDqQQR2Nd7oGpJqNkGJxKnEg/rQBY1n/kE3n/AFxf/wBBNcv4H/5C0v8A1xP8xXUaz/yCbz/ri/8A6Ca5fwP/AMhaX/rif5igDs6KKKACiiigAooooA//0PsuiiigAooooAK4E/8AI1f9vn/s9d8a89u5RB4hlnYEiO5LkDvhs0Adtq808Ni7W0TyTEbUCjkE964c6TqhJJspyTySVroB4stsY+xzf99Cj/hK7X/nzl/76FAHPnSdTx/x4z/981d0zRvL33eqr5NtFztbq5/wro7PVo5rF72SB7eBfutIcbvpXLatqFzq94IokYpnEca859zQAmq31xq12sEEZEQOIol/nWxBYzaPZeZBavc30oxlVyIxUVsbLw6i+epuL1wCyp/AP6VY/wCEstv+fSb/AL6FAGBLpmrSyNJJZ3DuxyzFetN/sjU/+fGf/vmug/4Su1/585f++hR/wldr/wA+cv8A30KAOf8A7I1P/nxn/wC+aP7I1P8A58Z/++a6D/hK7X/nzl/76FH/AAldr/z5y/8AfQoA5/8AsjU/+fGf/vmj+yNT/wCfGf8A75roP+Ertf8Anzl/76FH/CV2v/PnL/30KAOf/sjU/wDnxn/75o/sjU/+fGf/AL5roP8AhK7X/nzl/wC+hR/wldr/AM+cv/fQoA5/+yNT/wCfGf8A75o/sjU/+fGf/vmug/4Su1/585f++hR/wldr/wA+cv8A30KAOf8A7I1P/nxn/wC+aP7I1P8A58Z/++a6D/hK7X/nzl/76FH/AAldr/z5y/8AfQoA5/8AsjU/+fGf/vmrmkW+r6ferOllPtzh12n5hWp/wldr/wA+cv8A30KP+Ertf+fOX/voUAa+rNu0a6bBGYGOD1HymuZ8D/8AIWl/64n+YqzfeJre4spoBayqZI2UEkcZGKreB/8AkKyn/pif5igDs6KKKACiiigAooooA//R+y6KKKACiiigArHn8OadPO80nm73YscNjknNbFFAGJ/wjGmf9N/+/lRXGg6NZxG4nMnlpyQ0mQfatq7uIrWBppnCoozk1xGrajdaxeLFCh2E4jjHf3NACapfT6tdpBDGfKU4hjUfrXTeH9HTT4vNkw1yw5JH3fYUeHtHj0+LzZMNcMOSR932FbFAGNL4b0+WRpJXuHdjks0nJNN/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTP+m/8A38o/4RjTP+m//fytuigDE/4RjTPSf/v5VrTNGs9PnM1v5m4qVO5s8ZB/pWjRQAUUUUAFFFFABRRRQB//0vsuiiigAooooAKhu7mK1t2nmYKijkmpq5fxda6jNcReXukgYgBVHQ+9AGVq2oXOsXqxRK2zdiNB39zXS+H9Hj0+ISSYa4Ycn+77Cjw/o8enxebLhrhhySPu+wrYoAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9P7LooooAKKKKACkxS0UAFFFFABRRTW6D6igB1FN7n8KQE+YRQA+iiigAopsnEZI64pR90UALRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAH//2Q=="!==e){if(e.startsWith("data:image/")){const t=e.split(",")[1];return t&&t.length>20?e:void 0}return e.startsWith("blob:")?e:e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")?null!==(t=(e=>{if(e&&"string"==typeof e){if(e.startsWith("data:")||e.startsWith("blob:"))return e;try{if(e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")){const t=new URL(e.startsWith("/")?`https://x${e}`:e),o=e.startsWith("/")?"":`${t.protocol}//${t.host}`,r=t.pathname.split("/").map(e=>{if(!e)return"";try{return encodeURIComponent(decodeURIComponent(e))}catch(t){return encodeURIComponent(e)}}).join("/");return e.startsWith("/")?r+(t.search||"")+(t.hash||""):`${o}${r}${t.search}${t.hash}`}}catch(e){}return e}})(e))&&void 0!==t?t:e:void 0}}function qi(e,t){var o;if(!e)return null;const r=zi(null!==(o=e.src)&&void 0!==o?o:void 0);return e.exhausted?Object.assign(Object.assign({},e),{src:null}):r?Object.assign(Object.assign({},e),{src:r}):Object.assign(Object.assign({},e),{src:null!=t?t:null,changed:!1,reason:"unchanged"})}function Wi(e){var t;const{options:o}=mn(),r=null===(t=o.config)||void 0===t?void 0:t.getProxiedUrl,n=c([]),l=c(!1),s=c(0),f=c(null),[h,m]=i(!1),p=u(()=>{const t=e.map(e=>zi(e)).filter((e,t,o)=>Boolean(e)&&o.indexOf(e)===t);return(o=n.current)===(r=t)||o.length===r.length&&o.every((e,t)=>e===r[t])?n.current:(n.current=t,t);var o,r},[e]),[g,v]=i([]),[y,w]=i(0);a(()=>{let e=!1;if(w(0),l.current=!1,s.current=0,f.current=null,m(!1),0!==p.length)return(async()=>{const t=await Promise.all(p.map(async e=>{if(!r||!(t=e).startsWith("http://")&&!t.startsWith("https://"))return[{originalSrc:e,src:e}];var t;try{const t=await Promise.resolve(r(e)),o=zi(null==t?void 0:t.src);return o?[{originalSrc:e,src:o,stabilityKey:t.stabilityKey,handleChangeSrc:t.handleChangeSrc,handleSuccess:t.handleSuccess,handleError:t.handleError,subscribeToSrcChange:t.subscribeToSrcChange}]:[{originalSrc:e,src:e}]}catch(t){return[{originalSrc:e,src:e}]}}));if(!e){const e=function(e){const t=new Set;return e.filter(e=>!(!e.src||t.has(e.src)||(t.add(e.src),0)))}(t.flat());v(t=>function(e,t){return e===t||e.length===t.length&&e.every((e,o)=>{const r=t[o];return e.originalSrc===r.originalSrc&&e.src===r.src&&e.stabilityKey===r.stabilityKey})}(t,e)?t:e)}})(),()=>{e=!0};v(e=>0===e.length?e:[])},[r,p]);const b=g[y];a(()=>{if(!(null==b?void 0:b.subscribeToSrcChange))return;let e,t=!1;return Promise.resolve(b.subscribeToSrcChange(e=>{if(t||l.current)return;const o=qi(e,b.src);(null==o?void 0:o.changed)&&o.src&&!t&&v(e=>e.map((e,t)=>t===y?Object.assign(Object.assign({},e),{src:o.src}):e))})).then(o=>{t?null==o||o():e=o}),()=>{t=!0,null==e||e()}},[b,y]),a(()=>{var e;if(!(null==b?void 0:b.handleChangeSrc))return;if(l.current)return;const t=`${b.originalSrc}::${null!==(e=b.stabilityKey)&&void 0!==e?e:""}::${y}`;if(f.current===t)return;f.current=t;let o=!1;return Promise.resolve(b.handleChangeSrc()).then(e=>{const t=qi(e,b.src);(null==t?void 0:t.changed)&&t.src&&!o&&v(e=>e.map((e,o)=>o===y?Object.assign(Object.assign({},e),{src:t.src}):e))}),()=>{o=!0}},[b,y]);const C=d(async()=>{var e;if(!(null==b?void 0:b.handleChangeSrc))return{src:null!==(e=null==b?void 0:b.src)&&void 0!==e?e:null,changed:!1,exhausted:!1,reason:"unchanged"};if(l.current)return{src:null,changed:!1,exhausted:!0,reason:"exhausted"};const t=qi(await Promise.resolve(b.handleChangeSrc()),b.src);return(null==t?void 0:t.changed)&&t.src&&t.src!==b.src?(v(e=>e.map((e,o)=>o===y?Object.assign(Object.assign({},e),{src:t.src}):e)),t):null!=t?t:{src:b.src,changed:!1,exhausted:!1,reason:"unchanged"}},[b,y]),I=d(async()=>{var e,t;if(l.current)return{src:null,changed:!1,exhausted:!0,reason:"exhausted"};if(!b)return l.current=!0,m(!0),{src:null,changed:!1,exhausted:!0,reason:"exhausted"};const o=(r=g.length,Math.max(8,6*r));var r;if(s.current>=o)return l.current=!0,m(!0),{src:null,changed:!1,exhausted:!0,reason:"exhausted"};s.current+=1;const n=b.handleError?qi(await Promise.resolve(b.handleError()),b.src):null;return(null==n?void 0:n.exhausted)?(l.current=!0,m(!0),n):(null==n?void 0:n.changed)&&n.src&&n.src!==b.src?(v(e=>e.map((e,t)=>t===y?Object.assign(Object.assign({},e),{src:n.src}):e)),n):y+1>=g.length?(l.current=!0,m(!0),null!=n?n:{src:null,changed:!1,exhausted:!0,reason:"exhausted"}):(w(e=>e+1),{src:null!==(t=null===(e=g[y+1])||void 0===e?void 0:e.src)&&void 0!==t?t:null,changed:!0,exhausted:!1,reason:"candidate-fallback"})},[b,y,g]),F=d(()=>{var e;l.current||b&&(s.current=0,null===(e=b.handleSuccess)||void 0===e||e.call(b))},[b]);return{src:h||null==b?void 0:b.src,hasNextCandidate:y+1<g.length,handleError:I,handleLoad:F,handleChangeSrc:C}}const Vi=/(auto|scroll|overlay)/;function $i(e,t){const o=Math.max(0,null!=t?t:e.clientWidth);return Math.max(1,Math.round(o-function(e){if("undefined"==typeof window)return 0;const t=window.getComputedStyle(e);return(Number.parseFloat(t.paddingLeft||"0")||0)+(Number.parseFloat(t.paddingRight||"0")||0)}(e)))}function Hi(e){if("undefined"==typeof window)return!1;const t=window.getComputedStyle(e);return Vi.test(t.overflowY)||Vi.test(t.overflow)||Vi.test(t.overflowX)}function Gi(e){if("undefined"==typeof window)return e;let t=e;for(;t;){if(Hi(t))return t;t=t.parentElement}return null}function Ki(e){if("undefined"==typeof window)return[e];const t=Gi(e);return t?t===e?[window,e]:[window,t]:[window]}function Qi(e,t,o){Math.max(0,e.clientHeight),Math.max(0,Math.round(e.getBoundingClientRect().height));return Math.max(1,t)}function Ji(e,t){if(e===t){const o=function(e){var t;if("undefined"==typeof window)return Math.max(1,e.clientHeight);const o=e.getBoundingClientRect(),r=window.innerHeight||(null===(t=document.documentElement)||void 0===t?void 0:t.clientHeight)||0,n=Math.max(0,o.top),i=Math.min(r,o.bottom);return Math.max(0,Math.round(i-n))}(t);return{scrollTop:t.scrollTop,viewportHeight:Qi(e,Math.min(t.clientHeight,o||t.clientHeight)),viewportWidth:$i(t),scrollHeight:e.scrollHeight}}const o=t.getBoundingClientRect(),r=e.getBoundingClientRect(),n=Math.max(o.top,r.top),i=Math.min(o.bottom,r.bottom),a=Math.max(o.left,r.left),l=Math.min(o.right,r.right),s=Math.max(0,Math.round(i-n)),d=Math.max(0,Math.round(l-a));return{scrollTop:Math.max(0,Math.round(n-r.top)),viewportHeight:Qi(e,s),viewportWidth:$i(e,d||t.clientWidth||e.clientWidth),scrollHeight:e.scrollHeight}}function Yi(e){if("undefined"==typeof window)return{scrollTop:e.scrollTop,viewportHeight:Math.max(1,e.clientHeight),viewportWidth:$i(e),scrollHeight:e.scrollHeight};const t=Gi(e);return t&&function(e){return e.scrollHeight-e.clientHeight>1}(t)?Ji(e,t):function(e){var t,o;const r=e.getBoundingClientRect(),n=window.innerHeight||(null===(t=document.documentElement)||void 0===t?void 0:t.clientHeight)||0,i=window.innerWidth||(null===(o=document.documentElement)||void 0===o?void 0:o.clientWidth)||r.width,a=Math.max(0,r.top),l=Math.min(n,r.bottom),s=Math.max(0,Math.round(l-a));return{scrollTop:Math.max(0,Math.round(-r.top)),viewportHeight:Qi(e,s),viewportWidth:$i(e,Math.min(Math.round(r.width),i)),scrollHeight:e.scrollHeight}}(e)}function Zi(e,t){const o=c(null),r=d(t=>{e(Yi(t))},[e]);return a(()=>{o.current&&r(o.current)},[r,...t]),a(()=>{if(!o.current||"undefined"==typeof ResizeObserver)return;const e=o.current,t=new ResizeObserver(()=>{r(e)});return t.observe(e),()=>t.disconnect()},[r]),a(()=>{const e=o.current;if(!e)return;const t=()=>{r(e)},n=Ki(e);return n.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{n.forEach(e=>{e.removeEventListener("scroll",t)})}},[r,...t]),o}const Xi=({onSearch:t,placeholder:o,className:r})=>{const{t:n}=dr(),[l,s]=i(""),d=c(null),{options:u}=mn(),{config:f}=u,h=o||n("Search files...");a(()=>(d.current=Sn.debounce(e=>{t(e)},500),()=>{var e;null===(e=d.current)||void 0===e||e.cancel()}),[t]);return e(I,{value:l,onChange:e=>{var t;const o=e.target.value;s(o),null===(t=d.current)||void 0===t||t.call(d,o)},placeholder:h,prefix:e(_e,{size:16,strokeWidth:null==f?void 0:f.iconStrokeWidth}),className:r,allowClear:!0,onClear:()=>{s(""),t("")}})},ea=[{value:"date-desc",labelKey:"Newest first"},{value:"date-asc",labelKey:"Oldest first"},{value:"size-desc",labelKey:"Largest first"},{value:"size-asc",labelKey:"Smallest first"},{value:"name-asc",labelKey:"A-Z"},{value:"name-desc",labelKey:"Z-A"},{value:"type-asc",labelKey:"By type"}];var ta={contentLayout:"contentLayout",headerContainer:"headerContainer",actionsContainer:"actionsContainer",filesContainer:"filesContainer",filesLoadingOverlay:"filesLoadingOverlay",emptyStateWrapper:"emptyStateWrapper",paginationContainer:"paginationContainer",uploadIcon:"uploadIcon",tableContainer:"tableContainer",tableLoadingWrapper:"tableLoadingWrapper",imagePreview:"imagePreview",fileManagerTableFolder:"fileManagerTableFolder",fileManagerTableFolderInner:"fileManagerTableFolderInner",sortSelect:"sortSelect",fileNameCol:"fileNameCol",fileItemCount:"fileItemCount",fileSize:"fileSize",fileDate:"fileDate",tableMenu:"tableMenu",tableImagePreview:"tableImagePreview",tableFolderIcon:"tableFolderIcon",buttonDeselected:"buttonDeselected",buttonSelectAll:"buttonSelectAll",gridRow:"gridRow",gridCard:"gridCard",selectedRow:"selectedRow",gridCardSelected:"gridCardSelected",gridCheckbox:"gridCheckbox",gridCardContent:"gridCardContent",gridPreviewContainer:"gridPreviewContainer",gridPreviewContainerFolder:"gridPreviewContainerFolder",gridFolderIcon:"gridFolderIcon",gridFolderIconImage:"gridFolderIconImage",gridFileName:"gridFileName",gridFileInfo:"gridFileInfo",gridFileMenu:"gridFileMenu",gridFileMenuButton:"gridFileMenuButton",actionsBox:"actionsBox",uploadContainer:"uploadContainer",uploadArea:"uploadArea",blockText:"blockText",textTitle:"textTitle",textDescription:"textDescription",buttons:"buttons",btnAi:"btnAi",btnPhoto:"btnPhoto",dragOverlay:"dragOverlay",dragOverlayInner:"dragOverlayInner",dragCaptureLayer:"dragCaptureLayer",dragOverlayGlobal:"dragOverlayGlobal",noFiles:"noFiles",noFilesIcon:"noFilesIcon",textTitle_trash:"textTitle_trash",textDescription_trash:"textDescription_trash"};const{Text:oa}=F,{Option:ra}=A;const na=n.memo(({files:o,filesById:r,currentSortOption:n,isSmallScreen:i,iconStrokeWidth:a,multiSelectEnabled:l=!0,features:s,viewMode:d,setViewMode:c,handleSearch:f,handleSortOptionChange:h,sortOptions:m,onClearSelection:p,onRename:g,onDelete:v,onCopy:y,onMove:w,onEdit:b,t:C})=>{const I=u(()=>(null==m?void 0:m.length)?ea.filter(e=>m.includes(e.value)):ea,[m]),F=u(()=>I.map(e=>e.value).join("|")||"all",[I]),P=Pi(e=>e.selectedFiles),R=Pi(e=>e.selectedFiles.size),N=Pi(e=>e.selectAllVisible),k=o.length>0&&R===o.length,O=u(()=>Array.from(P)[0],[P]),T=u(()=>O?r.get(O):void 0,[r,O]),L=(null==T?void 0:T.isFolder)?!1!==(null==s?void 0:s.enableRenameFolder):!1!==(null==s?void 0:s.enableRenameFile),M=u(()=>Array.from(P).every(e=>{const t=r.get(e);return!!t&&(t.isFolder?!1!==(null==s?void 0:s.enableMoveFolder):!1!==(null==s?void 0:s.enableMoveItem))}),[s,r,P]),U=u(()=>Array.from(P).every(e=>{const t=r.get(e);return!!t&&(t.isFolder?!1!==(null==s?void 0:s.enableCopyFolder):!1!==(null==s?void 0:s.enableCopyItem))}),[s,r,P]),j=u(()=>1===R&&function(e){var t,o,r;if(!e||e.isFolder)return!1;const n=e.extension||(e.name&&e.name.includes(".")?e.name.split(".").pop():void 0)||((null===(t=e.type)||void 0===t?void 0:t.startsWith("image/"))?null===(r=null===(o=e.type.split("/")[1])||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim():void 0);return Boolean(n&&bt.includes(n.toLowerCase()))}(T),[R,T]);return t("div",R>0?{className:`header-container ${ta.headerContainer}`,children:[t(oa,{type:"secondary",className:"selected-text",children:[t("div",{children:[R," ",C("selected")]}),l&&e(_,{title:i?C("Select all"):null,children:e(S,{className:ta.buttonSelectAll,onClick:N,disabled:k||0===o.length,children:C("Select all")})}),e(_,{title:i?C("Deselected"):null,children:e(S,{className:ta.buttonDeselected,icon:e(Se,{size:16,strokeWidth:a}),onClick:p,children:C("Deselected")})})]}),t(E,{children:[j&&!1!==(null==s?void 0:s.enableEdit)&&e(_,{title:i?C("Edit"):null,children:e(S,{icon:e(Ee,{size:16,strokeWidth:a}),onClick:()=>b(T),disabled:!j,children:C("Edit")})}),M&&e(_,{title:i?C("Move to"):null,children:e(S,{icon:e(xe,{size:16,strokeWidth:a}),onClick:w,children:C("Move to")})}),U&&e(_,{title:i?C("Copy"):null,children:e(S,{icon:e(Pe,{size:16,strokeWidth:a}),onClick:y,children:C("Copy")})}),1===R&&L&&e(_,{title:i?C("Rename"):null,children:e(S,{icon:e(Re,{size:16,strokeWidth:a}),onClick:()=>g(),disabled:1!==R||!L,children:C("Rename")})}),!1!==(null==s?void 0:s.enableDelete)&&e(_,{title:i?C("Delete"):null,children:e(S,{danger:!0,icon:e(Ne,{size:16,strokeWidth:a}),onClick:e=>{e.stopPropagation(),e.preventDefault(),v()},children:C("Delete")})})]})]}:{className:ta.headerContainer,children:[e("div",{className:"search-container",children:e(Xi,{placeholder:C("Search file or folder"),onSearch:f,className:ta.searchInput})}),t("div",{className:ta.actionsBox,children:[e("div",{className:"sort-container",children:e(A,{value:n,onChange:h,className:ta.sortSelect,popupMatchSelectWidth:!1,suffixIcon:e(ke,{size:16,strokeWidth:a}),children:I.map(({value:t,labelKey:o})=>e(ra,{value:t,children:C(o)},t))},F)}),e("div",{className:ta.actionsContainer,children:e(x,{options:[{value:"grid",icon:e(Oe,{size:16,strokeWidth:a})},{value:"table",icon:e(Te,{size:20,strokeWidth:a})}],value:d,onChange:e=>c(e)})})]})]})});na.displayName="FileContentHeader";const ia=n.memo(({fileId:t,style:o})=>{const r=Pi(e=>e.selectedFiles.has(t)),n=Pi(e=>e.toggleFileSelection);return e(P,{checked:r,style:o,onClick:e=>{e.stopPropagation()},onChange:e=>{const o=e.nativeEvent;n(t,{metaKey:o.metaKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey,forceToggle:!0})}})});ia.displayName="FileSelectionCheckbox";const aa=n.memo(t=>{var{className:o}=t,r=Rn(t,["className"]);const n=r["data-row-key"],i=null==n?"":String(n),a=[o,Pi(e=>!!i&&e.selectedFiles.has(i))?ta.selectedRow:""].filter(Boolean).join(" ");return e("tr",Object.assign({},r,{className:a}))});aa.displayName="SelectableTableRow";const la=n.memo(({item:t,variant:o="table",t:r,iconStrokeWidth:n,setCurrentMenuFile:a,showMoveModal:l,showCopyModal:s,showRenameModal:c,showDeleteConfirm:f,onEdit:h})=>{const[m,p]=i(!1),g=u(()=>{if(!m)return[];const o=[];return t.canEdit&&o.push({key:"edit",label:r("Edit"),icon:e(Ee,{size:16,strokeWidth:n})}),t.canMove&&o.push({key:"move",label:r("Move to"),icon:e(xe,{size:16,strokeWidth:n})}),t.canCopy&&o.push({key:"copy",label:r("Copy"),icon:e(Pe,{size:16,strokeWidth:n})}),t.canRename&&o.push({key:"rename",label:r("Rename"),icon:e(Re,{size:16,strokeWidth:n})}),t.canDelete&&o.push({key:"delete",label:r("Delete"),icon:e(Ne,{size:16,strokeWidth:n}),style:{color:"#ff4d4f"}}),o},[n,m,t.canCopy,t.canDelete,t.canEdit,t.canMove,t.canRename,r]),v=d(({key:e})=>{switch(t.id&&(null==a||a(t.id)),e){case"edit":h(t.file);break;case"move":l();break;case"copy":s();break;case"rename":c(t.id);break;case"delete":null==f||f();break;default:null==a||a("")}},[t,h,a,s,f,l,c]),y=u(()=>({items:g,onClick:v}),[v,g]);return e(R,{arrow:!0,placement:"bottom",menu:y,trigger:["hover"],onOpenChange:p,children:"grid"===o?e(S,{type:"default",className:`${ta.gridFileMenuButton} gridFileMenuButton`,onClick:e=>{e.stopPropagation(),e.preventDefault()},children:e(Le,{size:16,strokeWidth:n})}):e("span",{className:`${ta.tableMenu} tableMenuButton`,onClick:e=>{e.stopPropagation(),e.preventDefault()},children:e(Le,{size:16,strokeWidth:n})})})});la.displayName="FileItemActionsDropdown";const sa=({thumbnailSrc:t,previewSrc:o,lightboxSrc:r,alt:i,className:l,width:s,height:f,preview:h=!1})=>{var m,p;const g=u(()=>[t,o],[t,o]),v=u(()=>[r,o,t],[r,o,t]),y=Wi(g),w=Wi(v),{handleError:b,handleLoad:C}=w,I=null!==(m=y.src)&&void 0!==m?m:wt,F=null!==(p=w.src)&&void 0!==p?p:y.src,A=c(!1);a(()=>{A.current=!1},[F]);const _=d(e=>n.cloneElement(e,{key:null!=F?F:wt,src:null!=F?F:wt,fallback:void 0,onError:()=>{A.current||(A.current=!0,b().finally(()=>{A.current=!1}).catch(()=>{}))},onLoad:()=>{C()}}),[F,b,C]),S=u(()=>!(!h||!F)&&{src:F,actionsRender:()=>null,destroyOnHidden:!0,cover:e(de,{style:{fontSize:"20px"}}),imageRender:_},[h,F,_]);return e(N,{className:l,src:I,alt:i,width:s,height:f,preview:S,onLoad:y.handleLoad,onError:()=>{y.handleError().catch(()=>{})},fallback:wt})},da=n.memo(({item:t,variant:o="table",FolderIcon:r,getFileData:n,className:i,width:a,height:l})=>t.isFolder?e("div","grid"===o?{className:ta.gridFolderIcon,children:e(r,{className:ta.gridFolderIconImage})}:{className:ta.fileManagerTableFolder,children:e("div",{className:ta.fileManagerTableFolderInner,children:e(r,{className:ta.tableFolderIcon,style:{width:null!=a?a:40,height:null!=l?l:40}})})}):t.thumbnailSrc||t.previewSrc?e(sa,{className:i,thumbnailSrc:t.thumbnailSrc,previewSrc:t.previewSrc,lightboxSrc:t.lightboxSrc,alt:t.file.name,width:a,height:l,preview:!0,file:t.file,getFileData:n}):null);da.displayName="FileItemPreview";const ca=[".ant-image",".ant-image-preview-root",".ant-image-preview-wrap",".ant-image-preview-mask",".ant-image-preview-close",".ant-image-preview-operations"].join(","),ua=e=>Boolean(e.closest(ca));function fa(e){var t,o,r;if(e.isFolder)return!1;const n="string"==typeof e.name?e.name:"",i=n?null===(t=n.split(".").pop())||void 0===t?void 0:t.toLowerCase():void 0,a=null!==(r=null===(o=e.extension)||void 0===o?void 0:o.toLowerCase())&&void 0!==r?r:i;return"string"==typeof e.type&&e.type.startsWith("image/")||"string"==typeof a&&Ct.includes(a)}const ha=n.memo(({item:o,t:r,iconStrokeWidth:n,FolderIcon:i,handleItemClick:a,setCurrentMenuFile:l,showMoveModal:s,showCopyModal:c,showRenameModal:u,showDeleteConfirm:f,onEdit:h,onEditorOk:m,getFileData:p,showSelectionCheckbox:g=!0})=>{const v=Pi(e=>e.selectedFiles.has(o.id)),y=d(e=>{const t=e.target;t.closest(".gridFileMenuButton")||t.closest(".ant-dropdown-menu")||ua(t)||1===e.detail&&(o.isFolder?a(o.file):m&&fa(o.file)&&m(o.file))},[a,o.file,o.isFolder,m]);return e(k,{className:ta.gridCard_col,style:{padding:0},children:t(O,{hoverable:!0,cover:e("div",{className:o.isFolder?ta.gridPreviewContainerFolder:ta.gridPreviewContainer,onClick:e=>{e.stopPropagation(),y(e)},children:e(da,{item:o,variant:"grid",FolderIcon:i,getFileData:p,className:ta.gridImagePreview})}),className:`${ta.gridCard} ${v?ta.gridCardSelected:""}`,onClick:e=>{e.stopPropagation(),e.preventDefault(),y(e)},children:[t("div",{className:ta.gridCardContent,onClick:e=>{e.stopPropagation(),e.preventDefault(),y(e)},children:[e("div",{className:ta.gridFileName,children:o.nameText||r("Untitled")}),e("div",{className:ta.gridFileInfo,children:o.gridInfoText})]}),e("div",{className:ta.gridFileMenu,onClick:e=>{e.stopPropagation()},children:e(la,{item:o,variant:"grid",t:r,iconStrokeWidth:n,setCurrentMenuFile:l,showMoveModal:s,showCopyModal:c,showRenameModal:u,showDeleteConfirm:f,onEdit:h})}),g?e("div",{onClick:e=>{e.stopPropagation()},className:ta.gridCheckbox,children:e(ia,{fileId:o.id,style:{height:20}})}):null]})})});ha.displayName="FileGridItem";const ma=n.memo(({rows:t,topOffset:r=0,bottomOffset:n=0,t:i,iconStrokeWidth:a,FolderIcon:l,handleItemClick:s,setCurrentMenuFile:d,showMoveModal:c,showCopyModal:u,showRenameModal:f,showDeleteConfirm:h,onEdit:m,onEditorOk:p,getFileData:g,showSelectionCheckbox:v=!0})=>e(o,{children:e("div",{style:{paddingTop:r,paddingBottom:n},children:e(T,{gutter:[16,16],className:ta.gridRow,style:{gap:20,padding:"0 24px 24px",margin:0},children:t.map(t=>e(ha,{item:t,handleItemClick:s,iconStrokeWidth:a,t:i,FolderIcon:l,setCurrentMenuFile:d,showMoveModal:c,showCopyModal:u,showRenameModal:f,showDeleteConfirm:h,onEdit:m,onEditorOk:p,getFileData:g,showSelectionCheckbox:v},t.id))})})}));ma.displayName="FileGridView";const pa=n.memo(({rows:t,columns:r,topOffset:n=0,bottomOffset:i=0,onRow:a,components:l})=>{const s=u(()=>e("div",{style:{paddingTop:n,paddingBottom:i},children:e(w,{renderEmpty:()=>e(M,{image:e(o,{}),description:""}),children:e(L,{dataSource:t,columns:r,rowKey:"id",pagination:!1,tableLayout:"fixed",onRow:a,components:l,showHeader:!1})})}),[i,r,l,a,t,n]);return e("div",{className:ta.tableLoadingWrapper,children:s})});pa.displayName="FileTableView";const ga=n.memo(({item:t})=>t.dateText?e(_,{title:t.dateText,placement:"bottom",className:ta.fileDate,children:t.dateText}):null);ga.displayName="FileItemDate";const va=n.memo(({item:o})=>t("div",{className:ta.fileName,children:[o.nameText,o.isFolder&&e("div",{className:ta.fileItemCount,children:o.folderItemsText})]}));va.displayName="FileItemName";const ya="filemanager_view_mode";class wa{constructor(){this.rowsById=new Map}reconcile(e,t,o){const r=new Map,n=[];for(const i of e){const e=t.getId(i),a=t.buildSignature(i,o),l=this.rowsById.get(e);if(l&&l.signature===a){r.set(e,l),n.push(l);continue}const s=t.buildRowModel(i,o,{id:e,signature:a});r.set(e,s),n.push(s)}return this.rowsById=r,n}}class ba{createRenderWindow(e,t){var o,r,n,i,a,l,s,d,c,u,f,h,m,p,g,v,y,w,b,C,I,F,A,_,S;const E=null!==(o=null==t?void 0:t.renderStrategy)&&void 0!==o?o:"full";if("windowed"!==E){if("positioned"===E){const o=null!==(n=null===(r=null==t?void 0:t.positioned)||void 0===r?void 0:r.layout)&&void 0!==n?n:[],v=null!==(a=null===(i=null==t?void 0:t.positioned)||void 0===i?void 0:i.viewportTop)&&void 0!==a?a:0,y=null!==(s=null===(l=null==t?void 0:t.positioned)||void 0===l?void 0:l.viewportBottom)&&void 0!==s?s:Number.MAX_SAFE_INTEGER,w=Math.max(0,null!==(c=null===(d=null==t?void 0:t.positioned)||void 0===d?void 0:d.overscanPx)&&void 0!==c?c:0),b=Math.max(0,null!==(f=null===(u=null==t?void 0:t.positioned)||void 0===u?void 0:u.containerHeight)&&void 0!==f?f:0),C=o.filter(e=>e.bottom>=v-w&&e.top<=y+w).map(t=>({row:e[t.index],layout:t})).filter(e=>Boolean(e.row)),I=null!==(m=null===(h=C[0])||void 0===h?void 0:h.layout.index)&&void 0!==m?m:-1,F=null!==(g=null===(p=C[C.length-1])||void 0===p?void 0:p.layout.index)&&void 0!==g?g:-1;return{rows:C.map(e=>e.row),startIndex:I,endIndex:F,topOffset:0,bottomOffset:0,totalCount:e.length,containerHeight:b,positionedItems:C}}return{rows:e,startIndex:0,endIndex:e.length>0?e.length-1:-1,topOffset:0,bottomOffset:0,totalCount:e.length}}const x=Math.max(0,null!==(y=null===(v=null==t?void 0:t.windowed)||void 0===v?void 0:v.startIndex)&&void 0!==y?y:0),P=null!==(b=null===(w=null==t?void 0:t.windowed)||void 0===w?void 0:w.endIndex)&&void 0!==b?b:e.length-1,R=Math.max(0,null!==(I=null===(C=null==t?void 0:t.windowed)||void 0===C?void 0:C.overscan)&&void 0!==I?I:0),N=Math.max(1,null!==(A=null===(F=null==t?void 0:t.windowed)||void 0===F?void 0:F.estimatedItemSize)&&void 0!==A?A:1),k=Math.max(1,null!==(S=null===(_=null==t?void 0:t.windowed)||void 0===_?void 0:_.itemsPerLane)&&void 0!==S?S:1),O=Math.ceil(e.length/k),T=Math.min(e.length-1,P),L=Math.floor(x/k),M=Math.floor(Math.max(x,T)/k),U=Math.max(0,L-R),j=Math.min(O-1,M+R),D=U*k,B=Math.min(e.length-1,(j+1)*k-1),z=Math.max(0,O-j-1);return{rows:e.slice(D,B+1),startIndex:D,endIndex:B,topOffset:U*N,bottomOffset:z*N,totalCount:e.length}}}function Ca({items:e,context:t,adapter:o,options:r}){const n=c(null),i=c(null);n.current||(n.current=new wa),i.current||(i.current=new ba);const a=u(()=>n.current.reconcile(e,o,t),[o,t,e]),l=u(()=>i.current.createRenderWindow(a,r),[r,a]);return{rowModels:a,renderWindow:l}}function Ia({totalCount:e,plan:t}){const[o,r]=i(null);return{engineOptions:u(()=>{var r,n;if(!t.enabled)return{renderStrategy:"full"};const i=function(e,t){var o;return Math.max(1,null!==(o=null==e?void 0:e.viewportHeight)&&void 0!==o?o:t)}(o,null!==(r=t.fallbackViewportHeight)&&void 0!==r?r:800),a=Math.max(1,Math.ceil(i/t.estimatedItemSize)),l=Math.max(1,Math.ceil(e/t.itemsPerLane)),s=Math.min(l-1,Math.max(0,Math.floor((null!==(n=null==o?void 0:o.scrollTop)&&void 0!==n?n:0)/t.estimatedItemSize))),d=s+a-1;return{renderStrategy:"windowed",windowed:{startIndex:s*t.itemsPerLane,endIndex:Math.min(e-1,(d+1)*t.itemsPerLane-1),overscan:t.overscan,estimatedItemSize:t.estimatedItemSize,itemsPerLane:t.itemsPerLane}}},[t.enabled,t.estimatedItemSize,t.fallbackViewportHeight,t.itemsPerLane,t.overscan,e,o]),handleViewportChange:d(e=>{r(t=>(null==t?void 0:t.viewportHeight)===e.viewportHeight&&(null==t?void 0:t.viewportWidth)===e.viewportWidth&&(null==t?void 0:t.scrollHeight)===e.scrollHeight&&(null==t?void 0:t.scrollTop)===e.scrollTop?t:e)},[])}}function Fa(e,t){if("number"==typeof e.childCount)return e.childCount;const o=t[e.id];return null===o?null:null!=o?o:0}function Aa(e){var t,o,r;const n=e.extension||(e.name&&e.name.includes(".")?e.name.split(".").pop():void 0)||((null===(t=e.type)||void 0===t?void 0:t.startsWith("image/"))?null===(r=null===(o=e.type.split("/")[1])||void 0===o?void 0:o.split(";")[0])||void 0===r?void 0:r.trim():void 0);return Boolean(n&&bt.includes(n.toLowerCase()))}function _a(e,t){if(!e)return"";const o=new Date(e);if(Number.isNaN(o.getTime()))return"";const r=[t("months.january"),t("months.february"),t("months.march"),t("months.april"),t("months.may"),t("months.june"),t("months.july"),t("months.august"),t("months.september"),t("months.october"),t("months.november"),t("months.december")];return t("Added",{date:`${o.getDate()} ${r[o.getMonth()]} ${o.getFullYear()}`})}const Sa={getId:e=>e.id,buildSignature:(e,t)=>function(e,t){var o,r,n,i,a,l,s,d;const c=Boolean(e.isFolder),u=c?Fa(e,t.folderFileCounts):null,f=c?null===u?"u":String(u):"0",h=_a(e.date,t.t),m=!c&&e.size?String(e.size):"",p=e.thumbnailUrl||e.thumbnail,g=e.url&&Aa(e)?e.url:"",v=t.previewFallbackToFileUrl?g:"",y=[!1!==(null===(o=t.features)||void 0===o?void 0:o.enableEdit),!1!==(null===(r=t.features)||void 0===r?void 0:r.enableMoveFolder),!1!==(null===(n=t.features)||void 0===n?void 0:n.enableMoveItem),!1!==(null===(i=t.features)||void 0===i?void 0:i.enableCopyFolder),!1!==(null===(a=t.features)||void 0===a?void 0:a.enableCopyItem),!1!==(null===(l=t.features)||void 0===l?void 0:l.enableRenameFolder),!1!==(null===(s=t.features)||void 0===s?void 0:s.enableRenameFile),!1!==(null===(d=t.features)||void 0===d?void 0:d.enableDelete)].join("|"),w=[p||"",v,g].join("::");return[e.id,e.name,e.folderId,e.type||"",e.extension||"",w,w,e.dimensions||"",m,h,c?"1":"0",f,y].join("::")}(e,t),buildRowModel:(e,t,o)=>{var r,n,i,a,l,s,d,c;const u=Boolean(e.isFolder),f=u?Fa(e,t.folderFileCounts):null,h=u&&null===f?"—":u?`${f} ${1===f?t.t("item"):t.t("items")}`:"",m=e.dimensions||"",p=!u&&e.size?Or(e.size):"",g=u?t.t("Folder"):function(e){var t,o,r;return e.extension||(null===(t=e.name.split(".").pop())||void 0===t?void 0:t.toLowerCase())||(e.url?null===(r=null===(o=e.url.split("?")[0].split("/").pop())||void 0===o?void 0:o.split(".").pop())||void 0===r?void 0:r.toLowerCase():"")||""}(e),v=_a(e.date,t.t),y=u?h:[m,p,g].filter(Boolean).join(" • "),w=e.thumbnailUrl||e.thumbnail,b=e.url&&Aa(e)?e.url:void 0,C=t.previewFallbackToFileUrl?b:void 0;return{id:o.id,signature:o.signature,item:e,file:e,isFolder:u,nameText:e.name||t.t("No name"),folderItemsText:h,dimensionsText:m,sizeText:p,typeText:g,dateText:v,gridInfoText:y,thumbnailSrc:w,previewSrc:C,lightboxSrc:b,canEdit:!u&&!1!==(null===(r=t.features)||void 0===r?void 0:r.enableEdit)&&Aa(e),canMove:u?!1!==(null===(n=t.features)||void 0===n?void 0:n.enableMoveFolder):!1!==(null===(i=t.features)||void 0===i?void 0:i.enableMoveItem),canCopy:u?!1!==(null===(a=t.features)||void 0===a?void 0:a.enableCopyFolder):!1!==(null===(l=t.features)||void 0===l?void 0:l.enableCopyItem),canRename:u?!1!==(null===(s=t.features)||void 0===s?void 0:s.enableRenameFolder):!1!==(null===(d=t.features)||void 0===d?void 0:d.enableRenameFile),canDelete:!1!==(null===(c=t.features)||void 0===c?void 0:c.enableDelete)}}};const Ea=n.memo(({files:o,searchTerm:r,handleSearch:n,sortBy:l,sortOrder:s,handleSortOptionChange:f,pagination:h,setPagination:m,loading:p,handleItemClick:g,onClearSelection:v,onRename:y,onDelete:w,onCopy:b,onMove:C,showRenameModal:I,showDeleteConfirm:F,showCopyModal:A,showMoveModal:_,onEdit:S,getFileData:E,handleAddFile:x})=>{var P;const{t:R}=dr(),N=On(),{DropZoneFileIcon:k,BigStockIcon:O,BigAIIcon:T,FolderIcon:L}=gn(),{options:M,actions:D,state:B}=mn(),{dataProviders:z,config:q}=M,W=null==q?void 0:q.disablePagination,{setCurrentMenuFile:V,setActiveLibraryItem:$}=D,H="Trash"===(null==B?void 0:B.selectedFolder),G=!1!==(null==B?void 0:B.multiSelect),{viewMode:K,setViewMode:Q}=(()=>{const[e,t]=i(()=>{try{return localStorage.getItem(ya)||"table"}catch(e){return"table"}}),o=d(e=>{t(e);try{localStorage.setItem(ya,e)}catch(e){console.warn("Не удалось сохранить режим отображения:",e)}},[]),r=d(()=>{o("table"===e?"grid":"table")},[e,o]);return{viewMode:e,setViewMode:o,toggleViewMode:r}})(),[J,Y]=i({}),[Z,X]=i(!1),ee=c(0),te=c(null);a(()=>{const e=window.matchMedia("(max-width: 1199px)"),t=e=>{X(e.matches)};t(e);const o=e=>t(e);return"function"==typeof e.addEventListener?(e.addEventListener("change",o),()=>e.removeEventListener("change",o)):(e.addListener(o),()=>e.removeListener(o))},[]);const oe=u(()=>(null==q?void 0:q.features)||{},[null==q?void 0:q.features]),re=null==q?void 0:q.iconStrokeWidth,ne=null==q?void 0:q.sortOptions,ie=u(()=>(null==ne?void 0:ne.length)?new Set(ne):null,[ne]),ae=`${l}-${s}`;a(()=>{var e;if(ie&&!ie.has(ae)){const t=null===(e=ea.find(e=>ie.has(e.value)))||void 0===e?void 0:e.value;t&&f(t)}},[ie,ae,f]);const le=u(()=>new Map(o.map(e=>[e.id,e])),[o]),{renderRows:se,renderWindow:de,hasAnyValidDate:ce,handleViewportChange:ue}=function({files:e,folderFileCounts:t,features:o,t:r,viewMode:n,previewFallbackToFileUrl:a}){const l=u(()=>({folderFileCounts:t,features:o,t:r,previewFallbackToFileUrl:a}),[o,t,r,a]),[s,c]=i(()=>Math.max(1,Math.floor(5))),f=u(()=>{const t=e.length>150;return"table"===n?{enabled:t,estimatedItemSize:56,overscan:10,itemsPerLane:1,fallbackViewportHeight:800}:{enabled:t,estimatedItemSize:320,overscan:2,itemsPerLane:s,fallbackViewportHeight:800}},[e.length,s,n]),{engineOptions:h,handleViewportChange:m}=Ia({totalCount:e.length,plan:f}),{rowModels:p,renderWindow:g}=Ca({items:e,context:l,adapter:Sa,options:h}),v=u(()=>p.some(e=>Boolean(e.dateText)),[p]),y=d(e=>{if("grid"===n){const t=Math.max(1,Math.floor(e.viewportWidth/240));c(e=>e===t?e:t)}m(e)},[m,n]);return{rowModels:p,renderRows:g.rows,renderWindow:g,hasAnyValidDate:v,handleViewportChange:y}}({files:o,folderFileCounts:J,features:oe,t:R,viewMode:K,previewFallbackToFileUrl:null==q?void 0:q.previewFallbackToFileUrl}),fe=d(async e=>{var t,o,r,n;try{if(null==z?void 0:z.getChildrenCount)return await z.getChildrenCount("folders"===e?void 0:e);if(null==z?void 0:z.getFiles){const{files:o,pagination:r}=await z.getFiles({folderId:"folders"===e?void 0:e,itemType:"all",page:W?void 0:1,limit:W?void 0:1});return W?Array.isArray(o)?o.length:0:null!==(t=null==r?void 0:r.total)&&void 0!==t?t:Array.isArray(o)?o.length:0}return 0}catch(t){if("StaleLoad"===(null==t?void 0:t.name))return 0;const i=t;if(404===(null==i?void 0:i.status)||"FileNotFound"===(null==i?void 0:i.code)||"path_folder_not_found"===(null==i?void 0:i.code)||"path_folder_not_found"===(null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.code)||404===(null===(n=null===(r=null==i?void 0:i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status))return 0;console.error(`Error getting the number of files for the folder ${e}:`,t);const a=await fi({folderId:e,dataProviders:z,folders:Array.isArray(B.folders)?B.folders:[],pathHistory:B.pathHistory,t:R});return N.error({id:"FOLDER_CHILDREN_COUNT_FAILED",message:R("Failed to load folder items count in folder",{folderName:a}),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{folderId:"folders"===e?null:e,folderName:a,reason:t instanceof Error?t.message:String(t)}}),null}},[z,W,N,B.folders,B.pathHistory,R]),he=d(async()=>{const e=ee.current+1;ee.current=e;const t=o.filter(e=>e.isFolder);if(0===t.length)return void Y(e=>0===Object.keys(e).length?e:{});const r={},n=t.map(async e=>{"number"!=typeof e.childCount?r[e.id]=await fe(e.id):r[e.id]=e.childCount});await Promise.all(n),ee.current===e&&Y(e=>{const t=Object.keys(e),o=Object.keys(r);return t.length===o.length&&t.every(t=>e[t]===r[t])?e:r})},[o,fe]);a(()=>{he()},[he]),a(()=>{te.current&&ue(Yi(te.current))},[o.length,ue,K]),a(()=>{if(!te.current||"undefined"==typeof ResizeObserver)return;const e=te.current,t=new ResizeObserver(()=>{ue(Yi(e))});return t.observe(e),()=>{t.disconnect()}},[ue]);const me=d(e=>{const t=Yi(e);ue(t)},[ue]);a(()=>{const e=te.current;if(!e)return;const t=()=>{me(e)},o=Ki(e);return o.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{o.forEach(e=>{e.removeEventListener("scroll",t)})}},[o.length,me,K]);const pe=d((e,t)=>e!==t,[]),ge=u(()=>[...G?[{key:"selection",width:46,shouldCellUpdate:pe,render:(t,o)=>e(ia,{fileId:o.id})}]:[],{key:"preview",width:60,shouldCellUpdate:pe,render:(t,o)=>e(da,{item:o,variant:"table",FolderIcon:L,getFileData:E,className:`${ta.imagePreview} ${ta.tableImagePreview}`,width:40,height:40})},{title:R("Name"),width:"calc(100% - 430px)",dataIndex:"nameText",key:"name",className:ta.fileNameCol,shouldCellUpdate:pe,render:(t,o)=>e(va,{item:o})},{title:R("Dimensions"),key:"dimensions",width:100,shouldCellUpdate:pe,render:(t,o)=>o.dimensionsText&&e("div",{className:ta.fileSize,children:o.dimensionsText})},{title:R("Size"),key:"size",width:90,shouldCellUpdate:pe,render:(t,o)=>o.sizeText?e("div",{className:ta.fileSize,children:o.sizeText}):null},{title:R("Type"),key:"type",width:90,shouldCellUpdate:pe,render:(t,o)=>e("div",{className:ta.fileSize,children:o.typeText})},...ce?[{title:R("Date"),dataIndex:"dateText",key:"date",width:200,shouldCellUpdate:pe,render:(t,o)=>e(ga,{item:o})}]:[],{width:40,title:"",dataIndex:"",key:"x",onCell:()=>({style:{padding:0}}),shouldCellUpdate:pe,render:(t,o)=>e(la,{item:o,variant:"table",t:R,iconStrokeWidth:re,setCurrentMenuFile:V,showMoveModal:_,showCopyModal:A,showRenameModal:I,showDeleteConfirm:F,onEdit:S})}],[L,E,ce,re,G,S,V,pe,A,F,_,I,R]),ve=u(()=>({body:{row:aa}}),[]),ye=d(e=>({onClick:t=>{if(t.stopPropagation(),t.preventDefault(),1!==t.detail)return;const o=t.target,r=Boolean(o.closest(".ant-checkbox-wrapper")),n=Boolean(o.closest(".tableMenuButton")),i=Boolean(o.closest(".ant-dropdown-menu"));r||ua(o)||n||i||(e.isFolder?g(e.file):M.onEditorOk&&fa(e.file)&&M.onEditorOk(e.file))}}),[g,M]);let we="table"===K?e(pa,{rows:se,columns:ge,topOffset:de.topOffset,bottomOffset:de.bottomOffset,onRow:ye,components:ve}):e(ma,{rows:se,topOffset:de.topOffset,bottomOffset:de.bottomOffset,t:R,iconStrokeWidth:re,FolderIcon:L,handleItemClick:g,setCurrentMenuFile:V,showMoveModal:_,showCopyModal:A,showRenameModal:I,showDeleteConfirm:F,onEdit:S,onEditorOk:M.onEditorOk,getFileData:E,showSelectionCheckbox:G});r&&!o.length&&(we=e(Cn,{}));const be=null===(P=null==q?void 0:q.availableImageExtensions)||void 0===P?void 0:P.map(e=>"."+e).join(", "),Ce=t("div",H?{className:`${ta.noFiles} ant-layout-sider-light`,children:[e(Me,{size:48,className:ta.noFilesIcon}),e("div",{className:`${ta.textTitle_trash} ant-menu-submenu-title`,children:R("Trash is empty")}),e("div",{className:`${ta.textDescription_trash} ant-menu-submenu-title`,children:R("Deleted files will be displayed here")})]}:{className:ta.uploadContainer,children:[t("div",{className:`${ta.uploadArea} `,onClick:x,children:[e("div",{className:ta.uploadIcon,children:e(k,{})}),e("div",{className:ta.textTitle,children:R("Click here to select a file")}),e("div",{className:ta.textDescription,children:R("Supported files:")+" "+(be||"jpeg, .svg, .png")})]}),t("div",{className:ta.buttons,children:[t("button",{className:ta.btnPhoto,onClick:()=>{$&&$(st)},children:[e("div",{className:ta.icon,children:e(O,{})}),t("div",{className:ta.blockText,children:[e("div",{className:ta.textTitle,children:R("Stock")}),e("div",{className:ta.textDescription,children:R("Select an image from our library")})]})]}),t("button",{className:ta.btnAi,onClick:()=>{$&&$(ct)},children:[e("div",{className:ta.icon,children:e(T,{})}),t("div",{className:ta.blockText,children:[e("div",{className:ta.textTitle,children:R("AI generation")}),e("div",{className:ta.textDescription,children:R("Creating an image on demand")})]})]})]})]});return e("div",{className:`content-layout ${ta.contentLayout}`,children:p||0!==(null==o?void 0:o.length)||r?t("div",{className:ta.tableContainer,children:[e(na,{files:o,filesById:le,currentSortOption:ae,isSmallScreen:Z,iconStrokeWidth:re,multiSelectEnabled:G,features:oe,viewMode:K,setViewMode:Q,handleSearch:n,handleSortOptionChange:f,sortOptions:ne,onClearSelection:v,onRename:y,onDelete:w,onCopy:b,onMove:C,onEdit:S,t:R}),t("div",{ref:te,className:ta.filesContainer,children:[we,p?e("div",{className:ta.filesLoadingOverlay,"aria-busy":"true","aria-live":"polite",children:e(U,{size:"large"})}):null]}),!W&&h.total>h.pageSize&&e("div",{className:ta.paginationContainer,children:e(j,{current:h.current,pageSize:h.pageSize,total:h.total,onChange:(e,t)=>m({current:e,pageSize:t,total:h.total}),showSizeChanger:!0,showTotal:e=>R("total pages",{total:e})})})]}):e("div",{className:ta.emptyStateWrapper,children:Ce})})});Ea.displayName="FileContent";var xa="folderTree",Pa="emptyFolderContainer",Ra="folderItemContainer",Na="folderLabel",ka="folderLabelItem",Oa="fileCount",Ta="foldersTitle",La="foldersTitleItem",Ma="folderMenu";const Ua=({selectedFolder:o,onSelect:r,onExpand:n,generateMenuItems:l,fetchChildFolders:s,disabledFolders:c=[],showFileCounts:f=!1,folderFileCounts:h={},className:m="",expandedKeys:p,setExpandedKeys:g,showTrashFolder:v=!1,mode:y="navigation",defaultExpandAll:w=!1})=>{const{t:b}=dr(),{options:C}=mn(),{config:I}=C,{ExpandArrowIcon:F,CollapseArrowIcon:A,CollapseFolderIcon:_,ExpandFolderIcon:S,EmptyFolderIcon:E}=gn(),x=d(e=>{const t=[],o=e=>{e.forEach(e=>{t.push(e.key),e.children&&o(e.children)})};return o(e),t},[]),[P,R]=i(()=>{if(w||"selection"===y&&w){const e=l();return x(e)}return[]}),N=void 0!==p?p:P,k=void 0!==g?g:R;a(()=>{if(w||"selection"===y&&w){const e=l(),t=x(e);void 0===p&&R(t)}},[w,y,l,x,p]);const O=d(async e=>{const t=e[0];t&&"empty"!==t&&!t.endsWith("_input")&&(null==r||r(e),await(null==s?void 0:s("folders"===t?null:t)))},[r,s]),T=d(async(e,t)=>{var o;k(e),null==n||n(e,t);if(!("lazy"===(null==I?void 0:I.folderTreeLoading)))return;const r=(null===(o=null==t?void 0:t.node)||void 0===o?void 0:o.key)||void 0;if(r&&"folders"!==r)try{await(null==s?void 0:s(r))}catch(e){console.warn("Failed to load child folders for",r,e)}},[null==I?void 0:I.folderTreeLoading,s,n,k]),L=d(()=>{var r,n;const i=l(),a=e=>e.filter(e=>"Trash"!==e.key).map(e=>Object.assign(Object.assign({},e),{children:e.children?a(e.children):void 0})),s=v?a(i):i,d=e=>{"selection"!==y?(N.includes(e)&&o===e?k(N.filter(t=>t!==e)):N.includes(e)||k([...N,e]),O([e])):O([e])},u=0===s.length||1===s.length&&(!s[0].children||0===s[0].children.length),m=o=>{var r;const n=f?h[o.key]:void 0,i=f&&null===n?null:f&&null!=n?n:0,a=N.includes(o.key),l=c.includes(o.key),s=(()=>{var t;return(null===(t=o.children)||void 0===t?void 0:t.length)?e(a?_:S,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}):e(E,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth})})(),u=t("div",{className:`${Ra} folder-item-container`,onClick:()=>!l&&d(o.key),style:{opacity:l?.5:1,cursor:l?"not-allowed":"pointer"},children:[t("div",{className:Na,children:[void 0!==o.icon?o.icon:s,e("span",{className:ka,children:o.label})]}),f&&e("div",{className:Oa,title:null===i?void 0:`${i} ${b(1===i?"item":"items")}`,children:null===i?"—":i})]});return{key:o.key,title:u,children:null===(r=o.children)||void 0===r?void 0:r.map(m),disabled:l}},p=N.includes("folders"),g=e("div",{className:Ta,onClick:()=>d("folders"),children:t("div",{className:La,children:[e(p?_:S,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}),e("span",{className:`${ka} folder-label-item`,children:"folders"===(null===(r=s[0])||void 0===r?void 0:r.key)?s[0].label:b("Folders")})]})}),w=()=>({key:"Trash",title:e("div",{className:Ta,onClick:()=>d("Trash"),children:t("div",{className:La,children:[e(Ne,{size:20,strokeWidth:null==I?void 0:I.iconStrokeWidth}),e("span",{className:ka,children:b("Trash")})]})}),children:void 0});if(u){if(!v)return[{key:"empty",title:e("div",{className:Pa,children:b("No folders yet")}),disabled:!0}];const t=[];return s.length>0&&"folders"===s[0].key&&t.push({key:"folders",title:g,children:[]}),t.push(w()),t}if(s.length>0&&"folders"===s[0].key){const e=[{key:"folders",title:g,children:null===(n=s[0].children)||void 0===n?void 0:n.map(m)}];return v&&e.push(w()),e}return s.map(m)},[l,N,_,null==I?void 0:I.iconStrokeWidth,S,b,o,O,f,h,E,c,v,y,k]),M=u(()=>L(),[L]);return e(D,{className:`${xa} ${Ma} ${m}`,selectedKeys:o?[o]:[],expandedKeys:N,onSelect:O,onExpand:T,treeData:M,switcherIcon:({expanded:t})=>e(t?A:F,{}),showLine:!1,focusable:"selection"!==y})},ja=({style:t={},wrap:o=!1})=>{const r=Object.assign({width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},t);return e(E,{size:"large",style:r,wrap:o,children:e(U,{})})};var Da={formFooter:"formFooter",folderButton:"folderButton",foldersWrapper:"foldersWrapper",formItem:"formItem",folderToolsField:"folderToolsField",inputButtonOk:"inputButtonOk",permanentDeleteWarning:"permanentDeleteWarning",clearTrashProgress:"clearTrashProgress",progressText:"progressText",closeIcon:"closeIcon",modalContentWithLoader:"modalContentWithLoader",modalLoaderOverlay:"modalLoaderOverlay"};const Ba=({folderId:r,activeFormField:n,EmptyFolderIcon:i,targetForm:a,handleModalOk:l,onComplete:s,setIsLoading:d,t:c})=>e(b.Item,{className:"form-item form-item-moveto "+(n===r?"form-item_active":""),name:"folderName",rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(c("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{className:"form-input",autoFocus:!0,onFocus:e=>e.stopPropagation(),prefix:e(i,{style:{marginRight:6}}),suffix:t(o,{children:[e(_,{placement:"top",title:"Clean",children:e(S,{icon:e(ce,{style:{fontSize:10}}),className:Da.inputButtonClose,type:"text",onClick:()=>{a.setFieldsValue({folderName:""})}})}),e(S,{className:Da.inputButtonOk,type:"text",onClick:()=>{d(!0),l(a).then(e=>{const t=null==e?void 0:e.id;s(t)}).finally(()=>d(!1))},children:c("Create")})]})})});function za({folders:r,selectedFolder:i,EmptyFolderIcon:a,handleCreateFolderModalOk:l,setIsLoading:s,t:d}){const[c,u]=n.useState(""),f=n.useCallback((t,o)=>r=>e(Ba,{folderId:r,activeFormField:c,EmptyFolderIcon:a,targetForm:t,handleModalOk:l,onComplete:o,setIsLoading:s,t:d},r),[a,c,l,s,d]),h=n.useCallback(e=>{const{folderId:t,targetForm:o,onTreeSelect:r,onComplete:n}=e;return{handleAddFolder:e=>{e.preventDefault(),e.stopPropagation(),u(t),o.setFieldsValue({folderName:d("New folder"),targetFolder:t})},handleSelectFolder:e=>{e.preventDefault(),e.stopPropagation(),r([t]).then(()=>n(t))}}},[d]),m=n.useCallback(n=>{const{targetForm:a,onTreeSelect:l,onComplete:s,actionButtonText:u}=n,m=f(a,s),p=Array.isArray(r)?r:[],g=(r=null,n=new Set)=>p.filter(e=>{const t=null===r&&!e.parentId,o=e.parentId===r;return t||o}).map(r=>{if(n.has(r.id))return{key:r.id,label:`${r.name} (циклическая ссылка)`};const d=new Set(n);d.add(r.id);const f=g(r.id,d),{handleAddFolder:p,handleSelectFolder:v}=h({folderId:r.id,targetForm:a,onTreeSelect:l,onComplete:s}),y=c===r.id?[{key:`${r.id}_input`,label:m(r.id),icon:null},...f]:f;return{key:r.id,label:t(o,{children:[r.name,i!==r.id&&t("div",{className:`${Da.folderToolsField} folder-tools-field`,children:[e(S,{onClick:p,children:"+"}),e(S,{onClick:v,children:u})]})]}),children:y}}),v=g(),{handleAddFolder:y,handleSelectFolder:w}=h({folderId:"folders",targetForm:a,onTreeSelect:l,onComplete:s}),b="folders"===c?[{key:"folders_input",label:m("folders"),icon:null},...v]:v;return[{key:"folders",label:t(o,{children:[d("Folders"),"folders"!==i&&null!==i&&t("div",{className:`${Da.folderToolsField} folder-tools-field`,children:[e(S,{onClick:y,children:"+"}),e(S,{onClick:w,children:u})]})]}),children:b}]},[c,f,h,r,i,d]);return{activeFormField:c,setActiveFormField:u,generateMenuItemsFromFolders:m}}const qa=h(({folderId:t,activeFormField:o,EmptyFolderIcon:r,targetForm:n,handleModalOk:i,onComplete:a,t:l,setIsLoading:s,defaultFolderName:c})=>{const u=d(()=>{s(!0),i(n).then(e=>a(null==e?void 0:e.id)).finally(()=>s(!1))},[i,n,a,s]);return e(b.Item,{className:"form-item form-item-moveto "+(o===t?"form-item_active":""),name:"folderName",initialValue:c,rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(l("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{className:"form-input",autoFocus:!0,prefix:e(r,{style:{marginRight:6}}),suffix:e(S,{className:Da.inputButtonOk,type:"text",onClick:()=>{s(!0),u()},children:l("Create")})})})});qa.displayName="CustomFolderInput";const Wa=({isModalVisible:r,handleModalOk:n,handleModalCancel:l,form:s,selectedFolder:c,folders:f,isUrlModalVisible:h,setIsUrlModalVisible:m,handleAddFileByUrl:p,urlForm:g,isRenameModalVisible:v,handleRenameOk:y,handleRenameCancel:w,renameForm:C,fileToRename:F,files:A,isMoveModalVisible:_,handleMoveOk:E,handleMoveCancel:x,moveForm:P,selectedFiles:R,isRenameFolderModalVisible:N,handleRenameFolderOk:k,handleRenameFolderCancel:O,renameFolderForm:T,folderToRename:L,isCopyModalVisible:M,handleCopyOk:U,handleCopyCancel:j,copyForm:D,isDeleteConfirmVisible:q,handleDeleteConfirmOk:W,handleDeleteConfirmCancel:V,isClearTrashConfirmVisible:$,handleClearTrashConfirm:H,handleClearTrashCancel:G,fetchChildFolders:K})=>{var Q,J,Y;const{t:Z}=dr(),{state:X,actions:ee,options:te}=mn(),{setCurrentMenuFile:oe}=ee,{config:re,getModalContainer:ne}=te,{currentMenuFile:ie}=X,ae=b.useWatch("folderName",s),{EmptyFolderIcon:le}=gn(),[se,de]=i(!1),ue=u(()=>{var e;return(null===(e=null==re?void 0:re.defaultFolderName)||void 0===e?void 0:e.trim())||Z("New folder")},[null==re?void 0:re.defaultFolderName,Z]),fe=!ae||0===String(ae).trim().length,he=u(()=>Array.isArray(A)?A:[],[A]),me=F?null===(Q=he.find(e=>e.id===F))||void 0===Q?void 0:Q.name:"",pe=Array.isArray(f)?f:[],ge=L?null===(J=pe.find(e=>e.id===L))||void 0===J?void 0:J.name:"",{activeFormField:ve,setActiveFormField:ye,generateMenuItemsFromFolders:we}=za({folders:pe,selectedFolder:c,EmptyFolderIcon:le,handleCreateFolderModalOk:n,setIsLoading:e=>de(Boolean(e)),t:Z});a(()=>{if(q){const e=setTimeout(()=>{const e=document.querySelector(".deleteModal");if(e){const t=e.querySelector(".ant-modal-footer");if(t){const e=t.querySelector(".ant-btn-primary");e&&e.focus()}}},100);return()=>clearTimeout(e)}},[q]);const be=F?he.find(e=>e.id===F):null,Ce=(null==be?void 0:be.isFolder)||(null==F?void 0:F.startsWith("folder_")),Ie=d(async e=>{e.length>0&&(P.setFieldsValue({targetFolder:e[0]}),ve!==e[0].toString()&&ye(""))},[P,ve,ye]),Fe=d(async e=>{e.length>0&&(D.setFieldsValue({targetFolder:e[0]}),ve!==e[0].toString()&&ye(""))},[ve,D,ye]),_e=d(async e=>{de(!0);try{await E(e)}finally{de(!1)}},[E]),Se=d(async e=>{de(!0);try{await U(e)}finally{de(!1)}},[U]),Ee=u(()=>{const e=Array.from(R).filter(e=>{const t=he.find(t=>t.id===e);return(null==t?void 0:t.isFolder)||f.some(t=>t.id===e)});return c&&"folders"!==c?e.push(c):c&&"folders"!==c||e.push("folders"),e},[R,he,f,c]);return t(o,{children:[e(B,{title:e("div",{className:"modal-title",children:Z("Creating a new folder")}),open:r,onOk:()=>n(),onCancel:l,okText:Z("Create"),cancelText:Z("Cancel"),okButtonProps:{disabled:fe,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>de(!1),centered:!0,getContainer:ne,children:t(b,{form:s,layout:"vertical",children:[e(b.Item,{name:"folderName",label:e("div",{className:"form-label",children:Z("Folder name")}),rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],initialValue:ue,className:"form-item",style:{marginBottom:5},children:e(I,{autoFocus:!0,className:"form-input",disabled:se,placeholder:Z("Enter the name"),onPressEnter:async()=>{de(!0);try{await s.validateFields(),fe||await n()}catch(e){de(!1)}}})}),e("div",{children:c&&"folders"!==c?t("p",{className:"fm-note",children:[Z("A folder will be created inside:")," ",(null===(Y=pe.find(e=>e.id===c))||void 0===Y?void 0:Y.name)||Z("selected folder"),"."]}):e("p",{className:"fm-note",children:Z("The folder will be created in the root directory.")})})]})}),e(B,{title:e("div",{className:"modal-title",children:Z("Upload file by URL")}),open:h,onOk:async()=>{var e;de(!0);try{const t=await g.validateFields(),o=String(null!==(e=t.fileUrl)&&void 0!==e?e:"").trim();await p(o,void 0,void 0,"uploadByUrl")}catch(e){}finally{de(!1)}},onCancel:()=>m(!1),okText:Z("Download"),okButtonProps:{loading:se},cancelText:Z("Cancel"),cancelButtonProps:{disabled:se},afterClose:()=>de(!1),centered:!0,getContainer:ne,children:e(b,{form:g,layout:"vertical",children:e(b.Item,{name:"fileUrl",label:e("div",{className:"form-label",children:Z("File URL")}),rules:[{required:!0,message:Z("Enter the URL of the image")},{validator:(e,t)=>{if(!t||!String(t).trim())return Promise.resolve();try{return Xn(String(t),Z),Promise.resolve()}catch(e){return Promise.reject(new Error(e instanceof Error?e.message:Z("The specified URL is not valid.")))}}}],validateTrigger:"onBlur",className:"form-item",children:e(I,{className:"form-input",placeholder:"https://example.com/image.jpg",autoFocus:!0,disabled:se,onPressEnter:async()=>{var e;de(!0);try{const t=await g.validateFields(),o=String(null!==(e=t.fileUrl)&&void 0!==e?e:"").trim();await p(o,void 0,void 0,"uploadByUrl")}catch(e){}finally{de(!1)}}})})})}),e(B,{title:e("div",{className:"modal-title",children:Ce?`${Z("Rename folder")} ${me}`:Z("Rename file",{currentFileName:me})}),open:v,onOk:y,okText:Z("Rename"),okButtonProps:{loading:se},onCancel:w,cancelText:Z("Cancel"),cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},centered:!0,getContainer:ne,children:e(b,{form:C,layout:"vertical",children:e(b.Item,{name:"newFileName",label:e("div",{className:"form-label",children:Z(Ce?"New folder name":"New file name")}),rules:[{required:!0,message:Z(Ce?"Enter a new folder name":"Enter a new file name")}],className:"form-item",children:e(I,{autoFocus:!0,className:"form-input",disabled:se,onPressEnter:async()=>{de(!0);try{await C.validateFields(),y()}catch(e){de(!1)}}})})})}),e(B,{title:e("div",{className:"modal-title",children:Z("Move to")}),open:_,onCancel:x,footer:t("div",{className:Da.formFooter,children:[t(S,{className:Da.folderButton,onClick:()=>{const e=null!=c?c:"folders";ye(e),P.setFieldsValue({folderName:ue,targetFolder:e})},loading:se,children:[e(Ae,{size:18,strokeWidth:null==re?void 0:re.iconStrokeWidth}),Z("Create folder")]}),e(S,{type:"primary",className:Da.folderButton,onClick:x,loading:se,children:Z("Done")})]}),afterClose:()=>{oe&&oe(""),ye(""),de(!1)},loading:se,centered:!0,getContainer:ne,children:t("div",{className:Da.modalContentWithLoader,children:[se&&e("div",{className:Da.modalLoaderOverlay,children:e(ja,{})}),e(b,{form:P,layout:"vertical",initialValues:{targetFolder:"folders",folderName:ue,is_force_create:!1},children:t("div",{className:Da.foldersWrapper,children:[e(b.Item,{name:"targetFolder",rules:[{required:!0,message:Z("Select the destination folder")}],className:Da.formItem,children:e(Ua,{onSelect:Ie,generateMenuItems:()=>we({targetForm:P,onTreeSelect:Ie,onComplete:_e,actionButtonText:Z("Move here")}),fetchChildFolders:K,disabledFolders:Ee,mode:"selection",className:"folderSelectionTree",defaultExpandAll:!0})}),e(b.Item,{name:"folderName",style:{display:"none"},rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{})}),e(b.Item,{name:"is_force_create",style:{display:"none"},children:e(I,{})})]})})]})}),e(B,{title:e("div",{className:"modal-title",children:Z("Copy to folder")}),open:M,onCancel:j,footer:t("div",{className:Da.formFooter,children:[t(S,{className:Da.folderButton,onClick:()=>{const e=null!=c?c:"folders";ye(e),D.setFieldsValue({folderName:ue,targetFolder:e})},loading:se,children:[e(Ae,{size:18,strokeWidth:null==re?void 0:re.iconStrokeWidth}),Z("Create folder")]}),e(S,{type:"primary",className:Da.folderButton,onClick:j,loading:se,children:Z("Done")})]}),afterClose:()=>{oe&&oe(""),ye(""),de(!1)},loading:se,centered:!0,getContainer:ne,children:t("div",{className:Da.modalContentWithLoader,children:[se&&e("div",{className:Da.modalLoaderOverlay,children:e(ja,{})}),e(b,{form:D,layout:"vertical",initialValues:{targetFolder:"folders",folderName:ue,is_force_create:!1},children:t("div",{className:Da.foldersWrapper,children:[e(b.Item,{name:"targetFolder",rules:[{required:!0,message:Z("Select the destination folder")}],className:Da.formItem,children:e(Ua,{onSelect:Fe,generateMenuItems:()=>we({targetForm:D,onTreeSelect:Fe,onComplete:Se,actionButtonText:Z("Copy here")}),fetchChildFolders:K,disabledFolders:Ee,mode:"selection",className:"folderSelectionTree",defaultExpandAll:!0})}),e(b.Item,{name:"folderName",style:{display:"none"},rules:[{required:!0,validator:(e,t)=>"string"==typeof t&&0===t.trim().length?Promise.reject(new Error(Z("Enter the name of the folder"))):Promise.resolve()}],children:e(I,{})}),e(b.Item,{name:"is_force_create",style:{display:"none"},children:e(I,{})})]})})]})}),e(B,{title:t("div",{className:"modal-title",children:[Z("Rename folder")," ",ge]}),open:N,onOk:k,onCancel:O,okText:Z("Rename"),cancelText:Z("Cancel"),okButtonProps:{loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},centered:!0,getContainer:ne,children:e(b,{form:T,layout:"vertical",children:e(b.Item,{name:"newFolderName",label:e("div",{className:"form-label",children:Z("New folder name")}),rules:[{required:!0,message:Z("Enter a new folder name")}],className:"form-item",children:e(I,{autoFocus:!0,className:"form-input",disabled:se,onPressEnter:async()=>{de(!0);try{await T.validateFields(),k()}catch(e){de(!1)}}})})})}),e(B,{className:`${Da.deleteModal} deleteModal`,title:(()=>{const t=!!(null==re?void 0:re.enableTrashFolder)&&"Trash"===c||!(null==re?void 0:re.enableTrashFolder),o=Z(t?"Permanently delete":"Move to Trash");return e("div",{className:"modal-title",children:o})})(),open:!!q,onOk:()=>{de(!0);try{W&&W()}catch(e){console.error(e),de(!1)}},onCancel:()=>V&&V(),okText:(null==re?void 0:re.enableTrashFolder)&&"Trash"===c?Z("Delete permanently"):(null==re?void 0:re.enableTrashFolder)?Z("Move to Trash"):Z("Delete"),cancelText:Z("Cancel"),okButtonProps:{danger:!(null==re?void 0:re.enableTrashFolder)||"Trash"===c,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1),oe&&oe("")},closeIcon:e(ce,{className:Da.closeIcon}),centered:!0,getContainer:ne,children:(()=>{var o,r;const n=(ie?[ie]:Array.from(R||[])).map(e=>he.find(t=>t.id===e)).filter(e=>!!e),i=n.filter(e=>e.isFolder||e.id.startsWith("folder_")),a=n.filter(e=>!(e.isFolder||e.id.startsWith("folder_"))),l=n.length,s=i.length,d=a.length,u=!!(null==re?void 0:re.enableTrashFolder);if(!u||u&&"Trash"===c){let r;if(1===l&&1===s){const e=i[0],t=(null==e?void 0:e.name)||"",n=null!==(o=null==e?void 0:e.childCount)&&void 0!==o?o:0;r=Z("delete_folder_permanent",{name:t,count:n})}else r=0===s&&d>0?Z("delete_files_permanent",{count:d}):Z("delete_mixed_permanent",{total:l,folders:s,images:d});return t("div",{children:[e("div",{children:r}),e("p",{className:Da.permanentDeleteWarning,children:Z("permanent_delete_warning")})]})}if(1===l&&1===s){const t=i[0],o=(null==t?void 0:t.name)||"",n=null!==(r=null==t?void 0:t.childCount)&&void 0!==r?r:0;return e("div",{children:Z("move_folder_to_trash",{name:o,count:n})})}return e("div",0===s&&d>0?{children:Z("move_files_to_trash",{count:d})}:{children:Z("move_mixed_to_trash",{total:l,folders:s,images:d})})})()}),t(B,{className:`${Da.deleteModal} deleteModal`,title:e("div",{className:"modal-title",children:Z("Clear Trash")}),open:!!$,onOk:async()=>{de(!0),H&&await H(),de(!1)},onCancel:()=>G&&G(),okText:Z("Delete permanently"),cancelText:Z("Cancel"),okButtonProps:{danger:!0,loading:se},cancelButtonProps:{disabled:se},afterClose:()=>{de(!1)},closeIcon:e(ce,{className:Da.closeIcon}),centered:!0,getContainer:ne,children:[e("div",{children:Z("Are you sure you want to permanently delete all items from Trash?")}),se&&t("div",{className:Da.clearTrashProgress,children:[e(z,{percent:99,status:"active",showInfo:!1}),e("div",{className:Da.progressText,children:Z("Deleting items...")})]})]})]})};var Va={button:"button",folderActions:"folderActions",uploadButton:"uploadButton",foldersContainer:"foldersContainer",buttonWrapper:"buttonWrapper",uploadButtonTitle:"uploadButtonTitle"};const $a=h(m(({selectedFolder:o,generateMenuItems:r,onFolderSelect:n,folders:l,fetchChildFolders:s,handleAddFile:f,setIsUrlModalVisible:h,handleCreateFolder:m,activeLibraryItem:g,setActiveLibraryItem:v},y)=>{var w,b,C,I;const F=u(()=>Array.isArray(l)?l:[],[l]),{t:A}=dr(),_=On(),[E,x]=i({}),{options:P,state:R}=mn(),{dataProviders:N,config:k}=P,O=R.pathHistory,T=!1!==(null===(w=null==k?void 0:k.features)||void 0===w?void 0:w.enableGif)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("gif")),L=!1!==(null===(b=null==k?void 0:k.features)||void 0===b?void 0:b.enableStockImages)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("stock")),M=!1!==(null===(C=null==k?void 0:k.features)||void 0===C?void 0:C.enableIconStock)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("icons")),U=!1!==(null===(I=null==k?void 0:k.features)||void 0===I?void 0:I.enableQrBarcodeTab)&&(!(null==k?void 0:k.enabledTabs)||k.enabledTabs.includes("codes")),j=d(e=>{const t=[],o=e=>{e.forEach(e=>{t.push(e.key),e.children&&o(e.children)})};return o(e),t},[]),[D,B]=i(()=>{if(!0===(null==k?void 0:k.expandAllFoldersOnInit)&&"lazy"!==(null==k?void 0:k.folderTreeLoading)){const e=r();return j(e)}return!0===(null==k?void 0:k.expandRootFolderOnInit)?["folders"]:[]}),z=c(!1),V=c(!1);a(()=>{if(z.current)return;"lazy"===(null==k?void 0:k.folderTreeLoading)&&!0===(null==k?void 0:k.expandRootFolderOnInit)&&(z.current=!0,(async()=>{try{await(null==s?void 0:s(null))}catch(e){console.warn("Could not load the root child folders during initialization",e)}})())},[null==k?void 0:k.folderTreeLoading,null==k?void 0:k.expandRootFolderOnInit,s]),a(()=>{!0===(null==k?void 0:k.expandRootFolderOnInit)&&Array.isArray(F)&&F.length>0&&(V.current||D&&0!==D.length||(V.current=!0,B(["folders"])))},[null==k?void 0:k.expandRootFolderOnInit,F,D]),a(()=>{if(!0===(null==k?void 0:k.expandAllFoldersOnInit)&&"lazy"!==(null==k?void 0:k.folderTreeLoading)){const e=r(),t=j(e);return void B(t)}!0===(null==k?void 0:k.expandRootFolderOnInit)&&B(e=>e&&e.length>0?[...e]:["folders"])},[F,r,j,null==k?void 0:k.expandAllFoldersOnInit,null==k?void 0:k.folderTreeLoading,null==k?void 0:k.expandRootFolderOnInit]);const $=null==k?void 0:k.disablePagination,H=d(async e=>{var t,o,r,n;try{if(null==N?void 0:N.getChildrenCount)return await N.getChildrenCount("folders"===e?void 0:e);if(null==N?void 0:N.getFiles){const{files:o,pagination:r}=await N.getFiles({folderId:"folders"===e?void 0:e,itemType:"all",page:$?void 0:1,limit:$?void 0:1});return $?Array.isArray(o)?o.length:0:null!==(t=null==r?void 0:r.total)&&void 0!==t?t:Array.isArray(o)?o.length:0}return 0}catch(t){if("StaleLoad"===(null==t?void 0:t.name))return 0;const i=t;if(404===(null==i?void 0:i.status)||"FileNotFound"===(null==i?void 0:i.code)||"path_folder_not_found"===(null==i?void 0:i.code)||"path_folder_not_found"===(null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.code)||404===(null===(n=null===(r=null==i?void 0:i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status))return 0;console.error(`Error getting the number of files for the folder ${e}:`,t);const a=await fi({folderId:e,dataProviders:N,folders:F,pathHistory:O,t:A});return _.error({id:"FOLDER_CHILDREN_COUNT_FAILED",message:A("Failed to load folder items count in folder",{folderName:a}),placement:"bottomRight",innerException:t,notificationDedupe:!0,data:{folderId:"folders"===e?null:e,folderName:a,reason:t instanceof Error?t.message:String(t)}}),null}},[N,$,_,O,F,A]),G=d(async()=>{if(0===F.length)return;const e={};e.folders=await H("folders");const t=F.map(async t=>{"number"!=typeof t.childCount?e[t.id]=await H(t.id):e[t.id]=t.childCount});await Promise.all(t),x(e)},[F,H]),K=d(async e=>{const t=await H(e);x(o=>Object.assign(Object.assign({},o),{[e]:t}))},[H]);p(y,()=>({refreshFileCounts:G}),[G]),a(()=>{G()},[G]),a(()=>{if(!o||"folders"===o)return;const e=(t,o=new Set)=>{if(o.has(t))return console.warn(`Cycle detected in the path to the folder with id=${t}`),[];const r=F.find(e=>e.id===t);if(!r)return[];if(!r.parentId)return[];const n=new Set(o);n.add(t);return[...e(r.parentId,n),r.parentId]},t=e(o);t.length>0?B(e=>{const o=new Set(e);return t.forEach(e=>o.add(e)),o.add("folders"),Array.from(o)}):B(e=>e.includes("folders")?e:[...e,"folders"])},[o,F]);const Q=d(async()=>{await f(),o?await K(o):await K("folders")},[f,o,K]),J=[{key:at,label:A("My files"),icon:e(Ue,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth})},{key:lt,label:A("GIF"),icon:e(je,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!T},{key:st,label:A("Stock images"),icon:e(De,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!L},{key:dt,label:A("Icons"),icon:e(ue,{size:20}),disabled:!M},{key:ut,label:A("QR & Barcode"),icon:e(Be,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!U},{key:ct,label:A("AI"),icon:e(ze,{size:20,strokeWidth:null==k?void 0:k.iconStrokeWidth}),disabled:!(null==k?void 0:k.sseQuery)}].filter(e=>!e.disabled),Y=d(async e=>{const t=e[0];t&&"empty"!==t&&(g!==at&&v(at),null==n||n(t),await(null==s?void 0:s(t)))},[n,g,v,s]),Z=d(({key:e})=>{v(e)},[v]),X=d(async(e,t)=>{var o;B(e);if(!("lazy"===(null==k?void 0:k.folderTreeLoading)))return;const r=(null===(o=null==t?void 0:t.node)||void 0===o?void 0:o.key)||void 0;if(r&&"folders"!==r)try{await(null==s?void 0:s(r))}catch(e){console.warn("Could not load the child folders for",r,e);const t=await fi({folderId:r,dataProviders:N,folders:F,pathHistory:O,t:A});_.error({id:"FOLDER_CHILDREN_FETCH_FAILED",message:A("Failed to load subfolders in folder",{folderName:t}),placement:"bottomRight",innerException:e,notificationDedupe:!0,data:{folderId:r,folderName:t,reason:e instanceof Error?e.message:String(e)}})}},[null==k?void 0:k.folderTreeLoading,N,s,_,O,F,A]);return t("div",{className:"sidebar-container",children:[t("div",{className:Va.buttonWrapper,children:[e(S,{type:"primary",size:"large",icon:e(qe,{size:24,strokeWidth:null==k?void 0:k.iconStrokeWidth}),onClick:Q,className:Va.uploadButton,style:{whiteSpace:"nowrap"},disabled:"Trash"===o,children:e("span",{className:Va.uploadButtonTitle,children:A("Upload file")})}),e(S,{type:"primary",size:"large",icon:e(We,{size:24,strokeWidth:null==k?void 0:k.iconStrokeWidth}),onClick:()=>null==h?void 0:h(!0),className:Va.uploadByURLButton,style:{whiteSpace:"nowrap"},disabled:"Trash"===o})]}),e(q,{className:"folder-menu",items:J,defaultSelectedKeys:[at],onSelect:({key:e})=>Z({key:e}),selectedKeys:[g]}),e(W,{className:Va.divider}),t("div",{className:Va.foldersContainer,children:[e(Ua,{selectedFolder:o,onSelect:Y,onExpand:X,generateMenuItems:r,fetchChildFolders:s,showFileCounts:!0,folderFileCounts:E,expandedKeys:D,setExpandedKeys:B,showTrashFolder:null==k?void 0:k.enableTrashFolder}),e("div",{className:Va.folderActions,children:e(S,{onClick:e=>{e.stopPropagation(),m()},className:Va.button,icon:e(Ae,{size:18,strokeWidth:null==k?void 0:k.iconStrokeWidth}),size:"middle"})})]})]})}));function Ha(e){if(!this.backgroundColor)return;const t=this._getNonTransformedDimensions(),o=-t.x/2,r=-t.y/2,n=t.x,i=t.y,a=this.backgroundColor;if("string"==typeof a||a instanceof CanvasGradient||a instanceof CanvasPattern)e.fillStyle=a,e.fillRect(o,r,n,i);else if("object"!=typeof a||!("type"in a)||"linear"!==a.type&&"radial"!==a.type){if("source"in a&&(a.source instanceof HTMLImageElement||a.source instanceof HTMLCanvasElement))if(a.repeat){const t=e.createPattern(a.source,a.repeat);t&&(e.fillStyle=t,e.fillRect(o,r,n,i))}else e.drawImage(a.source,o,r,n,i)}else{const t=function(e,t,o,r){var n,i;if("linear"===t.type){const n=e.createLinearGradient(o+t.coords.x1,r+t.coords.y1,o+t.coords.x2,r+t.coords.y2);return t.colorStops.forEach(e=>n.addColorStop(e.offset,e.color)),n}if("radial"===t.type){const a=e.createRadialGradient(o+t.coords.x1,r+t.coords.y1,null!==(n=t.coords.r1)&&void 0!==n?n:0,o+t.coords.x2,r+t.coords.y2,null!==(i=t.coords.r2)&&void 0!==i?i:0);return t.colorStops.forEach(e=>a.addColorStop(e.offset,e.color)),a}throw new Error("Unknown gradient type")}(e,a,o,r);e.fillStyle=t,e.fillRect(o,r,n,i)}this._removeShadow(e)}$a.displayName="FolderSidebar";const Ga="fm-pixie-editor";const Ka=new class{constructor(){this._container=document.createElement("div"),this._instance=null,this._container.classList.add(Ga),this._container.style.width="100%",this._container.style.height="85vh",this._container.style.minHeight="400px"}get className(){return`.${Ga}`}get canvas(){var e,t;return null===(t=null===(e=this._instance)||void 0===e?void 0:e.state.canvasRef)||void 0===t?void 0:t.current}get tools(){var e;return null===(e=this._instance)||void 0===e?void 0:e.tools}isLoaded(){return!!this._instance}async _setConfig(e){var t;this._instance?await this._instance.resetEditor(e):this._instance=await He.init(Object.assign(Object.assign({},e),{selector:this.className})),(t=this._instance).fabric?t.fabric.on("object:added",e=>{const t=e.target;t&&"text"===t.name&&(t._renderBackground=Ha)}):console.warn("Pixie fabric instance is not available")}async show(e,t,o=t.firstChild){t.insertBefore(this._container,o),await this._setConfig(e),this._instance.open()}close(){var e;null===(e=this._container.parentNode)||void 0===e||e.removeChild(this._container)}};function Qa(e,t){if(!e)return t;if(!t)return e;return`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`}function Ja(e){const t="undefined"!=typeof __webpack_public_path__?__webpack_public_path__:"";if(e&&/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(e))return e;let o=Qa(t,e||"");return!o||o.startsWith("/")||/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(o)||(o="/"+o),o}function Ya(e,t){if(/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(t))return t;const o=Qa(Ja(e),t||"");return!o||o.startsWith("/")||/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(o)?o:"/"+o}var Za,Xa;!function(e){e.TOP="top",e.BOTTOM="bottom",e.HIDDEN=""}(Za||(Za={})),function(e){e.TOP="top",e.BOTTOM="bottom",e.HIDDEN=""}(Xa||(Xa={}));const el=(e,t="image/png")=>fetch(`data:${t};base64,${e}`).then(e=>e.blob());function tl(e){return new Promise((t,o)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>{var e;return o(null!==(e=r.error)&&void 0!==e?e:new Error("Failed to convert blob to data URL"))},r.readAsDataURL(e)})}const ol=({visible:o,onClose:r,file:i,onSave:a,onSaveCopy:l})=>{var s;const{t:d}=dr(),c=n.useRef(null),u=On(),f=Ai(),{options:h,actions:m}=mn(),{i18n:p}=dr(),{config:g}=h,{setCurrentMenuFile:v}=m,{getFileData:y,resolveFileForEditByUrl:w}=f,[b,C]=n.useState(!1),[I,F]=n.useState(null),[A,_]=n.useState(""),[E,x]=n.useState(!1),[P,R]=n.useState(!1),[N,k]=n.useState(null),O=n.useRef(!1),T=n.useRef(),L=n.useRef(),M=n.useRef("saveCopy"),U=n.useRef(void 0);T.current=a,L.current=l,n.useEffect(()=>{i&&!O.current&&(async()=>{if(U.current!==i)if("object"!=typeof i){U.current=i,C(!0);try{if(i.startsWith("data:"))k({thumbnail:i,saveWithoutFolder:!0});else{const e=await w(i);U.current===i&&k(e)}}catch(e){console.error("Failed to load file for editor:",e),U.current===i&&(U.current=null),null==r||r()}finally{C(!1)}}else k(i)})()},[i,r,w]);const j=n.useCallback(async e=>{try{if("string"==typeof e.thumbnail&&e.thumbnail.startsWith("data:"))return e.thumbnail;const t=await y(e.id,!0);if(!t)throw new Error(d("Error loading image"));return new Promise(e=>{const o=new FileReader;o.onload=()=>e(o.result),o.readAsDataURL(t)})}catch(e){throw console.error("Error getting the image data:",e),e}},[y,d]);n.useEffect(()=>{if(!I&&o&&N){let e=!1;const t=async()=>{var t,o,n;C(!0);try{const t=await j(N);if(!t||"string"!=typeof t||""===t.trim())throw new Error("Invalid image data: empty or null");if(!t.startsWith("data:"))throw new Error("Invalid image data: not a valid data URL");const o=t.match(/^data:([^;]+);base64,(.+)$/);if(!o)throw new Error("Invalid image data: malformed data URL format");const[,r,n]=o;if(!r.startsWith("image/"))throw new Error(`Invalid image data: unsupported MIME type ${r}`);if(n.length<10)throw new Error("Invalid image data: base64 content too short");if(!/^[A-Za-z0-9+/]+=*$/.test(n))throw new Error("Invalid image data: corrupted base64 content");if(!e){F(t);const e=ei(N,"image/png");_(e.mimeType)}}catch(i){e||(u.error({id:"IMAGE_DOWNLOAD_FAILED",innerException:i,message:d("Error loading image"),placement:"bottomRight",data:{itemId:null!==(t=null==N?void 0:N.id)&&void 0!==t?t:void 0,itemName:null!==(o=null==N?void 0:N.name)&&void 0!==o?o:void 0,folderId:null!==(n=null==N?void 0:N.folderId)&&void 0!==n?n:null,thumbnail:null==N?void 0:N.thumbnail}}),null==r||r())}finally{C(!1)}};return t(),()=>{e=!0}}},[N,j,I,r,d,o]);const D=n.useCallback(async(e,t,o)=>{var r;let n=await function(e,t){if("json"===e)return new Blob([t],{type:"application/json"});if("svg"===e)return new Blob([t],{type:"image/svg+xml"});let o=`image/${e}`;if(t.startsWith("data:")){const e=kt(t);e&&e.startsWith("image/")&&(o=e);const r=t.replace(/data:image\/[^;]+;base64,/,"");return el(r,Nt(o))}return el(t,Nt(o))}(o,e),i=Nt(n.type||`image/${o}`);const a=null!==(r=null==g?void 0:g.compessorUrl)&&void 0!==r?r:null==g?void 0:g.compressorUrl;if(i.startsWith("image/"))try{const e=new File([n],t,{type:i}),o=await ui(e,{maxSizeMB:null==g?void 0:g.compressMaxSize,maxWidthOrHeight:null==g?void 0:g.compressMaxWidthOrHeight,mimeType:i,fileName:t,libURL:a,enableCompression:Boolean(g)&&"image/gif"!==i});n=o,i=o.type}catch(e){console.warn("Image preparation failed, using original:",e)}return{blob:n,mimeType:i,thumbnailDataUrl:await tl(n)}},[g]),z=n.useCallback(async(e,t,o,r)=>{var n,i,a,l,s,c;const f="save"===r?T.current:L.current;if(!N||!f)return;const h="object"==typeof N&&null!==N?N:null;let m=null;try{C(!0);const{blob:i,mimeType:a,thumbnailDataUrl:l}=await D(e,t,o),s=Object.assign(Object.assign({},N),{thumbnail:l,size:i.size,date:(new Date).toISOString().split("T")[0],type:a,folderId:N.folderId||"",name:N.name||t,extension:N.extension||(null===(n=(N.name||t).split(".").pop())||void 0===n?void 0:n.toLowerCase())||""});m=s;const c={blob:i,mimeType:a,thumbnail:l,mode:r},u=await f(s,c);if(u)return C(!1),u;throw new Error(d("saveCopy"===r?"Failed to save image copy":"Failed to save changes"))}catch(e){console.error("Error saving:",e);const o=null!=m?m:h,n=e;if(!(null==n?void 0:n.notificationShown)){const n=Dn(e),f=null!==(a=null!==(i=Un(null==n?void 0:n.code,d))&&void 0!==i?i:null==n?void 0:n.message)&&void 0!==a?a:d("saveCopy"===r?"Failed to save image copy":"Error saving image");u.error({id:"saveCopy"===r?"IMAGE_SAVE_COPY_FAILED":"IMAGE_SAVE_FAILED",message:f,placement:"bottomRight",data:{itemId:null!==(l=null==o?void 0:o.id)&&void 0!==l?l:void 0,itemName:null!==(s=null==o?void 0:o.name)&&void 0!==s?s:t,folderId:null!==(c=null==o?void 0:o.folderId)&&void 0!==c?c:null,thumbnail:null==o?void 0:o.thumbnail},innerException:e})}C(!1)}},[N,u,D,d]),q=n.useCallback(async e=>{var t;if(!Ka.isLoaded()||!N)return void console.error("❌ Pixie instance or file is missing");M.current=e;const o=N.name||"edited-image",r=ei(N,A);try{await(null===(t=Ka.tools)||void 0===t?void 0:t.export.save(o.replace(/\.[^/.]+$/,""),r.pixieFormat,ti.QUALITY))}catch(t){console.error("🎨 Error saving through the button:",t);try{const t=Ka.canvas,n=t?t.toDataURL(r.mimeType):null;n&&await z(n,o,r.extension,e)}catch(e){console.error("🎨 Alternative method also did not work:",e)}}},[N,A,z]),W=n.useCallback(async()=>{var t;if(I&&o&&E&&!O.current)try{O.current=!0;const o=c.current;let n=0;for(;n<20&&(0===o.clientWidth||0===o.clientHeight);)await new Promise(e=>setTimeout(e,50)),n++;const i=(null==g?void 0:g.locale)?null==g?void 0:g.locale.replace("_","-"):"en",a=matchMedia(vt).matches?pt:mt,l=(null==g?void 0:g.theme)===gt?a:null==g?void 0:g.theme,s=((null==g?void 0:g.locale)||p.language||"en").split("-")[0].split("_")[0],d=(p.getResourceBundle(s,"translation")||{}).pixie||{},u=e=>e.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "),f={};Object.entries(d).forEach(([e,t])=>{const o=u(e);f[o]=t,f[e]=t});const h={[i]:f},m=ei(N,A),v={selector:"#pixie-editor",baseUrl:Ya((null==g?void 0:g.baseUrl)||"",(null==g?void 0:g.assetsUrl)||"assets/image-editor"),image:I,activeLanguage:i,languages:h,ui:{activeTheme:l,mode:"inline",forceOverlayModeOnMobile:!1,visible:!0,menubar:{replaceDefaultItems:!0,position:Za.TOP,items:[{type:"undoWidget",align:"left"},{type:"zoomWidget",align:"center",desktopOnly:!0},{type:"button",align:"right",desktopOnly:!0,icon:()=>e(fe,{style:{fontSize:20}}),action:e=>{e.togglePanel("history")}},{type:"button",icon:()=>e(ce,{style:{fontSize:20}}),align:"right",desktopOnly:!0,action:r}]},nav:{position:Xa.TOP}},tools:{export:{defaultFormat:m.pixieFormat,defaultQuality:ti.QUALITY,defaultName:(null===(t=null==N?void 0:N.name)||void 0===t?void 0:t.replace(/\.[^/.]+$/,""))||"image"},text:{replaceDefaultItems:!0,defaultText:"Handwriting",items:[{family:"Inter",src:"fonts/inter-v20-cyrillic_latin-regular.woff2"},{family:"Commissioner",src:"fonts/commissioner-v24-cyrillic_latin-regular.woff2"},{family:"Montserrat Light",src:"fonts/Montserrat-Light.woff2"},{family:"Montserrat Regular",src:"fonts/Montserrat-Regular.woff2"},{family:"Montserrat Bold",src:"fonts/Montserrat-Bold.woff2"},{family:"Montserrat Black",src:"fonts/Montserrat-Black.woff2"},{family:"Roboto Light",src:"fonts/Roboto-Light.woff2"},{family:"Roboto Regular",src:"fonts/Roboto-Regular.woff2"},{family:"Roboto Bold",src:"fonts/Roboto-Bold.woff2"},{family:"Roboto Black",src:"fonts/Roboto-Black.woff2"},{family:"Lato Light",src:"fonts/Lato-Light.woff2"},{family:"Lato Regular",src:"fonts/Lato-Regular.woff2"},{family:"Lato Bold",src:"fonts/Lato-Bold.woff2"},{family:"Lato Black",src:"fonts/Lato-Black.woff2"},{family:"Rubik Light",src:"fonts/Rubik-Light.woff2"},{family:"Rubik Regular",src:"fonts/Rubik-Regular.woff2"},{family:"Rubik Bold",src:"fonts/Rubik-Bold.woff2"},{family:"Rubik Black",src:"fonts/Rubik-Black.woff2"},{family:"Bebas Neue Light",src:"fonts/BebasNeueLight.woff2"},{family:"Bebas Neue Regular",src:"fonts/BebasNeueRegular.woff2"},{family:"Bebas Neue Book",src:"fonts/BebasNeueBook.woff2"},{family:"Bebas Neue Bold",src:"fonts/BebasNeueBold.woff2"},{family:"Fira Sans",src:"fonts/fira-sans-v11-latin-ext_latin_cyrillic-regular.woff2"},{family:"Lobster",src:"fonts/Lobster.woff2"},{family:"Pacifico",src:"fonts/pacifico-v23-cyrillic_latin-regular.woff2"},{family:"Playfair Display",src:"fonts/playfair-display-v40-cyrillic_latin-regular.woff2"},{family:"Oswald",src:"fonts/oswald-v57-cyrillic_latin-regular.woff2"},{family:"Caveat",src:"fonts/caveat-v23-cyrillic_latin-regular.woff2"}]}},onSave:async function(e,t,o){try{C(!0);return await z(e,t,o,M.current)}catch(e){throw console.error("🎨 PIXIE onSave ERROR:",e),C(!1),e}}};try{R(!1),await Ka.show(v,c.current);const e=Ka.canvas;e&&e.focus(),R(!0),C(!1)}catch(e){console.error("init pixie failed:",e)}}catch(e){console.error("Error initializing Pixie:",e),u.error({id:"EDITOR_INIT_FAILED",message:d("Error initializing editor"),placement:"bottomRight",innerException:e}),O.current=!1,null==r||r()}},[N,A,I,o,E,null==g?void 0:g.locale,null==g?void 0:g.theme,null==g?void 0:g.baseUrl,null==g?void 0:g.assetsUrl,r,z,u,p,d]);n.useEffect(()=>{o&&I&&E&&W()},[o,I,E,W]),n.useEffect(()=>{if(!o){try{Ka.close()}catch(e){console.warn("Error closing Pixie:",e)}C(!1),F(null),_(""),O.current=!1,x(!1),R(!1)}return()=>{try{Ka.close()}catch(e){console.warn("Error closing Pixie when unmounting:",e)}}},[o]);const V=Boolean(null==N?void 0:N.id)&&!1!==(null===(s=null==g?void 0:g.features)||void 0===s?void 0:s.enableUpdateFile);return e(B,{title:(null==N?void 0:N.name)?d("Editing: {{name}}",{name:N.name}):d("Editing image"),open:o,closeIcon:null,onCancel:r,afterOpenChange:e=>x(e),forceRender:!0,width:"100vw",getContainer:h.getModalContainer,style:{top:0,height:"100vh",maxWidth:"none",padding:10},styles:{body:{height:"85vh",padding:0}},footer:[e(S,{onClick:r,disabled:!E||b,children:d("Cancel")},"cancel"),e(S,{type:"primary",onClick:()=>q("saveCopy"),loading:b,children:d("Save as copy and choose")},"save-copy"),...V?[e(S,{type:"primary",onClick:()=>q("save"),loading:b,children:d("Save and choose")},"save")]:[]],mask:{closable:!1},destroyOnHidden:!1,afterClose:()=>{v&&v("")},children:t("div",{ref:c,style:{position:"relative",width:"100%",height:"100%"},children:[o&&!P?e("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(255,255,255,0.45)",backdropFilter:"blur(1px)",pointerEvents:"all",zIndex:10},children:e("span",{style:{fontSize:14,color:"#555"},children:d("Loading editor...")})}):null,b&&P&&e(ja,{style:{position:"absolute",top:0,background:"var(--colorBgLayout)",zIndex:100,opacity:.7}})]})})};var rl="uploadProgress",nl="uploadProgress__card",il="uploadProgress__header",al="uploadProgress__header-title",ll="uploadProgress__header-buttons",sl="uploadProgress__header-button",dl="uploadProgress__close-icon",cl="uploadProgress__body",ul="uploadProgress__common-error",fl="uploadProgress__common-error-row",hl="uploadProgress__common-error-hint",ml="uploadProgress__list-wrapper",pl="uploadProgress__status-icon",gl="uploadProgress__file-item",vl="uploadProgress__file-item--error",yl="uploadProgress__body--error",wl="uploadProgress__error-item",bl="uploadProgress__error-message",Cl="uploadProgress__error-hint",Il="uploadProgress__file-avatar",Fl="uploadProgress__file-info",Al="uploadProgress__file-name",_l="uploadProgress__file-size",Sl="uploadProgress__progress-bar",El="uploadProgress__minimized",xl="uploadProgress__minimized-button",Pl="uploadProgress__file-list";const{Text:Rl}=F,Nl=({visible:o,files:r,totalFiles:n,completedFiles:i,onClose:a,onMinimize:l,onInsert:s,minimized:d=!1})=>{var c;const{token:u}=y.useToken(),{t:f}=dr();if(!o)return null;const h=t=>{switch(t){case"success":return e("div",{className:pl,children:e(pe,{style:{color:u.colorSuccess}})});case"error":return e(he,{style:{color:u.colorError}});default:return e(me,{style:{color:"#1890ff"}})}},m=t=>"success"===t.status?[e(S,{type:"primary",size:"small",onClick:()=>s(t),children:f("Insert")},"insert")]:[];if(d)return e("div",{className:El,children:e(S,{type:"primary",size:"small",onClick:l,className:xl,children:f("Upload progress",{completed:i,total:n})})});const p=r.filter(e=>"uploading"===e.status).length,g=r.filter(e=>"success"===e.status).length,v=r.filter(e=>"error"===e.status).length,w=r.filter(e=>"error"===e.status),b=w.length>1&&w.every(e=>{var t;return e.error&&e.error===(null===(t=w[0])||void 0===t?void 0:t.error)}),C=b?null===(c=w[0])||void 0===c?void 0:c.error:null;return e("div",{className:rl+" fm-upload-progress",children:t("div",{className:nl,children:[t("div",{className:il,children:[e(Rl,{strong:!0,className:al,children:p>0?f("Uploading files",{completed:i,total:n}):g>0?f("Uploaded files",{success:g,total:n}):f("Upload error files",{errorCount:v})}),e("div",{className:ll,children:e(S,{type:"text",size:"small",icon:e(ce,{className:dl}),onClick:a,className:sl})})]}),t("div",{className:`${cl} ${r.some(e=>"error"===e.status)?yl:""}`,children:[e("div",{className:ml,children:e(V,{className:Pl,size:"small",dataSource:r,renderItem:o=>{const r="error"===o.status,n=r?(e=>{if(!e)return null;const t=e.toLowerCase();return t.includes("type")||t.includes("format")||t.includes("формат")||t.includes("тип")||t.includes("not allowed")||t.includes("дозволен")||t.includes("name")||t.includes("invalid")||t.includes("назва")||t.includes("неприпустим")||t.includes("allowed characters")?null:t.includes("large")||t.includes("size")||t.includes("розмір")||t.includes("размер")?f("upload_error_hint_size"):t.includes("exists")||t.includes("вже існує")||t.includes("уже существует")?f("upload_error_hint_exists"):null})(o.error):null;return e(V.Item,{className:`${gl} ${r?vl:""}`,actions:m(o),children:e(V.Item.Meta,{avatar:e($,{size:"small",icon:h(o.status),className:Il}),title:t("div",{className:Fl,children:[e(Rl,{ellipsis:!0,className:Al,children:o.name}),e(Rl,{type:"secondary",className:_l,children:void 0!==o.size?Or(o.size):""})]}),description:"uploading"===o.status?e(z,{percent:o.progress,size:"small",status:"active",showInfo:!1,className:Sl}):r?b?null:t("div",{className:wl,children:[e(Rl,{type:"danger",className:bl,children:o.error||f("Error")}),n&&e(Rl,{type:"secondary",className:Cl,children:n})]}):null})})}})}),C&&t("div",{className:ul,children:[t("div",{className:fl,children:[e(he,{style:{color:u.colorError,marginRight:8,flexShrink:0}}),e(Rl,{type:"danger",children:C})]}),e(Rl,{type:"secondary",className:hl,children:f("Applies to all {{count}} files",{count:w.length})})]})]})]})})},{Header:kl}=H,{Title:Ol}=F,Tl=({activeLibraryItem:o,selectedFolder:n,isTrashFolder:i,onClearTrash:a,files:l,loading:s,onRefresh:d,refreshDisabled:c,showRefresh:u=!1})=>{const{t:f}=dr(),h=o===at&&(null!=i?i:n===ht),[m,p]=r.useState(!1),g={[at]:f("My files"),[lt]:f("GIF"),[st]:f("Stock images"),[dt]:f("Icons"),[ut]:f("QR & Barcode"),[ct]:f("AI image generation")};let v;return r.useEffect(()=>{const e=setTimeout(()=>{p(h&&l.length>0&&!s)},200);return()=>clearTimeout(e)},[h,l.length,s]),v=o===at?h?f("Trash"):n:g[o],e(kl,{className:"actions-header",children:t("div",{className:"header-title-container",children:[e(Ol,{level:5,className:"header-title",children:v}),m&&a&&e(S,{type:"default",onClick:a,className:"clear-trash-button","aria-label":f("Clear Trash"),children:f("Clear")}),o===at&&u&&d&&e(_,{title:f("Refresh"),children:e(S,{type:"text",className:"folder-refresh-button",icon:e(Ve,{size:16}),onClick:d,disabled:c})})]})})};function Ll(e,t){return!e||!t||e<=0||t<=0?1:e/t}const Ml=1200;function Ul({items:e,getId:t,getPreviewSrc:o,getAltText:r,getWidth:n,getHeight:a,layoutMode:l="masonry",minColumnWidth:s=240,estimatedItemHeight:d=240,gap:c=20,overscanPx:f=800,prefetchThresholdPx:h=1200,resolveColumnCount:m,virtualizationThreshold:p=40}){var g,v;const[y,w]=i({scrollTop:0,viewportHeight:800,viewportWidth:Ml,scrollHeight:0}),b=u(()=>function(e){return{getId:e,buildSignature:(t,o)=>{var r,n;const i=o.getPreviewSrc(t)||"",a=o.getAltText(t),l=null===(r=o.getWidth)||void 0===r?void 0:r.call(o,t),s=null===(n=o.getHeight)||void 0===n?void 0:n.call(o,t);return[e(t),i,a,null!=l?l:"",null!=s?s:""].join("::")},buildRowModel:(e,t,o)=>{var r,n;const i=null===(r=t.getWidth)||void 0===r?void 0:r.call(t,e),a=null===(n=t.getHeight)||void 0===n?void 0:n.call(t,e);return{id:o.id,signature:o.signature,item:e,previewSrc:t.getPreviewSrc(e),altText:t.getAltText(e),width:i,height:a,aspectRatio:Ll(i,a)}}}}(t),[t]),C=u(()=>({getPreviewSrc:o,getAltText:r,getWidth:n,getHeight:a}),[r,a,o,n]),I=u(()=>{const e=Math.max(1,y.viewportWidth||Ml);return m?Math.max(1,m(e)):Math.max(1,Math.floor((e+c)/(s+c)))},[c,s,m,y.viewportWidth]),F=u(()=>{const e=Math.max(1,y.viewportWidth||Ml);return Math.max(1,(e-c*Math.max(0,I-1))/I)},[I,c,y.viewportWidth]),A=u(()=>{const t=new Array(I).fill(0),o=[];e:for(let r=0;r<e.length;r+=1){const i=e[r],s=null==n?void 0:n(i),u=null==a?void 0:a(i),f=s&&u&&s>0&&u>0?s/u:void 0,h=f?F/f:d;if("grid"===l){const e=Math.floor(r/I)*(h+c),t=r%I*(F+c);o.push({index:r,top:e,left:t,width:F,height:h,bottom:e+h});continue e}let m=0;for(let e=1;e<t.length;e+=1)t[e]<t[m]&&(m=e);const p=t[m],g=m*(F+c);t[m]=p+h+c,o.push({index:r,top:p,left:g,width:F,height:h,bottom:p+h})}const r=0===o.length?0:"grid"===l?Math.max(...o.map(e=>e.bottom)):Math.max(0,...t.map(e=>e-c));return{positionedItems:o,containerHeight:r}},[I,F,d,c,a,n,e,l]),_=u(()=>e.length<=p?{renderStrategy:"full"}:{renderStrategy:"positioned",positioned:{layout:A.positionedItems,viewportTop:y.scrollTop,viewportBottom:y.scrollTop+y.viewportHeight,overscanPx:f,containerHeight:A.containerHeight}},[e.length,A.containerHeight,A.positionedItems,f,y.scrollTop,y.viewportHeight,p]),{rowModels:S,renderWindow:E}=Ca({items:e,context:C,adapter:b,options:_}),x=null!==(g=E.positionedItems)&&void 0!==g?g:S.map((e,t)=>{var o;return{row:e,layout:null!==(o=A.positionedItems[t])&&void 0!==o?o:{index:t,top:0,left:0,width:F,height:d,bottom:d}}}),P=null!==(v=E.containerHeight)&&void 0!==v?v:A.containerHeight,R=P>0&&y.scrollTop+y.viewportHeight>=P-h;return{rowModels:S,renderRows:E.rows,renderWindow:E,positionedItems:x,containerHeight:P,isNearEnd:R,viewportMetrics:y,handleViewportChange:e=>{w(t=>t.scrollTop===e.scrollTop&&t.viewportHeight===e.viewportHeight&&t.viewportWidth===e.viewportWidth&&t.scrollHeight===e.scrollHeight?t:e)}}}const jl=t=>{var o,{imageId:r,sourceUrl:n,shouldLoad:l=!0,loader:s,onLoad:d}=t,f=Rn(t,["imageId","sourceUrl","shouldLoad","loader","onLoad"]);const h=Wi(u(()=>[n],[n])),[m,p]=i(()=>s.getSnapshot(r,n)),g=c(null);return a(()=>(p(s.getSnapshot(r,n)),s.subscribe(r,n,p)),[r,s,n]),a(()=>(s.setActive(r,n,l),()=>{s.setActive(r,n,!1),s.release(r)}),[r,s,l,n]),m.shouldLoad&&h.src?e("img",Object.assign({},f,{ref:g,src:h.src,loading:null!==(o=f.loading)&&void 0!==o?o:"lazy",onLoad:e=>{h.handleLoad(),s.markLoaded(r),null==d||d(e)},onError:async e=>{var t;(await h.handleError()).exhausted&&s.markError(r),null===(t=f.onError)||void 0===t||t.call(f,e)}})):null};var Dl={gifTab:"gifTab",scrollableDiv:"scrollableDiv",gifSearchInput:"gifSearchInput",search:"search",searchResults:"searchResults",virtualCanvas:"virtualCanvas",listItem:"listItem",loaded:"loaded",loadedImage:"loadedImage",searchOutputWrapper:"searchOutputWrapper",divider:"divider",resultsContainer:"resultsContainer",playButton:"playButton",title:"title",subtitle:"subtitle"};const Bl=e=>{const t="undefined"!=typeof window?window.innerWidth:e;return t<=700?1:t<=1100?2:t<=1600?3:4},zl=e=>e.images.downsized.url,ql=({setImageGifList:r,imageGifList:n=[],currentReqGif:l,setCurrentReqGif:s,inputRef:u,customRequest:f})=>{const{t:h}=dr(),{GifPlayIcon:m}=gn(),{options:p}=mn(),{config:g}=p,v=Bi({maxConcurrent:6}),[y,w]=i(null),[C,F]=i(new Set),[A,_]=i(!1),[S,E]=i(!1),[x,P]=i(!1),[R]=b.useForm(),N=c(l),k=c(null),O=c(null),T=c(null),L=c(0),M=c(0),j=c(new Set);a(()=>{N.current=l},[l]),a(()=>{R.setFieldsValue({keywords:l.keywords})},[]);const D=null==g?void 0:g.handleProxyUrl,B=null==g?void 0:g.fetchWithProxy,z=async e=>{if(!D)return e;const t=await Promise.resolve(D(e));return null!=t?t:e},q=d(async e=>B?Promise.resolve(B(e,void 0,{intent:"metadata"})):fetch(await z(e)),[B,z]),W=async function({query:e,page:t}){var o;const r=e.keywords.replace(/[^\w\sа-яёА-ЯЁ]|_/g,"").replace(/[\s_-]+/g," ");try{const e=`https://api.giphy.com/v1/gifs/search?api_key=${null!==(o=null==g?void 0:g.REACT_APP_GIPHY_KEY)&&void 0!==o?o:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F"}&q=${encodeURIComponent(r)}&limit=50&offset=${t}&lang=en`,n=await q(e);return{data:await n.json()}}catch(e){console.warn(e)}},{positionedItems:V,containerHeight:$,isNearEnd:H,viewportMetrics:G,handleViewportChange:K}=Ul({items:n,getId:e=>e.id,getPreviewSrc:zl,getAltText:e=>e.title,getWidth:e=>e.images.downsized.width?Number(e.images.downsized.width):void 0,getHeight:e=>e.images.downsized.height?Number(e.images.downsized.height):void 0,layoutMode:"masonry",minColumnWidth:240,estimatedItemHeight:220,prefetchThresholdPx:320,resolveColumnCount:Bl}),Q=Zi(K,[n.length]),J=()=>{k.current&&(clearTimeout(k.current),k.current=null)},Y=e=>!j.current.has(e)&&(j.current.add(e),!0),Z=e=>{j.current.delete(e)},X=d(async()=>{var e,t,o;const n=null===(e=N.current.keywords)||void 0===e?void 0:e.trim();if(!n||A||S||!x)return;const i=`gif:${n}:${M.current}`;if(!Y(i))return;const a=L.current;E(!0);try{const e=await W({query:N.current,page:M.current});if(a!==L.current)return;const n=null!==(o=null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.data)&&void 0!==o?o:[];if(!Array.isArray(n)||0===n.length)return void P(!1);const i=n;if(a!==L.current)return;r(e=>{const t=new Set(e.map(e=>e.id)),o=i.filter(e=>!t.has(e.id));return o.length>0?[...e,...o]:e}),M.current+=n.length,P(50===n.length)}finally{Z(i),a===L.current&&E(!1)}},[x,A,S,r]),ee=async()=>{var e,t;J();const o=null===(e=N.current.keywords)||void 0===e?void 0:e.trim();if(!o)return O.current=null,T.current=null,L.current+=1,M.current=0,r([]),F(new Set),P(!1),void E(!1);if(T.current===o)return;if(O.current===o||A&&O.current===o)return;const n=`gif:${o}:0`;if(!Y(n))return;const i=L.current+1;L.current=i,O.current=o,M.current=0,r([]),F(new Set),P(!1),E(!1),_(!0);try{const e=await W({query:N.current,page:0});if(i!==L.current)return;const n=null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.data;if(Array.isArray(n)&&n.length>0){const e=n;if(i!==L.current)return;r(e),M.current=n.length,P(50===n.length)}else r([]),P(!1);T.current=o}catch(e){P(!1)}finally{Z(n),O.current===o&&(O.current=null),_(!1)}};return a(()=>()=>{J()},[]),a(()=>{!A&&!S&&x&&n.length>0&&H&&X()},[x,n.length,H,X,A,S]),e("div",{className:Dl.gifTab,children:e("div",{className:Dl.searchOutputWrapper,children:t("div",{id:"scrollableDiv",ref:Q,className:Dl.scrollableDiv,children:[t(b,{form:R,onValuesChange:e=>{if(void 0!==e.keywords){const t=Object.assign(Object.assign({},N.current),{keywords:e.keywords});s(t),N.current=t,J(),k.current=setTimeout(ee,800)}},className:n.length>0?Dl.searchResults:Dl.search,children:[e(b.Item,{name:"keywords",className:Dl.gifSearchInput,children:e(I,{onPressEnter:()=>{ee()},allowClear:!0,placeholder:h("Search GIFs"),ref:u,spellCheck:"false",prefix:e(_e,{size:16,strokeWidth:null==g?void 0:g.iconStrokeWidth,onClick:()=>{ee()}})})}),n.length>0&&!A&&e("div",{className:`ant-divider ${Dl.divider}`,role:"separator"})]}),!n.length&&!A&&e(o,{children:l.keywords?e(Cn,{}):t("div",{className:Dl.resultsContainer,children:[e("div",{className:Dl.videoIcon,children:e(m,{className:Dl.playButton})}),e("h1",{className:Dl.title,children:h("Over 350,000 live images")}),e("p",{className:Dl.subtitle,children:h("Enter a search query and we'll find the perfect image for you")})]})}),!n.length&&A&&e(ja,{}),n.length>0&&t(o,{children:[e("div",{className:Dl.virtualCanvas,style:{height:$},children:V.map(({row:o,layout:r})=>{const n=o.item,i=C.has(n.id),a=zl(n),l=r.bottom>=G.scrollTop-240&&r.top<=G.scrollTop+G.viewportHeight+240;return t("div",{className:`${Dl.listItem} ${i?Dl.loaded:""}`,onClick:()=>(async(e,t)=>{var o;w(t),setTimeout(()=>{w(null)},2e3);let r=e.split("?")[0].split("#")[0].split("/"),n=r[r.length-1]||"uploaded-file";n.includes(".")&&(null===(o=n.split(".").pop())||void 0===o?void 0:o.length)&&n.split(".").pop().length<=5||(n+=".gif"),f(e,n)})(n.images.downsized.url,n.id,n.title),style:{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height,minHeight:r.height,maxHeight:"none",marginBottom:0},children:[e(jl,{imageId:n.id,sourceUrl:a,shouldLoad:l,loader:v,className:y===n.id?Dl.loadedImage:"",width:"100%",height:"100%",alt:n.title,decoding:"async",onLoad:()=>{F(e=>{if(e.has(n.id))return e;const t=new Set(e);return t.add(n.id),t})}}),e("a",{rel:"noreferrer",href:"https://giphy.com/",target:"_blank",onClick:e=>e.stopPropagation()}),y===n.id&&e(U,{className:Dl.antSpin})]},n.id)})}),S&&e(ja,{})]})]})})})};var Wl={stockTab:"stockTab",stockSearchInput:"stockSearchInput",searchOutputWrapper:"searchOutputWrapper",divider:"divider",search:"search",searchResults:"searchResults",virtualCanvas:"virtualCanvas",scrollableDiv:"scrollableDiv",listItem:"listItem",loaded:"loaded",loadedImage:"loadedImage",creatorInfo:"creatorInfo",stockColorFilter:"stockColorFilter",allColors:"allColors",blackColor:"blackColor",bwColor:"bwColor",whiteColor:"whiteColor",orangeColor:"orangeColor",redColor:"redColor",purpleColor:"purpleColor",magentaColor:"magentaColor",greenColor:"greenColor",tealColor:"tealColor",blueColor:"blueColor",resultsContainer:"resultsContainer",playButton:"playButton",title:"title",subtitle:"subtitle"};const Vl=e=>{const t="undefined"!=typeof window?window.innerWidth:e;return t<=650?1:t<=1e3?2:t<=1450?3:4},$l=(e,t)=>{const o=new URL(e);return o.searchParams.set("w",t.toString()),o.toString()},Hl=({imageStockList:r,setImageStockList:n,currentReq:l,setCurrentReq:s,inputRef:u,customRequest:f})=>{var h,m;const{t:p}=dr(),{StockBigIcon:g,MixedViewIcon:v,LandscapeViewIcon:y,PortraitViewIcon:w,SquareViewIcon:C}=gn(),{options:F}=mn(),{config:A}=F,S=Bi({maxConcurrent:6}),[E,x]=i(!1),[P,R]=i(!1),[N,O]=i(!1),[L,M]=i(null),[j,D]=i(new Set),[B]=b.useForm(),z=null==A?void 0:A.fetchWithProxy,q=null==A?void 0:A.handleProxyUrl,W=null!==(h=null==A?void 0:A.UNSPLASH_KEY)&&void 0!==h?h:"HX2_qqq3F3ljmtYtfmb9P6h0dn2u9mnnOl36IdV8el0",V=(null===(m=null==A?void 0:A.locale)||void 0===m?void 0:m.slice(0,2))||"ru",$=c(l),H=c(null),K=c(null),Q=c(0),J=c(1),Y=c(new Set),Z=async e=>{if(!q)return e;const t=await Promise.resolve(q(e));return null!=t?t:e},X=d(async e=>z?Promise.resolve(z(e,void 0,{intent:"metadata"})):fetch(await Z(e)),[z,Z]),ee=()=>{H.current&&(clearTimeout(H.current),H.current=null)},te=e=>!Y.current.has(e)&&(Y.current.add(e),!0),oe=e=>{Y.current.delete(e)},re=e=>e.map(e=>Object.assign(Object.assign({},e),{urls:{raw:$l(e.urls.raw,1200),small:$l(e.urls.raw,540)}}));a(()=>{$.current=l},[l]),a(()=>{0===r.length&&B.setFieldsValue({color:"",orientation:""})},[r,B]),a(()=>{B.setFieldsValue({keywords:l.keywords,color:l.color,orientation:l.orientation})},[]);const ne=async function({query:e,page:t}){const o=e.keywords.replace(/[^\w\sа-яёА-ЯЁ]|_/g,"").replace(/[\s_-]+/g," ");try{let r=`https://api.unsplash.com/search/photos?client_id=${W}&lang=${V}&per_page=30&query=${encodeURIComponent(o)}&page=${t}`;""!==e.color&&(r+=`&color=${e.color}`),""!==e.orientation&&(r+=`&orientation=${e.orientation}`);const n=await X(r);return{data:await n.json()}}catch(e){console.warn(e)}},{positionedItems:ie,containerHeight:ae,isNearEnd:le,viewportMetrics:se,handleViewportChange:de}=Ul({items:r,getId:e=>e.id,getPreviewSrc:e=>e.urls.small,getAltText:e=>e.description||e.user.name,getWidth:e=>e.width,getHeight:e=>e.height,layoutMode:"masonry",minColumnWidth:240,estimatedItemHeight:220,prefetchThresholdPx:320,resolveColumnCount:Vl}),ce=Zi(de,[r.length]),ue=d(async()=>{var e,t;if(E||P||!N||!$.current.keywords.trim())return;const o=Q.current,r=J.current,i=`stock:${`${$.current.keywords.trim()}|${$.current.color}|${$.current.orientation}`}:${r}`;if(te(i)){R(!0);try{const i=await ne({query:$.current,page:r});if(o!==Q.current)return;const a=null!==(t=null===(e=null==i?void 0:i.data)||void 0===e?void 0:e.results)&&void 0!==t?t:[];if(0===a.length)return void O(!1);const l=re(a);if(o!==Q.current)return;n(e=>{const t=new Set(e.map(e=>e.id)),o=l.filter(e=>!t.has(e.id));return o.length>0?[...e,...o]:e}),J.current=r+1,O(30===a.length)}finally{oe(i),o===Q.current&&R(!1)}}},[N,E,P,n]),fe=async()=>{var e,t;ee();const o=`${$.current.keywords.trim()}|${$.current.color}|${$.current.orientation}`;if(!$.current.keywords.trim())return void(K.current=null);if(K.current===o)return;const r=`stock:${o}:1`;if(!te(r))return;const i=Q.current+1;Q.current=i,x(!0),R(!1),O(!1),J.current=1,n([]),D(new Set);try{const r=await ne({query:$.current,page:1});if(i!==Q.current)return;const a=null!==(t=null===(e=null==r?void 0:r.data)||void 0===e?void 0:e.results)&&void 0!==t?t:[];if(a.length>0){const e=re(a);if(i!==Q.current)return;n(e),J.current=2,O(30===a.length)}else O(!1);K.current=o}finally{oe(r),x(!1)}};a(()=>()=>{ee()},[]),a(()=>{!E&&!P&&N&&r.length>0&&le&&ue()},[N,r.length,le,ue,E,P]);const he=async(e,t,o,r)=>{var n;!async function(e){try{const t=`${e}${e.includes("?")?"&":"?"}client_id=${W}`,o=await X(t);return{data:await o.json()}}catch(e){console.warn(e)}}(t.download_location),M(o),setTimeout(()=>M(null),2e3);const i=e.raw,a=i.split("?")[0].split("#")[0].split("/");let l=a[a.length-1]||"uploaded-file";l.includes(".")&&(null===(n=l.split(".").pop())||void 0===n?void 0:n.length)&&l.split(".").pop().length<=5||(l+=".jpg"),f(i,l)};return e("div",{className:Wl.stockTab,children:e("div",{className:Wl.searchOutputWrapper,children:t("div",{className:Wl.scrollableDiv,id:"scrollableDiv",ref:ce,children:[t(b,{form:B,initialValues:It,onValuesChange:(e,t)=>{const o=Object.assign(Object.assign({},It),t);s(o),$.current=o,ee(),""!==o.keywords?H.current=setTimeout(fe,800):(K.current=null,Q.current+=1,J.current=1,n([]),D(new Set),O(!1),R(!1),s(Object.assign({},It)),$.current=It,B.resetFields())},className:r.length>0?Wl.searchResults:Wl.search,children:[t(T,{gutter:24,children:[e(k,{span:r.length>0?void 0:24,children:e(b.Item,{name:"keywords",className:Wl.stockSearchInput,children:e(I,{allowClear:!0,placeholder:p("Search image"),ref:u,spellCheck:"false",prefix:e(_e,{size:16,strokeWidth:null==A?void 0:A.iconStrokeWidth})})})}),!!r.length&&t(o,{children:[e(k,{children:e(b.Item,{name:"orientation",children:t(G.Group,{onChange:e=>s(t=>Object.assign(Object.assign({},t),{orientation:e.target.value})),children:[e(_,{title:p("All"),placement:"top",children:e(G.Button,{value:"",children:e(v,{})})}),e(_,{title:p("Landscape"),placement:"top",children:e(G.Button,{value:"landscape",children:e(y,{})})}),e(_,{title:p("Portrait"),placement:"top",children:e(G.Button,{value:"portrait",children:e(w,{})})}),e(_,{title:p("Squarish"),placement:"top",children:e(G.Button,{value:"squarish",children:e(C,{})})})]})})}),e(k,{children:e(b.Item,{name:"color",children:t(G.Group,{className:Wl.stockColorFilter,onChange:e=>s(t=>Object.assign(Object.assign({},t),{color:e.target.value})),children:[e(_,{title:p("All"),placement:"top",children:e(G.Button,{className:Wl.allColors,value:"",children:"All"})}),e(_,{title:p("Black"),placement:"top",children:e(G.Button,{className:Wl.blackColor,value:"black",children:"B"})}),e(_,{title:p("Black and White"),placement:"top",children:e(G.Button,{className:Wl.bwColor,value:"black_and_white",children:"B&W"})}),e(_,{title:p("White"),placement:"top",children:e(G.Button,{className:Wl.whiteColor,value:"white",children:"W"})}),e(_,{title:p("Orange"),placement:"top",children:e(G.Button,{className:Wl.orangeColor,value:"orange",children:"O"})}),e(_,{title:p("Red"),placement:"top",children:e(G.Button,{className:Wl.redColor,value:"red",children:"R"})}),e(_,{title:p("Purple"),placement:"top",children:e(G.Button,{className:Wl.purpleColor,value:"purple",children:"P"})}),e(_,{title:p("Magenta"),placement:"top",children:e(G.Button,{className:Wl.magentaColor,value:"magenta",children:"M"})}),e(_,{title:p("Green"),placement:"top",children:e(G.Button,{className:Wl.greenColor,value:"green",children:"G"})}),e(_,{title:p("Teal"),placement:"top",children:e(G.Button,{className:Wl.tealColor,value:"teal",children:"T"})}),e(_,{title:p("Blue"),placement:"top",children:e(G.Button,{className:Wl.blueColor,value:"blue",children:"B"})})]})})})]})]}),r.length>0&&!E&&e("div",{className:`ant-divider ${Wl.divider}`,role:"separator"})]}),!r.length&&!E&&e(o,{children:l.keywords?e(Cn,{}):t("div",{className:Wl.resultsContainer,children:[e("div",{className:Wl.videoIcon,children:e(g,{className:Wl.playButton})}),e("h1",{className:Wl.title,children:p("Millions of free stock images")}),e("p",{className:Wl.subtitle,children:p("Enter a search query and we'll find the perfect image for you")})]})}),!r.length&&E&&e(ja,{}),r.length>0&&t(o,{children:[e("div",{className:Wl.virtualCanvas,style:{height:ae},children:ie.map(({row:o,layout:r})=>{const n=o.item,i=j.has(n.id),a=r.bottom>=se.scrollTop-240&&r.top<=se.scrollTop+se.viewportHeight+240;return t("div",{className:`${Wl.listItem} ${i?Wl.loaded:""}`,onClick:()=>he(n.urls,n.links,n.id,n.description),style:{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height,minHeight:r.height,maxHeight:"none",marginBottom:0},children:[e(jl,{imageId:n.id,sourceUrl:n.urls.small,shouldLoad:a,loader:S,className:L===n.id?Wl.loadedImage:"",width:"100%",height:"100%",alt:n.description,decoding:"async",onLoad:()=>{D(e=>{if(e.has(n.id))return e;const t=new Set(e);return t.add(n.id),t})}}),t("p",{className:Wl.creatorInfo,onClick:e=>e.stopPropagation(),children:[p("Photo by")," ",e("a",{target:"_blank",href:`${n.user.links.html}?utm_source=${null==A?void 0:A.APP_NAME_UNSPLASH}&utm_medium=referral`,rel:"noreferrer",children:n.user.name})," ",p("on")," ",e("a",{target:"_blank",href:`https://unsplash.com/?utm_source=${null==A?void 0:A.APP_NAME_UNSPLASH}&utm_medium=referral`,rel:"noreferrer",children:"Unsplash"})]}),L===n.id&&e(U,{className:Wl.antSpin})]},n.id)})}),P&&e(ja,{})]})]})})})},Gl=()=>{const{options:e}=mn(),t=e.config;return d((e,o)=>{!1!==(null==t?void 0:t.pushToGTM)&&((e,t)=>{const o=()=>{try{const t=Object.assign(Object.assign({},e),{appLabel:"blocks_app"});window.dataLayer&&"function"==typeof window.dataLayer.push&&window.dataLayer.push(t)}catch(e){console.error("Ошибка при вызове GTM:",e)}};t?setTimeout(o,t):o()})(e,o)},[null==t?void 0:t.pushToGTM])};var Kl="slideshowContainer",Ql="slideshowImage";const Jl=({images:t,transitionDuration:o=1e3,frameHeight:r})=>{const[n,l]=i([]),[s,d]=i(r);a(()=>{const e=()=>{if("undefined"==typeof window)return void d(r);const e=window.innerHeight,t=Math.max(e-260,130);if("number"==typeof r){const e=Math.min(r,t);d(e)}else d(t)};if(e(),"undefined"!=typeof window)return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[r]);const c=()=>{l(e=>e.map((t,o)=>o===e.length-1?Object.assign(Object.assign({},t),{opacity:1}):t))};return a(()=>{if(t.length>0){const e=t[t.length-1];l(t=>[...t,{src:e,opacity:0}]),setTimeout(c,1e3)}else l([])},[t]),e("div",{className:Kl,style:{height:s,minHeight:130},children:n.map((t,r)=>e("img",{src:`data:image/jpeg;base64, ${t.src}`,alt:`Slide ${r+1}`,className:Ql,style:{opacity:t.opacity,transition:`opacity ${o}ms linear`,display:"block"}},r))})},Yl=t=>{var{className:o,style:r,color:n,text:i,variant:a}=t,l=Rn(t,["className","style","color","text","variant"]);const s=i||"";return e(K,Object.assign({style:r,color:n,variant:a,className:o},l,{children:s}))},Zl=({text:o,counter:r,limits:n,wrapperStyles:i})=>{const{t:a}=dr(),{options:l}=mn(),s=l.config,{token:d}=y.useToken(),c=+n>0,u=!c||r<+n,f=(null==s?void 0:s.billingPageUrl)||"/billing",h=r+" "+a("of")+" "+(c?n:"∞")+" "+(o||a("tests",{count:n}))+" "+a("was used",{count:r});return t("div",{className:"limits-couter-wrapper",style:i,children:[e(Yl,{variant:"filled",text:h,className:"limit-counter",style:{color:u?d.colorText:"white"},color:u?d.colorFillSecondary:"rgb(255, 77, 79)"}),c&&e("div",{style:{fontSize:14,textDecoration:"underline",cursor:"pointer"},onClick:()=>window.location.assign(f),children:a("Need more?")})]})};var Xl={imageAi:"imageAi",imageAiExample:"imageAiExample",imageItem:"imageItem",textAreaInputHybrid:"textAreaInputHybrid",loading:"loading",carousel:"carousel",arrow:"arrow",arrowNext:"arrowNext",arrowPrev:"arrowPrev",arrowBtn:"arrowBtn",arrowBtnNext:"arrowBtnNext",arrowBtnPrev:"arrowBtnPrev",row:"row",inputAffixWrapper:"inputAffixWrapper",textarea:"textarea",inputIcon:"inputIcon"};const es=h(({className:t,onClick:o})=>e("div",{className:`${Xl.arrow} ${Xl.arrowNext} ${t||""}`,onClick:o,children:e(S,{className:`${Xl.arrowBtn} ${Xl.arrowBtnNext}`,size:"large",icon:e(ge,{})})}));es.displayName="SampleNextArrow";const ts=h(({className:t,onClick:o})=>e("div",{className:`${Xl.arrow} ${Xl.arrowPrev} ${t||""}`,onClick:o,children:e(S,{className:`${Xl.arrowBtn} ${Xl.arrowBtnPrev}`,size:"large",icon:e(ve,{})})}));ts.displayName="SamplePrevArrow";const os=({customRequest:o,inputAiRef:r,isImageUploaded:l,setIsImageUploaded:s,aiImageRequest:f,setAiImageRequest:h,imageAiList:m,setImageAiList:p,isLoadingAi:g,setIsLoadingAi:v})=>{const{t:y}=dr(),{AiIcon_2:w}=gn(),C=n.useRef(null),[F,A]=i("auto"),{aiImageCounter:_,currentAiImgLimits:E,loadingDuringGeneration:x,requestStatus:P,handleGenerate:R,convertBase64ToFile:N,isShiftPressed:O,setIsShiftPressed:L,limitsInPlugin:M}=function({setFrameHeight:e,customRequest:t,aiTabRef:o,isImageUploaded:r,setIsImageUploaded:n,aiImageRequest:l,imageAiList:s,setImageAiList:f,isLoadingAi:h,setIsLoadingAi:m}){const{t:p}=dr(),{options:g}=mn(),v=g.config,y=On(),w=Gl(),{messages:b}=g.config,[C,I]=i([]),[F,A]=i(0),[_,S]=i(null),[E,x]=i(!1),[P,R]=i(p("Evaluating the task")),[N,k]=i(!1),O=c(new Set),T=c(new Set),L=c(new Set);a(()=>{I(b)},[b]),a(()=>{s.length||_||(I([]),O.current.clear(),T.current.clear(),L.current.clear(),j.current=-1)},[s,_]);const M=u(()=>v&&"function"==typeof(null==v?void 0:v.sendAIImageRequest)?null==v?void 0:v.sendAIImageRequest:()=>Promise.resolve({}),[v]),U=d(e=>{const t=`${_}-${e.progress}-${JSON.stringify(e.images||e.data)}`;if(!L.current.has(t))if(L.current.add(t),"error"!==e.status&&"Canceled"!==e.status){if(e.images){if(R(String(e.status)),100===e.progress){m(!1),f(e.images);const t=_,o=Array.isArray(e.images)?e.images:[];o.length>0&&t&&!O.current.has(t)&&(O.current.add(t),y.success({id:"AI_IMAGE_GENERERATION_SUCCESS",message:p("Images generated successfully"),placement:"bottomRight",data:{request:l,taskId:t,images:o}})),S(null),k(!1)}}else if(e.data&&(f([String(e.data)]),100===e.progress)){m(!1);const t=_,o=e.data?[String(e.data)]:[];o.length>0&&t&&!O.current.has(t)&&(O.current.add(t),y.success({id:"AI_IMAGE_GENERERATION_SUCCESS",message:p("Images generated successfully"),placement:"bottomRight",data:{request:l,taskId:t,images:o}})),S(null),k(!1)}}else m(!1),k(!1),_&&!T.current.has(_)&&(T.current.add(_),y.error({id:"AI_RESPONSE_INVALID",message:p("Something went wrong, please try again"),placement:"bottomRight",description:String(_)||void 0,data:{requestId:_,request:l,response:e},innerException:e}))},[l,f,R,p,m,_,y,k]),j=c(-1);a(()=>{if(C.length>0){const e=C.length-1;e>j.current&&(j.current=e,U(C[e]))}},[U,C]);const D=u(()=>{if(v&&"function"==typeof(null==v?void 0:v.sseQuery)){const e=null==v?void 0:v.sseQuery;return t=>e(t)}return e=>{}},[v]),B=u(()=>v&&"object"==typeof(null==v?void 0:v.handleLimitUsageEmitter)?null==v?void 0:v.handleLimitUsageEmitter:{fire:()=>{}},[v]),z=null==v?void 0:v.elementId,{projectId:q}=v,{limits:W}=(null==v?void 0:v.limits)?v:{limits:{ai_img_limit:0}},{ai_img_limit:V}=W,$=V>0&&F>=V,H=!(!(null==v?void 0:v.limits)||!v.counters)&&yt,G=d(()=>{B.fire({name:"AiImgCount",count:F+1})},[B,F]),K=u(()=>!$&&!H,[$,H,F,V]),Q=d(async()=>{R(p("Evaluating the task")),""===l||h||(m(!0),k(!0),f([]),I([]),w({event:"submit_form",action:"ai_image_generation",entity_id:z,project_id:q}),M({body:{project_id:q,request:"create-image",connection:"midjourney",message:l}}).then(e=>{var t,o,r,n,i,a,s,d,c;const{data:u,error:h}=e||{};if(h)throw h;const g=u;if(401===(null==g?void 0:g.status)||401===(null===(t=null==g?void 0:g.data)||void 0===t?void 0:t.status))throw new Error("ERROR");const v=null!==(o=null==g?void 0:g.data)&&void 0!==o?o:g;if((null==v?void 0:v._eventResult)&&Array.isArray(null===(r=v.task)||void 0===r?void 0:r.images)&&(null!==(i=null===(n=v.task.images)||void 0===n?void 0:n.length)&&void 0!==i?i:0)>0){const e=v.task.images;return f(e),m(!1),k(!1),void S(null)}const w=(null==g?void 0:g.task)||(null===(a=null==g?void 0:g.data)||void 0===a?void 0:a.task),b=null!==(d=null!==(s=null==w?void 0:w.id)&&void 0!==s?s:_)&&void 0!==d?d:void 0;200===(null==g?void 0:g.status)||200===(null===(c=null==g?void 0:g.data)||void 0===c?void 0:c.status)?((null==w?void 0:w.id)&&(R(w.message),S(w.id)),(null==g?void 0:g.message)&&y.success({id:"AI_IMAGE_GENERATION_STARTED",message:g.message,placement:"bottomRight",data:{request:l,taskId:b,response:null==g?void 0:g.data}}),D({task_id:null==w?void 0:w.id,entity_id:z})):(m(!1),k(!1),b&&!T.current.has(b)&&(T.current.add(b),y.error({id:"AI_IMAGE_GENERATION_FAILED",message:(null==g?void 0:g.message)||p("Something went wrong, please try again"),placement:"bottomRight",description:l,data:{request:l,taskId:b,response:g},innerException:g})))}).catch(e=>{m(!1),k(!1);const t=e;return((null==t?void 0:t.error)||(null==t?void 0:t.data))&&_&&!T.current.has(_)&&(T.current.add(_),null==y||y.error({id:"AI_IMAGE_GENERATION_FAILED",message:p("Something went wrong, please try again"),placement:"bottomRight",description:l,innerException:e,data:{request:l,taskId:_,response:null==t?void 0:t.data,error:Dn(null==t?void 0:t.error)}})),t}))},[l,h,m,k,f,w,z,q,M,y,D,p,_]),J=d(()=>{K&&Q()},[K,H,A,G,Q,y,p]);a(()=>{},[v,H]);const Y=d(e=>{if(r)return;const o=e.match(/^data:image\/([A-Za-z-+/]+);base64,(.+)$/);if(!o)return;const i=o[1],a=o[2],l=atob(a),s=new Array(l.length);for(let e=0;e<l.length;e++)s[e]=l.charCodeAt(e);const d=new Uint8Array(s),c=new Blob([d],{type:`image/${i}`}),u=new File([c],"image.jpeg",{type:c.type,lastModified:Date.now()});n(!0),(async()=>{try{"function"==typeof t&&await Promise.resolve(t({file:u}))}catch(e){console.error("FM AI: customRequest error",e)}finally{n(!1)}})()},[r,n,t]);return a(()=>{(h||s.length>0)&&setTimeout(()=>{var t,r;let n=350;if(o.current){const e=null===(t=o.current)||void 0===t?void 0:t.firstChild;e&&e instanceof HTMLElement&&(n=(null===(r=o.current.getBoundingClientRect())||void 0===r?void 0:r.height)-48-e.clientHeight)}e(n)},0)},[o,s.length,h,e]),{aiImageCounter:F,setAiImageCounter:A,currentAiImgLimits:V,isFieldsDisabled:$,canGenerateImage:K,aiImageRequest:l,imageAiList:s,setImageAiList:f,isLoadingAi:h,setIsLoadingAi:m,loadingDuringGeneration:N,setLoadingDuringGeneration:k,requestStatus:P,setRequestStatus:R,handleGenerate:J,handleLimitAiImgCount:G,convertBase64ToFile:Y,isShiftPressed:E,setIsShiftPressed:x,currentReqId:_,setCurrentReqId:S,limitsInPlugin:H}}({setFrameHeight:A,customRequest:o,aiTabRef:C,isImageUploaded:l,setIsImageUploaded:s,aiImageRequest:f,imageAiList:m,setImageAiList:p,isLoadingAi:g,setIsLoadingAi:v});a(()=>{},[l]);const[U,j]=i(!1),D=d(()=>j(!0),[]),B=d(()=>j(!1),[]),z=d(e=>h(e.target.value),[h]),q=d(e=>{"Shift"===e.key?L(!0):"Enter"!==e.key||O||(e.preventDefault(),R())},[O,R,L]),W=d(e=>{"Shift"===e.key&&L(!1)},[L]);return t("div",{className:Xl.imageAi,ref:C,children:[M&&e(Zl,{text:"images",counter:_,limits:E,wrapperStyles:{marginTop:-25}}),e(T,{gutter:24,className:Xl.row,children:t(k,{span:24,children:[e(b.Item,{children:t("span",{className:`ant-input-affix-wrapper ant-input-affix-wrapper-lg ${Xl.inputAffixWrapper}${U?" ant-input-affix-wrapper-focused":""}`,children:[e(I.TextArea,{ref:r,onKeyDown:q,onKeyUp:W,onFocus:D,onBlur:B,autoSize:!0,allowClear:!0,className:`${Xl.textAreaInputHybrid} ${Xl.textarea}`,placeholder:y("Generate image"),value:f,onChange:z,spellCheck:"false"}),e("span",{className:`ant-input-suffix ${Xl.inputSuffix}`,children:g||x?e(Z,{className:`${Xl.inputIcon} input-icon`,spin:!0}):e(w,{className:`${Xl.inputIcon} input-icon`,onClick:R})})]})}),t("div",{className:Xl.imageAiExample,children:[e("span",{children:y("For example:")})," ",y("A beautiful image of a sunset over a calm ocean.")]})]})}),(g||m.length>0)&&t(Q,{dotPlacement:"top",arrows:!0,nextArrow:e(es,{}),prevArrow:e(ts,{}),className:Xl.carousel,infinite:!1,children:[g&&!m.length&&e("div",{className:Xl.loading,children:t("div",{className:"spin",children:[e(Z,{style:{fontSize:48},spin:!0}),e("p",{className:"status",children:P})]})}),m.length>0&&m.map((o,r)=>t("div",{className:Xl.imageItem,children:[e(Jl,{images:m,frameHeight:F}),e("div",{className:"buttons",children:m.length>0&&!g&&e(S,{onClick:()=>N(`data:image/jpeg;base64, ${o}`),loading:l,icon:e(ye,{}),children:y("Use this variant")})})]},r))]})]})},rs=e=>{(null==e?void 0:e.customTheme)&&((e={})=>{const t=document.querySelector("head");if(!t)return;const o=document.createElement("style");if(o.type="text/css",o.dataset.themeVariablesFm="true",o.setAttribute("data-file-manager","true"),Object.entries(e).length){let r="";Object.entries(e).forEach(([e,t])=>{"object"!=typeof t&&(r+=`\t--${e}: ${t};\n`)}),r=`.em-filemanager {\n${r}}`,o.appendChild(document.createTextNode(r));const n=t.querySelector('[data-theme-variables-fm="true"]');n?t.replaceChild(o,n):t.insertBefore(o,t.firstChild)}})(null==e?void 0:e.customTheme)},{Sider:ns,Content:is}=H,as=n.lazy(()=>import("./file-manager-IconsTab-BMy0LDoU.js")),ls=n.lazy(()=>import("./file-manager-ImageCodeGenerator-CBdZ5eV3.js")),ss={keywords:""},ds=()=>{var l,s,u;const f=Kn(),h=Di(),m=(()=>{var e,t;const{state:o,actions:r,options:n}=mn(),{selectedFolder:i,pathHistory:a,folders:l}=o,{t:s}=dr(),{setSelectedFolder:c,setPathHistory:u}=r,f=d(()=>{var e;return`em_fm:lastFolder:${(null===(e=null==n?void 0:n.config)||void 0===e?void 0:e.projectId)||"default"}`},[null===(e=null==n?void 0:n.config)||void 0===e?void 0:e.projectId]),h=d((e,t=new Set)=>{if(t.has(e))return console.warn(`Cycle detected in the path to the folder with id=${e}`),[];const o=(Array.isArray(l)?l:[]).find(t=>t.id===e);if(!o)return[];const r=new Set(t);return r.add(e),o.parentId?o.parentId===o.id?(console.warn(`Cycle detected: folder ${o.id} is a parent of itself`),[{id:o.id,name:o.name+" (ошибка)"}]):[...h(o.parentId,r),{id:o.id,name:o.name}]:[{id:o.id,name:o.name}]},[l]),m=d(e=>{var t;if("undefined"==typeof window)return;const o=!0===(null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.rememberLastFolder),r=f();try{if(!o)return void localStorage.removeItem(r);e?localStorage.setItem(r,e):localStorage.removeItem(r)}catch(e){}},[f,null===(t=null==n?void 0:n.config)||void 0===t?void 0:t.rememberLastFolder]),p=d(e=>{if("folders"===e){const e=[{id:"folders",name:s("Folders")}];return null==u||u(e),void(n.onPathChange&&n.onPathChange([]))}if(!(Array.isArray(l)?l:[]).find(t=>t.id===e))return void console.warn("⚠️ Folder not found:",e);const t=h(e),o=[{id:"folders",name:s("Folders")},...t];null==u||u(o),n.onPathChange&&n.onPathChange(o.map(e=>e.name))},[l,h,u,n,s]),g=d(e=>{const t="folders"===e?null:e;t!==i&&(null==c||c(t),m(t),p(e))},[m,i,c,p]),v=d(e=>{if(-1===e)null==c||c(null),null==u||u([{id:"folders",name:s("Folders")}]),n.onPathChange&&n.onPathChange([]);else{const t=a.slice(0,e+1),o=t[t.length-1],r="folders"===o.id?void 0:o.id;null==c||c(r||null),null==u||u(t),n.onPathChange&&n.onPathChange(t.map(e=>e.name))}},[n,a,u,c,s]),y=d(e=>{if(!e.isFolder)return;null==c||c(e.id);const t={id:e.id,name:e.name};if(u){const e=[...a,t];u(e)}if(n.onPathChange){const t=[...a.map(e=>e.name),e.name];n.onPathChange(t)}},[n,a,u,c]);return{state:{selectedFolder:i,pathHistory:a},actions:{handleFolderSelect:g,handleBreadcrumbClick:v,handleItemClick:y},selectedFolder:i,pathHistory:a,handleFolderSelect:g,handleBreadcrumbClick:v,handleItemClick:y}})(),p=(()=>{const{state:e,actions:t}=mn(),{pagination:o}=e,{setPagination:r}=t,n=d((e,t)=>{const n=t||o.pageSize;null==r||r({current:e,pageSize:n,total:o.total})},[o.pageSize,o.total,r]);return{state:{pagination:o},actions:{handlePaginationChange:n}}})(),v=(()=>{const[e,t]=i([]),[o,r]=i(!1),[n,a]=i(!1),l=c(0),s=c(new Map),u=d(()=>(l.current+=1,`upload_${l.current}_${Date.now()}`),[]),f=d(e=>Or(e.size),[]),h=d((e,o)=>{const n=o.map(t=>({id:u(),folderId:e,name:t.name,size:f(t),status:"uploading",progress:0}));return t(n),r(!0),a(!1),n.map(e=>e.id)},[u,f]),m=d((e,o)=>{const n={id:u(),folderId:e,name:o,size:void 0,status:"uploading",progress:0};return t(e=>[...e,n]),r(!0),a(!1),n.id},[u]),p=d((e,o)=>{t(t=>t.map(t=>t.id===e?Object.assign(Object.assign({},t),{progress:Math.min(100,Math.max(0,o))}):t))},[]),g=d((e,o)=>{o&&s.current.set(e,o),t(t=>t.map(t=>{if(t.id===e){const e=Object.assign(Object.assign({},t),{status:"success",progress:100});return(null==o?void 0:o.name)&&(e.name=o.name),(null==o?void 0:o.size)&&void 0===t.size&&(e.size=Or(o.size)),e}return t}))},[]),v=d((e,o)=>{t(t=>t.map(t=>t.id===e?Object.assign(Object.assign({},t),{status:"error",error:o}):t))},[]),y=d(()=>{r(!1),a(!1),setTimeout(()=>{t([]),s.current.clear()},300)},[]),w=d(()=>{a(e=>!e)},[]),b=d(e=>s.current.get(e),[]),C=e.length,I=e.filter(e=>"success"===e.status||"error"===e.status).length;return{uploadFiles:e,isUploadVisible:o,isUploadMinimized:n,totalFiles:C,completedFiles:I,startUpload:h,startUploadByUrl:m,updateProgress:p,markAsSuccess:g,markAsError:v,getUploadedFile:b,closeUpload:y,minimizeUpload:w}})(),y=Ai(),{deleteItems:w}=Qn(),b=On(),{t:C}=dr(),{options:I,state:F,actions:A}=mn(),_=I,S=null==_?void 0:_.onChangeSelection,E=F,x=null==_?void 0:_.config,{dataProviders:P}=_,{form:R,urlForm:N,renameForm:k,moveForm:O,renameFolderForm:T,copyForm:L,isModalVisible:M,isUrlModalVisible:j,isMoveModalVisible:D,isRenameFolderModalVisible:B,isCopyModalVisible:z,isDeleteConfirmVisible:q,folderToRename:V,activeLibraryItem:$}=F,{setIsUrlModalVisible:G,setActiveLibraryItem:K}=A,{config:Q}=I,{DropZoneFileIcon:J}=gn(),[Y,Z]=i(!1),[X,ee]=i(!1),[te,oe]=i(!1),re=c(0),ne=c(!1);ne.current=X;const ie=n.useRef(null),ae=n.useRef([]),[le,se]=i(!1),[de,ce]=i(!1),ue=Pi(e=>e.selectedFiles),fe=Pi(e=>e.clearSelection),he=Pi(e=>e.syncVisibleFiles),{folders:me,loading:pe}=f.state,{fetchFolders:ge,fetchChildFolders:ve,handleCreateFolder:ye,handleModalOk:we,handleModalCancel:Ce,generateMenuItems:Ie}=f.actions,Fe=(e=>{var t;const{state:o,actions:r,options:n}=mn(),{t:i}=dr(),a=On(),{folders:l,folderToRename:s,renameFolderForm:c,isRenameFolderModalVisible:u}=o,{setFolderToRename:f,setIsRenameFolderModalVisible:h}=r,{apiEndpoints:m,dataProviders:p,config:g}=n,v=d(e=>{null==f||f(e),null==h||h(!0);const t=null==l?void 0:l.find(t=>t.id===e);t&&c&&c.setFieldsValue({newFolderName:t.name})},[f,h,l,c]),y=d(()=>{null==h||h(!1),null==f||f(null),null==c||c.resetFields()},[h,f,c]),w=d(async()=>{var t,o;if(s&&c)try{const n=await c.validateFields();if(!(null==n?void 0:n.newFolderName))return void a.warning({id:"FOLDER_OPERATION_VALIDATION_FAILED",message:i("Folder name cannot be empty"),placement:"bottomRight",data:{folderId:s,folderName:null==n?void 0:n.newFolderName,reason:"emptyName"}});if(!1===(null===(t=null==g?void 0:g.features)||void 0===t?void 0:t.enableRenameFolder))return void a.error({id:"FOLDER_RENAME_DISABLED_BY_CONFIG",message:i("Folder rename is disabled by config"),placement:"bottomRight",data:{itemId:null!=s?s:void 0,itemName:null==n?void 0:n.newFolderName}});if(!(null==p?void 0:p.renameFolder))throw new Error(i("renameFolder is not implemented in dataProviders"));const l=await p.renameFolder(s,n.newFolderName.trim());if(!(null==l?void 0:l.id))return void a.error({id:"FOLDER_RENAME_FAILED",message:i("Unexpected response when renaming folder"),placement:"bottomRight",data:{itemId:null!=s?s:void 0,itemName:n.newFolderName,error:{message:"invalidResponse"}}});a.success({id:"FOLDER_RENAME_SUCCESS",message:i("Folder renamed"),placement:"bottomRight",data:{itemId:l.id,itemName:l.name,folderId:null!==(o=l.parentId)&&void 0!==o?o:null}}),y(),await e(),s!==l.id&&r.setSelectedFolder&&r.setSelectedFolder(l.id)}catch(e){console.error("Ошибка при переименовании папки:",e),a.error({id:"FOLDER_RENAME_FAILED",message:i("Failed to rename folder"),placement:"bottomRight",innerException:e,data:{itemId:null!=s?s:void 0,itemName:null==c?void 0:c.getFieldValue("newFolderName"),error:{message:e instanceof Error?e.message:String(e)}}})}},[s,c,m,y,e,i,null===(t=null==g?void 0:g.features)||void 0===t?void 0:t.enableRenameFolder,a]);return{state:{isRenamingFolder:u||!1,folderToRename:s},actions:{showRenameFolderModal:v,handleRenameFolderCancel:y,handleRenameFolderOk:w}}})(ge),{files:Ae,loading:_e,isRenamingFile:Se,fileToRename:Ee}=h.state,{fetchFiles:xe,handleDeleteFile:Pe,handleDeleteFolder:Re,handleAddFile:Ne,handleAddFileByUrl:ke,showRenameModal:Oe,handleRenameCancel:Te,handleRenameOk:Le,handleDroppedFiles:Me,showMoveModal:Ue,handleMoveCancel:je,handleMoveOk:De,handleCopyOk:Be,handleCopyCancel:ze,showDeleteConfirm:qe,handleDeleteConfirmCancel:We,handleDeleteConfirmOk:Ve}=h.actions,{selectedFolder:$e,pathHistory:He}=m.state,{handleFolderSelect:Ge,handleItemClick:Ke}=m.actions,{pagination:Qe}=p.state,Je=Pn(xe),{searchTerm:Ye,sortBy:Ze,sortOrder:Xe}=Je.state,{handleSearch:et,handleSort:tt,handlePaginationChange:ot}=Je.actions,rt=d(async()=>{const e=(e=>Vn(e))(He||[]);try{await Gn({options:_,pathFolder:e,dataProviders:null==_?void 0:_.dataProviders})}catch(e){console.error("Cache clear failed:",e)}await ge(),await xe({folderId:$e||"",page:Qe.current,limit:Qe.pageSize,search:Ye,sortBy:Ze,sortOrder:Xe,itemType:"all"})},[xe,ge,_,Qe,He,Ye,$e,Ze,Xe]),nt=(({files:e,fetchFiles:t,selectedFolder:o})=>{var n;const{t:i}=dr(),a=On(),{options:l,actions:s,state:d}=r.useContext(hn),{setActiveLibraryItem:c}=s,{activeLibraryItem:u}=d,f=Ai(),[h,m]=r.useState(!1),[p,g]=r.useState(null),v=r.useCallback(e=>{var t;if(e.type&&e.type.startsWith("image/"))return!0;if(e.extension){const t=e.extension.toLowerCase();return bt.includes(t)}const o=null===(t=e.name.split(".").pop())||void 0===t?void 0:t.toLowerCase();return!!o&&bt.includes(o)},[]),y=r.useCallback(async(e,t)=>{var o,r;const{dataProviders:n}=l;if(!1===(null===(r=null===(o=l.config)||void 0===o?void 0:o.features)||void 0===r?void 0:r.enableUpdateFile))throw new Jn(i("Updating files is disabled by configuration"),"UnsupportedOperation");if(!e.id||!e.thumbnail||!(null==n?void 0:n.updateFile))throw new Jn(i("Failed to save changes"),"UnsupportedOperation");const a=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),s=Tt(a),d=e.name.lastIndexOf("."),c=`${d>0?e.name.substring(0,d):e.name}.${s}`,u=(null==t?void 0:t.blob)||Bt(e.thumbnail,a);return n.updateFile(e.id,{name:c,type:a,data:u})},[l,i]),w=r.useCallback(async(e,t)=>{var o,r,n;if(!e.thumbnail)throw new Jn(i("Failed to save changes"),"ValidationError");const a=!(!0===(null===(o=l.config)||void 0===o?void 0:o.saveCopyToCurrentFolder))||(null!==(r=e.saveWithoutFolder)&&void 0!==r?r:!e.id),s=a?void 0:null!==(n=e.folderId)&&void 0!==n?n:void 0,d=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),c=(null==t?void 0:t.blob)||Bt(e.thumbnail,d),u=new File([c],e.name,{type:d,lastModified:Date.now()}),h=await f.uploadFileWithProvider(u,s,void 0,a);if(!h)throw new Jn(i("Failed to save image copy"),"FileWriteError");return h},[f,null===(n=l.config)||void 0===n?void 0:n.saveCopyToCurrentFolder,i]),b=r.useCallback(t=>{let o;if(t)o=t;else{const t=Pi.getState().selectedFiles;if(1!==t.size)return;const r=Array.from(t)[0];if(o=e.find(e=>e.id===r),!o||o.isFolder||!v(o))return}c&&c(ft),g(o),m(!0)},[e,v,m,c]),C=r.useCallback(()=>{c&&u===ft&&c(at),m(!1),g(null)},[u,c]),I=r.useCallback(async(e,r)=>{var n,s,d,c,u,f;try{const d=await y(e,r);return a.success({id:"IMAGE_UPDATE_SUCCESS",message:i("Success"),description:i("Image updated successfully"),placement:"bottomRight",data:{itemId:null!==(n=null==d?void 0:d.id)&&void 0!==n?n:void 0,itemName:null==d?void 0:d.name,folderId:null!==(s=null==d?void 0:d.folderId)&&void 0!==s?s:null,thumbnail:null==d?void 0:d.thumbnail}}),d&&l.onEditorOk&&l.onEditorOk(d,{mode:r.mode}),await t({folderId:o||""}),C(),null!=d?d:void 0}catch(t){const o=Dn(t),r=null!==(c=null!==(d=Un(null==o?void 0:o.code,i))&&void 0!==d?d:null==o?void 0:o.message)&&void 0!==c?c:i("Failed to save changes");throw a.error({id:"IMAGE_SAVE_FAILED",message:r,innerException:t,placement:"bottomRight",data:{itemId:null!==(u=e.id)&&void 0!==u?u:void 0,itemName:e.name,folderId:null!==(f=e.folderId)&&void 0!==f?f:null,thumbnail:e.thumbnail}}),t.notificationShown=!0,t}},[y,l,t,o,a,C,i]),F=r.useCallback(async(e,r)=>{var n,s,d,c,u,f;try{const d=await w(e,r);return a.success({id:"IMAGE_SAVE_COPY_SUCCESS",message:i("Success"),description:i("Image copy saved successfully"),placement:"bottomRight",data:{itemId:null!==(n=null==d?void 0:d.id)&&void 0!==n?n:void 0,itemName:null==d?void 0:d.name,folderId:null!==(s=null==d?void 0:d.folderId)&&void 0!==s?s:null,thumbnail:null==d?void 0:d.thumbnail}}),d&&l.onEditorOk&&l.onEditorOk(d,{mode:r.mode}),await t({folderId:o||""}),C(),null!=d?d:void 0}catch(t){const o=Dn(t),r=null!==(c=null!==(d=Un(null==o?void 0:o.code,i))&&void 0!==d?d:null==o?void 0:o.message)&&void 0!==c?c:i("Failed to save image copy");throw a.error({id:"IMAGE_SAVE_COPY_FAILED",message:r,innerException:t,placement:"bottomRight",data:{itemId:null!==(u=e.id)&&void 0!==u?u:void 0,itemName:e.name,folderId:null!==(f=e.folderId)&&void 0!==f?f:null,thumbnail:e.thumbnail}}),t.notificationShown=!0,t}},[w,l,t,o,a,C,i]);return{isPixieEditorVisible:h,editingFile:p,handleEdit:b,handlePixieEditorSave:I,handlePixieEditorSaveCopy:F,handlePixieEditorClose:C}})({files:Ae||[],fetchFiles:xe,selectedFolder:$e||null}),[it,mt]=i(!1),pt=d(e=>{if(e.preventDefault(),e.stopPropagation(),!e.dataTransfer||!e.dataTransfer.types||!e.dataTransfer.types.includes("Files"))return;e.dataTransfer.dropEffect="copy";const t=e.relatedTarget,o=e.currentTarget;t&&o.contains(t)||(re.current+=1,re.current>0&&Z(!0))},[]),gt=d(e=>{e.preventDefault(),e.stopPropagation();const t=e.relatedTarget,o=e.currentTarget;if(t&&!o.contains(t))re.current=Math.max(0,re.current-1),re.current<=0&&Z(!1);else if(t){const e=t.closest('[class*="dragOverlay"]');if(e&&o.contains(e))return}},[]),vt=d(e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")},[]),yt=d(e=>{e.preventDefault(),e.stopPropagation(),Z(!1),re.current=0;const t=(()=>{var t;const o=e.dataTransfer;if(!o)return[];if(null===(t=o.files)||void 0===t?void 0:t.length)return Array.from(o.files);const r=[];if(o.items)for(let e=0;e<o.items.length;e++){const t=o.items[e].getAsFile();t&&r.push(t)}return r})();t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error("Ошибка при загрузке файлов:",e)}).finally(()=>{mt(!1)}))},[Me]),wt=d(()=>{Z(!1),re.current=0,document.body.removeAttribute("data-fm-dragging"),oe(!1),ee(!1)},[]);n.useEffect(()=>{ae.current=Ae||[]},[Ae]);const Ct=null==E?void 0:E.activeLibraryItem;a(()=>{const e=e=>{e?document.body.setAttribute("data-fm-dragging","true"):document.body.removeAttribute("data-fm-dragging")};let t=!1;const o=o=>{var r,n;!t&&(null===(n=null===(r=o.dataTransfer)||void 0===r?void 0:r.types)||void 0===n?void 0:n.includes("Files"))&&(t=!0,oe(!0),e(!0),Ct===at&&ee(!0))},r=o=>{const r=o.relatedTarget;(!r||!document.documentElement.contains(r))&&t&&(t=!1,oe(!1),ee(!1),e(!1))};return window.addEventListener("dragenter",o,!0),window.addEventListener("dragleave",r,!0),()=>{window.removeEventListener("dragenter",o,!0),window.removeEventListener("dragleave",r,!0),document.body.removeAttribute("data-fm-dragging")}},[Ct]),a(()=>{const e=e=>{var t,o;if(document.body.removeAttribute("data-fm-dragging"),oe(!1),!(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files")))return;e.preventDefault();const r=(e=>{var t;if(!e)return[];if(null===(t=e.files)||void 0===t?void 0:t.length)return Array.from(e.files);const o=[];if(e.items)for(let t=0;t<e.items.length;t++){const r=e.items[t].getAsFile();r&&o.push(r)}return o})(e.dataTransfer);if(!r.length)return;const n=e.target,i=n.closest(`.${ta.filesContainer.replace(/\s+/g,".")}`)||n.closest("[data-files-container]"),a=n.closest(".em-filemanager")||n.closest(".file-manager__layout")||n.closest("[data-drop-overlay]")||n.closest("[data-drag-capture]");(ne.current||Y||i||a)&&(e.preventDefault(),e.stopPropagation(),ee(!1),Z(!1),re.current=0,mt(!0),Me(r).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error("Ошибка при загрузке файлов:",e)}).finally(()=>mt(!1)))},t=e=>{var t,o;(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",document.body.hasAttribute("data-fm-dragging")||(document.body.setAttribute("data-fm-dragging","true"),oe(!0)),Ct!==at||ne.current||ee(!0))},o=e=>{var t,o;(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",document.body.setAttribute("data-fm-dragging","true"),oe(!0))},r={capture:!0,passive:!1};return window.addEventListener("drop",e,r),window.addEventListener("dragover",t,r),window.addEventListener("dragenter",o,r),()=>{window.removeEventListener("drop",e,r),window.removeEventListener("dragover",t,r),window.removeEventListener("dragenter",o,r)}},[Y,Me,Ct]),a(()=>{const e=e=>{Y&&wt(),ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging")};return window.addEventListener("dragend",e,!0),()=>window.removeEventListener("dragend",e,!0)},[Y,wt]),a(()=>{let e=null;const t=t=>{Y&&(e=setTimeout(()=>{Y&&wt()},200))};return document.addEventListener("mouseup",t,!0),()=>{document.removeEventListener("mouseup",t,!0),e&&clearTimeout(e)}},[Y,wt]),a(()=>{const e=e=>{"Escape"===e.key&&Y&&wt()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[Y,wt]),a(()=>{const e=e=>{Y&&setTimeout(()=>{Y&&wt()},100)};return document.addEventListener("click",e,!0),()=>{document.removeEventListener("click",e,!0)}},[Y,wt]);const Ft=n.useCallback(async()=>{await Ve(),await ge(),$e===ht&&ve&&await ve(ht),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var e,t;return null===(t=null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts)||void 0===t?void 0:t.call(e)})})},[ge,ve,Ve,$e]),At=n.useCallback(()=>{ce(!0)},[]),_t=n.useCallback(async()=>{var e,t;if($e!==ht)return console.error("Clear trash called outside of trash folder"),void ce(!1);try{if(null==P?void 0:P.cleanTrash){const t=await P.cleanTrash();await xe({folderId:ht}),await(null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts()),t.success?b.success({id:"TRASH_CLEARED_SUCCESS",message:C("Trash cleared successfully"),description:C("{{count}} items permanently deleted",{count:t.deletedCount||0}),placement:"bottomRight"}):b.error({id:"TRASH_CLEAR_FAILED",message:C("Failed to clear trash"),placement:"bottomRight"})}else{const e=ae.current||[];if(0===e.length)return void ce(!1);const o=e.map(e=>({id:e.id,isFolder:e.isFolder})),r=await w({items:o,selectedFolder:ht,getItemNameById:t=>{var o;return(null===(o=e.find(e=>e.id===t))||void 0===o?void 0:o.name)||t||""},showNotifications:!1});await xe({folderId:ht}),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts());const{successCount:n,failCount:i}=r;0===i?b.success({id:"TRASH_CLEARED_SUCCESS",message:C("Trash cleared successfully"),description:C("{{count}} items permanently deleted",{count:n}),placement:"bottomRight"}):n>0?b.warning({id:"TRASH_CLEARED_PARTIAL",message:C("Trash partially cleared"),description:C("{{succeeded}} items deleted, {{failed}} items failed",{succeeded:n,failed:i}),placement:"bottomRight"}):b.error({id:"TRASH_CLEAR_FAILED",message:C("Failed to clear trash"),placement:"bottomRight"})}ce(!1)}catch(e){console.error("Error clearing trash:",e),b.error({id:"TRASH_CLEAR_ERROR",message:C("Error clearing trash"),placement:"bottomRight"}),ce(!1)}},[$e,P,xe,b,C,w]),St=n.useCallback(()=>{ce(!1)},[]),Et=n.useCallback(async e=>{var t;await De(e),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[De]),xt=n.useCallback(async e=>{var t;await Be(e),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[Be]),Rt=n.useCallback(async()=>{let e=[],t=new Map;const o=null==_?void 0:_.config;await Ne({onStartBatch:r=>{e=v.startUpload($e||void 0,r),t=new Map,r.forEach((r,n)=>{const i=e[n];i&&(t.set(r.name,i),t.set(Yt(r.name,o),i))})},onStart:r=>{if(0===e.length){e=v.startUpload($e||void 0,[r]);const n=e[0];n&&(t.set(r.name,n),t.set(Yt(r.name,o),n))}},onProgress:(e,o)=>{const r=t.get(e);r&&v.updateProgress(r,o)},onComplete:async e=>{var o;const r=t.get(e);if(r){await new Promise(e=>setTimeout(e,100));const t=null==Ae?void 0:Ae.find(t=>t.name===e&&!t.isFolder);v.markAsSuccess(r,t)}await(null===(o=ie.current)||void 0===o?void 0:o.refreshFileCounts())},onError:(o,r,n)=>{var i;const a=null!==(i=t.get(o))&&void 0!==i?i:null!=n&&n<e.length?e[n]:void 0;a&&v.markAsError(a,r)},onBatchComplete:async o=>{var r,n,i,a,l,s,d,c;for(let c=0;c<o.successes.length;c++){const u=o.successes[c],f=null===(r=o.uploadedFiles)||void 0===r?void 0:r.get(u),h=null!==(a=null!==(i=null!==(n=t.get(u))&&void 0!==n?n:(null==f?void 0:f.originalFileName)?t.get(f.originalFileName):void 0)&&void 0!==i?i:null!=(null==f?void 0:f.originalIndex)&&f.originalIndex<e.length?e[f.originalIndex]:void 0)&&void 0!==a?a:c<e.length?e[c]:void 0;if(h){let e;if(null==f?void 0:f.id){const t=f;e={id:t.id,name:null!==(l=t.name)&&void 0!==l?l:u,folderId:null!==(d=null!==(s=t.folderId)&&void 0!==s?s:$e)&&void 0!==d?d:null,isFolder:!1,size:t.size}}else await new Promise(e=>setTimeout(e,100)),e=null==Ae?void 0:Ae.find(e=>e.name===u&&!e.isFolder);v.updateProgress(h,100),v.markAsSuccess(h,e)}}o.errors.forEach(({fileName:e,error:o})=>{const r=t.get(e);r&&v.markAsError(r,o)}),await(null===(c=ie.current)||void 0===c?void 0:c.refreshFileCounts())}})},[Ne,v,Ae,$e,null==_?void 0:_.config]),Nt=n.useCallback(async(e,t,o,r)=>{var n,i;try{se(!0);let a=o||"uploaded-file";if(!o&&e){const t=e.split("?")[0].split("#")[0].split("/");a=t[t.length-1]||"uploaded-file";a.includes(".")&&(null===(n=a.split(".").pop())||void 0===n?void 0:n.length)&&a.split(".").pop().length<=5||(a+=".jpg")}const l=v.startUploadByUrl($e||void 0,a);try{const o=await ke(e,t,!0,null!=r?r:"uploadByUrl");if(v.updateProgress(l,100),o){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===o.id&&!e.isFolder))||o;v.markAsSuccess(l,e)}else v.markAsSuccess(l);await(null===(i=ie.current)||void 0===i?void 0:i.refreshFileCounts())}catch(e){const t=Dn(e),o=Wn(t,C);v.markAsError(l,o)}}finally{se(!1)}},[ke,v,$e,Ae,C]),kt=n.useCallback(async({file:e})=>{var t;const o=v.startUpload($e||void 0,[e])[0];let r=0;const n=setInterval(()=>{r=Math.min(r+10+Math.floor(Date.now()%10),90),v.updateProgress(o,r)},200);try{const r=await y.uploadFileWithProvider(e,void 0,!0);if(clearInterval(n),v.updateProgress(o,100),r){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===r.id&&!e.isFolder))||r;v.markAsSuccess(o,e)}else v.markAsSuccess(o);const i=r&&r.folderId||$e||null;return Ge&&Ge(i&&"folders"!==i?i:"folders"),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts()),r}catch(e){clearInterval(n);const t=e instanceof Error?e.message:String(e);throw v.markAsError(o,t),e}},[y,v,$e,Ae,Ge]),Lt=n.useCallback(async e=>{var t;if(Me){const o=v.startUpload($e||void 0,e);e.forEach(async(e,t)=>{const r=o[t];if(!r)return;let n=0;const i=setInterval(()=>{n=Math.min(n+10+Math.floor(Date.now()%10),85),v.updateProgress(r,n)},200);setTimeout(()=>{clearInterval(i)},2e3)}),await Me(e),o.forEach(e=>{v.updateProgress(e,100),v.markAsSuccess(e)}),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())}},[Me,v,$e]),Mt=n.useCallback(async e=>{var t;await Re(e),await ge(),await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())},[Re,ge]),Ut=(({files:e,clearSelection:t,showRenameModal:o,showMoveModal:n,showCopyModal:i,handleDeleteFile:a,handleDeleteFolder:l,showDeleteConfirm:s,onEdit:d})=>{const c=r.useCallback(()=>{t()},[t]),u=r.useCallback(e=>{const t=Pi.getState().selectedFiles;if(t&&1===t.size||e){const r=e||Array.from(t)[0];o(r)}},[o]),f=r.useCallback(t=>{const o=Pi.getState().selectedFiles;if(o&&o.size>0||(null==t?void 0:t.id)){if(s)return void s();(t?[t.id]:o).forEach(t=>{const o=e.find(e=>e.id===t);o?o.isFolder?l(t):a(t):console.warn(`Объект с ID ${t} не найден в списке файлов`)})}},[e,a,l,s]);return{handleClearSelection:c,handleRename:u,handleDeleteSelected:f,handleCopy:r.useCallback(()=>{i()},[i]),handleMove:r.useCallback(()=>{n()},[n]),handleEdit:r.useCallback(()=>{d()},[d])}})({files:Ae||[],clearSelection:fe,showRenameModal:Oe,showMoveModal:Ue,showCopyModal:h.actions.showCopyModal||(()=>{}),handleDeleteFile:Pe,handleDeleteFolder:Mt,showDeleteConfirm:qe,onEdit:nt.handleEdit}),jt=pe||_e||it;a(()=>{Pt()},[]),g(()=>{$!==at?fe():he(Ae||[])},[$,Ae,he,fe]),a(()=>{if(!S||$!==at)return;if(!vo.current)return void(vo.current=!0);const e=(Array.isArray(Ae)?Ae:[]).filter(e=>ue.has(e.id));S(e)},[$,Ae,ue,S]),n.useEffect(()=>{if(!Ge||0===me.length)return;const e=!1!==(null==x?void 0:x.rememberLastFolder),t=`em_fm:lastFolder:${(null==x?void 0:x.projectId)||"default"}`;if(e&&"undefined"!=typeof window)try{const e=localStorage.getItem(t);if(e&&me.some(t=>t.id===e))return void Ge(e)}catch(e){}$e||Ge("folders")},[$e,Ge,me,null==x?void 0:x.rememberLastFolder,null==x?void 0:x.projectId]);const{handleRenameFolderCancel:Dt,handleRenameFolderOk:zt}=Fe.actions;a(()=>{const e=async e=>{if($!==at)return;const t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||"true"===(null==t?void 0:t.getAttribute("contenteditable")))return;const o=e.clipboardData;if(!o)return;const r=Array.from(o.items),n=r.filter(e=>e.type.startsWith("image/"));if(n.length>0){const t=n.map(e=>e.getAsFile()).filter(e=>null!==e);return void(t.length>0&&(e.preventDefault(),await Lt(t)))}const i=r.find(e=>"text/plain"===e.type);i&&i.getAsString(async t=>{const o=t.trim();if(o.startsWith("http://")||o.startsWith("https://"))e.preventDefault(),await Nt(o);else if(o.includes("<meta")||o.includes("http")){const t=o.match(/https?:\/\/[^\s"']+/);t&&(e.preventDefault(),await Nt(t[0]))}})};return document.addEventListener("paste",e),()=>{document.removeEventListener("paste",e)}},[$,Nt,Lt]);const qt=c(Qe);a(()=>{qt.current=Qe},[Qe]);const Wt=d(e=>{ot(e.current||qt.current.current,e.pageSize||qt.current.pageSize)},[ot]),Vt=d(e=>{null==Ke||Ke(e)},[Ke]),$t=n.useCallback(e=>{const{sortBy:t,sortOrder:o}=(e=>{const[t,o]=e.split("-");return{sortBy:t,sortOrder:o}})(e);tt(t,o)},[tt]),[Ht,Gt]=i(ss),[Kt,Qt]=i([]),Jt=c(null),[Zt,Xt]=i(It),[eo,to]=i([]),oo=c(null),[ro,no]=i(""),io=c(null),[ao,lo]=i(""),[so,co]=i([]),uo=n.useRef(void 0),[fo,ho]=i(!1),[mo,po]=i(!1),go=n.useRef(null),vo=n.useRef(!1),[yo,wo]=i({mode:"qr",rawText:"",foregroundHex:"#000000",backgroundHex:"#ffffff",transparentBackground:!1,qrSidePx:200,barcodeBarHeightPx:60}),bo=n.useRef($),Co=n.useCallback(e=>{const t=e.indexOf(",");if(-1===t)return null;const o=e.substring(0,t),r=o.match(/^data:([^;]+)/),n=r&&r[1]||"image/svg+xml";let i,a="svg";if(n.includes("png")?a="png":(n.includes("jpeg")||n.includes("jpg"))&&(a="jpg"),/;base64/i.test(o)){const o=e.substring(t+1),r=atob(o),a=new Uint8Array(r.length);for(let e=0;e<r.length;e+=1)a[e]=r.charCodeAt(e);i=new Blob([a],{type:n})}else{const o=decodeURIComponent(e.substring(t+1));i=new Blob([o],{type:n})}return new File([i],`icon_${Date.now()}.${a}`,{type:n})},[]),Io=n.useCallback(async e=>{var t;const o=v.startUpload($e||void 0,[e])[0];let r=0;const n=setInterval(()=>{r=Math.min(r+10+Math.floor(Date.now()%10),90),v.updateProgress(o,r)},200);try{const r=await y.uploadFileWithProvider(e,void 0,!0);if(clearInterval(n),v.updateProgress(o,100),r){await new Promise(e=>setTimeout(e,100));const e=(null==Ae?void 0:Ae.find(e=>e.id===r.id&&!e.isFolder))||r;v.markAsSuccess(o,e)}else v.markAsSuccess(o);await(null===(t=ie.current)||void 0===t?void 0:t.refreshFileCounts())}catch(e){clearInterval(n);const t=e instanceof Error?e.message:String(e);throw v.markAsError(o,t),e}},[v,Ae,y,$e]),Fo=d(async e=>{if(Boolean(e&&e.startsWith("data:"))){const t=Co(e);if(!t)return;return void await Io(t)}e&&await Nt(e,void 0,void 0,"iconStock")},[Co,Nt,Io]),Ao=d(async()=>{const e=null==Q?void 0:Q.fileForEdit;if(uo.current===e)return;if($===ft&&e&&!nt.editingFile){uo.current=e;try{if("string"==typeof e){if(e.startsWith("data:"))return void(null==nt||nt.handleEdit({thumbnail:e,saveWithoutFolder:!0}));const t=await y.resolveFileForEditByUrl(e);uo.current===e&&(null==nt||nt.handleEdit(t))}}catch(t){uo.current===e&&(uo.current=null),console.error("Failed to open file in editor:",t),null==nt||nt.handlePixieEditorClose()}}},[null==Q?void 0:Q.fileForEdit,$,nt,y]);a(()=>{Ao()},[Ao]),a(()=>{var e,t,o,r;const n=bo.current;bo.current=$,$===at?(Qt([]),Gt(ss),to([]),Xt(It),co([]),lo(""),po(!1),ho(!1),n===at||n!==st&&n!==lt&&n!==ct||et("")):$===ct?null===(e=go.current)||void 0===e||e.focus():$===lt?null===(t=Jt.current)||void 0===t||t.focus():$===st?null===(o=oo.current)||void 0===o||o.focus():$===dt&&(null===(r=io.current)||void 0===r||r.focus())},[$,et]);const _o=n.useCallback(async()=>{var e;await zt(),await(null===(e=ie.current)||void 0===e?void 0:e.refreshFileCounts())},[zt]),So=d(e=>{var t;return e?(null===(t=e.files)||void 0===t?void 0:t.length)?Array.from(e.files):e.items?Array.from(e.items).map(e=>e.getAsFile()).filter(e=>Boolean(e)):[]:[]},[]);return t(o,{children:[te&&Ct===at&&be(e("div",{className:ta.dragCaptureLayer,"data-drag-capture":"true",onDragOver:e=>{var t,o;e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy"),(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&!ne.current&&ee(!0)},onDragEnter:e=>{var t,o;e.preventDefault(),e.stopPropagation(),(null===(o=null===(t=e.dataTransfer)||void 0===t?void 0:t.types)||void 0===o?void 0:o.includes("Files"))&&ee(!0)},onDragLeave:e=>{const t=e.relatedTarget;t&&document.documentElement.contains(t)||(ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging"))},onDrop:e=>{e.preventDefault(),e.stopPropagation(),oe(!1),ee(!1),document.body.removeAttribute("data-fm-dragging");const t=So(e.dataTransfer);t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error(e)}).finally(()=>mt(!1)))},"aria-hidden":"true"}),document.body),X&&be(e("div",{className:ta.dragOverlayGlobal,"data-drop-overlay":"true",onDragOver:e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")},onDragEnter:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.stopPropagation(),ee(!1),oe(!1),document.body.removeAttribute("data-fm-dragging");const t=So(e.dataTransfer);t.length&&(mt(!0),Me(t).catch(e=>{"StaleLoad"!==(null==e?void 0:e.name)&&console.error(e)}).finally(()=>mt(!1)))},"aria-hidden":"true",children:t("div",{className:ta.dragOverlayInner,children:[e("div",{className:ta.uploadIcon,children:e(J,{})}),e("div",{className:ta.textTitle,children:C("Drop files here to upload")}),e("div",{className:ta.textDescription,children:C("Supported files:")+" .jpg, .jpeg, .svg, .png"})]})}),document.body),e(H,{className:"file-manager__layout",children:t("div",{className:ta.filesContainer,"data-files-container":"true",onDragOver:vt,onDragLeave:gt,onDragEnter:pt,onDrop:yt,children:[Y&&e("div",{className:ta.dragOverlay,children:t("div",{className:ta.dragOverlayInner,children:[e("div",{className:ta.uploadIcon,children:e(J,{})}),e("div",{className:ta.textTitle,children:C("Drop files here to upload")}),e("div",{className:ta.textDescription,children:C("Supported files:")+" .jpg, .jpeg, .svg, .png"})]})}),t(H,{className:"file-manager__content",children:[e(ns,{width:320,theme:"light",className:"file-manager-sider",children:e($a,{ref:ie,selectedFolder:$e||"folders",generateMenuItems:Ie,onFolderSelect:e=>null==Ge?void 0:Ge(e),folders:me||[],fetchFolders:ge,fetchChildFolders:ve,handleAddFile:Rt,setIsUrlModalVisible:e=>null==G?void 0:G(e),handleDeleteFolder:Mt,handleCreateFolder:ye,activeLibraryItem:$,setActiveLibraryItem:e=>null==K?void 0:K(e)})}),t(H,{className:"file-manager__main-content",children:[it&&e(ja,{style:{position:"absolute",width:"100%",height:"100%",top:0,left:0,zIndex:100,background:"var(--colorBgLayout)"}}),t(is,{className:"main-content",children:[e(Tl,{activeLibraryItem:$,selectedFolder:(null===(l=null==me?void 0:me.find(e=>(null==e?void 0:e.id)===$e))||void 0===l?void 0:l.name)||C("Folders"),isTrashFolder:"Trash"===$e,onClearTrash:At,files:Ae||[],loading:jt,onRefresh:rt,refreshDisabled:_e||pe,showRefresh:!(!(null===(s=null==_?void 0:_.apiEndpoints)||void 0===s?void 0:s.clearCache)&&!(null===(u=null==_?void 0:_.dataProviders)||void 0===u?void 0:u.clearCache))}),e(W,{className:"zero-divider"}),$===at&&e(Ea,{searchTerm:Ye,handleAddFile:Rt,files:Ae||[],handleSearch:et,sortBy:Ze,sortOrder:Xe,handleSortOptionChange:$t,pagination:Qe,setPagination:Wt,loading:jt,handleItemClick:Vt,onClearSelection:Ut.handleClearSelection,onRename:Ut.handleRename,onCopy:Ut.handleCopy,onMove:Ut.handleMove,onDelete:Ut.handleDeleteSelected,showRenameModal:Oe,showDeleteConfirm:qe,showCopyModal:h.actions.showCopyModal||(()=>{}),showMoveModal:Ue,onEdit:nt.handleEdit,getFileData:y.getFileData}),$===lt&&e(ql,{imageGifList:Kt,setImageGifList:Qt,currentReqGif:Ht,setCurrentReqGif:Gt,inputRef:Jt,customRequest:(e,t)=>Nt(e,void 0,t,"gif")}),$===st&&e(Hl,{imageStockList:eo,setImageStockList:to,currentReq:Zt,setCurrentReq:Xt,inputRef:oo,customRequest:(e,t)=>Nt(e,void 0,t,"imageStock")}),$===dt&&e(n.Suspense,{fallback:e("div",{style:{display:"flex",justifyContent:"center",padding:"48px 0"},children:e(U,{size:"large"})}),children:e(as,{customRequest:Fo,query:ro,setQuery:no,inputRef:io})}),$===ut&&e(n.Suspense,{fallback:e("div",{style:{display:"flex",justifyContent:"center",padding:"48px 0"},children:e(U,{size:"large"})}),children:e(ls,{customRequest:kt,state:yo,setState:wo})}),$===ct&&!!(null==Q?void 0:Q.sseQuery)&&e(os,{imageAiList:so,setImageAiList:co,aiImageRequest:ao,setAiImageRequest:lo,inputAiRef:go,customRequest:kt,isLoadingAi:fo,setIsLoadingAi:ho,isImageUploaded:mo,setIsImageUploaded:po}),$===ft&&e(o,{})]})]})]}),le&&!v.isUploadVisible&&e("div",{style:{position:"fixed",inset:0,zIndex:1500,backgroundColor:"rgba(255, 255, 255, 0.5)",pointerEvents:"all",display:"flex",alignItems:"center",justifyContent:"center"},children:e(U,{size:"large"})}),e(Wa,{isModalVisible:M,handleModalOk:we,handleModalCancel:Ce,form:R,selectedFolder:$e||null,folders:me||[],isUrlModalVisible:j,setIsUrlModalVisible:e=>null==G?void 0:G(e),handleAddFileByUrl:Nt,urlForm:N,isRenameModalVisible:Se,handleRenameOk:()=>null==Le?void 0:Le(),handleRenameCancel:()=>null==Te?void 0:Te(),renameForm:k,fileToRename:Ee,files:Ae||[],isMoveModalVisible:D,handleMoveOk:Et,handleMoveCancel:je,moveForm:O,selectedFiles:ue||new Set,isRenameFolderModalVisible:B,handleRenameFolderOk:_o,handleRenameFolderCancel:Dt,renameFolderForm:T,folderToRename:V,isCopyModalVisible:z,handleCopyOk:xt,handleCopyCancel:ze,copyForm:L,isDeleteConfirmVisible:q,handleDeleteConfirmOk:Ft,handleDeleteConfirmCancel:()=>null==We?void 0:We(),isClearTrashConfirmVisible:de,handleClearTrashConfirm:_t,handleClearTrashCancel:St,fetchChildFolders:ve}),e(ol,{visible:nt.isPixieEditorVisible,onClose:nt.handlePixieEditorClose,file:nt.editingFile,onSave:nt.handlePixieEditorSave,onSaveCopy:nt.handlePixieEditorSaveCopy}),e(Nl,{files:v.uploadFiles,visible:v.isUploadVisible,minimized:v.isUploadMinimized,totalFiles:v.totalFiles,completedFiles:v.completedFiles,onClose:v.closeUpload,onMinimize:v.minimizeUpload,onInsert:e=>{var t;const o=v.getUploadedFile(e.id)||e;null===(t=I.onEditorOk)||void 0===t||t.call(I,o)}})]})})]})},cs=h(({config:r={},onPathChange:i,onChangeSelection:l,onEditorOk:s,searchQuery:u="",sortBySize:f="name",apiEndpoints:h={},customIcons:m,dragDropIcon:p,dataProviders:g,handleNotify:v,handleError:y,handleSuccess:b})=>{const I=n.useMemo(()=>Object.assign({folderTreeLoading:"lazy",expandAllFoldersOnInit:!1,expandRootFolderOnInit:!1,iconStrokeWidth:1.4,availableImageExtensions:["jpg","jpeg","png","gif"],fileNameProcessing:Object.assign(Object.assign({},{transliterate:!0,replaceSpaces:!0,removeForbiddenChars:!0,toLowerCase:!0}),r.fileNameProcessing),folderNameProcessing:Object.assign(Object.assign({},{transliterate:!0,replaceSpaces:!0,removeForbiddenChars:!0,toLowerCase:!0}),r.folderNameProcessing)},r),[r]);n.useEffect(()=>{I.theme&&(e=>{if("system"===e){const t=matchMedia(vt).matches?pt:mt;e=e===gt?t:e}document.documentElement.setAttribute("data-theme",e)})(I.theme),rs(I)},[I]),a(()=>{I.locale&&I.locale!==Vo.language&&Vo.changeLanguage(I.locale),I.customLocale&&I.locale&&Vo.addResourceBundle(I.locale,"translation",I.customLocale,!0,!0)},[I.locale,I.customLocale]);const F=c(null),A=d(()=>{var e;return null!==(e=F.current)&&void 0!==e?e:document.body},[]),_=n.useMemo(()=>({apiEndpoints:h,searchQuery:u,sortBySize:f,onPathChange:i,onChangeSelection:l,onEditorOk:s,config:I,customIcons:m,dragDropIcon:p,dataProviders:g,handleNotify:v,handleError:y,handleSuccess:b,getModalContainer:A}),[h,u,f,i,l,s,I,m,p,g,v,y,b,A]);return e(C,{className:"em-filemanager",children:t(o,{children:[e(w,{getPopupContainer:()=>F.current||document.body,children:e(pn,{options:_,children:e(ds,{})})}),e("div",{ref:F,className:"file-manager-modal-root"})]})})});cs.displayName="FileManagerApp";const us=J.ErrorBoundary,fs=t=>{var o,r,n;return e(cr,{i18n:Vo,children:e(_t,{externalTheme:null!==(r=null===(o=t.config)||void 0===o?void 0:o.theme)&&void 0!==r?r:"light",customThemeToken:null===(n=t.config)||void 0===n?void 0:n.customTheme,children:e(us,{children:e(cs,Object.assign({},t))})})})},hs=new Map,ms=(t,o)=>{var r;let n;Pt();let i={};const a=e=>{const t=!e||"fileManager"!==e.mode&&"imageCenter"!==e.mode&&"plugin"!==e.mode?void 0:e.mode;return"imageCenter"===t?Et("imageCenter",e):Et(t)};if(t instanceof HTMLElement){n=t;i={config:a(o),apiEndpoints:null==o?void 0:o.apiEndpoints}}else{n=t.element;const e=a(t.config),o=Object.assign(Object.assign({},null===(r=t.config)||void 0===r?void 0:r.apiEndpoints),t.apiEndpoints);i={config:e,currentPath:t.currentPath,onPathChange:t.onPathChange,onChangeSelection:t.onChangeSelection,searchQuery:t.searchQuery,sortBySize:t.sortBySize,apiEndpoints:o,dataProviders:t.dataProviders,customIcons:t.customIcons,dragDropIcon:t.dragDropIcon,handleNotify:t.handleNotify,handleError:t.handleError,handleSuccess:t.handleSuccess}}const l=v(n);l.render(e(fs,Object.assign({},i))),hs.set(n.id||`container_${Date.now()}`,l)},ps=e=>{const t=e.id||Object.keys(hs).find(e=>e.startsWith("container_"));if(t&&hs.has(t)){const e=hs.get(t);null==e||e.unmount(),hs.delete(t)}else{console.warn("Couldn t find the root to unmount");try{v(e).unmount()}catch(e){console.error("Error unmounting the component:",e)}}},gs=new Map,vs=r=>{const{onClose:i,onSave:l,dataProviders:s,theme:u,locale:f,hasPagination:h,disablePagination:m,paginationAvailable:p,dedupeUploadNamesOnClient:g,saveCopyToCurrentFolder:v}=r,y=n.useMemo(()=>{var e,t;return{theme:null!=u?u:"light",locale:f,baseUrl:r.baseUrl,assetsUrl:r.assetsUrl,compressMaxSize:r.compressMaxSize,compressMaxWidthOrHeight:r.compressMaxWidthOrHeight,compessorUrl:null!==(e=r.compessorUrl)&&void 0!==e?e:r.compressorUrl,compressorUrl:null!==(t=r.compressorUrl)&&void 0!==t?t:r.compessorUrl,showNotifications:r.showNotifications,fetchWithProxy:r.fetchWithProxy,handleFileProxy:r.handleFileProxy,hasPagination:h,disablePagination:m,paginationAvailable:p,dedupeUploadNamesOnClient:g,saveCopyToCurrentFolder:v}},[u,f,r.baseUrl,r.assetsUrl,r.compressMaxSize,r.compressMaxWidthOrHeight,r.compessorUrl,r.compressorUrl,r.showNotifications,r.fetchWithProxy,r.handleFileProxy,h,m,p,g,v]),b=n.useCallback(async(e,t,o,r)=>{if(!e&&!t||!(null==s?void 0:s.getFiles))return null;try{const n=await s.getFiles({folderId:r?void 0:null!=o?o:void 0,noFolder:r,search:t||void 0,itemType:"file",page:1,limit:1}),[i]=n.files;return i?e&&i.id!==e?null:i:null}catch(e){return console.warn("Standalone Pixie: failed to resolve uploaded file from provider",e),null}},[s]),I=n.useCallback(async e=>{var t;if(!e||"function"!=typeof(null==s?void 0:s.getFileById))return null;try{return null!==(t=await s.getFileById(e))&&void 0!==t?t:null}catch(e){return console.warn("Standalone Pixie: failed to resolve uploaded file by id",e),null}},[s]),F=n.useMemo(()=>{if(r.file)return r.file;const e=r.name||"edited-image",t=r.extension||(r.type?r.type.split("/")[1]:"png"),o=r.type||`image/${t}`;return{thumbnail:r.imageDataUrl||"",name:e,id:void 0,type:o,extension:t,saveWithoutFolder:!0}},[r.file,r.imageDataUrl,r.name,r.extension,r.type]),A=n.useCallback(async(e,t)=>{if((null==s?void 0:s.updateFile)&&e.thumbnail)try{const o=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),r=Tt(o),n=e.name.substring(0,e.name.lastIndexOf("."))+"."+r,i=(null==t?void 0:t.blob)||Bt(e.thumbnail,o);return await s.updateFile(e.id,{name:n,type:o,data:i})}catch(e){return console.error("Error updating the file through updateFile:",e),null}return console.warn("DataProvider for updating files is not configured"),null},[s]),_=n.useCallback(async(e,t)=>{var o,r,n,i,a;if(!e.thumbnail)return null;try{const l=!0!==y.saveCopyToCurrentFolder||(null!==(o=e.saveWithoutFolder)&&void 0!==o?o:!e.id),d=l?"":e.folderId||"",c=(null==t?void 0:t.mimeType)||Ot(e.thumbnail,e.type),u=(null==t?void 0:t.blob)||Bt(e.thumbnail,c),f=Yt(e.name,y),h=await Lr(s,f,d,l,Xt(y)),m=new File([u],h,{type:c,lastModified:Date.now()});if(null==s?void 0:s.uploadFiles){const t=await s.uploadFiles({items:[{name:m.name,size:m.size,type:m.type,folderId:d,noFolder:l,data:m,extension:Tt(c)}],folderId:d}),o=null===(r=t.detailed)||void 0===r?void 0:r[0];if(t.success&&(null==o?void 0:o.success)&&o.data){const t=o.data;if(t.url||t.thumbnailUrl||t.thumbnail)return{id:t.id||e.id||"",name:t.name||e.name,folderId:null!==(n=t.folderId)&&void 0!==n?n:d,type:t.type||m.type,size:null!==(i=t.size)&&void 0!==i?i:m.size,extension:t.extension||Tt(c),url:t.url,thumbnailUrl:t.thumbnailUrl,thumbnail:t.thumbnail,date:t.date,dimensions:t.dimensions,aspectRatio:t.aspectRatio,sourceUrl:t.sourceUrl,isFolder:!1,selected:!1};const r=await b(o.data.id,o.data.name||m.name,null!==(a=o.data.folderId)&&void 0!==a?a:d,l);if(r)return r;const s=await I(o.data.id);return s||null}}if(null==s?void 0:s.uploadFile){const e=await s.uploadFile({name:m.name,size:m.size,type:m.type,folderId:d,noFolder:l,data:m,extension:Tt(c)});if(!e)return null;if(e.url||e.thumbnailUrl||e.thumbnail)return e;const t=await I(e.id);return t||null}return null}catch(e){return console.error("Error saving file copy:",e),null}},[s,b,I,y]),S=n.useCallback(async(e,t)=>{if((null==s?void 0:s.updateFile)&&e.id&&e.thumbnail)try{const o=await A(e,t);o&&(e=o)}catch(e){console.error("Standalone Pixie: saveFileToServer error",e)}return l&&await l(e,t),i&&i(),e},[s,l,i,A]),E=n.useCallback(async(e,t)=>{if(e.thumbnail)try{const o=await _(e,t);if(!o)return;return l&&await l(o,t),i&&i(),o}catch(e){return void console.error("Standalone Pixie: saveFileCopyToServer error",e)}},[i,l,_]),x=c(null),P=d(()=>{var e;return null!==(e=x.current)&&void 0!==e?e:document.body},[]);return a(()=>{f&&f!==Vo.language&&Vo.changeLanguage(f)},[f]),e(C,{className:"em-filemanager",children:t(o,{children:[e(w,{getPopupContainer:()=>x.current||document.body,children:e(cr,{i18n:Vo,children:e(_t,{externalTheme:null!=u?u:"light",children:e(us,{children:e(pn,{options:{dataProviders:s,handleNotify:r.handleNotify,handleError:r.handleError,handleSuccess:r.handleSuccess,config:y,getModalContainer:P},children:e(ol,{visible:!0,onClose:i,file:F,onSave:S,onSaveCopy:E})})})})})}),e("div",{ref:x,className:"file-manager-modal-root"})]})})},ys=t=>{Pt();const o=t.element,r=v(o);r.render(e(vs,Object.assign({},t))),gs.set(o.id||`pixie_container_${Date.now()}`,r)},ws=e=>{const t=Array.from(gs.keys()).find(e=>e.startsWith("pixie_container_")),o=e.id||t;if(o&&gs.has(o)){const e=gs.get(o);null==e||e.unmount(),gs.delete(o)}else{console.warn("Couldn t find the root to unmount Pixie");try{v(e).unmount()}catch(e){console.error("Error unmounting Pixie:",e)}}},bs=e=>{var t,o;const{mode:r,element:n,fileManager:i,pixieEditor:a,theme:l,dataProviders:s}=e;let d,c;const u={unmount:()=>{d&&ps(d),c&&ws(c)},unmountFileManager:void 0,unmountPixieEditor:void 0};switch(r){case"fileManager":d=n,ms(n,Object.assign(Object.assign({},null==i?void 0:i.config),{theme:l||(null===(t=null==i?void 0:i.config)||void 0===t?void 0:t.theme),apiEndpoints:null==i?void 0:i.apiEndpoints})),u.unmountFileManager=()=>ps(d);break;case"pixieEditor":c=n,ys(Object.assign({element:n,theme:l||(null==a?void 0:a.theme),dataProviders:s||(null==a?void 0:a.dataProviders)},a)),u.unmountPixieEditor=()=>ws(c);break;case"both":{const e=document.createElement("div");e.id="file-manager-container",e.style.cssText="height: 50%; border-bottom: 1px solid #d9d9d9;";const t=document.createElement("div");t.id="pixie-editor-container",t.style.cssText="height: 50%;",n.appendChild(e),n.appendChild(t),d=e,c=t,ms(d,Object.assign(Object.assign({},null==i?void 0:i.config),{theme:l||(null===(o=null==i?void 0:i.config)||void 0===o?void 0:o.theme),apiEndpoints:null==i?void 0:i.apiEndpoints})),ys(Object.assign({element:c,theme:l||(null==a?void 0:a.theme),dataProviders:s||(null==a?void 0:a.dataProviders)},a)),u.unmountFileManager=()=>ps(d),u.unmountPixieEditor=()=>ws(c);break}}return u};function Cs(e,t="BackendError"){switch(e){case 400:return"ValidationError";case 401:return"AuthenticationFailed";case 403:return"AuthorizationFailed";case 404:return"FileNotFound";case 413:return"PayloadTooLarge";case 415:return"UnsupportedMediaType";case 429:return"RateLimitExceeded";case 500:return"BackendError";case 503:return"ServiceUnavailable";case 504:return"Timeout";default:return t}}const Is="";class Fs{constructor(){this.map=new Map}static childrenViewKey(e,t){return`v${Is}${e}${Is}${t}`}static childrenCountKey(e){return`c${Is}${e}`}getFreshError(e,t){const o=this.map.get(e);return o?t!==1/0&&Date.now()-o.updatedAt>t?(this.map.delete(e),null):o.error:null}setError(e,t){this.map.set(e,{error:t,updatedAt:Date.now()})}delete(e){this.map.delete(e)}clearChildrenViewErrorsForParent(e){const t=`v${Is}${e}${Is}`;for(const e of[...this.map.keys()])e.startsWith(t)&&this.map.delete(e)}clearAll(){this.map.clear()}}class As{constructor(){this.deletingIds=new Set}beginDeleting(e){for(const t of e)t&&this.deletingIds.add(t)}endDeleting(e){for(const t of e)t&&this.deletingIds.delete(t)}isDeleting(e){return!!e&&this.deletingIds.has(e)}}const _s=18e5;function Ss(e){return null==e||""===e?"":e}function Es(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function xs(e){if(!e)return null;const t=e.folderId;return null==t?null:String(t)}function Ps(e){return!!e&&!!e.isFolder}function Rs(){var e;if("function"==typeof(null===(e=null===globalThis||void 0===globalThis?void 0:globalThis.crypto)||void 0===e?void 0:e.randomUUID))return globalThis.crypto.randomUUID();try{const e=globalThis.crypto||globalThis.msCrypto;if(e&&"function"==typeof e.getRandomValues){const t=new Uint8Array(16);e.getRandomValues(t);let o="";for(let e=0;e<t.length;e++)o+=t[e].toString(16).padStart(2,"0");return`id_${o}`}}catch(e){}return`id_fallback_${Date.now().toString(36)}_${Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(36).slice(0,8)}`}function Ns(e){var t,o,r,n;if(!e||"object"!=typeof e)return!1;const i=e;return"path_folder_not_found"===i.code||"folder_not_found"===i.code||"FolderNotFound"===i.code||"path_folder_not_found"===(null===(t=i.data)||void 0===t?void 0:t.code)||"folder_not_found"===(null===(o=i.data)||void 0===o?void 0:o.code)||404===i.status||404===(null===(n=null===(r=i.data)||void 0===r?void 0:r.data)||void 0===n?void 0:n.status)}function ks(e){if(!e||"object"!=typeof e)return String(null!=e?e:"");const t=e,o=[],r={},n=["page","pageSize","sortBy","sortOrder","search","itemType","limit"];for(const e of Object.keys(t).sort()){const i=t[e];n.includes(e)?o.push(`${e}=${String(null!=i?i:"")}`):r[e]=i}const i=Object.keys(r).length?JSON.stringify(r):"",a=o.join("|"),l=i?function(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(36)}(i):"";return`${a}${l?`|${l}`:""}`}class Os{constructor(){this.entities=new Map,this.childrenByParent=new Map,this.maxCacheSize=1e4}now(){return Date.now()}checkCacheSize(){if(this.entities.size>this.maxCacheSize){const e=Array.from(this.entities.entries()).sort((e,t)=>e[1].updatedAt-t[1].updatedAt),t=Math.floor(.1*this.maxCacheSize);for(let o=0;o<t&&o<e.length;o++){const[t,r]=e[o];this.deleteEntityById(t)}}}getEntity(e){var t;return null===(t=this.entities.get(e))||void 0===t?void 0:t.value}getRecord(e){return this.entities.get(e)}getFileSystemItem(e){const t=this.getEntity(e);return t&&!Ps(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&Ps(t)?t:void 0}getChildrenIds(e,t={}){const o=Ss(e),r=this.childrenByParent.get(o);return r?t.onlyFileSystemItems?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}searchByUrl(e){for(const t of this.entities.values())if(t.value.url===e)return t.value;return null}upsertEntity(e){var t;const o=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=o?o.value:null,n=r?xs(r):null,i=xs(e),a=!!r&&Ps(r),l=Ps(e);let s;if(r&&Ps(r)&&l){const t=r.childrenCount,o=e.childrenCount;void 0!==t&&void 0===o&&(s=t)}if(r&&(n!==i||a!==l)){const t=Ss(n),o=this.childrenByParent.get(t);o&&(a?o.folders.delete(e.id):o.files.delete(e.id),0===o.files.size&&0===o.folders.size&&this.childrenByParent.delete(t))}let d=e;void 0!==s&&(d=Object.assign(Object.assign({},e),{childrenCount:s})),this.entities.set(e.id,{value:Object.assign({},d),updatedAt:this.now()}),this.checkCacheSize();const c=Ss(i);let u=this.childrenByParent.get(c);u||(u={files:new Set,folders:new Set},this.childrenByParent.set(c,u)),l?u.folders.add(e.id):u.files.add(e.id)}updateServerChildrenCount(e,t){if(null==e||null==t||Number.isNaN(t))return;const o=this.entities.get(e);if(!o||!Ps(o.value))return;const r=Object.assign(Object.assign({},o.value),{childrenCount:t});this.entities.set(e,{value:r,updatedAt:this.now()})}deleteEntityById(e){var t;const o=null!==(t=this.entities.get(e))&&void 0!==t?t:null;if(!o)return{entity:null,parentId:null};const r=o.value,n=xs(r),i=Ss(n),a=this.childrenByParent.get(i);return a&&(Ps(r)?a.folders.delete(e):a.files.delete(e),0===a.files.size&&0===a.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(e),{entity:Object.assign({},r),parentId:n}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!Ps(t.value))return{deletedFolderRecords:[],deletedFileSystemItemRecords:[]};const o=[{id:e,parentId:xs(t.value)}],r=[],n=[];for(;o.length;){const e=o.shift();r.push(e);const t=this.childrenByParent.get(Ss(e.id));if(t){for(const e of Array.from(t.folders)){const t=this.entities.get(e);t&&o.push({id:e,parentId:xs(t.value)})}for(const e of Array.from(t.files))n.push(e)}}const i=[];for(const e of n){const t=this.entities.get(e);if(!t)continue;const o=t.value,r=Ss(xs(o)),n=this.childrenByParent.get(r);n&&(n.files.delete(e),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(r)),this.entities.delete(e),i.push(Object.assign({},o))}const a=[];for(let e=r.length-1;e>=0;e--){const{id:t,parentId:o}=r[e],n=this.entities.get(t);if(!n)continue;const i=n.value,l=Ss(i.id);this.childrenByParent.delete(l);const s=Ss(o),d=this.childrenByParent.get(s);d&&(d.folders.delete(t),0===d.files.size&&0===d.folders.size&&this.childrenByParent.delete(s)),this.entities.delete(t),a.push(Object.assign({},i))}return{deletedFolderRecords:a,deletedFileSystemItemRecords:i}}moveEntityById(e,t){var o;const r=null!==(o=this.entities.get(e))&&void 0!==o?o:null;if(!r)return null;const n=r.value,i=Ss(xs(n)),a=this.childrenByParent.get(i);a&&(Ps(n)?a.folders.delete(e):a.files.delete(e),0===a.files.size&&0===a.folders.size&&this.childrenByParent.delete(i));const l=Object.assign(Object.assign({},n),{folderId:t});if(Ps(n)&&Ps(l)){const e=n.childrenCount;void 0!==e&&(l.childrenCount=e)}this.entities.set(e,{value:l,updatedAt:this.now()});const s=Ss(t);let d=this.childrenByParent.get(s);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(s,d)),Ps(l)?d.folders.add(e):d.files.add(e),Object.assign({},l)}copyFileSystemItem(e,t,o){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||Ps(n.value))return null;const i=n.value,a=Object.assign(Object.assign({},i),{id:t,folderId:o});return this.upsertEntity(a),Object.assign({},a)}copyFolderShallow(e,t,o){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||!Ps(n.value))return null;const i=n.value,a=Object.assign(Object.assign({},i),{id:t,folderId:o});return this.upsertEntity(a),Object.assign({},a)}isEntityStale(e,t){var o;const r=null!==(o=this.entities.get(e))&&void 0!==o?o:null;return!r||t!==1/0&&this.now()-r.updatedAt>t}touch(e,t){const o=this.entities.get(e);o&&(o.updatedAt=null!=t?t:this.now())}getEntitiesByIds(e){return e.map(e=>{var t,o;return null!==(o=null===(t=this.entities.get(e))||void 0===t?void 0:t.value)&&void 0!==o?o:null})}searchByName(e,t){var o,r,n,i,a;if(!e||""===e.trim())return[];const l=null==t?void 0:t.parentId,s=null!==(o=null==t?void 0:t.recursive)&&void 0!==o&&o,d=null!==(r=null==t?void 0:t.itemType)&&void 0!==r?r:"all",c=null!==(n=null==t?void 0:t.caseSensitive)&&void 0!==n&&n,u=null!==(i=null==t?void 0:t.limit)&&void 0!==i?i:1/0,f=c?e.trim():e.trim().toLowerCase(),h=[];let m=null;if(void 0!==l){m=new Set;const e=Ss(l);if(m.add(e),s){const t=[e],o=new Set;for(;t.length>0;){const e=t.shift();if(o.has(e))continue;o.add(e);const r=this.childrenByParent.get(e);if(r)for(const e of r.folders)m.add(e),t.push(e)}}}for(const[,e]of this.entities){if(h.length>=u)break;const t=e.value;if(null!==m){const e=Ss(xs(t));if(!m.has(e))continue}if("file"===d&&Ps(t))continue;if("folder"===d&&!Ps(t))continue;const o=null!==(a=t.name)&&void 0!==a?a:"";(c?o:o.toLowerCase()).includes(f)&&h.push(Object.assign({},t))}return h}toJSON(){return{entities:Array.from(this.entities.entries()),childrenByParent:Array.from(this.childrenByParent.entries()).map(([e,t])=>[e,{files:Array.from(t.files),folders:Array.from(t.folders)}])}}static fromJSON(e){var t,o;const r=new Os;for(const[o,n]of null!==(t=e.entities)&&void 0!==t?t:[])r.entities.set(o,{value:n.value,updatedAt:n.updatedAt});for(const[t,n]of null!==(o=e.childrenByParent)&&void 0!==o?o:[])r.childrenByParent.set(t,{files:new Set(n.files),folders:new Set(n.folders)});return r}}class Ts{constructor(e={},t=18e5,o,r,n=new Fs,i=Ns){var a,l,s,d,c;this.views=new Map,this.maxViewsPerParent=50,this.strategy={allowSortedInsert:null===(a=e.allowSortedInsert)||void 0===a||a,allowSearchInsert:null===(l=e.allowSearchInsert)||void 0===l||l,invalidateOnPaginationFull:null===(s=e.invalidateOnPaginationFull)||void 0===s||s,preloadPagesBefore:null!==(d=e.preloadPagesBefore)&&void 0!==d?d:0,preloadPagesAfter:null!==(c=e.preloadPagesAfter)&&void 0!==c?c:1,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=null!=o?o:t,this.entityTtl=null!=r?r:t,this.failedRequests=n,this.isFolderNotFoundError=i}setServerChildrenCountHandler(e){this.serverChildrenCountHandler=e}setChildrenCountInvalidator(e){this.childrenCountInvalidator=e}now(){return Date.now()}parentKey(e){return Ss(null!=e?e:null)}isExpired(e){return null==e||this.ttl!==1/0&&this.now()-e>this.ttl}areEntitiesStale(e,t){return!e||e.some(e=>!t.getEntity(e)||t.isEntityStale(e,this.entityTtl))}isEntityTypeCompatible(e,t){return!t||"all"===t||("file"===t&&!Ps(e)||!("folder"!==t||!Ps(e)))}cleanupOldViews(e){if(e.size<=this.maxViewsPerParent)return;const t=Array.from(e.entries()).sort((e,t)=>(t[1].view.updatedAt||0)-(e[1].view.updatedAt||0));for(;e.size>this.maxViewsPerParent&&t.length>0;){const[o]=t.pop();e.delete(o)}}async getOrCreateChildren(e,t,o,r){var n,i,a;const l=this.parentKey(e),s=ks(null!=t?t:{});let d=this.views.get(l);d||(d=new Map,this.views.set(l,d));const c=Fs.childrenViewKey(l,s);let u=d.get(s);if(!u){u={params:t,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:null}},d.set(s,u),this.cleanupOldViews(d)}const f=this.failedRequests.getFreshError(c,this.errorTtl);if(null!=f)throw f;if(u.view.value&&!this.isExpired(u.view.updatedAt)&&!this.areEntitiesStale(u.view.value,r)&&!(null===(n=u.view.meta)||void 0===n?void 0:n.stale)){const e=u.view.value.map(e=>r.getEntity(e)).filter(Boolean),t=(null===(i=u.params)||void 0===i?void 0:i.itemType)||"all",o=e.filter(e=>this.isEntityTypeCompatible(e,t));return Object.assign({items:o},null!==(a=u.view.meta)&&void 0!==a?a:{})}if(u.view.promise)return u.view.promise;const h=Rs();u.view.loadId=h;const m=(async()=>{var n,i,a,s;try{const d=await o(e,t),f=function(e){return!!e&&"string"==typeof e.search&&e.search.trim().length>0}(t),m=f?Object.assign(Object.assign({},d),{total:void 0}):d,p=null===(n=this.views.get(l))||void 0===n?void 0:n.get(ks(t));if(!p||p.view.loadId!==h){const e=new Error("StaleLoad");throw e.name="StaleLoad",e}for(const e of m.items)r.upsertEntity(e);u.view.value=m.items.map(e=>e.id);const{items:g}=m,v=Rn(m,["items"]),y=Object.assign({},v);u.view.meta=y,u.view.meta&&(u.view.meta.stale=!1),this.failedRequests.delete(c),u.view.updatedAt=this.now(),f||"number"!=typeof y.total||(this.serverChildrenCountHandler?this.serverChildrenCountHandler(null!=e?e:null,y.total,r):r.updateServerChildrenCount(e,y.total));const w=null!==(i=this.strategy.preloadPagesAfter)&&void 0!==i?i:0,b=null!==(a=this.strategy.preloadPagesBefore)&&void 0!==a?a:0,C=Es(null==t?void 0:t.pageSize),I=Number.isFinite(C);if((w>0||b>0)&&I){const n=e,i=Object.assign({},t),a="number"==typeof y.totalPages?y.totalPages:1,l=null!==(s=null==t?void 0:t.page)&&void 0!==s?s:1,d=C,c=o,u=h;setTimeout(()=>{this.preloadPagesAsync(n,i,l,a,d,w,b,r,y,c,u)},0)}return m}catch(e){if("StaleLoad"===(null==e?void 0:e.name))throw this.failedRequests.delete(c),u.view.value=void 0,u.view.updatedAt=this.now(),e;if(this.isFolderNotFoundError(e))return this.failedRequests.delete(c),u.view.value=[],u.view.meta={total:0,totalPages:0},u.view.updatedAt=this.now(),{items:[],total:0,totalPages:0};throw this.failedRequests.setError(c,e),u.view.value=void 0,u.view.updatedAt=this.now(),e}finally{u.view.promise=null}})();return u.view.promise=m,m}async preloadPagesAsync(e,t,o,r,n,i,a,l,s,d,c){try{const n=this.parentKey(e),s=this.views.get(n);if(!s)return;const u=s.get(ks(t));if(!u)return;if(null!=c&&u.view.loadId!==c)return;const f=s.get(ks(t));if(!(null==f?void 0:f.view.meta))return;const h="number"==typeof f.view.meta.totalPages?f.view.meta.totalPages:1;if(h!==r)return;const m=async o=>{const r=Object.assign(Object.assign({},t),{page:o});try{const i=await d(e,r),a=this.views.get(n);if(!a)return;const s=a.get(ks(t));if(!s)return;if(null!=c&&s.view.loadId!==c)return;if(s.view.loadId!==c)return;for(const e of i.items)l.upsertEntity(e);const u=ks(r);let f=a.get(u);if(!f){f={params:r,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:s.view.loadId}},a.set(u,f),this.cleanupOldViews(a)}if(!f.view.value||this.isExpired(f.view.updatedAt)){f.view.value=i.items.map(e=>e.id);const{items:e}=i,t=Rn(i,["items"]);f.view.meta=Object.assign(Object.assign({},t),{page:o,totalPages:h}),f.view.updatedAt=this.now()}}catch(e){console.debug("Preload failed silently:",e)}};if(i>0&&o<h)for(let e=1;e<=Math.min(i,h-o);e++){const r=o+e,n=ks(Object.assign(Object.assign({},t),{page:r})),i=s.get(n);(null==i?void 0:i.view.value)&&!this.isExpired(i.view.updatedAt)||m(r)}if(a>0&&o>1)for(let e=1;e<=Math.min(a,o-1);e++){const r=o-e,n=ks(Object.assign(Object.assign({},t),{page:r})),i=s.get(n);(null==i?void 0:i.view.value)&&!this.isExpired(i.view.updatedAt)||m(r)}}catch(e){console.debug("Preload process failed:",e)}}removeEmptyPageIfNeeded(e,t,o,r,n){if(t.view.value&&0===t.view.value.length&&o<r){const t=ks(Object.assign(Object.assign({},n),{page:o}));e.delete(t)}}updateTotalPagesForAllViews(e,t){for(const[,o]of e)o.view.meta&&(o.view.meta.totalPages=t)}isParamsSame(e,t){const o=Object.keys(null!=e?e:{}).filter(e=>"page"!==e).sort(),r=Object.keys(null!=t?t:{}).filter(e=>"page"!==e).sort();if(o.length!==r.length)return!1;for(let n=0;n<o.length;n++){const i=o[n];if(i!==r[n])return!1;if(e[i]!==t[i])return!1}return!0}syncTotalsInSameViews(e,t){var o,r,n;const i=t.view.meta;if(!i||"number"!=typeof i.total)return;const a=Number(i.total),l=Es(null===(o=t.params)||void 0===o?void 0:o.pageSize),s=Number.isFinite(l)&&l>0?Math.max(1,Math.ceil(a/l)):void 0;for(const[,o]of e)this.isParamsSame(null!==(r=o.params)&&void 0!==r?r:{},null!==(n=t.params)&&void 0!==n?n:{})&&(o.view.meta||(o.view.meta={}),o.view.meta.total=a,void 0!==s&&(o.view.meta.totalPages=s))}canSafelyModifySortedView(e){return!e.sortBy&&!e.sortOrder||!!this.strategy.comparator}cascadeShiftPages(e,t,o,r,n,i,a){var l,s,d;let c=t,u=o,f=!1;let h=0;for(;c.view.value&&c.view.value.length<r&&u<n&&h<100;){h++;const t=ks(Object.assign(Object.assign({},a),{page:u+1})),o=e.get(t);if(!(null==o?void 0:o.view.value)||this.isExpired(o.view.updatedAt)){c.view.meta=Object.assign(Object.assign({},null!==(l=c.view.meta)&&void 0!==l?l:{}),{stale:!0});break}const n=r-c.view.value.length,d=o.view.value.slice(0,n).filter(e=>i.getEntity(e));if(0===d.length){c.view.meta=Object.assign(Object.assign({},null!==(s=c.view.meta)&&void 0!==s?s:{}),{stale:!0});break}if(c.view.value=[...c.view.value,...d],c.view.updatedAt=Date.now(),o.view.value=o.view.value.slice(d.length),o.view.updatedAt=Date.now(),0===o.view.value.length){const t=u+1,r=o.view.meta;if(t<(r&&"number"==typeof r.totalPages?r.totalPages:1)){const o=ks(Object.assign(Object.assign({},a),{page:t}));e.delete(o),f=!0}break}c=o,u++}return(!c.view.value||c.view.value.length<r)&&u>=n&&(c.view.meta=Object.assign(Object.assign({},null!==(d=c.view.meta)&&void 0!==d?d:{}),{stale:!0})),f}cascadeShiftToNextPage(e,t,o,r,n,i,a){var l,s,d;if(!t.view.value||t.view.value.length<=r)return!1;if(o-(a.page||1)>=10)return t.view.meta=Object.assign(Object.assign({},null!==(l=t.view.meta)&&void 0!==l?l:{}),{stale:!0}),!1;const c=Object.assign(Object.assign({},a),{page:o+1}),u=ks(c);let f=e.get(u),h=!1;if(!(null==f?void 0:f.view.value)||this.isExpired(f.view.updatedAt)){if(!(o>=n))return t.view.meta=Object.assign(Object.assign({},null!==(s=t.view.meta)&&void 0!==s?s:{}),{stale:!0}),!1;{f={params:c,view:{promise:null,value:void 0,meta:void 0,updatedAt:0,loadId:null}},e.set(u,f),this.cleanupOldViews(e);const r=t.view.meta;r&&(f.view.meta=Object.assign(Object.assign({},r),{page:o+1})),h=!0}}const m=t.view.value.slice(r).filter(e=>i.getEntity(e));if(0===m.length)return h&&e.delete(u),!1;t.view.value=t.view.value.slice(0,r),t.view.updatedAt=Date.now(),f.view.value=[...m,...null!==(d=f.view.value)&&void 0!==d?d:[]],f.view.updatedAt=Date.now();const p=f.view.meta&&"number"==typeof f.view.meta.totalPages?f.view.meta.totalPages:n;if(!h){if(this.cascadeShiftToNextPage(e,f,o+1,r,p,i,a))return!0}if(!f.view.value||0===f.view.value.length){const t=o+1,r=f.view.meta,n=r&&"number"==typeof r.totalPages?r.totalPages:1;this.removeEmptyPageIfNeeded(e,f,t,n,a)}return h}tryInsertSorted(e,t,o){var r;const n=this.strategy.comparator;if(!n)return!1;if(!e.view.value)return!1;const i=(null===(r=e.params)||void 0===r?void 0:r.itemType)||"all";if(!this.isEntityTypeCompatible(t,i))return!1;const a=e.view.value.map(e=>o.getEntity(e));if(a.some(e=>!e))return!1;let l=0,s=a.length;for(;l<s;){const o=Math.floor((l+s)/2),r=n(t,a[o],e.params);if("number"!=typeof r||Number.isNaN(r))return!1;r>=0?l=o+1:s=o}return e.view.value.includes(t.id)?(e.view.updatedAt=this.now(),!0):(e.view.value=[...e.view.value.slice(0,l),t.id,...e.view.value.slice(l)],e.view.updatedAt=this.now(),e.view.meta&&"number"==typeof e.view.meta.total&&(e.view.meta.total=Number(e.view.meta.total)+1),!0)}updateChildrenCountForOperation(e,t,o,r){var n,i,a,l;const s=xs(t);switch(e){case"delete":this.adjustChildrenCount(r,s,-1),null===(n=this.childrenCountInvalidator)||void 0===n||n.call(this,s);break;case"insert":case"copy":this.adjustChildrenCount(r,s,1),null===(i=this.childrenCountInvalidator)||void 0===i||i.call(this,s);break;case"move":this.adjustChildrenCount(r,null!=o?o:null,-1),this.adjustChildrenCount(r,s,1),null===(a=this.childrenCountInvalidator)||void 0===a||a.call(this,null!=o?o:null),null===(l=this.childrenCountInvalidator)||void 0===l||l.call(this,s)}}adjustChildrenCount(e,t,o){if(!t)return;const r=e.getFolder(t);if(r&&"number"==typeof r.childrenCount){const n=Math.max(0,r.childrenCount+o);e.updateServerChildrenCount(t,n)}}smartInvalidateChildrenViews(e,t,o,r,n,i){var a,l,s,d;if(!t)return;this.updateChildrenCountForOperation(o,t,n,r);const c=this.parentKey(e),u=this.views.get(c);if(u)for(const[,e]of u){const i=null!==(a=e.params)&&void 0!==a?a:{},c=null!==(l=null==i?void 0:i.page)&&void 0!==l?l:1,f=Es(null==i?void 0:i.pageSize),h=Number.isFinite(f),m=!(!(null==i?void 0:i.sortBy)&&!(null==i?void 0:i.sortOrder)),p=!!(null==i?void 0:i.search),g=(null==i?void 0:i.itemType)||"all";if(!this.isEntityTypeCompatible(t,g))continue;if(p&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,e.params)){(null===(s=e.view.value)||void 0===s?void 0:s.includes(t.id))&&(e.view.value=e.view.value.filter(e=>e!==t.id),e.view.meta&&"number"==typeof e.view.meta.total&&(e.view.meta.total=Math.max(0,e.view.meta.total-1)),e.view.updatedAt=Date.now());continue}if(!e.view.value){e.view.meta&&(e.view.meta.stale=!0),e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0);continue}e.view.value.includes(t.id);if(this.shouldInvalidateCompletely(e,o,t,m,h,c))e.view.meta=Object.assign(Object.assign({},null!==(d=e.view.meta)&&void 0!==d?d:{}),{stale:!0}),e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0);else switch(o){case"delete":this.handleDelete(u,e,c,f,h,t,r);break;case"insert":case"copy":this.handleInsert(u,e,c,f,h,m,t,r);break;case"update":this.handleUpdate(u,e,c,f,h,m,p,t,r);break;case"move":this.handleMove(u,e,c,f,h,m,t,n,r)}}}shouldInvalidateCompletely(e,t,o,r,n,i){return!(!(n&&i>1)||"insert"!==t&&"delete"!==t&&"move"!==t)||(!(!r||this.strategy.comparator||"insert"!==t&&"move"!==t)||!!this.isExpired(e.view.updatedAt))}tryReinsertEntity(e,t,o,r,n){var i,a;const l=(null===(i=e.params)||void 0===i?void 0:i.itemType)||"all";if(!this.isEntityTypeCompatible(t,l))return!1;if(this.strategy.comparator&&this.strategy.filterMatch){if(!this.strategy.filterMatch(t,e.params))return!1;if(this.tryInsertSorted(e,t,o))return!0}const s=null!==(a=e.params)&&void 0!==a?a:{};return!!(!s.sortBy&&!s.sortOrder||this.canSafelyModifySortedView(s))&&((!r||e.view.value.length<n)&&(e.view.value.push(t.id),!0))}handleDelete(e,t,o,r,n,i,a){var l;const s=t.view.value.includes(i.id);if(s&&(t.view.value=t.view.value.filter(e=>e!==i.id)),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(t.view.updatedAt=Date.now(),s&&n&&t.view.value.length<r&&a){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,a,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}handleInsert(e,t,o,r,n,i,a,l){var s,d,c,u;if(!t.view.value.includes(a.id)){if(i&&this.strategy.allowSortedInsert&&this.strategy.comparator&&l){if(this.tryInsertSorted(t,a,l)&&t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(n&&(null!==(d=null===(s=t.view.value)||void 0===s?void 0:s.length)&&void 0!==d?d:0)>r&&l){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftToNextPage(e,t,o,r,i,l,null!==(c=t.params)&&void 0!==c?c:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=t.view.meta.totalPages+1;t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}}else if(!n||t.view.value.length<r){if(t.view.value.push(a.id),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else t.view.meta=Object.assign(Object.assign({},null!==(u=t.view.meta)&&void 0!==u?u:{}),{stale:!0});t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleUpdate(e,t,o,r,n,i,a,l,s){var d,c,u,f;const h=t.view.value.includes(l.id),m=this.isEntityTypeCompatible(l,(null===(d=t.params)||void 0===d?void 0:d.itemType)||"all");if(h&&!m){if(t.view.value=t.view.value.filter(e=>e!==l.id),t.view.meta&&"number"==typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(c=t.params)&&void 0!==c?c:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}return t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h&&(i||a)){t.view.value=t.view.value.filter(e=>e!==l.id);if(this.tryReinsertEntity(t,l,s,n,r)){if(t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else{if(t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(u=t.params)&&void 0!==u?u:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}}return t.view.updatedAt=Date.now(),t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h)return t.view.updatedAt=Date.now(),t.view.loadId=Rs(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0));if(m&&!a){if(i&&this.strategy.allowSortedInsert&&this.strategy.comparator&&s){if(this.tryInsertSorted(t,l,s)&&t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else if(!n||t.view.value.length<r){if(t.view.value.push(l.id),t.view.meta&&"number"==typeof t.view.meta.total){if(t.view.meta.total+=1,n&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else t.view.meta=Object.assign(Object.assign({},null!==(f=t.view.meta)&&void 0!==f?f:{}),{stale:!0});t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleMove(e,t,o,r,n,i,a,l,s){var d;if(t.view.value.includes(a.id)){if(t.view.value=t.view.value.filter(e=>e!==a.id),t.view.meta&&"number"==typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),n&&Number.isFinite(r)&&"number"==typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),n&&t.view.value.length<r&&s){const n=t.view.meta,i=n&&"number"==typeof n.totalPages?n.totalPages:1;if(this.cascadeShiftPages(e,t,o,r,i,s,null!==(d=t.params)&&void 0!==d?d:{})&&t.view.meta&&"number"==typeof t.view.meta.totalPages){const o=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=o,this.updateTotalPagesForAllViews(e,o)}}this.syncTotalsInSameViews(e,t)}t.view.loadId=Rs(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}forceInvalidateChildrenViews(e){const t=this.parentKey(null!=e?e:null);this.failedRequests.clearChildrenViewErrorsForParent(t);const o=this.views.get(t);if(o)for(const[,e]of o)e.view.value=void 0,e.view.meta=void 0,e.view.promise=null,e.view.updatedAt=0,e.view.loadId=Rs(),e.view.abortController&&(e.view.abortController.abort(),e.view.abortController=void 0)}getKnownTotal(e){var t,o;const r=this.parentKey(null!=e?e:null),n=this.views.get(r);if(!n)return;let i=null;for(const[,e]of n){const r=e.view.meta;r&&"number"==typeof r.total&&(!i||(null!==(t=e.view.updatedAt)&&void 0!==t?t:0)>i.updatedAt)&&(i={total:Number(r.total),updatedAt:null!==(o=e.view.updatedAt)&&void 0!==o?o:0})}return i?i.total:void 0}toJSON(){return{views:Array.from(this.views.entries()).map(([e,t])=>[e,Array.from(t.entries())]),ttl:this.ttl,errorTtl:this.errorTtl,entityTtl:this.entityTtl,strategy:{allowSortedInsert:this.strategy.allowSortedInsert,allowSearchInsert:this.strategy.allowSearchInsert,invalidateOnPaginationFull:this.strategy.invalidateOnPaginationFull,preloadPagesBefore:this.strategy.preloadPagesBefore,preloadPagesAfter:this.strategy.preloadPagesAfter}}}static fromJSON(e,t){var o,r,n,i,a,l;const s=null!==(r=null!==(o=null==t?void 0:t.ttl)&&void 0!==o?o:null==e?void 0:e.ttl)&&void 0!==r?r:_s,d=null!==(i=null!==(n=null==t?void 0:t.errorTtl)&&void 0!==n?n:null==e?void 0:e.errorTtl)&&void 0!==i?i:s,c=null!==(a=null==t?void 0:t.failedRequests)&&void 0!==a?a:new Fs,u=new Ts({},s,d,void 0,c,null==t?void 0:t.isFolderNotFoundError);for(const[t,o]of null!==(l=e.views)&&void 0!==l?l:[]){const e=new Map;for(const[t,r]of o){const o=r;(null==o?void 0:o.view)&&"error"in o.view&&delete o.view.error,e.set(t,o)}u.views.set(t,e)}return u}}class Ls{invalidateChildrenCountCache(e){const t=Ss(null!=e?e:"");this.childrenCountPromises.delete(t),this.failedRequests.delete(Fs.childrenCountKey(t))}constructor(e={},t=18e5,o,r){var n,i,a,l;this.childrenCountPromises=new Map,this.isFolderNotFoundError=null!==(n=null==r?void 0:r.isFolderNotFoundError)&&void 0!==n?n:Ns,this.failedRequests=new Fs,this.ttl=null!==(i=null==r?void 0:r.ttl)&&void 0!==i?i:t,this.errorTtl=null!==(l=null!==(a=null==r?void 0:r.errorTtl)&&void 0!==a?a:o)&&void 0!==l?l:this.ttl,this.entities=new Os,this.views=new Ts(e,this.ttl,this.errorTtl,void 0,this.failedRequests,this.isFolderNotFoundError),this.views.setServerChildrenCountHandler((e,t,o)=>{this.handleServerReportedChildrenCount(e,t,null!=o?o:this.entities)}),this.views.setChildrenCountInvalidator(e=>{this.invalidateChildrenCountCache(e)})}getEntity(e){var t;return null!==(t=this.entities.getEntity(e))&&void 0!==t?t:null}getFileSystemItem(e){var t;return null!==(t=this.entities.getFileSystemItem(e))&&void 0!==t?t:null}getFolder(e){var t;return null!==(t=this.entities.getFolder(e))&&void 0!==t?t:null}async getOrCreateChildren(e,t,o){return this.views.getOrCreateChildren(e,t,o,this.entities)}upsertEntity(e){const t=this.entities.getEntity(e.id),o=t?xs(t):null,r=xs(e),n=!!t&&Ps(t),i=Ps(e);if(this.entities.upsertEntity(e),t){if(o!==r||n!==i)return this.views.smartInvalidateChildrenViews(o,t,"delete",this.entities),void this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities);this.views.smartInvalidateChildrenViews(r,e,"update",this.entities,void 0,t)}else this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities)}isAncestor(e,t){let o=t;const r=new Set;for(;o&&!r.has(o);){r.add(o);if(Ss(o)===Ss(e))return!0;const t=this.entities.getEntity(o);if(!t)break;o=xs(t),null===o&&(o="")}return!1}moveEntity(e,t){const o=this.entities.getEntity(e);if(!o)return null;if(Ps(o)&&null!==t&&this.isAncestor(e,t))return null;const r=xs(o),n=this.entities.moveEntityById(e,t);return n?(this.views.smartInvalidateChildrenViews(r,o,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,n,"insert",this.entities),n):null}copyEntity(e,t,o,r){var n,i,a,l,s;const d=this.entities.getEntity(e);if(!d)return null;let c=null;if(Ps(d)){const o=[e],n=[];for(;o.length;){const e=o.shift();n.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const e of t)o.push(e)}const i=new Map;for(const e of n)i.set(e,Rs());for(const o of n){const n=this.entities.getFolder(o),s=i.get(o),d=xs(n),c=null===d?t:null!==(a=i.get(d))&&void 0!==a?a:null,u=Object.assign(Object.assign(Object.assign({},n),o===e?r:void 0),{id:s,folderId:null!==(l=o===e?null==r?void 0:r.folderId:void 0)&&void 0!==l?l:c});this.entities.upsertEntity(u)}for(const e of n){const t=i.get(e),o=this.entities.getChildrenIds(e,{onlyFileSystemItems:!0});for(const e of o){const o=this.entities.getFileSystemItem(e);if(!o)continue;const r=Rs(),n=Object.assign(Object.assign({},o),{id:r,folderId:t});this.entities.upsertEntity(n)}}c=null!==(s=this.entities.getEntity(i.get(e)))&&void 0!==s?s:null}else{const a=null!=o?o:Rs();if(c=this.entities.copyFileSystemItem(e,a,null!=t?t:null),c&&r){const e=Object.assign(Object.assign(Object.assign({},c),r),{id:a,folderId:null!==(i=null!==(n=r.folderId)&&void 0!==n?n:t)&&void 0!==i?i:null});this.entities.upsertEntity(e),c=e}}return c&&this.views.smartInvalidateChildrenViews(t,c,"copy",this.entities),c}searchByUrl(e){var t;return null!==(t=this.entities.searchByUrl(e))&&void 0!==t?t:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(Ps(t)){const{deletedFolderRecords:o,deletedFileSystemItemRecords:r}=this.entities.deleteFolderRecursive(e);for(const e of r)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of o)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of o)this.views.forceInvalidateChildrenViews(e.id);return t}{const{entity:t,parentId:o}=this.entities.deleteEntityById(e);return t&&this.views.smartInvalidateChildrenViews(o,t,"delete",this.entities),t}}deleteFolderRecursive(e){const{deletedFolderRecords:t,deletedFileSystemItemRecords:o}=this.entities.deleteFolderRecursive(e);for(const e of o)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of t)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of t)this.views.forceInvalidateChildrenViews(e.id);return{deletedFileSystemItemIds:o.map(e=>e.id),deletedFolderIds:t.map(e=>e.id)}}forceInvalidate(e){var t;const o=this.entities.getEntity(e);if(!o)return;const r=new Set;if(Ps(o)){const t=[e];for(;t.length;){const e=t.pop();if(r.has(e))continue;r.add(e),this.views.forceInvalidateChildrenViews(e),this.invalidateChildrenCountCache(e);const o=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const e of o)t.push(e)}}else{const e=null!==(t=o.folderId)&&void 0!==t?t:null;this.views.forceInvalidateChildrenViews(e),this.invalidateChildrenCountCache(e)}}getChildrenIds(e){return this.entities.getChildrenIds(e)}searchByName(e,t){return this.entities.searchByName(e,t)}async getChildrenCount(e="",t){const o=Ss(e),r=Fs.childrenCountKey(o),n=this.failedRequests.getFreshError(r,this.errorTtl);if(null!=n)return Promise.reject(n);const i=this.childrenCountPromises.get(o);if(i)return i;const a=(async()=>{try{const o=this.entities.getFolder(e);if(o&&"number"==typeof o.childrenCount)return this.failedRequests.delete(r),o.childrenCount;const n=this.views.getKnownTotal(e);if("number"==typeof n)return o&&this.handleServerReportedChildrenCount(e,n,this.entities),this.failedRequests.delete(r),n;if(t){const o=await t(e);return this.entities.getFolder(e)&&this.handleServerReportedChildrenCount(e,o,this.entities),this.failedRequests.delete(r),o}return this.failedRequests.delete(r),this.entities.getChildrenIds(e).length}catch(e){if(this.childrenCountPromises.delete(o),this.isFolderNotFoundError(e))return this.failedRequests.delete(r),0;throw this.failedRequests.setError(r,e),e}finally{this.childrenCountPromises.delete(o)}})();return this.childrenCountPromises.set(o,a),a}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t,o){var r,n,i,a,l,s,d,c,u,f,h;const m=null!==(n=null!==(r=null==o?void 0:o.ttl)&&void 0!==r?r:null==e?void 0:e.ttl)&&void 0!==n?n:_s,p=null!==(a=null!==(i=null==o?void 0:o.errorTtl)&&void 0!==i?i:null==e?void 0:e.errorTtl)&&void 0!==a?a:m,g=new Ls(null!=t?t:{},m,p,o),v=Os.fromJSON(null!==(l=null==e?void 0:e.entities)&&void 0!==l?l:{}),y=Ts.fromJSON(null!==(s=null==e?void 0:e.views)&&void 0!==s?s:{},{failedRequests:g.failedRequests,ttl:m,errorTtl:p,isFolderNotFoundError:null==o?void 0:o.isFolderNotFoundError});return t&&(y.strategy={allowSortedInsert:null===(d=t.allowSortedInsert)||void 0===d||d,allowSearchInsert:null===(c=t.allowSearchInsert)||void 0===c||c,invalidateOnPaginationFull:null===(u=t.invalidateOnPaginationFull)||void 0===u||u,preloadPagesBefore:null!==(f=t.preloadPagesBefore)&&void 0!==f?f:0,preloadPagesAfter:null!==(h=t.preloadPagesAfter)&&void 0!==h?h:1,comparator:t.comparator,filterMatch:t.filterMatch}),g.entities=v,g.views=y,y.setServerChildrenCountHandler((e,t,o)=>{g.handleServerReportedChildrenCount(e,t,null!=o?o:v)}),y.setChildrenCountInvalidator(e=>{g.invalidateChildrenCountCache(e)}),g}handleServerReportedChildrenCount(e,t,o){this.checkAndResolveChildrenCountConflict(e,t,o),this.invalidateChildrenCountCache(e)}checkAndResolveChildrenCountConflict(e,t,o){if(!o||void 0===t)return;const r=null!=e?e:null;if(!r)return void o.updateServerChildrenCount(r,t);const n=o.getFolder(r),i=null==n?void 0:n.childrenCount;void 0!==i&&i!==t&&(console.warn(`Conflict: folder "${r}" has childrenCount=${i} but server says total=${t}`),this.views.forceInvalidateChildrenViews(r)),o.updateServerChildrenCount(r,t)}}function Ms(e,t){const o=null!=e?e:{},r=Array.isArray(o.detailed)?o.detailed.map(e=>{var o;return{requestId:null!==(o=e.requestId)&&void 0!==o?o:e.id,success:!!e.success,data:t(e.data),error:e.error}}):void 0;return{success:!!o.success,error:o.error,detailed:r}}function Us(e){return null==e?"":String(e)}function js(e){return Object.assign(Object.assign({},e),{name:Us(e.name)})}function Ds(e){return e&&"object"==typeof e&&"name"in e?Object.assign(Object.assign({},e),{name:Us(e.name)}):e}class Bs{async _findOrCreateFolderByPath(e){const t=(o=e)?o.replaceAll("\\","/").split("/").filter(Boolean):[];var o;if(t.length>10){const e="Path depth exceeds maximum limit of %s".replace("%s",String(10));throw new Jn(e,"ValidationError")}let r;for(const o of t){const{files:t}=await this.getFiles({folderId:(null==r?void 0:r.id)||"",itemType:"folder"}),n=t.find(e=>e.name===o);if(n){if(!n.isFolder){const t="Path component '%s' in '%s' is not a folder".replace("%s",o).replace("%s",e);throw new Jn(t,"ValidationError")}r={id:n.id,name:n.name,parentId:n.folderId}}else{if("function"!=typeof this._dataProvider.createFolder)throw new Jn("Create folder operation is not supported by data provider","UnsupportedOperation");r=await this.createFolder({name:o,parentId:null==r?void 0:r.id})}}return r}getTrashFolder(){return this._findOrCreateFolderByPath(this._pathOptions.trashPath||"Trash")}async getTempFolder(){var e;const t=null!==(e=this._pathOptions.tempPath)&&void 0!==e?e:"Edited";if(t)try{return await this._findOrCreateFolderByPath(t)}catch(e){if(e instanceof Jn&&"ValidationError"===e.code)throw e;return void console.warn("getTempFolder: temp folder unavailable, falling back to root",e)}}constructor(e,t={},o,r={}){var n,i;this._dataProvider=e,this._options=t,this._pathOptions=o,this._blobFetchForceReloadOnceIds=new Set,this._mutationRegistry=new As,this._mapItem=async e=>{var{childrenCount:t}=e;const o=js(Rn(e,["childrenCount"]));if(o.isFolder)return Object.assign(Object.assign({},o),{childCount:t,url:"",thumbnailUrl:""});const[r,n]=await Promise.all([this._getUrl(o),this._getThumbnailUrl(o)]);return Object.assign(Object.assign({},o),{childCount:0,url:r,thumbnailUrl:n})},this._config=r,this._useSoftDelete=this._pathOptions.useSoftDelete,this._rootId=this._pathOptions.rootId||"",this._enableTrash=void 0===this._options.enableTrash||this._options.enableTrash,this._validateDuplicates=this._dataProvider.validateDuplicates,this._cache=new Ls(t.cacheStrategy||{},null===(n=t.cacheStrategy)||void 0===n?void 0:n.ttl,null===(i=t.cacheStrategy)||void 0===i?void 0:i.errorTtl),this.setController({invalidateItemCache:e=>{this._cache.forceInvalidate(e)},getCachedItem:e=>this._cache.getEntity(e)}),"function"!=typeof this._dataProvider.clearCache&&(this.clearCache=void 0);const a=Object.getPrototypeOf(this);for(const e of Object.getOwnPropertyNames(a)){const t=Object.getOwnPropertyDescriptor(a,e);"constructor"!==e&&"function"==typeof(null==t?void 0:t.value)&&(this[e]=t.value.bind(this))}}setController(e){"function"==typeof this._dataProvider.setController&&this._dataProvider.setController(e)}async clearCache(e){if("function"!=typeof this._dataProvider.clearCache)throw new Jn("Clear cache is not supported by data provider","UnsupportedOperation");this._cache.forceInvalidate(this._rootId),await this._dataProvider.clearCache(e)}markNextFileBlobFetchBypassHttpCache(e){this._blobFetchForceReloadOnceIds.add(this.normalizeId(e))}normalizeId(e){return e?"root"===e||"folders"===e?this._rootId:e:this._rootId}_isDeletingId(e){return this._mutationRegistry.isDeleting(this.normalizeId(e))}_collectDeletingIds(e){const t=this.normalizeId(e),o=new Set([t]),r=this._cache.getEntity(t);if(!(null==r?void 0:r.isFolder))return Array.from(o);const n=[t];for(;n.length>0;){const e=n.pop(),t=this._cache.getChildrenIds(e);for(const e of t){if(o.has(e))continue;o.add(e);const t=this._cache.getEntity(e);(null==t?void 0:t.isFolder)&&n.push(e)}}return Array.from(o)}_emptyFilesResult(e,t){return{files:[],pagination:Object.assign(Object.assign(Object.assign({},"number"==typeof e?{page:e}:{}),"number"==typeof t?{limit:t}:{}),{total:0,totalPages:1,hasNext:!1,hasPrev:!1})}}_validateName(e,t=!1){if(!e||0===e.trim().length){throw new Jn(t?"Folder name cannot be empty":"File name cannot be empty",t?"FolderInvalidName":"FileInvalidName")}if(/[\/\\:*?"<>|]/.test(e)){const o=t?"FolderInvalidName":"FileInvalidName",r=t?"Folder name contains invalid characters: %s".replace("%s",e):"File name contains invalid characters: %s".replace("%s",e);throw new Jn(r,o)}}_validateTargetFolderType(e){const t=this.normalizeId(e);if(t===this._rootId)return;const o=this._cache.getEntity(t);if(o&&!o.isFolder){const t="Target item with id '%s' is not a folder".replace("%s",e);throw new Jn(t,"ValidationError")}}_checkNameExistsInCache(e,t,o,r){const n=this.normalizeId(e),i=this._cache.getChildrenIds(n);for(const e of i){const n=this._cache.getEntity(e);if(n&&n.name===t&&!!n.isFolder===o&&(!r||n.id!==r))return!0}return!1}async _getUrl(e){var t;if(e){if(e.url)return e.url;try{return"function"==typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getUrl)&&this._dataProvider.getUrl(e)||void 0}catch(e){console.log(e)}}}async _getThumbnailUrl(e){var t;if(e){if(e.thumbnailUrl)return e.thumbnailUrl;try{return"function"==typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getThumbnailUrl)&&this._dataProvider.getThumbnailUrl(e)||void 0}catch(e){console.log(e)}}}_isAncestor(e,t){if(!t)return!1;const o=this.normalizeId(t),r=this.normalizeId(e);if(o===r)return!0;let n=this._cache.getEntity(o);const i=new Set;for(;n&&n.folderId&&!i.has(n.id);){i.add(n.id);const e=this.normalizeId(n.folderId);if(e===r)return!0;if(n=this._cache.getEntity(e),!n||!n.isFolder)break}return!1}async getFile(e,t){return this._isDeletingId(e)?null:this._cache.searchByName(t,{parentId:this.normalizeId(e),caseSensitive:!0,recursive:!1,itemType:"file"})[0]||(await this.getFiles({folderId:e,itemType:"file",search:t})).files[0]}async getFileById(e){const t=this.normalizeId(e);if(this._isDeletingId(t))return null;const o=this._cache.getFileSystemItem(t);if(o&&!o.isFolder)return await this._mapItem(o);if(!this._dataProvider.pathMode)return null;const r=await this._getFileByPathStyleId(t);if(r&&!r.isFolder){const e=js(r);return this._cache.upsertEntity(e),await this._mapItem(e)}return null}async _getFileByPathStyleId(e){const t=e.replace(/\\/g,"/").replace(/^\/+/,""),o=t.lastIndexOf("/"),r=o<0?"":t.slice(0,o),n=o<0?t:t.slice(o+1);return n?this.getFile(r,n):null}async getFileUrl(e,t){const o=await this.getFile(null!=e?e:"",t);if(o)return await this._getUrl(o)||await this._getThumbnailUrl(o)||o.thumbnail}async getFiles({folderId:e,search:t,sortBy:o,sortOrder:r,page:n,limit:i,itemType:a="all",noFolder:l=!1}){var s,d;l&&(e=null===(s=await this.getTempFolder())||void 0===s?void 0:s.id);const c=this.normalizeId(null!=e?e:this._rootId),u=!1===this._options.enablePagination,f=u?1:n,h=u?1e4:i,m=this._options.clientSideFilter,p=this._options.clientSideSorting,g=this._options.clientSidePaging,v=g?Math.max(1,null!=n?n:1):void 0,y=g?"number"==typeof i&&Number.isFinite(i)&&i>0?i:25:void 0,w=this._emptyFilesResult(g?v:f,g?y:h);if(this._isDeletingId(c))return w;const b=!1!==this._options.unifiedCatalogFetch&&u&&("folder"===a||"file"===a),C=b?"all":a,I={};m||(I.search=t),p||(I.sortBy=null!=o?o:"folder"!==C?"date":void 0,I.sortOrder=null!=r?r:"folder"!==C?"desc":void 0),g||(I.page=f,I.limit=b?1e4:h);const F=b?1e4:g?void 0:h,A={folderId:c,itemType:C,search:m?void 0:t,sortBy:p?void 0:I.sortBy,sortOrder:p?void 0:I.sortOrder,page:g?void 0:f,pageSize:F};let _;try{_=await this._cache.getOrCreateChildren(c,A,async(e,t)=>{var o;const r=t.pageSize,n=null!=r&&Number.isFinite(Number(r))?Number(r):1e4,i=await this._dataProvider.getItems(Object.assign(Object.assign({},t),{folderId:e,limit:n})),a=function(e){return(null!=e?e:[]).map(js)}(i.items);return g?{items:a,total:"number"==typeof(null===(o=i.pagination)||void 0===o?void 0:o.total)?i.pagination.total:a.length}:Object.assign({items:a},i.pagination)})}catch(e){if(this._isDeletingId(c))return w;throw e}let S,E=_.items;if(b&&("folder"===a?E=E.filter(e=>e.isFolder):"file"===a&&(E=E.filter(e=>!e.isFolder))),m)if("function"==typeof this._options.clientSideFilter)E=this._options.clientSideFilter(E,t);else if(t){const e=t.toLowerCase();E=E.filter(t=>{var o;return null===(o=t.name)||void 0===o?void 0:o.toLowerCase().includes(e)})}p&&(E="function"==typeof this._options.clientSideSorting?this._options.clientSideSorting(E,o,r):this._defaultClientSideSort(E,o,r)),S=g||m||b?E.length:null!==(d=_.total)&&void 0!==d?d:E.length;let x=E;if(g)if("function"==typeof this._options.clientSidePaging)x=this._options.clientSidePaging(E,v,y);else{const e=(v-1)*y,t=e+y;x=E.slice(e,t)}if("function"==typeof this._dataProvider.getUrl||"function"==typeof this._dataProvider.getThumbnailUrl){const e=x.map(async e=>{if(e.isFolder)return e;const[t,o]=await Promise.all([e.url?Promise.resolve(e.url):"function"==typeof this._dataProvider.getUrl?this._dataProvider.getUrl(e):Promise.resolve(void 0),e.thumbnailUrl?Promise.resolve(e.thumbnailUrl):"function"==typeof this._dataProvider.getThumbnailUrl?this._dataProvider.getThumbnailUrl(e):Promise.resolve(void 0)]);return Object.assign(Object.assign({},e),{url:t,thumbnailUrl:o})});x=await Promise.all(e)}const P=g?{page:v,limit:y,total:S,totalPages:Math.max(1,Math.ceil(S/y)),hasNext:v*y<S,hasPrev:v>1}:Object.assign(Object.assign({page:f,limit:h,total:S},!g&&_.totalPages&&{totalPages:_.totalPages}),!g&&_.hasNextPage&&{hasNextPage:_.hasNextPage});return{files:await Promise.all(x.map(this._mapItem)),pagination:P}}_defaultClientSideSort(e,t,o){return e.sort((e,r)=>{let n=0;switch(t){case"name":default:n=(e.name||"").localeCompare(r.name||"");break;case"date":n=new Date(e.date||0).getTime()-new Date(r.date||0).getTime();break;case"size":n=(Number(e.size)||0)-(Number(r.size)||0)}return"desc"===o?-n:n})}async getFileData(e,t){var o;const r=this.normalizeId("string"==typeof e?e:e.id);let n=t;this._blobFetchForceReloadOnceIds.delete(r)&&(n=Object.assign(Object.assign({},t),{forceReload:!0}));const i=this._cache.getEntity(r)||("string"==typeof e?{id:r,name:"",folderId:this._rootId,isFolder:!1}:Object.assign(Object.assign({},e),{childrenCount:e.childCount}));if("function"==typeof this._dataProvider.getFileData)return await this._dataProvider.getFileData(i,n);if(!i.url&&"function"!=typeof this._dataProvider.getUrl)throw new Jn("Cannot read file","FileReadError");const a=i.url||("function"==typeof this._dataProvider.getUrl?await this._dataProvider.getUrl(i):"");if(a){const e=null!==(o=this._config.fetchWithProxy)&&void 0!==o?o:fetch;return(await e(a,(null==n?void 0:n.forceReload)?{cache:"no-store"}:void 0)).blob()}throw new Jn("Unable to get file data","FileReadError")}async findFileByUrl(e){const t=this._cache.searchByUrl(e);if(t)return t;if("function"==typeof this._dataProvider.findFileByUrl)try{const t=await this._dataProvider.findFileByUrl(e);if(t){const e=js(t);return this._cache.upsertEntity(e),e}}catch(e){console.log(e)}return null}async getChildrenCount(e){if(!e)return 0;const t=this.normalizeId(null!=e?e:this._rootId);return this._isDeletingId(t)?0:this._cache.getChildrenCount(t,async()=>{var e;try{if(this._options.clientSidePaging){const o=await this.getFiles({folderId:t,itemType:"all",page:1,limit:25});return null!==(e=o.pagination.total)&&void 0!==e?e:o.files.length}const o=await this._dataProvider.getItems({folderId:t,limit:0,itemType:"all"});return void 0!==o.pagination?o.pagination.total||0:!1===this._options.enablePagination?o.items.length:0}catch(e){if(this._isDeletingId(t))return 0;if(this._isPathFolderNotFoundError(e))return 0;throw e}})}_isPathFolderNotFoundError(e){var t,o,r;if(!e||"object"!=typeof e)return!1;const n=e;return"path_folder_not_found"===n.code||"path_folder_not_found"===(null===(t=n.data)||void 0===t?void 0:t.code)||404===n.status||404===(null===(r=null===(o=n.data)||void 0===o?void 0:o.data)||void 0===r?void 0:r.status)}async _uploadFile(e){var t,o;const r=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);if("function"!=typeof this._dataProvider.uploadFile)throw new Jn("Upload file operation is not supported by data provider","UnsupportedOperation");if(this._validateName(e.name,!1),this._validateDuplicates){if(this._checkNameExistsInCache(r,e.name,!1)){const t="File '%s' already exists in target folder".replace("%s",e.name);throw new Jn(t,"FileAlreadyExists")}}const n=await this._dataProvider.uploadFile(Object.assign(Object.assign({},e),{folderId:r})),i=js(Object.assign(Object.assign({name:e.name,size:e.size},n),{folderId:null!==(o=n.folderId)&&void 0!==o?o:r}));return this._cache.upsertEntity(i),i}async uploadFiles(e){var t,o,r,n,i;const a=e.items.some(e=>e.noFolder)?await this.getTempFolder():null;e=Object.assign(Object.assign({},e),{items:null===(t=e.items)||void 0===t?void 0:t.map(e=>Object.assign(Object.assign({},e),{folderId:e.noFolder?null==a?void 0:a.id:e.folderId}))});for(const t of e.items)t.folderId&&(e.folderId=t.folderId);const l=e.items||[],s=null!==(o=e.folderId)&&void 0!==o?o:this._rootId,d=this.normalizeId(s);if(this._validateDuplicates)for(const e of l)if(e.name){this._validateName(e.name,!1);const t=this.normalizeId(null!==(r=e.folderId)&&void 0!==r?r:d);if(this._checkNameExistsInCache(t,e.name,!1)){const t="File '%s' already exists in target folder".replace("%s",e.name);throw new Jn(t,"FileAlreadyExists")}}const c=this._cache.getEntity(d);let u={detailed:new Array(l.length),success:!0};if("function"==typeof this._dataProvider.uploadFiles){const e=l.map(e=>{var t;return Object.assign(Object.assign({},e),{folderId:this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:d)})});if(u=Ms(await this._dataProvider.uploadFiles({folderId:d,items:e}),e=>{if(e)return{id:e.id,name:Us(e.name),folderId:e.folderId,url:e.url,thumbnailUrl:e.thumbnailUrl,thumbnail:e.thumbnail}}),u.detailed&&u.detailed.length){for(let e=0;e<u.detailed.length;e++){const t=u.detailed[e];if(t&&t.success){const e=t.data,o=null!==(n=null==e?void 0:e.id)&&void 0!==n?n:t.requestId,r=js(Object.assign(Object.assign(Object.assign({},c),e),{folderId:null!==(i=null==e?void 0:e.folderId)&&void 0!==i?i:d}));this._cache.upsertEntity(r),t.requestId=o}}void 0===u.success&&(u.success=!u.detailed.some(e=>!e.success))}else u.success=!u.error&&!!u.success}else{if("function"!=typeof this._dataProvider.uploadFile)throw new Jn("Upload files is not supported by data provider","UnsupportedOperation");u.detailed=await Promise.all(l.map(async e=>{var t;const o=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:d);try{const t=await this._uploadFile(Object.assign(Object.assign({},e),{folderId:o}));return{requestId:t.id,data:t,success:!0}}catch(t){return{requestId:null==e?void 0:e.id,success:!1,error:t}}})),u.success=!u.detailed.some(e=>!e.success)}if(u.success&&this._enableTrash)try{this._cache.forceInvalidate(d)}catch(e){}return u}async deleteFile(e){const t=this.normalizeId(e),o=[t];this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash){const e=await this.getTrashFolder();return await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!1})}return await this.hardDeleteItem(t)}finally{this._mutationRegistry.endDeleting(o)}}async deleteItems(e,t){const o=Array.from(new Set(e.flatMap(e=>this._collectDeletingIds(this.normalizeId(e)))));this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash&&!0!==t.permanent){const t=await this.getTrashFolder();return await this.moveItems(t.id,e)}return await this.hardDeleteItems(e,t)}finally{this._mutationRegistry.endDeleting(o)}}async hardDeleteItems(e,t){let o={success:!0,detailed:[]};const r=t.permanent?null:await this.getTrashFolder();if("function"==typeof this._dataProvider.deleteItems){if(o=Ms(await this._dataProvider.deleteItems(e.map(e=>this._cache.getEntity(e)),t),e=>e),o.success){const t=o.detailed||e.map(e=>({requestId:e,success:!0,error:void 0}));for(const e of t)e.success&&(r?this._cache.moveEntity(e.requestId,r.id):this._cache.deleteEntity(e.requestId))}}else"function"==typeof this._dataProvider.deleteItem&&(o.detailed=await Promise.all(e.map(async e=>{const o=this._cache.getEntity(e);if(!o){const t="FileNotFound",o="Item with id '%s' not found".replace("%s",e);return{requestId:e,success:!1,error:new Jn(o,t)}}try{return await this._dataProvider.deleteItem(o,t),r?this._cache.moveEntity(e,r.id):this._cache.deleteEntity(e),{requestId:e,success:!0}}catch(t){return{requestId:e,error:t,success:!1}}})),o.success=!o.detailed.some(e=>!e.success));if(o.success&&r)try{this._cache.forceInvalidate(r.id)}catch(e){}return o}async hardDeleteItem(e){const t=this._cache.getEntity(e);if(!t){const t="Item with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}if("function"!=typeof this._dataProvider.deleteItem)throw new Jn("Delete item operation is not supported by data provider","DeleteNotAllowed");if(await this._dataProvider.deleteItem(t,{permanent:!0}),this._cache.deleteEntity(e),this._enableTrash)try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(e){}return!0}async cleanTrash(){if(!this._enableTrash)throw new Jn("Trash is not enabled","UnsupportedOperation");if("function"==typeof this._dataProvider.cleanTrash){const e=await this._dataProvider.cleanTrash();try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(e){}return e}throw new Jn("Clean trash is not supported by data provider","UnsupportedOperation")}async createFolder({name:e,parentId:t,is_force_create:o}){const r=this.normalizeId(null!=t?t:this._rootId);if(this._validateName(e,!0),this._validateDuplicates){if(this._checkNameExistsInCache(r,e,!0)){const t="Folder '%s' already exists in parent folder".replace("%s",e);throw new Jn(t,"FolderAlreadyExists")}}const n=await this._dataProvider.createFolder(e,r,o),i=js({id:n.id,folderId:r,name:n.name,isFolder:!0,childrenCount:n.childrenCount});return this._cache.upsertEntity(i),Object.assign(Object.assign({},n),{name:i.name})}async deleteFolder(e){const t=this.normalizeId(e),o=this._collectDeletingIds(t);this._mutationRegistry.beginDeleting(o);try{if(this._useSoftDelete&&this._enableTrash)try{const e=await this.getTrashFolder();return!!await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!0})&&(this._cache.deleteFolderRecursive(t),!0)}catch(e){return console.error("Error moving folder to trash:",e),await this.hardDeleteItem(t)}return await this.hardDeleteItem(t)}finally{this._mutationRegistry.endDeleting(o)}}async renameFolder(e,t){if("function"!=typeof this._dataProvider.renameItem)throw new Jn("Rename folder is not supported","RenameNotAllowed");const o=this.normalizeId(e),r=this._cache.getEntity(o);if(!r){const t="Folder with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FolderNotFound")}if(this._validateName(t,!0),this._validateDuplicates){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t,!0,o)){const e="Folder '%s' already exists in parent folder".replace("%s",t);throw new Jn(e,"FolderAlreadyExists")}}const n=Ds(await this._dataProvider.renameItem(r,t));return this._cache.upsertEntity(js(Object.assign(Object.assign({},this._cache.getEntity(n.id)),n))),this._cache.getEntity(n.id)}async renameFile(e,t){if("function"!=typeof this._dataProvider.renameItem)throw new Jn("Rename file is not supported","RenameNotAllowed");const o=this._cache.getEntity(e);if(!o){const t="File with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}const r=this.normalizeId(e);if(this._validateName(t,!1),this._validateDuplicates){const e=this.normalizeId(o.folderId);if(this._checkNameExistsInCache(e,t,!1,r)){const e="File '%s' already exists in parent folder".replace("%s",t);throw new Jn(e,"FileAlreadyExists")}}const n=Ds(await this._dataProvider.renameItem(o,t));return n&&this._cache.upsertEntity(js(Object.assign(Object.assign({},this._cache.getEntity(r)),n))),this._cache.getEntity(r)}async moveItem({itemId:e,targetFolderId:t,isFolder:o}){if("function"!=typeof this._dataProvider.moveItem)throw new Jn("Move item operation is not supported by data provider","MoveNotAllowed");const r=this.normalizeId(t);this._validateTargetFolderType(t);const n=this._cache.getEntity(e);if(!n){const t=Ds(await this._dataProvider.moveItem({id:e,folderId:r,isFolder:o},r));if(t.id===e)this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:r})));else{try{this._cache.deleteEntity(e)}catch(e){}this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:r})))}return!0}if(n.isFolder){if(e===r)throw new Jn("Cannot move folder into itself","MoveIntoSelf");if(this._isAncestor(e,r))throw new Jn("Cannot move folder into its descendant","MoveIntoDescendant")}if(this._validateDuplicates){if(r!==this.normalizeId(n.folderId)&&n.name){if(this._checkNameExistsInCache(r,n.name,!!n.isFolder,e)){const e=n.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${n.isFolder?"Folder":"File"} '${n.name}' already exists in target folder`,e)}}}const i=Ds(await this._dataProvider.moveItem(n,r));if(i.id===e){const t=this._cache.moveEntity(e,r);return this._cache.upsertEntity(js(Object.assign(Object.assign({},t),i))),!0}{const t=this._cache.deleteEntity(e);return this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},t),i),{folderId:r}))),!0}}async moveItems(e,t){const o=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>this._cache.getEntity(e));for(const e of r)if(e){if(e.isFolder){if(e.id===o){const t="Cannot move folder '%s' into itself".replace("%s",e.name);throw new Jn(t,"MoveIntoSelf")}if(this._isAncestor(e.id,o)){const t="Cannot move folder '%s' into its descendant".replace("%s",e.name);throw new Jn(t,"MoveIntoDescendant")}}if(this._validateDuplicates){const t=this.normalizeId(e.folderId);if(o!==t&&e.name){if(this._checkNameExistsInCache(o,e.name,!!e.isFolder,e.id)){const t=e.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${e.isFolder?"Folder":"File"} '${e.name}' already exists in target folder`,t)}}}}let n={detailed:new Array(r.length),success:!0};if("function"==typeof this._dataProvider.moveItems){n=Ms(await this._dataProvider.moveItems(r,o),e=>e)}else{if("function"!=typeof this._dataProvider.moveItem)throw new Jn("Move items is not supported","MoveNotAllowed");n.detailed=await Promise.all(t.map(async(e,t)=>{const n=r[t]||{id:e,folderId:null,isFolder:!1,name:e};try{return{requestId:e,data:Ds(await this._dataProvider.moveItem(n,o)),success:!0}}catch(t){return{requestId:e,success:!1,error:t}}}))}if(n.success){const e=n.detailed||t.map(e=>({requestId:e,success:!0,data:void 0}));for(const t of e)if(t.success)if(t.data&&t.data.id!==t.requestId){const e=this._cache.deleteEntity(t.requestId);this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},e),t.data),{folderId:o})))}else this._cache.moveEntity(t.requestId,o),t.data&&this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},this._cache.getEntity(t.requestId)),t.data),{folderId:o})));return n}return{success:!1,error:n.error||new Jn("Move items failed","MoveNotAllowed")}}async copyItem({itemId:e,targetFolderId:t}){if("function"!=typeof this._dataProvider.copyItem)throw new Jn("Copy item is not supported","CopyNotAllowed");const o=this.normalizeId(t);this._validateTargetFolderType(t);const r=this._cache.getEntity(e);if(!r){const t=Ds(await this._dataProvider.copyItem({id:e,folderId:o},o));return this._cache.copyEntity(e,o,t.id),this._cache.upsertEntity(js(Object.assign(Object.assign({},t),{folderId:o}))),!0}if(this._validateDuplicates&&r.name){const t=o===this.normalizeId(r.folderId)?e:void 0;if(this._checkNameExistsInCache(o,r.name,!!r.isFolder,t)){const e=r.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${r.isFolder?"Folder":"File"} '${r.name}' already exists in target folder`,e)}}const n=Ds(await this._dataProvider.copyItem(r,o));return this._cache.copyEntity(e,o,n.id,Object.assign(Object.assign({},n),{folderId:o}))||this._cache.upsertEntity(js(Object.assign(Object.assign({},n),{folderId:o}))),!0}async copyItems(e,t){var o;const r=this.normalizeId(e);this._validateTargetFolderType(e);const n=t.map(e=>"string"==typeof e?{id:e}:e),i=n.map(e=>e.id),a=i.map((e,t)=>{var o;const r=this._cache.getEntity(e),i=null===(o=n[t])||void 0===o?void 0:o.newName;return r?i?Object.assign(Object.assign({},r),{name:i}):r:void 0});if(this._validateDuplicates)for(let e=0;e<a.length;e++){const t=a[e];if(t&&t.name){const o=this.normalizeId(t.folderId),n=r===o?i[e]:void 0;if(this._checkNameExistsInCache(r,t.name,!!t.isFolder,n)){const e=t.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new Jn(`${t.isFolder?"Folder":"File"} '${t.name}' already exists in target folder`,e)}}}let l={detailed:new Array(a.length),success:!0};if("function"==typeof this._dataProvider.copyItems){l=Ms(await this._dataProvider.copyItems(a,r),e=>e)}else{if("function"!=typeof this._dataProvider.copyItem)throw new Jn("Copy items is not supported","CopyNotAllowed");l.detailed=await Promise.all(i.map(async(e,t)=>{const o=a[t]||{id:e,folderId:null,isFolder:!1};try{return{requestId:e,data:Ds(await this._dataProvider.copyItem(o,r)),success:!0}}catch(t){return{requestId:e,success:!1,error:t}}}))}if(l.success&&l.detailed)for(let e=0,t=l.detailed.length;e<t;e++){const t=l.detailed[e];if(t.success)if(null===(o=t.data)||void 0===o?void 0:o.id){const e=t.data.folderId||r;!this._cache.copyEntity(t.requestId,e,t.data.id,Object.assign(Object.assign({},t.data),{folderId:e}))&&t.data&&this._cache.upsertEntity(js(Object.assign(Object.assign({},t.data),{folderId:e})))}else console.error("batchResult in copy method must have ids")}else if(!l.detailed)throw new Jn("batchResult in copy method must have detailed results","ValidationError");return l}async uploadFileByUrl(e){var t;if(e.noFolder){const t=await this.getTempFolder();e=Object.assign(Object.assign({},e),{folderId:null==t?void 0:t.id})}const o=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);try{const t=await this._dataProvider.uploadFileByUrl(e.url,o,{eventSource:e.eventSource}),r=js(Object.assign(Object.assign({},t),{folderId:o}));return this._cache.upsertEntity(r),r}catch(e){throw console.error("uploadFileByUrl error:",e),e}}async updateFile(e,t){if("function"!=typeof this._dataProvider.updateFile)throw new Jn("Update file is not supported","UnsupportedOperation");const o=this.normalizeId(e),r=this._cache.getEntity(o);if(!r){const t="File with id '%s' not found in cache".replace("%s",e);throw new Jn(t,"FileNotFound")}if(t.name&&t.name!==r.name&&this._validateName(t.name,!1),this._validateDuplicates&&t.name&&t.name!==r.name){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t.name,!1,o)){const e="File '%s' already exists in parent folder".replace("%s",t.name);throw new Jn(e,"FileAlreadyExists")}}const n=Ds(await this._dataProvider.updateFile(r,Object.assign({},t)));return this._cache.upsertEntity(js(Object.assign(Object.assign(Object.assign({},this._cache.getEntity(o)),n),t))),this._cache.getEntity(o)}}var zs,qs=new Uint8Array(16);function Ws(){if(!zs&&!(zs="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return zs(qs)}var Vs=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var $s=[],Hs=0;Hs<256;++Hs)$s.push((Hs+256).toString(16).substr(1));function Gs(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=($s[e[t+0]]+$s[e[t+1]]+$s[e[t+2]]+$s[e[t+3]]+"-"+$s[e[t+4]]+$s[e[t+5]]+"-"+$s[e[t+6]]+$s[e[t+7]]+"-"+$s[e[t+8]]+$s[e[t+9]]+"-"+$s[e[t+10]]+$s[e[t+11]]+$s[e[t+12]]+$s[e[t+13]]+$s[e[t+14]]+$s[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Vs.test(e)}(o))throw TypeError("Stringified UUID is invalid");return o}function Ks(e,t,o){var r=(e=e||{}).random||(e.rng||Ws)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,Gs(r)}class Qs{constructor(e,t="",o="Trash",r="Trash",n=!0){var i;this._inner=e,this.rootPath=t,this.trashId=o,this.trashPath=r,this.ensureFolderTrailingSlash=n,this._pathToId=new Map,this._idToPath=new Map,this.validateDuplicates=null!==(i=this._inner.validateDuplicates)&&void 0!==i&&i,"function"==typeof e.getUrl&&(this.getUrl=t=>e.getUrl(Object.assign(Object.assign({},t),{id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath}))),"function"==typeof e.getThumbnailUrl&&(this.getThumbnailUrl=t=>e.getThumbnailUrl(Object.assign(Object.assign({},t),{id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})));const a=this;"function"!=typeof this._inner.deleteItems&&(a.deleteItems=void 0),"function"!=typeof this._inner.deleteItem&&(a.deleteItem=void 0),"function"!=typeof this._inner.moveItems?a.moveItems=void 0:a.moveItem=void 0,"function"!=typeof this._inner.copyItems?a.copyItems=void 0:a.copyItem=void 0,"function"!=typeof this._inner.uploadFiles?a.uploadFiles=void 0:a.uploadFile=void 0,"function"!=typeof this._inner.clearCache&&(a.clearCache=void 0),this._getOrGenerateId(this.rootPath)}setController(e){"function"==typeof this._inner.setController&&this._inner.setController({invalidateItemCache:t=>{const o=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(o);r&&e.invalidateItemCache(r)},getCachedItem:t=>{var o,r,n;const i=t.replace(/^\/+|\/+$/g,""),a=this._pathToId.get(i);if(a){const t=e.getCachedItem(a);if(t)return Object.assign(Object.assign({},t),{id:this.pathForId(t.id,null!==(o=t.isFolder)&&void 0!==o&&o),folderId:this.pathForId(null!==(r=t.folderId)&&void 0!==r?r:"",null!==(n=t.isFolder)&&void 0!==n&&n)})}}})}clearCache(e){if("function"==typeof this._inner.clearCache)return this._inner.clearCache(e)}_getOrGenerateId(e){if(e===this.rootPath)return"";const t=e.replaceAll(/^\/+|\/+$/g,"");if(t===this.trashPath.replaceAll(/^\/+|\/+$/g,""))return this.trashId;if(this._pathToId.has(t))return this._pathToId.get(t);const o=Ks();return this._pathToId.set(t,o),this._idToPath.set(o,t),o}pathForId(e,t,o){if(""===e||void 0===e)return this.rootPath;if(e===this.trashId)return this.trashPath;let r=this._idToPath.get(e);if(!r){if(o)return`unknown folder ${e}`;throw new Jn(`Path for id '${e}' not found in mapping`,"FileNotFound")}let n=0;for(;n<this.rootPath.length&&"/"===this.rootPath[n];)n++;if(n){let e=0;for(;e<r.length&&"/"===r[e];)e++;const t=r.slice(e);r="/".repeat(n)+t}return t&&this.ensureFolderTrailingSlash&&!r.endsWith("/")&&(r+="/"),r}_updateIdMapping(e,t){const o=t.replace(/^\/+|\/+$/g,""),r=this._idToPath.get(e);r&&this._pathToId.delete(r),this._idToPath.set(e,o),this._pathToId.set(o,e)}async getItems(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,o=await this._inner.getItems(Object.assign(Object.assign({},e),{folderId:t})),r=o.items.map(e=>{const t=this._getOrGenerateId(e.id),o=e.folderId?this._getOrGenerateId(e.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},e),{id:t,folderId:o})});return Object.assign(Object.assign({},o),{items:r})}async createFolder(e,t,o){const r=t?this.pathForId(t,!0):this.rootPath,n=await this._inner.createFolder(e,r,o),i=this._getOrGenerateId(n.id),a=n.folderId?this._getOrGenerateId(n.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},n),{id:i,folderId:a})}async renameItem(e,t){var o,r;if("function"!=typeof this._inner.renameItem){throw new Jn("Rename item is not supported by inner storage","RenameNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=n;let a=Rn(await this._inner.renameItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),t),[]);return this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,i,a.id),a.folderId&&(a=Object.assign(Object.assign({},a),{folderId:this._getOrGenerateId(a.folderId)})),Object.assign(Object.assign({},a),{id:this._getOrGenerateId(a.id)})}async deleteItem(e,t){var o,r;if("function"!=typeof this._inner.deleteItem){throw new Jn("Delete item is not supported by inner storage","DeleteNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o);await this._inner.deleteItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),t),this.recursivelyRemoveMappings(e.id,n)}async uploadFile(e){if("function"!=typeof this._inner.uploadFile){throw new Jn("Upload file is not supported by inner storage","UnsupportedOperation")}const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,o=await this._inner.uploadFile(Object.assign(Object.assign({},e),{folderId:t})),r=this._getOrGenerateId(o.id),n=o.folderId?this._getOrGenerateId(o.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},o),{id:r,folderId:n})}async uploadFiles(e){var t,o,r,n,i;const a=e.folderId,l=null!==(o=null===(t=e.items)||void 0===t?void 0:t.map(e=>e.folderId))&&void 0!==o?o:[],s=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,d=Object.assign(Object.assign({},e),{folderId:s,items:null!==(n=null===(r=e.items)||void 0===r?void 0:r.map(e=>{var t;return Object.assign(Object.assign({},e),{folderId:e.folderId?this.pathForId(null!==(t=e.folderId)&&void 0!==t?t:"",!0):s})}))&&void 0!==n?n:[]}),c=await this._inner.uploadFiles(d);return Object.assign(Object.assign({},c),{detailed:null===(i=c.detailed)||void 0===i?void 0:i.map((e,t)=>{var o,r;if(!(null==e?void 0:e.data))return e;const n=e.data.id?this._getOrGenerateId(e.data.id):"",i=e.data.folderId?this._getOrGenerateId(e.data.folderId):null!==(r=null!==(o=l[t])&&void 0!==o?o:a)&&void 0!==r?r:this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},e),{data:Object.assign(Object.assign({},e.data),{id:n,folderId:i})})})})}async findFileByUrl(e,t){const o=t?this.pathForId(t,!0):this.rootPath;if("function"==typeof this._inner.findFileByUrl){const t=await this._inner.findFileByUrl(e,o);if(!t)return;const r=this._getOrGenerateId(t.id),n=t.folderId?this._getOrGenerateId(t.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},t),{id:r,folderId:n})}}async uploadFileByUrl(e,t,o){const r=t?this.pathForId(t,!0):this.rootPath,n=await this._inner.uploadFileByUrl(e,r,o),i=this._getOrGenerateId(n.id),a=n.folderId?this._getOrGenerateId(n.folderId):this._getOrGenerateId(this.rootPath);return Object.assign(Object.assign({},n),{id:i,folderId:a})}async moveItem(e,t){var o,r;if("function"!=typeof this._inner.moveItem){throw new Jn("Move item is not supported by inner storage","MoveNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.moveItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),i);this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,n,a.id);const l=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return Object.assign(Object.assign({},a),{id:l,folderId:s})}async moveItems(e,t){var o;if("function"!=typeof this._inner.moveItems){throw new Jn("Move items is not supported by inner storage","MoveNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,n=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),i=await this._inner.moveItems(n,r),a=[];if(i.detailed&&i.detailed.length>0){const r=new Map;for(let t=0;t<i.detailed.length;t++){const o=i.detailed[t],n=o.requestId||(t<e.length?e[t].id:void 0);n&&r.set(n,o)}for(const n of e){const l=r.get(n.id)||(i.detailed.length===e.length?i.detailed[e.indexOf(n)]:void 0);if((null==l?void 0:l.success)&&l.data){if(this._updateIdMapping(n.id,l.data.id),n.isFolder){const e=this.pathForId(n.id,null!==(o=n.isFolder)&&void 0!==o&&o);this.remapCachedFolderContents(n.id,e,l.data.id)}a.push({requestId:n.id,success:!0,data:Object.assign(Object.assign({},l.data),{id:this._getOrGenerateId(l.data.id),folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)})})}else{const e="Move operation failed - no detailed result";a.push({requestId:n.id,success:!1,error:(null==l?void 0:l.error)||{message:e,code:"MoveNotAllowed"}})}}}else for(const t of e){const e="Move operation failed - no detailed results";a.push({requestId:t.id,success:!1,error:{message:e,code:"MoveNotAllowed"}})}return{success:i.success,detailed:a,error:i.error}}async copyItems(e,t){var o;if("function"!=typeof this._inner.copyItems){throw new Jn("Copy items is not supported by inner storage","CopyNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,n=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),i=await this._inner.copyItems(n,r),a=[];if(i.detailed&&i.detailed.length>0){const r=new Map;for(let t=0;t<i.detailed.length;t++){const o=i.detailed[t],n=o.requestId||(t<e.length?e[t].id:void 0);n&&r.set(n,o)}for(const n of e){const l=r.get(n.id)||(i.detailed.length===e.length?i.detailed[e.indexOf(n)]:void 0);if((null==l?void 0:l.success)&&(null===(o=l.data)||void 0===o?void 0:o.id)){const e=this._getOrGenerateId(l.data.id);a.push({requestId:n.id,success:!0,data:Object.assign(Object.assign({},l.data),{id:e,folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)})})}else{const e=l?l.success?l.data?l.data.id?{message:"Unknown copy error",code:"CopyNotAllowed"}:{message:"No ID in copied item data",code:"CopyNotAllowed"}:{message:"No data returned from copy operation",code:"CopyNotAllowed"}:l.error||{message:"Copy operation failed",code:"CopyNotAllowed"}:{message:"No detailed result from copy operation",code:"CopyNotAllowed"};a.push({requestId:n.id,success:!1,error:e})}}}else for(const t of e){const e="No detailed results from copy operation";a.push({requestId:t.id,success:!1,error:{message:e,code:"CopyNotAllowed"}})}const l=a.every(e=>e.success);return{success:l,detailed:a,error:l?void 0:i.error||{message:"Copy operation completed with errors",code:"CopyNotAllowed"}}}async deleteItems(e,t){var o,r,n,i;if("function"!=typeof this._inner.deleteItems){throw new Jn("Delete items is not supported by inner storage","DeleteNotAllowed")}const a=e.map(e=>{var t,o;return Object.assign(Object.assign({},e),{id:this.pathForId(e.id,null!==(t=e.isFolder)&&void 0!==t&&t),folderId:e.folderId?this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0):this.rootPath})}),l=await this._inner.deleteItems(a,t),s=[];if(l.detailed&&l.detailed.length>0){const n=new Map;for(let t=0;t<l.detailed.length;t++){const o=l.detailed[t],r=o.requestId||(t<e.length?e[t].id:void 0);r&&n.set(r,o)}for(const i of e){const a=n.get(i.id)||(l.detailed.length===e.length?l.detailed[e.indexOf(i)]:void 0);if(null==a?void 0:a.success){const e=this.pathForId(i.id,null!==(o=i.isFolder)&&void 0!==o&&o);if(t.permanent)this.recursivelyRemoveMappings(i.id,e);else if(this._updateIdMapping(i.id,this.trashPath+"/"+e+(i.isFolder?"/":"")),i.isFolder){const t=this.pathForId(i.id,null!==(r=i.isFolder)&&void 0!==r&&r);this.remapCachedFolderContents(i.id,t,this.trashPath+"/"+e+(i.isFolder?"/":""))}s.push({requestId:i.id,success:!0})}else{const e="Delete operation failed";s.push({requestId:i.id,success:!1,error:(null==a?void 0:a.error)||{message:e,code:"DeleteNotAllowed"}})}}}else for(const o of e)if(l.success){const e=this.pathForId(o.id,null!==(n=o.isFolder)&&void 0!==n&&n);if(t.permanent)this.recursivelyRemoveMappings(o.id,e);else if(this._updateIdMapping(o.id,this.trashPath+"/"+e+(o.isFolder?"/":"")),o.isFolder){const t=this.pathForId(o.id,null!==(i=o.isFolder)&&void 0!==i&&i);this.remapCachedFolderContents(o.id,t,this.trashPath+"/"+e+(o.isFolder?"/":""))}s.push({requestId:o.id,success:!0})}else{const e="Delete operation failed";s.push({requestId:o.id,success:!1,error:l.error||{message:e,code:"DeleteNotAllowed"}})}const d=s.every(e=>e.success);return{success:d,detailed:s,error:d?void 0:l.error||{message:"Some items failed to delete",code:"DeleteNotAllowed"}}}remapCachedFolderContents(e,t,o){const r=t.replace(/\/+$/,""),n=o.replace(/\/+$/,""),i=[];for(const[e,t]of this._idToPath.entries()){const o=t.replace(/\/+$/,"");o!==r&&o.startsWith(r+"/")&&i.push({id:e,oldPath:o})}for(const{id:e,oldPath:t}of i){const o=n+t.substring(r.length);this._updateIdMapping(e,o)}}recursivelyRemoveMappings(e,t){const o=t.replace(/\/+$/,""),r=[],n=[];for(const[e,t]of this._idToPath.entries()){const i=t.replace(/\/+$/,"");(i===o||i.startsWith(o+"/"))&&(r.push(e),n.push(i))}for(let e=0;e<r.length;e++)this._idToPath.delete(r[e]),this._pathToId.delete(n[e])}async copyItem(e,t){var o,r;if("function"!=typeof this._inner.copyItem){throw new Jn("Copy item is not supported by inner storage","CopyNotAllowed")}const n=this.pathForId(e.id,null!==(o=e.isFolder)&&void 0!==o&&o),i=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.copyItem(Object.assign(Object.assign({},e),{id:n,folderId:this.pathForId(null!==(r=e.folderId)&&void 0!==r?r:"",!0)}),i),l=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):null!=t?t:"";return Object.assign(Object.assign({},a),{id:l,folderId:s})}async updateFile(e,t){var o;if("function"!=typeof this._inner.updateFile){throw new Jn("Update file is not supported by inner storage","UnsupportedOperation")}const r=this.pathForId(e.id,!1);let n=Rn(await this._inner.updateFile(Object.assign(Object.assign({},e),{id:r,folderId:this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0)}),t),[]);return this._updateIdMapping(e.id,n.id),n.folderId&&(n=Object.assign(Object.assign({},n),{folderId:this._getOrGenerateId(n.folderId)})),Object.assign(Object.assign({},n),{id:this._getOrGenerateId(n.id)})}async getFileData(e,t){var o;const r=this.pathForId(e.id,!1);if("function"==typeof this._inner.getFileData)return this._inner.getFileData(Object.assign(Object.assign({},e),{id:r,folderId:this.pathForId(null!==(o=e.folderId)&&void 0!==o?o:"",!0)}),t);const n=e.url||("function"==typeof this.getUrl?await this.getUrl(e):void 0);if(!n){throw new Jn("Cannot get file data: no url and no inner.getFileData","FileReadError")}return fetch(n,(null==t?void 0:t.forceReload)?{cache:"no-store"}:void 0).then(e=>e.blob())}async cleanTrash(){if("function"!=typeof this._inner.cleanTrash){throw new Jn("Clean trash is not supported by inner storage","UnsupportedOperation")}return await this._inner.cleanTrash()}}var Js={init:ms,unmount:ps,initPixieEditor:ys,unmountPixieEditor:ws,initFileManager:bs};export{Ea as A,Wa as B,$a as C,Pt as D,Rt as E,Ua as F,Jn as G,Cs as H,Ya as I,Qa as J,Ja as K,Fs as L,As as M,Cn as N,_s as O,vs as P,Ns as Q,Bs as R,Qs as S,Ls as T,gi as U,Ts as V,mn as a,gn as b,Ul as c,Zi as d,On as e,Kn as f,za as g,Tn as h,Xt as i,ri as j,ni as k,si as l,Da as m,Yt as n,Sn as o,Ho as p,ms as q,Lr as r,ps as s,fs as t,dr as u,ys as v,ws as w,bs as x,Js as y,cs as z};
10
+ //# sourceMappingURL=file-manager-index-Z8TrA-pu.js.map