import{t as G,a as x,c as se}from"../chunks/BQSWrPvQ.js";import{a as N,b as ie,s as R,c as f,i as ne}from"../chunks/BZbDFF1N.js";import{c as oe}from"../chunks/qqT9E5ug.js";import{u as re,g as le,I as de,s as ce,a as me}from"../chunks/DE1eCaeQ.js";import{p as pe,n as ue,o as A,e as fe,a as _e,j as t,c as H,f as ve,q as w,l as k,r as z,s as O,t as ge}from"../chunks/BlPzMKBp.js";import{u as he}from"../chunks/Dfop2hpa.js";import{S as Se,a as be}from"../chunks/2uHotzhW.js";import{G as xe}from"../chunks/CnN2HWU0.js";import{r as we}from"../chunks/BJiwio4j.js";import{S as ye}from"../chunks/Bk6sjZbM.js";import"../chunks/DXG5MlPL.js";const Ie=async({dataset_id:_,offset:e=0,limit:i=10,annotationLabels:v,tagIds:c,min_width:m,max_width:p,min_height:u,max_height:g})=>{const l={data:[],error:void 0};try{const h=m!==void 0?{min_width:m,max_width:p,min_height:u,max_height:g}:{},n=await oe.GET("/api/samples",{params:{query:{dataset_id:_,offset:e,limit:i,annotation_labels:v,tag_ids:c,...h}}});if(n.error)throw new Error(JSON.stringify(n.error,null,2));if(!n.data)throw new Error("No data");l.data=n.data}catch(h){l.error="Error loading samples: "+String(h)}return l};var Ae=G('<div class="relative"><div class="absolute right-7 top-1 z-10"><!></div> <a class="block"><!> <!></a></div>'),He=G('<div slot="noMore"></div>'),ke=G('<div slot="noResults"></div>'),ze=G('<div class="viewport flex-1 svelte-gzepom"><!></div>');function Ge(_,e){pe(e,!0);const[i,v]=R(),c=()=>f(h,"$infiniteLoaderIdentifier",i),m=()=>f(e.dimensions,"$dimensions",i),p=()=>f(e.selectedAnnotations,"$selectedAnnotations",i),u=()=>f(l,"$tagsSelected",i),g=()=>f(C,"$selectedSampleIds",i),{tagsSelected:l}=he({dataset_id:e.dataset_id,kind:["sample"]});let h=ue([e.selectedAnnotations,l,e.dimensions],([r,S,s])=>r.join(",")+Array.from(S).join(",")+s.min_width+s.max_width+s.min_height+s.max_height),n=A(0);const L=100;let o=A(N([])),W=A(null),P=A(!0);fe(()=>{c(),w(o,N([])),w(n,0)});async function B({detail:{loaded:r,complete:S}}){const s=t(P)?void 0:m(),a=await Ie({dataset_id:e.dataset_id,limit:L,offset:t(n),annotationLabels:p().length>0?p():void 0,tagIds:u().size>0?Array.from(u()):void 0,...s});a.data.length?(w(n,t(n)+L),t(o).push(...a.data),w(P,!1),a.data.length<L?S():r()):S()}const{selectedSampleIds:C,toggleSampleSelection:J}=re(),T=16,D=le(),[K,Le]=D;var y=ze(),Q=H(y);const U=k(()=>e.sampleHeight+T),V=k(()=>e.sampleWidth+T),X=k(()=>{var r;return((r=t(W))==null?void 0:r.clientHeight)||0});xe(Q,{get itemCount(){return t(o).length},get itemHeight(){return t(U)},get itemWidth(){return t(V)},get height(){return t(X)},class:"overflow-none overflow-y-auto dark:[color-scheme:dark]",get style(){return`--sample-width: ${e.sampleWidth??""}px; --sample-height: ${e.sampleHeight??""}px;`},overScan:100,item:(s,a)=>{let d=()=>a==null?void 0:a().index,b=()=>a==null?void 0:a().style;var q=se(),Y=ve(q);{var Z=j=>{var I=Ae(),F=H(I),$=H(F);const ee=k(()=>g().has(t(o)[d()].sample_id));ye($,{onSelect:()=>J(t(o)[d()].sample_id),get isSelected(){return t(ee)}}),z(F);var E=O(F,2),M=H(E);Se(M,{get sample(){return t(o)[d()]},objectFit:"cover"});var te=O(M,2);be(te,{get sample(){return t(o)[d()]},get containerWidth(){return e.sampleWidth},sampleImageObjectFit:"cover",get containerHeight(){return e.sampleHeight}}),z(E),z(I),ge(ae=>{ce(I,b()),me(E,"href",ae)},[()=>K(we.toSample(t(o)[d()].sample_id),void 0)]),x(j,I)};ne(Y,j=>{t(o)[d()]&&j(Z)})}x(s,q)},footer:s=>{de(s,{get identifier(){return c()},$$events:{infinite:B},$$slots:{noMore:(a,d)=>{var b=He();x(a,b)},noResults:(a,d)=>{var b=ke();x(a,b)}}})},$$slots:{item:!0,footer:!0}}),z(y),ie(y,r=>w(W,r),()=>t(W)),x(_,y),_e(),v()}function Be(_,e){const[i,v]=R(),c=()=>f(l,"$boundedSampleSize",i),{datasetId:m,sampleSize:p,dimensions:u,selectedAnnotations:g}=e.data,l=p.sampleSize;Ge(_,{get sampleHeight(){return c().height},get sampleWidth(){return c().width},dataset_id:m,selectedAnnotations:g,dimensions:u}),v()}export{Be as component};
