import"./svelte/svelte_internal_flags_async.js";import*as e from"./svelte/svelte_internal_client.js";import"./i18n-CqG9A4Dp.js";import{G as q}from"./utils.svelte-kG009vb9.js";import{tick as C}from"./svelte/svelte_svelte.js";import{B as D}from"./Button-BRi4buhz.js";import{p as E}from"./index-aMLoRFR_.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_store.js";import"./Image-Bdf4wQSw.js";import"./ImagePreview-BMFpVSQw.js";import"./ScrollFade-DGw40oqj.js";import"./MarkdownCode-VTUoaX6K.js";import"./prism-python-BRxZ6l4O.js";import"./ShareButton-LQS1LEKZ.js";import"./FullscreenButton-C4AREqtB.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";var F=e.from_html('<img class="button-icon svelte-94gmgt"/>'),H=e.from_html("<!> <!>",1),J=e.from_html('<input class="hide svelte-94gmgt" type="file"/> <!>',1);function K(g,t){e.push(t,!0);let h=e.prop(t,"elem_id",3,""),r=e.prop(t,"elem_classes",19,()=>[]),d=e.prop(t,"visible",3,!0),c=e.prop(t,"file_types",19,()=>[]),v=e.prop(t,"size",3,"lg"),i=e.prop(t,"icon",3,null),m=e.prop(t,"scale",3,null),f=e.prop(t,"min_width",3,void 0),w=e.prop(t,"variant",3,"secondary"),z=e.prop(t,"disabled",3,!1),k=e.prop(t,"max_file_size",3,null),b,x=e.derived(()=>c()==null?null:c().map(a=>a.startsWith(".")?a:a+"/*").join(", "));function B(){t.onclick?.(),b.click()}async function G(l){let a=Array.from(l);if(!l.length)return;t.file_count==="single"&&(a=[l[0]]);let o=await E(a);await C();try{o=(await t.upload(o,t.root,void 0,k()??1/0))?.filter(p=>p!==null)}catch(p){t.onerror?.(p.message);return}const _=t.file_count==="single"?o?.[0]:o;t.onchange?.(_),t.onupload?.(_)}async function I(l){const a=l.target;a.files&&await G(a.files)}function P(l){const a=l.target;a.value&&(a.value="")}var y=J(),n=e.first_child(y);n.__change=I,n.__click=P,e.bind_this(n,l=>b=l,()=>b);var U=e.sibling(n,2);D(U,{get size(){return v()},get variant(){return w()},get elem_id(){return h()},get elem_classes(){return r()},get visible(){return d()},onclick:B,get scale(){return m()},get min_width(){return f()},get disabled(){return z()},children:(l,a)=>{var o=H(),_=e.first_child(o);{var p=s=>{var u=F();e.template_effect(()=>{e.set_attribute(u,"src",i().url),e.set_attribute(u,"alt",`${t.value} icon`)}),e.append(s,u)};e.if(_,s=>{i()&&s(p)})}var j=e.sibling(_,2);{var A=s=>{var u=e.comment(),W=e.first_child(u);e.snippet(W,()=>t.children),e.append(s,u)};e.if(j,s=>{t.children&&s(A)})}e.append(l,o)},$$slots:{default:!0}}),e.template_effect(()=>{e.set_attribute(n,"accept",e.get(x)),n.multiple=t.file_count==="multiple"||void 0,n.webkitdirectory=t.file_count==="directory"||void 0,e.set_attribute(n,"mozdirectory",t.file_count==="directory"||void 0),e.set_attribute(n,"data-testid",`${t.label??""}-upload-button`)}),e.append(g,y),e.pop()}e.delegate(["change","click"]);function me(g,t){e.push(t,!0);const h=e.rest_props(t,["$$slots","$$events","$$legacy"]),r=new q(h);let d=e.proxy(r.props.value);e.user_effect(()=>{d!==r.props.value&&(r.props.value=d)});async function c(i,m){r.props.value=i,r.dispatch(m)}const v=e.derived(()=>!r.shared.interactive);K(g,{get elem_id(){return r.shared.elem_id},get elem_classes(){return r.shared.elem_classes},get visible(){return r.shared.visible},get file_count(){return r.props.file_count},get file_types(){return r.props.file_types},get size(){return r.props.size},get scale(){return r.shared.scale},get icon(){return r.props.icon},get min_width(){return r.shared.min_width},get root(){return r.shared.root},get value(){return d},get disabled(){return e.get(v)},get variant(){return r.props.variant},get label(){return r.shared.label},get max_file_size(){return r.shared.max_file_size},onclick:()=>r.dispatch("click"),onchange:i=>c(i,"change"),onupload:i=>c(i,"upload"),onerror:i=>{r.dispatch("error",i)},upload:(...i)=>r.shared.client.upload(...i),children:(i,m)=>{e.next();var f=e.text();e.template_effect(()=>e.set_text(f,r.shared.label??"")),e.append(i,f)},$$slots:{default:!0}}),e.pop()}export{K as BaseUploadButton,me as default};
