1import{r,j as e,aa as A,B as m,I as D,a as S,C as k,s as c,t as l,b as P}from"./index-Dydja8pP.js";import{A as q}from"./AppShell-DMr5GyWj.js";import{T as _}from"./textarea-CVE40QTU.js";import{L as C}from"./label-C9B76zRo.js";import{C as F,c as H}from"./card-7Kxng_NQ.js";import{P as O}from"./plus-gKdKiCxz.js";import"./ImpersonationBanner-_SDP5yvj.js";import"./impersonation-BWMQYz88.js";import"./shield-alert-DId_hyDA.js";import"./triangle-alert-36c5grIM.js";import"./notifications-BGnvAPTo.js";import"./bell-BN5h0msY.js";import"./clock-CP1hj2Iy.js";import"./mail-C2rLthCp.js";import"./file-text-CgJfXItU.js";import"./circle-check-t2OzquCS.js";import"./wrench-Ef7kknWP.js";import"./message-square-BaiYqNdw.js";import"./logo-full-color-ChBM89SD.js";import"./LanguageToggle-w46eQSnu.js";import"./index-C-w9_zL2.js";import"./index-CKrzct6Y.js";import"./index--zv5pQPp.js";import"./index-By3pKgiT.js";import"./chevron-right-DSrC1FYA.js";import"./check-adlNfffy.js";import"./chevron-down-pfJDsTSr.js";import"./users-Dhwpfhxl.js";import"./layout-dashboard-D9dXpCiE.js";import"./house-DUbk6vWk.js";import"./archive-oJa616sr.js";import"./life-buoy-BzjKniLS.js";import"./credit-card-CYOkjJHW.js";import"./hard-hat-WQPsMCe7.js";function U({userId:i}){const[f,T]=r.useState([]),[B,L]=r.useState({}),[z,E]=r.useState(!0),[g,p]=r.useState(!1),[u,b]=r.useState(""),[x,y]=r.useState(""),[h,w]=r.useState(!1),[n,N]=r.useState({}),j=async()=>{const{data:s}=await c.from("support_tickets").select("*").eq("user_id",i).order("updated_at",{ascending:!1}),t=s??[];if(T(t),t.length){const{data:a}=await c.from("support_messages").select("*").in("ticket_id",t.map(d=>d.id)).order("created_at",{ascending:!0}),o={};for(const d of a??[])(o[d.ticket_id]??=[]).push(d);L(o)}E(!1)};r.useEffect(()=>{j()},[i]);const v=async(s,t)=>{const{data:a,error:o}=await c.functions.invoke("support-translate-message",{body:{ticket_id:s,text:t}});if(o)throw o;if(a?.error)throw new Error(a.error)},M=async()=>{if(!u.trim()||!x.trim()){l.error("Subject and message required");return}w(!0);try{const{data:s,error:t}=await c.from("support_tickets").insert({user_id:i,subject:u.trim()}).select().maybeSingle();if(t)throw t;const a=s.id;await v(a,x.trim()),await c.functions.invoke("support-notify",{body:{action:"new_ticket",ticketId:a}}),b(""),y(""),p(!1),await j(),l.success("Ticket submitted")}catch(s){l.error(s.message)}finally{w(!1)}},R=async s=>{const t=(n[s]??"").trim();if(t){try{await v(s,t)}catch(a){l.error(a.message);return}N({...n,[s]:""}),await j()}};return e.jsx(F,{children:e.jsxs(H,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(A,{className:"h-4 w-4"})," Help & Support"]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"Contact our support team"})]}),!g&&e.jsxs(m,{size:"sm",onClick:()=>p(!0),children:[e.jsx(O,{className:"h-4 w-4"})," New ticket"]})]}),g&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border p-3",children:[e.jsxs("div",{children:[e.jsx(C,{children:"Subject"}),e.jsx(D,{value:u,onChange:s=>b(s.target.value),placeholder:"What do you need help with?"})]}),e.jsxs("div",{children:[e.jsx(C,{children:"Message"}),e.jsx(_,{rows:4,value:x,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>p(!1),disabled:h,children:"Cancel"}),e.jsxs(m,{size:"sm",onClick:M,disabled:h,children:[h?e.jsx(S,{className:"h-4 w-4 animate-spin"}):e.jsx(k,{className:"h-4 w-4"}),"Submit"]})]})]}),z?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(S,{className:"h-4 w-4 animate-pulse"})}):f.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No tickets yet."}):e.jsx("div",{className:"space-y-3",children:f.map(s=>e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-semibold",children:s.subject}),e.jsx("span",{className:"text-[11px] uppercase text-muted-foreground",children:s.status.replace("_"," ")})]}),e.jsx("div",{className:"mt-2 space-y-2",children:(B[s.id]??[]).map(t=>e.jsxs("div",{className:`rounded p-2 text-sm ${t.is_admin_reply?"bg-primary/10 border border-primary/30":"bg-muted"}`,children:[e.jsxs("div",{className:"mb-0.5 text-[10px] uppercase text-muted-foreground",children:[t.is_admin_reply?"Support":"You"," · ",new Date(t.created_at).toLocaleStr
1ing()]}),e.jsx("div",{className:"whitespace-pre-wrap",children:t.is_admin_reply?t.translated_text??t.message:t.original_text??t.message})]},t.id))}),s.status!=="closed"&&e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(_,{rows:2,placeholder:"Replyâ¦",value:n[s.id]??"",onChange:t=>N({...n,[s.id]:t.target.value})}),e.jsx(m,{size:"sm",onClick:()=>R(s.id),children:e.jsx(k,{className:"h-4 w-4"})})]})]},s.id))})]})})}function ve(){const{user:i}=P();return e.jsx(q,{children:e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Help & Support"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Open a support ticket and our team will get back to you."}),e.jsx("div",{className:"mt-6",children:i&&e.jsx(U,{userId:i.id})})]})})}export{ve as component};
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.