import './async-Djx13DAD.js';
import { c as bind_props, d as attr_class, g as attr_style, j as stringify, e as ensure_array_like, a as attr } from './index-B7gr0Dsc.js';
import './MarkdownCode.svelte_svelte_type_style_lang-DJRtJayx.js';
import { k } from './BlockLabel-DYKzuObf.js';
import { w } from './IconButton-7VBZdgpA.js';
import { p } from './Empty-uaeWNu3s.js';
import { y as y$1 } from './ShareButton-B1Vd_e6T.js';
import { o } from './Clear-CiR-WD8W.js';
import { l } from './Download-rAXPPveZ.js';
import { i } from './Image2-CJoaEJF4.js';
import { h, e } from './Upload-C6YVFLtW.js';
import { n } from './Play-BVmRHWoH.js';
import { r } from './Video-Cl-Q8BCK.js';
import { h as h$1 } from './Webcam-D2mdKJI9.js';
import { y } from './IconButtonWrapper-DlgTGGi-.js';
import { v } from './FullscreenButton-DPSRpBkM.js';
import { I as Ie } from './2-CeYbpaU1.js';
import { e as ee } from './Upload2-BHtWS_cp.js';
import { z } from './ModifyUpload-Dqp1u9XX.js';
import { c } from './Image-Bw5_tidM.js';
import { Q as Qu } from './Video2-pxW-QOKm.js';
import { w as w$1 } from './utils.svelte-D8Xdzglu.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './context-BZS6UlnY.js';
import './uneval-DjLoL4oF.js';
import './clone-BLo8hHdj.js';
import './prism-python-BaDPvmdn.js';
import './index-server-lqjMX237.js';
import './Maximize-DxOGYNPn.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import './DownloadLink-BLkRTIUs.js';
import './Edit-DVsun1ou.js';
import './Undo-DlTKhhuO.js';

async function It(m){return m?`<div style="display: flex; flex-wrap: wrap; gap: 16px">${(await Promise.all(m.map(async([p,g])=>p===null||!p.url?"":await w$1(p.url)))).map(p=>`<img src="${p}" style="height: 400px" />`).join("")}</div>`:""}async function al(m,v,p="uploaded_file"){const g=m.type.split("/")[1]||"png",h=new File([m],`${p}.${g}`),f=[new Ie({path:h.name,orig_name:h.name,blob:h,size:h.size,mime_type:h.type,is_stream:false})];return await v(...f)}function rt(m,v$1){m.component(p$1=>{let{show_label:g=true,label:h$2,value:f=void 0,columns:O=[2],rows:R=void 0,height:d="auto",preview:xt,allow_preview:S=true,object_fit:V="cover",show_share_button:C=false,show_download_button:W=false,i18n:_,selected_index:c$1=void 0,interactive:E,_fetch:A,show_fullscreen_button:H=true,fullscreen:q=false,root:J="",file_types:K=["image","video"],sources:k$1,max_file_size:N=null,upload:L,stream_handler:P,fit_columns:Q=true,buttons:X=null,oncustom_button_click:Y=null,onpreview_open:Ut=()=>{},onchange:jt=()=>{},onclear:Z=()=>{},onselect:Et=t=>{},onshare:Lt=t=>{},onerror:$=t=>{},onpreview_close:tt=()=>{},onfullscreen:lt=t=>{},ondelete:Pt=()=>{},onupload:at=()=>{},onsource_change:y$2=()=>{}}=v$1,B=null,I="normal",it=false,r$1=false,u=f==null?null:f.map(t=>"video"in t?{video:t.video,caption:t.caption}:"image"in t?{image:t.image,caption:t.caption}:{});function ot(t,n,a){if(t&&n&&a){const l=t.length;return Array.isArray(n)?n.map(i=>Math.min(i,l)):Math.min(n,l)}else return n}let st=ot(u,O,Q);((c$1??0)+(u?.length??0)-1)%(u?.length??0),((c$1??0)+1)%(u?.length??0);async function ut(t,n){let a;try{a=await A(t);}catch(z){if(z instanceof TypeError){window.open(t,"_blank","noreferrer");return}throw z}const l=await a.blob(),i=URL.createObjectURL(l),e=document.createElement("a");e.href=i,e.download=n,e.click(),URL.revokeObjectURL(i);}let s$1=c$1!=null&&u!=null?u[c$1]:null;let M=false,w$1=true,x;function nt(t){if(g?(t.push("<!--[-->"),k(t,{show_label:g,Icon:i,label:h$2||"Gallery"})):t.push("<!--[!-->"),t.push("<!--]--> "),f==null||u==null||u.length===0)t.push("<!--[-->"),p(t,{unpadded_box:true,size:"large",children:n=>{i(n);},$$slots:{default:true}});else {if(t.push("<!--[!-->"),t.push('<div class="gallery-container">'),s$1&&S){t.push("<!--[-->"),t.push(`<span${attr_class("preview svelte-7anmrz",void 0,{minimal:I==="minimal"})}>`),y(t,{display_top_corner:it,buttons:X,on_custom_button_click:Y,children:l$1=>{W?(l$1.push("<!--[-->"),w(l$1,{Icon:l,label:_("common.download"),onclick:()=>{const i="image"in s$1?s$1?.image:s$1?.video;if(i==null)return;const{url:e,orig_name:z}=i;e&&ut(e,z??"image");}})):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),H?(l$1.push("<!--[-->"),v(l$1,{fullscreen:q,onclick:i=>lt(i)})):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),C?(l$1.push("<!--[-->"),l$1.push('<div class="icon-button">'),y$1(l$1,{i18n:_,value:u,formatter:It}),l$1.push("<!----></div>")):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),(l$1.push("<!--[-->"),w(l$1,{Icon:o,label:"Close",onclick:()=>{c$1=null,tt();}})),l$1.push("<!--]-->");}}),t.push(`<!----> <button class="media-button svelte-7anmrz"${attr_style(`height: calc(100% - ${stringify(s$1.caption?"80px":"60px")})`)} aria-label="detailed view of selected image">`),"image"in s$1?(t.push("<!--[-->"),c(t,{restProps:{alt:s$1.caption||"",title:s$1.caption||null,class:s$1.caption&&"with-caption",loading:"lazy"},src:s$1.image.url,data_testid:"detailed-image"})):(t.push("<!--[!-->"),Qu(t,{src:s$1.video.url,"data-testid":"detailed-video",alt:s$1.caption||"",loading:"lazy",loop:false,is_stream:false,muted:false,controls:true})),t.push("<!--]--></button> "),s$1?.caption?(t.push("<!--[-->"),t.push(`<caption class="caption svelte-7anmrz">${escape_html(s$1.caption)}</caption>`)):t.push("<!--[!-->"),t.push(`<!--]--> <div class="thumbnails scroll-hide svelte-7anmrz" data-testid="container_el"${attr_style(`justify-content: ${stringify("center")};`)}><!--[-->`);const a=ensure_array_like(u);for(let l=0,i=a.length;l<i;l++){let e=a[l];t.push(`<button${attr_class("thumbnail-item thumbnail-small svelte-7anmrz",void 0,{selected:c$1===l&&I!=="minimal"})}${attr("aria-label","Thumbnail "+(l+1)+" of "+u.length)}>`),"image"in e?(t.push("<!--[-->"),c(t,{src:e.image.url,restProps:{title:e.caption||null,alt:"",class:"with-caption",loading:"lazy"},data_testid:`thumbnail ${l+1}`})):(t.push("<!--[!-->"),n(t),t.push("<!----> "),Qu(t,{src:e.video.url,title:e.caption||null,is_stream:false,"data-testid":"thumbnail "+(l+1),alt:"",loading:"lazy",loop:false}),t.push("<!---->")),t.push("<!--]--></button>");}t.push("<!--]--></div></span>");}else t.push("<!--[!-->");t.push(`<!--]--> <div${attr_class("grid-wrap svelte-7anmrz",void 0,{minimal:I==="minimal","fixed-height":!d||d=="auto",hidden:r$1})}${attr_style("",{height:d!=="auto"?d+"px":null})}>`),E&&c$1===null?(t.push("<!--[-->"),z(t,{i18n:_,onclear:()=>{f=[],y$2("upload"),Z();},children:a=>{L&&P?(a.push("<!--[-->"),w(a,{Icon:h,label:_("upload_text.click_to_upload"),children:l=>{ee(l,{icon_upload:true,onload:i=>at(i),filetype:K,file_count:"multiple",max_file_size:N,root:J,onerror:i=>$(i),stream_handler:P,upload:L,get upload_promise(){return B},set upload_promise(i){B=i,w$1=false;},get uploading(){return M},set uploading(i){M=i,w$1=false;}});}})):a.push("<!--[!-->"),a.push("<!--]--> "),k$1.includes("webcam")?(a.push("<!--[-->"),w(a,{Icon:h$1,label:_("common.webcam"),onclick:()=>{y$2("webcam");}})):a.push("<!--[!-->"),a.push("<!--]--> "),k$1.includes("webcam-video")?(a.push("<!--[-->"),w(a,{Icon:r,label:_("common.video"),onclick:()=>{y$2("webcam-video");}})):a.push("<!--[!-->"),a.push("<!--]--> "),k$1.includes("clipboard")?(a.push("<!--[-->"),w(a,{label:_("upload_text.paste_clipboard"),onclick:()=>{y$2("clipboard");},Icon:e})):a.push("<!--[!-->"),a.push("<!--]-->");}})):t.push("<!--[!-->"),t.push(`<!--]--> <div${attr_class("grid-container svelte-7anmrz",void 0,{"pt-6":g})}${attr_style(`--grid-cols:${stringify(st)}; --grid-rows:${stringify(R)}; --object-fit: ${stringify(V)};`)}><!--[-->`);const n$1=ensure_array_like(u);for(let a=0,l=n$1.length;a<l;a++){let i=n$1[a];t.push(`<div class="gallery-item svelte-7anmrz"><button${attr_class("thumbnail-item thumbnail-lg svelte-7anmrz",void 0,{selected:c$1===a})}${attr("aria-label","Thumbnail "+(a+1)+" of "+u.length)}>`),"image"in i?(t.push("<!--[-->"),c(t,{alt:i.caption||"",src:typeof i.image=="string"?i.image:i.image.url})):(t.push("<!--[!-->"),n(t),t.push("<!----> "),Qu(t,{src:i.video.url,title:i.caption||null,is_stream:false,"data-testid":"thumbnail "+(a+1),alt:"",loading:"lazy",loop:false}),t.push("<!---->")),t.push("<!--]--> "),i.caption?(t.push("<!--[-->"),t.push(`<div class="caption-label svelte-7anmrz">${escape_html(i.caption)}</div>`)):t.push("<!--[!-->"),t.push("<!--]--></button> "),E?(t.push("<!--[-->"),t.push('<button class="delete-button svelte-7anmrz" aria-label="Delete image">'),o(t),t.push("<!----></button>")):t.push("<!--[!-->"),t.push("<!--]--></div>");}t.push("<!--]--></div></div></div>");}t.push("<!--]-->");}do w$1=true,x=p$1.copy(),nt(x);while(!w$1);p$1.subsume(x),bind_props(v$1,{value:f,selected_index:c$1});});}const il=Object.freeze(Object.defineProperty({__proto__:null,default:rt},Symbol.toStringTag,{value:"Module"}));

export { rt as G, il as a, al as h };
//# sourceMappingURL=Gallery-tZ5Higzi.js.map
