import './async-Djx13DAD.js';
import { c as bind_props, g as attr_style, e as ensure_array_like, d as attr_class, a as attr, f as html, i as slot } from './index-B7gr0Dsc.js';
import { t as tick } from './index-server-lqjMX237.js';
import { e as ee } from './Upload2-BHtWS_cp.js';
import './MarkdownCode.svelte_svelte_type_style_lang-DJRtJayx.js';
import { k } from './BlockLabel-DYKzuObf.js';
import { w } from './IconButton-7VBZdgpA.js';
import { o } from './Clear-CiR-WD8W.js';
import { i } from './File-CWWp_-I1.js';
import { h } from './Upload-C6YVFLtW.js';
import './2-CeYbpaU1.js';
import { y } from './IconButtonWrapper-DlgTGGi-.js';
import { u } from './DownloadLink-BLkRTIUs.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';

const Q=f=>{let g=["B","KB","MB","GB","PB"],t=0;for(;f>1024;)f/=1024,t++;let l=g[t];return f.toFixed(1)+"&nbsp;"+l};function S(f,g){f.component(t=>{let{value:l,selectable:A=false,height:c=void 0,i18n:r,allow_reordering:d=false,onselect:U,onchange:x,ondelete:B,ondownload:b}=g,y=null,m=null;function v(s){const p=s.lastIndexOf(".");return p===-1?[s,""]:[s.slice(0,p),s.slice(p)]}let o=(Array.isArray(l)?l:[l]).map(s=>{const[p,n]=v(s.orig_name??"");return {...s,filename_stem:p,filename_ext:n}});const I=typeof window<"u";t.push(`<div class="file-preview-holder svelte-al0bnp"${attr_style("",{"max-height":c?typeof c=="number"?c+"px":c:"auto"})}><table class="file-preview svelte-al0bnp"><tbody class="svelte-al0bnp"><!--[-->`);const u$1=ensure_array_like(o);for(let s$1=0,p=u$1.length;s$1<p;s$1++){let n=u$1[s$1];t.push(`<tr${attr_class("file svelte-al0bnp",void 0,{selectable:A,dragging:y===s$1,"drop-target":m===s$1||s$1===o.length-1&&m===o.length})}${attr("data-drop-target",m===o.length&&s$1===o.length-1||m===s$1+1?"after":"before")}${attr("draggable",d&&o.length>1)}><td class="filename svelte-al0bnp"${attr("aria-label",n.orig_name)}>`),d&&o.length>1?(t.push("<!--[-->"),t.push('<span class="drag-handle svelte-al0bnp">⋮⋮</span>')):t.push("<!--[!-->"),t.push(`<!--]--> <span class="stem svelte-al0bnp">${escape_html(n.filename_stem)}</span> <span class="ext svelte-al0bnp">${escape_html(n.filename_ext)}</span></td><td class="download svelte-al0bnp">`),n.url?(t.push("<!--[-->"),u(t,{href:n.url,download:I&&window.__is_colab__?null:n.orig_name,children:k=>{k.push(`${html(n.size!=null?Q(n.size):"(size unknown)")} ⇣`);},$$slots:{default:true}})):(t.push("<!--[!-->"),t.push(`${escape_html(r("file.uploading"))}`)),t.push("<!--]--></td>"),o.length>1?(t.push("<!--[-->"),t.push('<td class="svelte-al0bnp"><button class="label-clear-button svelte-al0bnp" aria-label="Remove this file">×</button></td>')):t.push("<!--[!-->"),t.push("<!--]--></tr>");}t.push("<!--]--></tbody></table></div>");});}function ul(f,g){f.component(t=>{let{value:l=void 0,label:A,show_label:c=true,file_count:r="single",file_types:d=null,selectable:U=false,root:x,height:B=void 0,i18n:b,max_file_size:y$1=null,upload:m,stream_handler:v,uploading:o$1=false,allow_reordering:I=false,upload_promise:u=void 0,buttons:s$1=null,on_custom_button_click:p=null,onchange:n,onclear:k$1,ondrag:T,onupload:K,onerror:P,ondelete:M,onselect:O}=g;async function C(a){Array.isArray(l)?l=[...l,...Array.isArray(a)?a:[a]]:l?l=[l,...Array.isArray(a)?a:[a]]:l=a,await tick(),n?.(l),K?.(l);}function R(){l=null,n?.(null),k$1?.();}let w$1=false,h$1=true,F;function W(a){c&&s$1&&s$1.length>0?(a.push("<!--[-->"),y(a,{buttons:s$1,on_custom_button_click:p})):a.push("<!--[!-->"),a.push("<!--]--> "),k(a,{show_label:c,Icon:i,float:!l,label:A||"File"}),a.push("<!----> "),l&&(!Array.isArray(l)||l.length>0)?(a.push("<!--[-->"),y(a,{buttons:s$1||[],on_custom_button_click:p,children:e=>{r==="single"&&(Array.isArray(l)?l.length>0:l!==null)?e.push("<!--[!-->"):(e.push("<!--[-->"),w(e,{Icon:h,label:b("common.upload"),children:z=>{ee(z,{icon_upload:true,onload:C,filetype:d,file_count:r,max_file_size:y$1,root:x,onerror:P,stream_handler:v,upload:m,get upload_promise(){return u},set upload_promise(_){u=_,h$1=false;},get dragging(){return w$1},set dragging(_){w$1=_,h$1=false;},get uploading(){return o$1},set uploading(_){o$1=_,h$1=false;}});}})),e.push("<!--]--> "),w(e,{Icon:o,label:b("common.clear"),onclick:z=>{z.stopPropagation(),R();}}),e.push("<!---->");}}),a.push("<!----> "),S(a,{i18n:b,onselect:O,selectable:U,value:l,height:B,onchange:n,ondelete:M,allow_reordering:I}),a.push("<!---->")):(a.push("<!--[!-->"),ee(a,{onload:C,filetype:d,file_count:r,max_file_size:y$1,root:x,onerror:P,stream_handler:v,upload:m,height:B,get upload_promise(){return u},set upload_promise(e){u=e,h$1=false;},get dragging(){return w$1},set dragging(e){w$1=e,h$1=false;},get uploading(){return o$1},set uploading(e){o$1=e,h$1=false;},children:e=>{e.push("<!--[-->"),slot(e,g,"default",{},null),e.push("<!--]-->");},$$slots:{default:true}})),a.push("<!--]-->");}do h$1=true,F=t.copy(),W(F);while(!h$1);t.subsume(F),bind_props(g,{value:l,uploading:o$1,upload_promise:u});});}

export { S, ul as u };
//# sourceMappingURL=FileUpload-CsdPUa5j.js.map
