1import{aD as v,r as a,s as c,j as s,g as S}from"./index-BcBk5ocr.js";import{M as E}from"./MentionInput-CJhJN0lk.js";import{S as M}from"./send-DgGoxcuh.js";import{A}from"./at-sign-DybFgLSj.js";const p=2e3;function P({tipId:i}){const{volunteer:f,user:d}=v(),[r,j]=a.useState([]),[l,x]=a.useState(""),[h,g]=a.useState(!1),[_,N]=a.useState([]),y=a.useRef(null),m=a.useCallback(async()=>{const{data:e}=await c.rpc("get_tip_messages_anonymized",{_tip_id:i});j(e||[])},[i]);a.useEffect(()=>{(async()=>{const[e]=await Promise.all([c.from("admin_profiles").select("user_id, display_name")]),o=[];if(r.length>0){const n=new Set;for(const t of r)!t.is_mine&&t.pseudonym&&t.pseudonym!=="Unknown"&&!n.has(t.pseudonym)&&n.add(t.pseudonym)}if(e.data)for(const n of e.data)o.push({user_id:n.user_id,display_name:n.display_name||"Admin",role:"admin"});N(o)})()},[i,r.length,d==null?void 0:d.id]),a.useEffect(()=>{m()},[m]),a.useEffect(()=>{const e=c.channel(`tip-messages-${i}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"tip_messages",filter:`tip_id=eq.${i}`},()=>m()).subscribe();return()=>{c.removeChannel(e)}},[i,m]),a.useEffect(()=>{var e;(e=y.current)==null||e.scrollIntoView({behavior:"smooth"})},[r]);const b=async()=>{if(!l.trim()||!i||!f||h)return;const e=l.trim().slice(0,p).replace(/<[^>]*>/g,"");if(!e)return;g(!0);const{data:o}=await c.from("tip_messages").insert({tip_id:i,volunteer_id:f.id,content:e}).select().single();if(o&&d){const n=/@\[([^\]]+)\]\(([^)]+)\)/g;let t;for(;(t=n.exec(e))!==null;){const u=t[2];await c.from("mentions").insert({tip_id:i,source_type:"message",source_id:o.id,mentioner_user_id:d.id,mentioned_user_id:u,content_preview:e.slice(0,200)})}}x(""),g(!1)},w=e=>e.split(/(@\[[^\]]+\]\([^)]+\))/).map((n,t)=>{const u=n.match(/@\[([^\]]+)\]\(([^)]+)\)/);return u?s.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded bg-accent/15 px-1 py-0.5 text-accent font-semibold",children:[s.jsx(A,{className:"h-3 w-3"}),u[1]]},t):s.jsx("span",{children:n},t)});return s.jsxs("div",{className:"flex flex-col rounded-lg border border-border bg-card",style:{minHeight:400},children:[s.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[r.length===0&&s.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No messages yet. Start the discussion."}),r.map(e=>s.jsxs("div",{className:`flex flex-col ${e.is_mine?"items-end":"items-start"}`,children:[s.jsxs("span",{className:"mb-0.5 text-[11px] font-semibold text-muted-foreground flex items-center gap-1",children:[e.is_mine?"You":e.pseudonym,!e.is_mine&&_.some(o=>o.role==="admin"&&o.display_name===e.pseudonym)&&s.jsx(S,{className:"h-3 w-3 text-accent"})]}),s.jsx("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-sm ${e.is_mine?"bg-primary text-primary-foreground":"bg-secondary text-foreground"}`,children:w(e.content)}),s.jsx("span",{className:"mt-0.5 text-[10px] text-muted-foreground",children:new Date(e.created_at).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})})]},e.id)),s.jsx("div",{ref:y})]}),s.jsxs("div",{className:"border-t border-border p-3",children:[s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsx(E,{value:l,onChange:e=>x(e.slice(0,p)),onSubmit:b,mentionables:_,placeholder:"Type a message... Use @ to mention",className:"flex-1"}),s.jsx("button",{onClick:b,disabled:!l.trim()||h,className:"flex h-9 w-9 items-center justify-center rounded bg-accent text-accent-foreground hover:bg-accent/90 disabled:opacity-50 transition-colors shrink-0",children:s.jsx(M,{className:"h-4 w-4"})})]}),s.jsxs("p",{className:"mt-1 text-[10px] text-muted-foreground",children:[l.length,"/",p," ⢠Press Enter to send ⢠@ to mention"]})]})]})}export{P as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.