import { e as escape_html } from './async-Mo2Ia14K.js';
import { c as bind_props, f as attr_class, d as attr_style, g as stringify, e as ensure_array_like, a as attr } from './index-D1Ptw7Az.js';
import { e as y, l as w, z as o, q as c, j as w$1 } from './2-B89dC7Mi.js';
import { k } from './BlockLabel-qrJKniS-.js';
import { p } from './Empty-DPmCPCDI.js';
import { y as y$1 } from './ShareButton-BgNheG3R.js';
import { l } from './Download-CXUtRxuu.js';
import { i } from './Image2-rnCO69bR.js';
import { n } from './Play-D2fLH3is.js';
import { i as i$1 } from './Upload-DAOKtkC7.js';
import { v } from './FullscreenButton-Dv8H9Qim.js';
import { e as ee } from './Upload2-oakrmUYI.js';
import { z } from './ModifyUpload-D9r3woqq.js';
import { Q as Qu } from './Video2-BcnuCSWl.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import 'path';
import 'url';
import 'fs';
import './spring-DE8vsW2o.js';
import './Maximize-CwvDIx8B.js';
import './DownloadLink-CHK0Lliu.js';
import './Edit-CJCte_uE.js';
import './Undo-TMAmuanl.js';

async function vt(h){return h?`<div style="display: flex; flex-wrap: wrap; gap: 16px">${(await Promise.all(h.map(async([c,f])=>c===null||!c.url?"":await w$1(c.url)))).map(c=>`<img src="${c}" style="height: 400px" />`).join("")}</div>`:""}function Nt(h,d){h.component(c$1=>{let{show_label:f=true,label:T,value:m=void 0,columns:C=[2],rows:D=void 0,height:_="auto",preview:bt,allow_preview:F=true,object_fit:A="cover",show_share_button:G=false,show_download_button:O=false,i18n:g,selected_index:e=void 0,interactive:I,_fetch:S,show_fullscreen_button:V=true,fullscreen:H=false,root:W="",file_types:q=["image","video"],max_file_size:J=null,upload:U,stream_handler:E,fit_columns:K=true,buttons:N=null,oncustom_button_click:Q=null,onpreview_open:dt=()=>{},onchange:yt=()=>{},onclear:X=()=>{},onselect:wt=t=>{},onshare:rt=t=>{},onerror:Y=t=>{},onpreview_close:Z=()=>{},onfullscreen:zt=t=>{},ondelete:kt=()=>{},onupload:$=()=>{}}=d,L=null,y$2="normal",tt=false,w$1=false,u=m==null?null:m.map(t=>"video"in t?{video:t.video,caption:t.caption}:"image"in t?{image:t.image,caption:t.caption}:{});function lt(t,n,o){if(t&&n&&o){const l=t.length;return Array.isArray(n)?n.map(i=>Math.min(i,l)):Math.min(n,l)}else return n}let it=lt(u,C,K);((e??0)+(u?.length??0)-1)%(u?.length??0),((e??0)+1)%(u?.length??0);async function at(t,n){let o;try{o=await S(t);}catch(b){if(b instanceof TypeError){window.open(t,"_blank","noreferrer");return}throw b}const l=await o.blob(),i=URL.createObjectURL(l),p=document.createElement("a");p.href=i,p.download=n,p.click(),URL.revokeObjectURL(i);}let s$1=e!=null&&u!=null?u[e]:null;let B=false,v$1=true,r;function ot(t){if(f?(t.push("<!--[-->"),k(t,{show_label:f,Icon:i,label:T||"Gallery"})):t.push("<!--[!-->"),t.push("<!--]--> "),m==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&&F){t.push("<!--[-->"),t.push(`<span${attr_class("preview svelte-7anmrz",void 0,{minimal:y$2==="minimal"})}>`),y(t,{display_top_corner:tt,buttons:N,on_custom_button_click:Q,children:l$1=>{O?(l$1.push("<!--[-->"),w(l$1,{Icon:l,label:g("common.download"),onclick:()=>{const i="image"in s$1?s$1?.image:s$1?.video;if(i==null)return;const{url:p,orig_name:b}=i;p&&at(p,b??"image");}})):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),V?(l$1.push("<!--[-->"),v(l$1,{fullscreen:H})):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),G?(l$1.push("<!--[-->"),l$1.push('<div class="icon-button">'),y$1(l$1,{i18n:g,value:u,formatter:vt}),l$1.push("<!----></div>")):l$1.push("<!--[!-->"),l$1.push("<!--]--> "),(l$1.push("<!--[-->"),w(l$1,{Icon:o,label:"Close",onclick:()=>{e=null,Z();}})),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 o$1=ensure_array_like(u);for(let l=0,i=o$1.length;l<i;l++){let p=o$1[l];t.push(`<button${attr_class("thumbnail-item thumbnail-small svelte-7anmrz",void 0,{selected:e===l&&y$2!=="minimal"})}${attr("aria-label","Thumbnail "+(l+1)+" of "+u.length)}>`),"image"in p?(t.push("<!--[-->"),c(t,{src:p.image.url,restProps:{title:p.caption||null,alt:"",class:"with-caption",loading:"lazy"},data_testid:`thumbnail ${l+1}`})):(t.push("<!--[!-->"),n(t),t.push("<!----> "),Qu(t,{src:p.video.url,title:p.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:y$2==="minimal","fixed-height":!_||_=="auto",hidden:w$1})}${attr_style("",{height:_!=="auto"?_+"px":null})}>`),I&&e===null?(t.push("<!--[-->"),z(t,{i18n:g,onclear:()=>{m=[],X();},children:o=>{U&&E?(o.push("<!--[-->"),w(o,{Icon:i$1,label:g("upload_text.click_to_upload"),children:l=>{ee(l,{icon_upload:true,onload:i=>$(i),filetype:q,file_count:"multiple",max_file_size:J,root:W,onerror:i=>Y(i),stream_handler:E,upload:U,get upload_promise(){return L},set upload_promise(i){L=i,v$1=false;},get uploading(){return B},set uploading(i){B=i,v$1=false;}});}})):o.push("<!--[!-->"),o.push("<!--]-->");}})):t.push("<!--[!-->"),t.push(`<!--]--> <div${attr_class("grid-container svelte-7anmrz",void 0,{"pt-6":f})}${attr_style(`--grid-cols:${stringify(it)}; --grid-rows:${stringify(D)}; --object-fit: ${stringify(A)};`)}><!--[-->`);const n$1=ensure_array_like(u);for(let o$1=0,l=n$1.length;o$1<l;o$1++){let i=n$1[o$1];t.push(`<div class="gallery-item svelte-7anmrz"><button${attr_class("thumbnail-item thumbnail-lg svelte-7anmrz",void 0,{selected:e===o$1})}${attr("aria-label","Thumbnail "+(o$1+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 "+(o$1+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> "),I?(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 v$1=true,r=c$1.copy(),ot(r);while(!v$1);c$1.subsume(r),bind_props(d,{value:m,selected_index:e});});}

export { Nt as default };
//# sourceMappingURL=Gallery-BtyraTcF.js.map
