import{j as h,r as o}from"./react-vendor-MPLM8hiW.js";import{m as j,T as k,u as v,a3 as E}from"./index-saDuzM6I.js";import{u as w}from"./useRealtimeStream-B0wz0m00.js";function y(e){return/^#[0-9a-fA-F]{3,8}$/.test(e)||e.startsWith("rgb")||e.startsWith("hsl")}function B({state:e,stateName:n,className:s,size:l="md"}){const c=(e==null?void 0:e.label)??n??"—",t=e==null?void 0:e.color,m=t&&y(t)?{color:t,borderColor:t,backgroundColor:`${t}1f`}:void 0;return h.jsx(j,{variant:"outline",style:m,className:k("font-medium",l==="sm"?"text-[11px] px-1.5 py-0":"",s),children:c})}const p=o.createContext(null);function O({contentType:e,entryId:n,enabled:s=!0,children:l}){const c=v(u=>u.token),t=o.useRef(new Map),m=o.useMemo(()=>{const u=a=>i=>{const r=t.current.get(a);if(r)for(const A of Array.from(r))try{A(i)}catch{}};return Object.fromEntries(["content.updated","content.deleted","content.published","content.unpublished","comment.created","comment.updated","comment.deleted","comment.resolved","comment.reopened","assignment.created","assignment.updated","assignment.deleted","presence.list","presence.joined","presence.left"].map(a=>[a,u(a)]))},[]),f=o.useMemo(()=>c?E.streamUrl(e,n,c):null,[e,n,c]),{status:x,reconnectAttempt:b,reconnect:C}=w(f,m,{enabled:s&&!!c}),R=o.useCallback((u,d)=>{const a=Array.isArray(u)?u:[u];for(const i of a){let r=t.current.get(i);r||(r=new Set,t.current.set(i,r)),r.add(d)}return()=>{for(const i of a){const r=t.current.get(i);r==null||r.delete(d),r&&r.size===0&&t.current.delete(i)}}},[]),g=o.useMemo(()=>({contentType:e,entryId:n,status:x,reconnectAttempt:b,reconnect:C,subscribe:R}),[e,n,x,b,C,R]);return h.jsx(p.Provider,{value:g,children:l})}function P(){return o.useContext(p)}function $(e,n){const s=o.useContext(p),l=o.useRef(n);l.current=n;const c=Array.isArray(e)?e.join("|"):e,t=o.useRef(e);t.current=e,o.useEffect(()=>{if(!s)return;const m=f=>l.current(f);return s.subscribe(t.current,m)},[s,c])}function z(e,n){var s;return n!=null&&((s=e.actor)==null?void 0:s.type)==="admin"&&e.actor.id===n}export{O as C,B as W,P as a,z as i,$ as u};
