import{t as C,a as x,c as dt,n as lt}from"../chunks/Dp8zidyZ.js";import{a as N,b as ct,s as q,c as L,i as J}from"../chunks/OONWT0Nj.js";import{c as ht,P as mt}from"../chunks/BzArsHZA.js";import{u as _t,g as gt,I as vt,b as E,c as D}from"../chunks/rra-okeK.js";import{p as K,w as ut,o as y,e as Q,a as V,q as S,c as k,j as e,l as H,r as p,f as ft,s as X,t as O}from"../chunks/CaZnWIme.js";import{u as bt}from"../chunks/DFMU38cA.js";import{r as wt}from"../chunks/Cbydd1_z.js";import{G as xt}from"../chunks/C1kKhXuU.js";import{g as U}from"../chunks/pKKESLv8.js";import{a as St,S as kt}from"../chunks/DoZT-Mpu.js";import"../chunks/CYsOZZcr.js";const pt=async({dataset_id:g,offset:t=0,limit:a=10,annotation_label_ids:r,tag_ids:n})=>{const s={data:[],error:void 0};try{const i=await ht.GET("/api/datasets/{dataset_id}/annotations",{params:{path:{dataset_id:g},query:{annotation_label_ids:r,tag_ids:n,offset:t,limit:a}}});if(i.error)throw new Error(JSON.stringify(i.error,null,2));if(!i.data)throw new Error("No data");s.data=i.data}catch(i){s.error="Error loading annotations: "+String(i)}return s};var yt=C('<div><div class="absolute right-7 top-1 z-10"><!></div> <a class="block"><!></a></div>'),At=C('<div slot="noMore"></div>'),It=C('<div slot="noResults"></div>'),Lt=C('<div class="viewport flex-1 svelte-1ppli2f"><!></div>');function Ct(g,t){K(t,!0);const[a,r]=q(),n=()=>L(G,"$infiniteLoaderIdentifier",a),s=()=>L(t.selectedAnnotationFilterIds,"$selectedAnnotationFilterIds",a),i=()=>L(h,"$tagsSelected",a),v=()=>L(W,"$pickedAnnotationIds",a),{tagsSelected:h}=bt({dataset_id:t.dataset_id,kind:["annotation"]});let G=ut([t.selectedAnnotationFilterIds,h],([l,A])=>l.join(",")+Array.from(A).join(",")),m=y(0);const _=100;let o=y(N([])),u=y(null);Q(()=>{n(),S(o,N([])),S(m,0)});async function R({detail:{loaded:l,complete:A}}){const w=await pt({dataset_id:t.dataset_id,limit:_,offset:e(m),annotation_label_ids:s().length>0?s():void 0,tag_ids:i().size>0?Array.from(i()):void 0});w.data.length?(S(m,e(m)+_),e(o).push(...w.data),w.data.length<_?A():l()):A()}const{selectedSampleAnnotationCropIds:W,toggleSampleAnnotationCropSelection:f}=_t(),b=16,P=gt(),[Y,Et]=P;var z=Lt(),Z=k(z);const $=H(()=>t.itemHeight+b),tt=H(()=>t.itemWidth+b),et=H(()=>{var l;return((l=e(u))==null?void 0:l.clientHeight)||0});xt(Z,{get itemCount(){return e(o).length},get itemHeight(){return e($)},get itemWidth(){return e(tt)},get height(){return e(et)},class:"overflow-none overflow-y-auto dark:[color-scheme:dark]",get style(){return`--sample-width: ${t.itemWidth??""}px; --sample-height: ${t.itemHeight??""}px;`},item:(w,d)=>{let c=()=>d==null?void 0:d().index,I=()=>d==null?void 0:d().style;var T=dt(),nt=ft(T);{var at=B=>{var F=yt(),M=k(F),it=k(M);const ot=H(()=>v().has(e(o)[c()].annotation_id));St(it,{onSelect:()=>f(e(o)[c()].annotation_id),get isSelected(){return e(ot)}}),p(M);var j=X(M,2),st=k(j);Ht(st,{get annotation(){return e(o)[c()]},get width(){return t.itemWidth},get height(){return t.itemHeight}}),p(j),p(F),O(rt=>{E(F,I()),D(j,"href",rt)},[()=>Y(wt.toSampleWithAnnotation(e(o)[c()].sample.sample_id,e(o)[c()].annotation_id),void 0)]),x(B,F)};J(nt,B=>{e(o)[c()]&&e(o)[c()].sample&&B(at)})}x(w,T)},footer:w=>{vt(w,{get identifier(){return n()},$$events:{infinite:R},$$slots:{noMore:(d,c)=>{var I=At();x(d,I)},noResults:(d,c)=>{var I=It();x(d,I)}}})},$$slots:{item:!0,footer:!0}}),p(z),ct(z,l=>S(u,l),()=>e(u)),x(g,z),V(),r()}var zt=lt("<svg><!></svg>"),Ft=C('<div class="crop rounded-lg bg-black svelte-15maib4"><div class="annotation-box svelte-15maib4"><div class="annotation-label text-sm text-white svelte-15maib4"></div> <!></div></div>');function Ht(g,t){K(t,!0);const a=20,r=t.annotation.sample;let n=y(1),s=y(0),i=y(0);Q(()=>{S(n,N(Math.min(t.width/(t.annotation.width+a*2),t.height/(t.annotation.height+a*2)))),S(s,-(t.annotation.x-a)*e(n)+(t.width-(t.annotation.width+a*2)*e(n))/2),S(i,-(t.annotation.y-a)*e(n)+(t.height-(t.annotation.height+a*2)*e(n))/2)});let v=t.annotation.annotation_label.annotation_label_name;const h=U(v,1).color,G=U(v,.1).color,m=!!t.annotation.segmentation__binary_mask__rle_row_wise;var _=Ft(),o=k(_),u=k(o);E(u,`
    background-color: ${h};
`),u.textContent=v;var R=X(u,2);{var W=f=>{var b=zt(),P=k(b);kt(P,{get segmentation(){return t.annotation.segmentation__binary_mask__rle_row_wise},get width(){return r.width},colorFill:h}),p(b),O(()=>D(b,"viewBox",`${t.annotation.x} ${t.annotation.y} ${t.annotation.width} ${t.annotation.height}`)),x(f,b)};J(R,f=>{m&&f(W)})}p(o),p(_),O(f=>{E(_,f),E(o,`
            left: ${(t.width-t.annotation.width*e(n))/2}px;
            top: ${(t.height-t.annotation.height*e(n))/2}px;
            width: ${t.annotation.width*e(n)}px;
            height: ${t.annotation.height*e(n)}px;
            border-color: ${m?"transparent":h};
            background-color: ${m?"transparent":G};
        `)},[()=>`
        width: ${t.width}px;
        height: ${t.height}px;
        background-image: url("${mt+encodeURIComponent(r.file_path_abs)}");
        background-position: ${e(s)}px ${e(i)}px;
        background-size: ${r.width*e(n)}px ${r.height*e(n)}px;
    `]),x(g,_),V()}function qt(g,t){const[a,r]=q(),n=()=>L(h,"$boundedSampleSize",a),{datasetId:s,sampleSize:i,selectedAnnotationFilterIds:v}=t.data,h=i.sampleSize;Ct(g,{get itemHeight(){return n().height},get itemWidth(){return n().width},dataset_id:s,selectedAnnotationFilterIds:v}),r()}export{qt as component};
