import{s as N,a as b,t as A,e as V,b as u}from"../chunks/legacy.BFrtrUTY.js";import{b as X,I as Y,s as F}from"../chunks/index.svelte_svelte_type_style_lang.oHDPoyLK.js";import{p as Z,Q as $,d as x,u as ee,a as te,g as a,b as y,c as L,e as P,f as ae,s as se,t as j,r as k}from"../chunks/index.Chpxrmiw.js";import{a as M,b as ie,i as ne}from"../chunks/index-client.D0CpKjVb.js";import{S as oe}from"../chunks/index.C_KQ6kbL.js";import{c as re}from"../chunks/dataset.DUSx8dem.js";import{G as le}from"../chunks/Grid.CTo5z7L1.js";import{u as de}from"../chunks/useGlobalStorage.B7aqgx7w.js";import{r as me}from"../chunks/routes.BJiwio4j.js";import{S as ce}from"../chunks/SelectableBox.DAf3j8HI.js";const fe=async({dataset_id:p,offset:e=0,limit:o=10,annotationLabels:l,tagIds:_,min_width:d,max_width:f,min_height:g,max_height:v})=>{const i={data:[],error:void 0};try{const m=d!==void 0?{min_width:d,max_width:f,min_height:g,max_height:v}:{},s=await re.GET("/api/samples",{params:{query:{dataset_id:p,offset:e,limit:o,annotation_labels:l,tag_ids:_,...m}}});if(s.error)throw new Error(JSON.stringify(s.error,null,2));if(!s.data)throw new Error("No data");i.data=s.data}catch(m){i.error="Error loading samples: "+String(m)}return i};var ue=A('<div><!> <a class="block"><!></a></div>'),pe=A('<div slot="noMore"></div>'),_e=A('<div slot="noResults"></div>'),ge=A('<div class="viewport flex-1 svelte-1ppli2f"><!></div>');function ve(p,e){Z(e,!0);const o=N(),l=()=>u(v,"$infiniteLoaderIdentifier",o),_=()=>u(e.dimensions,"$dimensions",o),d=()=>u(e.selectedAnnotations,"$selectedAnnotations",o),f=()=>u(e.tagsSelected,"$tagsSelected",o),g=()=>u(T,"$selectedSampleIds",o);let v=$([e.selectedAnnotations,e.tagsSelected,e.dimensions],([r,h,n])=>r.join(",")+Array.from(h).join(",")+n.min_width+n.max_width+n.min_height+n.max_height),i=x(0);const m=100;let s=x(M([])),H=x(null),E=x(!0);ee(()=>{l(),y(s,M([])),y(i,0)});async function R({detail:{loaded:r,complete:h}}){const n=a(E)?void 0:_(),t=await fe({dataset_id:e.dataset_id,limit:m,offset:a(i),annotationLabels:d().length>0?d():void 0,tagIds:f().size>0?Array.from(f()):void 0,...n});t.data.length?(y(i,a(i)+m),a(s).push(...t.data),y(E,!1),t.data.length<m?h():r()):h()}const{selectedSampleIds:T,toggleSampleSelection:q}=de(),B=X(),[C,he]=B;var w=ge(),J=L(w),O=P(()=>{var r;return((r=a(H))==null?void 0:r.clientHeight)||0});le(J,{get itemCount(){return a(s).length},get itemHeight(){return e.sampleHeight},get itemWidth(){return e.sampleWidth},get height(){return a(O)},get style(){return`--sample-width: ${e.sampleWidth??""}px; --sample-height: ${e.sampleHeight??""}px;`},overScan:100,item:(n,t)=>{let c=()=>t==null?void 0:t().index,S=()=>t==null?void 0:t().style;var G=V(),Q=ae(G);ne(Q,()=>a(s)[c()],D=>{var I=ue(),W=L(I),K=P(()=>g().has(a(s)[c()].sample_id));ce(W,{onSelect:()=>q(a(s)[c()].sample_id),get isSelected(){return a(K)}});var z=se(W,2);j(()=>F(z,"href",C(me.toSample(a(s)[c()].sample_id),void 0)));var U=L(z);oe(U,{get sample(){return a(s)[c()]}}),k(z),k(I),j(()=>F(I,"style",S())),b(D,I)}),b(n,G)},footer:n=>{Y(n,{get identifier(){return l()},$$events:{infinite:R},$$slots:{noMore:(t,c)=>{var S=pe();b(t,S)},noResults:(t,c)=>{var S=_e();b(t,S)}}})},$$slots:{item:!0,footer:!0}}),k(w),ie(w,r=>y(H,r),()=>a(H)),b(p,w),te()}function ke(p,e){const o=N(),l=()=>u(i,"$boundedSampleSize",o),{datasetId:_,sampleSize:d,dimensions:f,selectedAnnotations:g,tagsSelected:v}=e.data,i=d.sampleSize;ve(p,{get sampleHeight(){return l().height},get sampleWidth(){return l().width},dataset_id:_,tagsSelected:v,selectedAnnotations:g,dimensions:f})}export{ke as component};
