import './async-D55cHugf.js';
import { d as bind_props, g as attr_style, e as ensure_array_like, f as attr_class, a as attr, s as slot } from './index-u8mz_F03.js';
import { t as tick } from './index-server-CQz6EZl_.js';
import { e as ee } from './Upload2-CnUKERBu.js';
import { k } from './BlockLabel-bKYWnOzQ.js';
import { w } from './IconButton-BRnu7KaR.js';
import { o } from './Clear-D7Yjckqz.js';
import { i } from './File-DQh5d1OO.js';
import { h } from './Upload-BbxeBrrD.js';
import './2-EyCg4N-O.js';
import { y } from './IconButtonWrapper-CjFRPb3y.js';
import { u } from './DownloadLink-fhqiT7bI.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import { h as html } from './html-CfyvkLET.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=0,p=u$1.length;s<p;s++){let n=u$1[s];t.push(`<tr${attr_class("file svelte-al0bnp",void 0,{selectable:A,dragging:y===s,"drop-target":m===s||s===o.length-1&&m===o.length})}${attr("data-drop-target",m===o.length&&s===o.length-1||m===s+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 pl(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=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&&s.length>0?(a.push("<!--[-->"),y(a,{buttons:s,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||[],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",{}),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, pl as p };
//# sourceMappingURL=FileUpload-Bo16oVud.js.map
