import{r as d,j as e,B as m,ax as j,I as u,ar as f,q as y,L as _,z as S,Q as v}from"./index-Dbk1Plmn.js";import{u as C}from"./use_relationships-QO4vMfMB.js";import{f as D}from"./use_mutations-BiggAKwe.js";import{P as T}from"./page_shell-C0CL85dt.js";import{D as b}from"./data-table-B-cqS3KC.js";import{E as x}from"./entity_link-qYsgSBpl.js";import{A as R}from"./agent_badge-BZd6ZAh5.js";import{u as E}from"./agent_filter-DUlgHUAb.js";import{L as p}from"./label-BKULM0qV.js";import{S as w,a as I,b as A,c as k,d as L}from"./select-B273iZTf.js";import{D as N,a as P,b as Q,c as K,d as $,e as B,f as F}from"./dialog-CIA-8Qg9.js";import{a as O,s as z}from"./query_loading-BFETHugg.js";import{Q as H}from"./query_refresh_indicator-1_XqkpX1.js";import{P as V}from"./plus-DrFK9jPU.js";import"./relationships-D_VYvxI6.js";import"./chevron-right-L2MnFoxW.js";import"./index-dCMWtMMp.js";import"./Combination-DUY7QPO8.js";import"./index-D3OXdV3z.js";import"./chevron-down-BMaycUN9.js";import"./check-C3ZzJelL.js";function me(){const s=C(),c=D(),[r,o]=d.useState(""),[i,n]=d.useState(""),[a,h]=d.useState(""),g=[{header:"Type",accessorKey:"relationship_type",cell:({getValue:t})=>e.jsx("span",{className:"font-mono text-xs font-medium",children:t()})},{header:"Source Entity",accessorKey:"source_entity_id",cell:({getValue:t})=>e.jsx(x,{id:t()})},{header:"Target Entity",accessorKey:"target_entity_id",cell:({getValue:t})=>e.jsx(x,{id:t()})},{header:"Observations",accessorKey:"observation_count"},{header:"Last Observed",accessorKey:"last_observation_at",cell:({getValue:t})=>y(t())},{header:"Agent",id:"agent",cell:({row:t})=>e.jsx(R,{provenance:t.original.agent_attribution??null})},{header:"",id:"actions",cell:({row:t})=>{const l=t.original;return e.jsx(_,{to:`/relationships/${encodeURIComponent(l.relationship_key||`${l.relationship_type}:${l.source_entity_id}:${l.target_entity_id}`)}`,className:"text-xs text-primary hover:underline",children:"Detail"})}}];return e.jsx(T,{title:"Relationships",description:s.data?`${s.data.relationships.length} total`:void 0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[O(s)?e.jsx(H,{}):null,e.jsxs(N,{children:[e.jsx(P,{asChild:!0,children:e.jsxs(m,{size:"sm",children:[e.jsx(V,{className:"h-3 w-3 mr-1"})," Create"]})}),e.jsxs(Q,{children:[e.jsxs(K,{children:[e.jsx($,{children:"Create Relationship"}),e.jsx(B,{children:"Create a typed edge between two entities."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Type"}),e.jsxs(w,{value:r,onValueChange:o,children:[e.jsx(I,{children:e.jsx(A,{placeholder:"Select type…"})}),e.jsx(k,{children:j.map(t=>e.jsx(L,{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Source Entity ID"}),e.jsx(u,{value:i,onChange:t=>n(t.target.value)})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Target Entity ID"}),e.jsx(u,{value:a,onChange:t=>h(t.target.value)})]})]}),e.jsx(F,{children:e.jsx(m,{onClick:()=>{!r||!i||!a||c.mutate({relationship_type:r,source_entity_id:i,target_entity_id:a},{onSuccess:()=>{f.success("Relationship created"),o(""),n(""),h("")}})},children:"Create"})})]})]})]}),children:e.jsx(M,{query:s,columns:g})})}function M({query:s,columns:c}){var a;const r=((a=s.data)==null?void 0:a.relationships)??[],{filterRows:o,AgentFilterControl:i}=E(r),n=o(r);return z(s)?e.jsx(S,{rows:12,cols:7}):s.error?e.jsx(v,{title:"Could not load relationships",children:s.error.message}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-3 flex flex-wrap items-end gap-3",children:e.jsx(i,{})}),e.jsx(b,{columns:c,data:n})]})}export{me as default};
