PageSourceSearch

https://toptiermedia.tv/assets/ContactUs-CWH2V_-w.js

js toptiermedia.tv collected 2026-10-05 08:53:41 UTC 5,105 bytes, 1 lines download raw bytes

1import{k as M,a as $,l as I,r as i,s as d,j as e,B as x,t as S}from"./index-DH6psoju.js";import{u as q,M as R,A as z,d as A}from"./AutoResizeTextarea-DjzxmOTM.js";import{S as B}from"./send-B2bGwPuW.js";import"./ExternalLinkWarning-hT41ZUmY.js";import"./link-2-fT9divWb.js";import"./textarea-BK-zErrT.js";const O=()=>{M();const{user:o}=$(),T=I(),[c,g]=i.useState([]),[m,N]=i.useState(""),[r,_]=i.useState(null),[h,b]=i.useState("open"),[E,k]=i.useState(!0),[j,v]=i.useState(!1),[p,w]=i.useState(!1),f=i.useRef(null);i.useEffect(()=>{if(!o)return;(async()=>{k(!0);const{data:s}=await d.from("support_tickets").select("id, status").eq("user_id",o.id).in("status",["open","awaiting_confirmation"]).order("created_at",{ascending:!1}).limit(1).maybeSingle();s&&(_(s.id),b(s.status||"open")),k(!1)})()},[o]),i.useEffect(()=>{if(!r)return;(async()=>{const{data:a}=await d.from("support_messages").select("*").eq("ticket_id",r).order("created_at",{ascending:!0});a&&g(a)})();const s=d.channel(`support-${r}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"support_messages",filter:`ticket_id=eq.${r}`},a=>{const l=a.new;g(n=>n.some(u=>u.id===l.id)?n:[...n,l])}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"support_tickets",filter:`id=eq.${r}`},a=>b(a.new.status||"open")).subscribe();return()=>{d.removeChannel(s)}},[r]),i.useEffect(()=>{var t;(t=f.current)==null||t.scrollTo({top:f.current.scrollHeight,behavior:"smooth"})},[c]),q(f,r),i.useEffect(()=>{if(r)try{localStorage.setItem(`tt_support_seen_${r}`,String(Date.now()))}catch{}},[r,c]);const C=async()=>{if(!m.trim()||!o||j)return;v(!0);const t=m.trim();let s=r;if(!s){const{data:n,error:u}=await d.from("support_tickets").insert({user_id:o.id}).select("id").single();if(u||!n){S({title:"Error",description:"Could not start a support chat.",variant:"destructive"}),v(!1);return}s=n.id,_(s)}const{data:a,error:l}=await d.from("support_messages").insert({ticket_id:s,sender_id:o.id,content:t}).select("*").single();l?S({title:"Error",description:A(l,"Failed to send message."),variant:"destructive"}):a&&(g(n=>n.some(u=>u.id===a.id)?n:[...n,a]),N("")),v(!1)},y=async t=>{if(!r||p)return;w(!0);const{error:s}=await d.from("support_tickets").update({status:t}).eq("id",r);s?S({title:"Error",description:"Could not update this conversation.",variant:"destructive"}):b(t),w(!1)};return o?e.jsx("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:E?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("div",{className:"h-6 w-6 border-2 border-primary border-t-transparent rounded-full animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:f,className:"flex-1 min-h-0 overflow-y-auto px-4 py-4 space-y-3",children:[c.length===0&&e.jsxs("div",{className:"text-center text-muted-foreground text-xs pt-12",children:[e.jsx("p",{className:"font-semibold text-sm text-foreground mb-1",children:"Welcome to Support"}),e.jsx("p",{children:"Send a message and a moderator will respond shortly."})]}),c.map(t=>{const s=t.sender_id===o.id;return e.jsx("div",{className:`flex ${s?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[75%] flex flex-col gap-0.5 ${s?"items-end":"items-start"}`,children:[e.jsx("div",{className:`px-3 py-2 rounded-xl text-base ${s?"bg-primary text-primary-foreground rounded-br-sm":"bg-muted text-foreground rounded-bl-sm"}`,children:t.content&&e.jsx(R,{content:t.content})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:new Date(t.created_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})},t.id)}),r&&c.length>0&&h==="open"&&e.jsx("div",{className:"flex justify-center pt-1 pb-1",children:e.jsx("button",{type:"button",onClick:()=>y("closed"),disabled:p,className:"text-xs text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2",children:"Mark as resolved"})})]}),h==="closed"?e.jsx("div",{className:"px-4 py-4 border-t border-border text-center text-xs text-muted-foreground",children:"This conversation is resolved."}):h==="awaiting_confirmation"?e.jsxs("div",{className:"px-4 py-4 border-t border-border text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-foreground",children:"Have we resolved your issue?"}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsx(x,{size:"sm",onClick:()=>y("closed"),disabled:p,children:"Yes"}),e.jsx(x,{size:"sm",variant:"outline",onClick:()=>y("open"),disabled:p,children:"No"})]})]}):e.jsx("div",{className:"px-4 py-3 border-t border-border",children:e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx(z,{value:m,onChange:t=>N(t.target.value),placeholder:"Type a message…",disabled:j}),e.jsx(x,{size:"icon",onClick:C,disabled:j||!m.trim(),children:e.jsx(B,{className:"h-4 w-4"})})]})})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please sign in to contact support."}),e.jsx(x,{variant:"outline",onClick:()=>T("/auth"),children:"Sign In"})]})};export{O 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.