"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[949],{93949:function(e,n,t){t.r(n),t.d(n,{SANDBOX_LINK_PREFIX:function(){return s},default:function(){return f},handleSandboxLinkClick:function(){return d}});var r=t(61706),a=t(45813),i=t(35250),c=t(70079),l=t(33264);function o(e){var n=e.accept,t=e.children,r=e.onFilePicked,a=(0,c.useRef)(null),l=(0,c.useCallback)(function(){var e;null===(e=a.current)||void 0===e||e.click()},[]),o=(0,c.useCallback)(function(e){var n,t=null===(n=e.target.files)||void 0===n?void 0:n[0];t&&(r(t),e.target.value="")},[r]);return(0,i.jsxs)(i.Fragment,{children:["function"==typeof t?t({onClick:l}):(0,i.jsx)("span",{role:"button",onClick:l,children:t}),(0,i.jsx)("input",{type:"file",accept:n,ref:a,className:"hidden",onChange:o})]})}var u=t(74516),s="sandbox:";function d(e,n,t){var i;return i=(0,r.Z)(function(r){var i,c,o,s,d,f,h,p,b,v;return(0,a.__generator)(this,function(a){switch(a.label){case 0:if(!(e.has("tools2")&&(null==n?void 0:null===(i=n.enabledTools)||void 0===i?void 0:i.includes("tools2"))))return[2];return c=r.substring(8),[4,l.ZP.checkFile(t.current,c)];case 1:if((o=a.sent()).exists)return[3,2];return u.m.warning("File does not exist: ".concat(c)),[3,6];case 2:if(!o.too_large)return[3,3];return s=(o.size/1024/1024).toFixed(0),d="100",u.m.warning("File is larger than download limit: ".concat(s," MB vs ").concat(d," MB")),[3,6];case 3:return[4,l.ZP.fetchFileForDownload(t.current,c)];case 4:return[4,a.sent().blob()];case 5:h=a.sent(),p=window.URL.createObjectURL(h),(b=document.createElement("a")).href=p,v=c.split("/").pop(),b.download=v,b.click(),a.label=6;case 6:return[2]}})}),function(e){return i.apply(this,arguments)}}function f(e){var n,t=e.onFileUpload,s=e.threadId,d=e.currentLeafId,f=e.modelBackend,h=e.disabled,p=e.children,b=(0,c.useState)(!1),v=b[0],k=b[1],g=(0,c.useCallback)((n=(0,r.Z)(function(e){var n,r,i;return(0,a.__generator)(this,function(a){switch(a.label){case 0:k(!0),a.label=1;case 1:if(a.trys.push([1,,3,4]),e.size>104857600)return n=(e.size/1024/1024).toFixed(0),r="100",u.m.warning("File is larger than upload limit: ".concat(n," MB vs ").concat(r," MB"),{hasCloseButton:!0,duration:15}),[2];return[4,l.ZP.upload(d,s,f,e)];case 2:return t(a.sent()),[3,4];case 3:return k(!1),[7];case 4:return[2]}})}),function(e){return n.apply(this,arguments)}),[t,s,d,f]);return h||v?p(v):(0,i.jsx)(o,{onFilePicked:g,children:p(v)})}}}]);