import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{ov as s}from"./shared-0-C4kdVF7Y.js";import{Ei as a,Mi as t,ki as l}from"./vendor-frame-CwiylG4Y.js";import{nn as i,rn as r}from"./vendor-all-2-BJdkbLSj.js";import{R as o}from"./shared-frame-DbQbH4Yr.js";import{t as n}from"./cf163d9fe-MOJY7C3p.js";import{i as c,n as d}from"./c18e80207-fe73_kvz.js";var h=e(t()),m=l(),f=1e3;function x({src:e,imageWidth:t,imageHeight:l,annotation:i,seedKey:r,alt:o,animate:c=!0,className:x}){const[u,g]=(0,h.useState)(!1),j=s("(prefers-reduced-motion: reduce)"),b=c&&!j,v=t>0&&l>0?t/l:1,k=f/v,y=`wipe-${(0,h.useId)().replace(/[^a-zA-Z0-9_-]/g,"")}`,w=(0,h.useMemo)(()=>d(i),[i]),M=(0,h.useMemo)(()=>function(e,s,a,t){const l=f/a,i=e.x1*f,r=e.y1*l,o=(e.x2-e.x1)*f,c=(e.y2-e.y1)*l,d=n.generator(),h={roughness:2.4,bowing:1.4,seed:t,disableMultiStroke:!1,strokeWidth:1},m="ellipse"===s?d.ellipse(i+o/2,r+c/2,o*Math.SQRT2,c*Math.SQRT2,h):d.rectangle(i,r,o,c,h);return d.toPaths(m).filter(e=>e.d.length>0&&"none"!==e.stroke).map(e=>({d:e.d}))}(w,i.shape,v,function(e){let s=0;for(let a=0;a<e.length;a++)s=Math.imul(31,s)+e.charCodeAt(a)|0;return(s>>>0)%2**31||1}(r)),[w,i.shape,v,r]),N=(w.x1+w.x2)/2*f,L=(w.y1+w.y2)/2*k,S=Math.hypot(f,k),C=u&&b;return(0,m.jsxs)("div",{className:a("relative w-fit max-w-full overflow-hidden rounded-lg bg-bg-200",x),children:[(0,m.jsx)("img",{src:e,alt:o,width:t,height:l,className:"block h-auto max-h-full w-full select-none",draggable:!1,onLoad:()=>g(!0)}),(0,m.jsxs)("svg",{className:"pointer-events-none absolute inset-0 h-full w-full",viewBox:`0 0 1000 ${k}`,preserveAspectRatio:"none",role:i.label?"img":void 0,"aria-label":i.label||void 0,"aria-hidden":!i.label||void 0,children:[b&&(0,m.jsx)("defs",{children:(0,m.jsx)("mask",{id:y,maskUnits:"userSpaceOnUse",children:(0,m.jsx)("circle",{cx:N,cy:L,r:S/2,fill:"none",stroke:"white",strokeWidth:S,transform:`rotate(-90 ${N} ${L})`,pathLength:1,strokeDasharray:1,strokeDashoffset:C?0:1,style:{transition:"stroke-dashoffset 500ms cubic-bezier(0.7, 0, 0.3, 1) 350ms"}})})}),(0,m.jsx)("g",{mask:b?`url(#${y})`:void 0,opacity:.92,children:M.map((e,s)=>(0,m.jsx)("path",{d:e.d,fill:"none",stroke:i.color,strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"},s))}),i.label&&(0,m.jsx)(p,{box:w,shape:i.shape,viewH:k,label:i.label})]})]})}function p({box:e,shape:s,viewH:a,label:t}){const l=e.x1*f,i=e.y1*a,r=(e.x2-e.x1)*f,o=(e.y2-e.y1)*a,n={fill:"transparent",style:{pointerEvents:"auto",cursor:"help"}};return"ellipse"===s?(0,m.jsx)("ellipse",{cx:l+r/2,cy:i+o/2,rx:r*Math.SQRT2/2,ry:o*Math.SQRT2/2,...n,children:(0,m.jsx)("title",{children:t})}):(0,m.jsx)("rect",{x:l,y:i,width:r,height:o,...n,children:(0,m.jsx)("title",{children:t})})}function u({toolUseId:e,file:s,annotation:a,goBack:t,onClose:l}){const n=r(),d=s.preview_asset;return(0,m.jsxs)("div",{className:"flex h-full flex-col pb-1 pl-5 pt-3",children:[(0,m.jsxs)("div",{className:"sticky flex items-center gap-1 pr-5",children:[t&&(0,m.jsx)(o,{onClick:t,variant:"ghost",iconOnly:!0,icon:"ArrowLeft",className:"-ml-2 shrink-0","aria-label":n.formatMessage({defaultMessage:"Go back",id:"orvpWhO3rI"})}),(0,m.jsx)("h2",{className:"font-ui flex-1 truncate text-lg font-medium",children:a.label?c(a.label):(0,m.jsx)(i,{defaultMessage:"Annotated image",id:"wL51Js4/qx"})}),(0,m.jsx)(o,{variant:"ghost",iconOnly:!0,icon:"X",className:"-mr-2",onClick:l,"data-testid":"close-image-annotation","aria-label":n.formatMessage({defaultMessage:"Close",id:"rbrahOGMC3"})})]}),(0,m.jsx)("div",{className:"mb-1 min-h-0 flex-1 overflow-y-auto pb-3 pr-5 pt-2",children:(0,m.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,m.jsx)(x,{src:d.url,imageWidth:d.image_width,imageHeight:d.image_height,annotation:a,seedKey:e,alt:s.file_name,className:"shadow-sm"},e),(0,m.jsx)("span",{className:"max-w-full truncate text-xs text-text-400",children:s.file_name})]})})]})}export{u as ImageAnnotationDetail};