import{t as y,a as b,c as ot}from"../chunks/BQSWrPvQ.js";import{a as M,b as st,s as N,c as I,i as dt}from"../chunks/BZbDFF1N.js";import{c as rt}from"../chunks/qqT9E5ug.js";import{u as lt,g as ct,I as ht,s as C,a as mt}from"../chunks/DE1eCaeQ.js";import{p as O,n as gt,o as p,e as T,a as U,q as v,c as x,j as e,l as L,r as w,f as ut,s as ft,t as q}from"../chunks/BlPzMKBp.js";import{u as _t}from"../chunks/Dfop2hpa.js";import{G as vt}from"../chunks/CnN2HWU0.js";import{r as bt}from"../chunks/BJiwio4j.js";import{g as B}from"../chunks/pKKESLv8.js";import{S as xt,P as wt}from"../chunks/Bk6sjZbM.js";import"../chunks/DXG5MlPL.js";const pt=async({dataset_id:m,offset:t=0,limit:a=10,annotation_label_ids:r,tag_ids:n})=>{const s={data:[],error:void 0};try{const i=await rt.GET("/api/datasets/{dataset_id}/annotations",{params:{path:{dataset_id:m},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 St=y('<div><div class="absolute right-7 top-1 z-10"><!></div> <a class="block"><!></a></div>'),kt=y('<div slot="noMore"></div>'),At=y('<div slot="noResults"></div>'),It=y('<div class="viewport flex-1 svelte-1ppli2f"><!></div>');function yt(m,t){O(t,!0);const[a,r]=N(),n=()=>I(E,"$infiniteLoaderIdentifier",a),s=()=>I(t.selectedAnnotationsIds,"$selectedAnnotationsIds",a),i=()=>I(u,"$tagsSelected",a),g=()=>I(J,"$pickedAnnotationIds",a),{tagsSelected:u}=_t({dataset_id:t.dataset_id,kind:["annotation"]});let E=gt([t.selectedAnnotationsIds,u],([c,k])=>c.join(",")+Array.from(k).join(",")),l=p(0);const f=100;let o=p(M([])),S=p(null);T(()=>{n(),v(o,M([])),v(l,0)});async function F({detail:{loaded:c,complete:k}}){const _=await pt({dataset_id:t.dataset_id,limit:f,offset:e(l),annotation_label_ids:s().length>0?s():void 0,tag_ids:i().size>0?Array.from(i()):void 0});_.data.length?(v(l,e(l)+f),e(o).push(..._.data),_.data.length<f?k():c()):k()}const{selectedAnnotationIds:J,toggleAnnotationSelection:D}=lt(),R=16,K=ct(),[Q,Lt]=K;var z=It(),V=x(z);const X=L(()=>t.itemHeight+R),Y=L(()=>t.itemWidth+R),Z=L(()=>{var c;return((c=e(S))==null?void 0:c.clientHeight)||0});vt(V,{get itemCount(){return e(o).length},get itemHeight(){return e(X)},get itemWidth(){return e(Y)},get height(){return e(Z)},class:"overflow-none overflow-y-auto dark:[color-scheme:dark]",get style(){return`--sample-width: ${t.itemWidth??""}px; --sample-height: ${t.itemHeight??""}px;`},item:(_,d)=>{let h=()=>d==null?void 0:d().index,A=()=>d==null?void 0:d().style;var j=ot(),$=ut(j);{var tt=G=>{var H=St(),P=x(H),et=x(P);const nt=L(()=>g().has(e(o)[h()].annotation_id));xt(et,{onSelect:()=>D(e(o)[h()].annotation_id),get isSelected(){return e(nt)}}),w(P);var W=ft(P,2),at=x(W);Ht(at,{get annotation(){return e(o)[h()]},get width(){return t.itemWidth},get height(){return t.itemHeight}}),w(W),w(H),q(it=>{C(H,A()),mt(W,"href",it)},[()=>Q(bt.toSample(e(o)[h()].sample.sample_id),void 0)]),b(G,H)};dt($,G=>{e(o)[h()]&&e(o)[h()].sample&&G(tt)})}b(_,j)},footer:_=>{ht(_,{get identifier(){return n()},$$events:{infinite:F},$$slots:{noMore:(d,h)=>{var A=kt();b(d,A)},noResults:(d,h)=>{var A=At();b(d,A)}}})},$$slots:{item:!0,footer:!0}}),w(z),st(z,c=>v(S,c),()=>e(S)),b(m,z),U(),r()}var zt=y('<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(m,t){O(t,!0);const a=20,r=t.annotation.sample;let n=p(1),s=p(0),i=p(0);T(()=>{v(n,M(Math.min(t.width/(t.annotation.width+a*2),t.height/(t.annotation.height+a*2)))),v(s,-(t.annotation.x-a)*e(n)+(t.width-(t.annotation.width+a*2)*e(n))/2),v(i,-(t.annotation.y-a)*e(n)+(t.height-(t.annotation.height+a*2)*e(n))/2)});let g=t.annotation.annotation_label.annotation_label_name;const u=B(g,1).color,E=B(g,.1).color;var l=zt(),f=x(l),o=x(f);C(o,`
                background-color: ${u};
            `),o.textContent=g,w(f),w(l),q(S=>{C(l,S),C(f,`
            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: ${u};
            background-color: ${E};
        `)},[()=>`
        width: ${t.width}px;
        height: ${t.height}px;
        background-image: url("${wt+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;
    `]),b(m,l),U()}function Tt(m,t){const[a,r]=N(),n=()=>I(u,"$boundedSampleSize",a),{datasetId:s,sampleSize:i,selectedAnnotationsIds:g}=t.data,u=i.sampleSize;yt(m,{get itemHeight(){return n().height},get itemWidth(){return n().width},dataset_id:s,selectedAnnotationsIds:g}),r()}export{Tt as component};
