import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{Cg as t,Cp as n,Dh as r,Eg as i,Gy as a,Hy as o,Lh as s,Ly as c,Mg as l,Sg as u,Tg as d,Ua as f,Zv as p,ap as m,dg as h,eg as g,gv as _,jg as v,kh as y,lh as b,m_ as x,mv as S,n as C,nl as w,pc as T,ph as E,pl as D,ri as O,ty as k,wg as A,xg as j,xh as M,yh as N,zo as P}from"./index-DDwwBb9e.js";import{t as F}from"./WithPermissionGuard-wX0IC3VF.js";import{t as I}from"./SettingsLayout-DkhRoxt1.js";import{t as L}from"./NoDataInfoBlock-B05u0nqM.js";var R=n(),z=e(a()),B=o();function V(){let{project:e}=m(),{isLiteMember:n}=O(),a=!n,{openDrawer:o,drawerOpen:_,closeDrawer:F}=C(),V=b.annotationScore.getAll.useQuery({projectId:e?.id??``},{enabled:!!e}),H=b.annotationScore.toggle.useMutation(),W=_(`addOrEditAnnotationScore`),[G,K]=(0,z.useState)(!1),[q,J]=(0,z.useState)(null),Y=b.annotationScore.delete.useMutation();(0,z.useEffect)(()=>{V.refetch()},[W]);let X=(t,n)=>{H.mutate({scoreId:t,active:n,projectId:e?.id??``},{onSuccess:()=>{V.refetch()},onError:e=>{g(e)||E.create({title:`Update score`,type:`error`,description:`Failed to update score`,duration:6e3,meta:{closable:!0}})}})},Z=e=>{J(e),K(!0)};return(0,B.jsxs)(I,{children:[(0,B.jsxs)(h,{gap:6,width:`full`,align:`start`,children:[(0,B.jsxs)(x,{width:`full`,marginTop:2,children:[(0,B.jsx)(k,{as:`h2`,children:`Annotation Scoring`}),(0,B.jsx)(v,{}),a&&(0,B.jsxs)(f.HeaderButton,{onClick:()=>o(`addOrEditAnnotationScore`),children:[(0,B.jsx)(r,{}),` Add new score metric`]})]}),V.data&&V.data.length==0?(0,B.jsx)(L,{title:`No scoring setup yet`,description:`Add new scoring metrics for your annotations.`,docsInfo:(0,B.jsxs)(p,{children:[`To learn more about scores and how to use them, please visit our`,` `,(0,B.jsx)(D,{color:`orange.400`,href:`https://docs.langwatch.ai/features/annotations#annotation-scoring`,isExternal:!0,children:`documentation`}),`.`]}),icon:(0,B.jsx)(M,{})}):(0,B.jsxs)(d,{variant:`line`,width:`full`,children:[(0,B.jsx)(A,{children:(0,B.jsxs)(i,{children:[(0,B.jsx)(t,{children:`Name`}),(0,B.jsx)(t,{children:`Description`}),(0,B.jsx)(t,{children:`Score Type`}),(0,B.jsx)(t,{children:`Score Options`}),(0,B.jsx)(t,{children:`Enabled`}),a&&(0,B.jsx)(t,{children:`Actions`})]})}),(0,B.jsx)(j,{children:V.isLoading?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(i,{children:(0,B.jsx)(u,{colSpan:a?6:5,children:(0,B.jsx)(l,{height:`20px`})})}),(0,B.jsx)(i,{children:(0,B.jsx)(u,{colSpan:a?6:5,children:(0,B.jsx)(l,{height:`20px`})})}),(0,B.jsx)(i,{children:(0,B.jsx)(u,{colSpan:a?6:5,children:(0,B.jsx)(l,{height:`20px`})})})]}):V.data?.map(e=>(0,B.jsxs)(i,{children:[(0,B.jsx)(u,{children:e.name}),(0,B.jsx)(u,{children:e.description}),(0,B.jsx)(u,{width:`20%`,children:(0,B.jsx)(p,{lineClamp:1,children:e.dataType===R.AnnotationScoreDataType.CHECKBOX?`Checkbox`:`Multiple choice`})}),(0,B.jsx)(u,{children:(0,B.jsx)(U,{options:Array.isArray(e.options)?e.options:[],dataType:e.dataType??``})}),(0,B.jsx)(u,{textAlign:`center`,children:(0,B.jsx)(w,{checked:e.active,disabled:!a,onCheckedChange:()=>{X(e.id,!e.active)}})}),a&&(0,B.jsx)(u,{children:(0,B.jsxs)(T.Root,{children:[(0,B.jsx)(T.Trigger,{asChild:!0,children:(0,B.jsx)(S,{variant:`ghost`,children:(0,B.jsx)(y,{})})}),(0,B.jsxs)(T.Content,{children:[(0,B.jsx)(T.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),o(`addOrEditAnnotationScore`,{annotationScoreId:e.id,onClose:()=>F()})},children:(0,B.jsxs)(c,{display:`flex`,alignItems:`center`,gap:2,children:[(0,B.jsx)(s,{size:14}),`Edit`]})}),(0,B.jsx)(T.Item,{value:`delete`,onClick:t=>{t.stopPropagation(),Z(e.id)},children:(0,B.jsxs)(c,{display:`flex`,alignItems:`center`,gap:2,color:`red.600`,children:[(0,B.jsx)(N,{size:14}),`Delete`]})})]})]})})]},e.id))})]})]}),(0,B.jsx)(P,{open:G,onClose:()=>K(!1),onConfirm:()=>{q&&Y.mutate({scoreId:q,projectId:e?.id??``},{onSuccess:()=>{V.refetch(),E.create({title:`Delete score`,type:`success`,description:`Score deleted successfully`,duration:6e3,meta:{closable:!0}})},onError:e=>{g(e)||E.create({title:`Delete score`,type:`error`,description:`Failed to delete score`,duration:6e3,meta:{closable:!0}})}}),K(!1)}})]})}var H=F(`annotations:view`,{layoutComponent:I})(V),U=({options:e,dataType:t})=>(0,B.jsx)(B.Fragment,{children:(0,B.jsx)(x,{children:(0,B.jsx)(x,{flexWrap:`wrap`,gap:4,children:e.map(e=>(0,B.jsx)(_,{children:e.label},e.value))})})});export{H as default};
//# sourceMappingURL=annotation-scores-DM_UPrbo.js.map