1import{u as G,_ as J,r as t,s as E,j as e,a0 as f,i as n,C as N,a as Q,b as W,d as X,B as x,e as I,S as Z,ax as ee,I as B,a1 as A,as as se,aT as ae,aU as F,at as te,au as re,av as ie,aw as le,ay as ne,aR as ce,m as de,aS as H}from"./index-BOi4GZy8.js";import{T as oe}from"./textarea-T_vDpkyb.js";import{S as R,a as L,b as U,c as q,d as l}from"./select-JSPdEN3s.js";import{i as me,c as ue,s as xe,d as he,j as pe,k as je}from"./supportService-CdTQOG0Y.js";import{A as ge}from"./arrow-left-C5cDf6bl.js";import{M as fe}from"./message-square-DtleMHbJ.js";import{S as Ne}from"./send-Du81UX8q.js";import{f as y}from"./format-BCzaqZJT.js";const O={open:"bg-yellow-500/10 text-yellow-600 border-yellow-500/20",in_progress:"bg-blue-500/10 text-blue-600 border-blue-500/20",resolved:"bg-primary/10 text-primary border-primary/20",closed:"bg-muted text-muted-foreground border-border"},V={low:"bg-muted text-muted-foreground",medium:"bg-blue-500/10 text-blue-600",high:"bg-orange-500/10 text-orange-600",urgent:"bg-red-500/10 text-red-600"},Y={open:e.jsx(ce,{className:"h-4 w-4"}),in_progress:e.jsx(de,{className:"h-4 w-4"}),resolved:e.jsx(H,{className:"h-4 w-4"}),closed:e.jsx(H,{className:"h-4 w-4"})},De=()=>{G();const{toast:o}=J(),[b,h]=t.useState([]),[a,p]=t.useState(null),[v,w]=t.useState([]),[$,C]=t.useState(!0),[S,T]=t.useState(!1),[j,k]=t.useState(!1),[m,D]=t.useState(""),[z,u]=t.useState(!1),[i,c]=t.useState({subject:"",description:"",priority:"medium",category:"general"}),g=t.useCallback(async()=>{C(!0);const s=await me();h(s),C(!1)},[]),_=t.useCallback(async s=>{const r=await ue(s);w(r)},[]);t.useEffect(()=>{g();const s=xe(r=>{r.eventType==="INSERT"?h(d=>[r.new,...d]):r.eventType==="UPDATE"&&(h(d=>d.map(P=>P.id===r.new.id?r.new:P)),(a==null?void 0:a.id)===r.new.id&&p(r.new))});return()=>{E.removeChannel(s)}},[g,a==null?void 0:a.id]),t.useEffect(()=>{if(!a)return;_(a.id);const s=he(a.id,r=>{r.eventType==="INSERT"&&w(d=>[...d,r.new])});return()=>{E.removeChannel(s)}},[a,_]);const K=async()=>{if(!i.subject.trim()||!i.description.trim()){o({title:"Error",description:"Please fill in all required fields",variant:"destructive"});return}T(!0);const s=await pe(i);T(!1),s?(o({title:"Ticket Created",description:"Your support ticket has been submitted successfully."}),c({subject:"",description:"",priority:"medium",category:"general"}),u(!1),g()):o({title:"Error",description:"Failed to create ticket. Please try again.",variant:"destructive"})},M=async()=>{if(!a||!m.trim())return;k(!0);const s=await je(a.id,m);k(!1),s?D(""):o({title:"Error",description:"Failed to send message. Please try again.",variant:"destructive"})};return $?e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(f,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs(n,{variant:"ghost",onClick:()=>p(null),className:"gap-2",children:[e.jsx(ge,{className:"h-4 w-4"}),"Back to tickets"]}),e.jsxs(N,{children:[e.jsx(Q,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(W,{children:a.subject}),e.jsxs(X,{children:["Created ",y(new Date(a.created_at),"PPp")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{variant:"outline",className:V[a.priority],children:a.priority}),e.jsxs(x,{variant:"outline",className:O[a.status],children:[Y[a.status],e.jsx("span",{className:"ml-1 capitalize",children:a.status.replace("_"," ")})]})]})]})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Description"}),e.jsx("p",{className:"whitespace-pre-wrap",children:a.description})]}),e.jsx(Z,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(fe,{className:"h-4 w-4"}),"Messages"]}),e.jsx(ee,{className:"h-[300px] pr-4",children:v.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No messages yet. Start the conversation below."}):e.jsx("div",{className:"space-y-4",children:v.map(s=>e.jsx("div",{className:`flex ${s.is_admin_reply?"justify-start":"justify-end"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-lg p-3 ${s.is_admin_reply?"bg-muted":"bg-primary text-primary-foreground"}`,children:[e.jsx("p",{className:"text-sm",children:s.message}),e.jsxs("p",{className:`text-xs mt-1 ${s.is_admin_reply?"text-muted-foreground":"text-primary-foreground
1/70"}`,children:[s.is_admin_reply?"Support Team ⢠":"",y(new Date(s.created_at),"PPp")]})]})},s.id))})}),a.status!=="closed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{placeholder:"Type your message...",value:m,onChange:s=>D(s.target.value),onKeyDown:s=>s.key==="Enter"&&!s.shiftKey&&M(),disabled:j}),e.jsx(n,{onClick:M,disabled:j||!m.trim(),children:j?e.jsx(f,{className:"h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4"})})]})]})]})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(A,{className:"h-6 w-6"}),"Help Desk"]}),e.jsx("p",{className:"text-muted-foreground",children:"Create and manage your support tickets"})]}),e.jsxs(se,{open:z,onOpenChange:u,children:[e.jsx(ae,{asChild:!0,children:e.jsxs(n,{className:"gap-2",children:[e.jsx(F,{className:"h-4 w-4"}),"New Ticket"]})}),e.jsxs(te,{className:"sm:max-w-[500px]",children:[e.jsxs(re,{children:[e.jsx(ie,{children:"Create Support Ticket"}),e.jsx(le,{children:"Describe your issue and we'll get back to you as soon as possible."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Subject"}),e.jsx(B,{placeholder:"Brief summary of your issue",value:i.subject,onChange:s=>c({...i,subject:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Description"}),e.jsx(oe,{placeholder:"Describe your issue in detail...",rows:5,value:i.description,onChange:s=>c({...i,description:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Priority"}),e.jsxs(R,{value:i.priority,onValueChange:s=>c({...i,priority:s}),children:[e.jsx(L,{children:e.jsx(U,{})}),e.jsxs(q,{children:[e.jsx(l,{value:"low",children:"Low"}),e.jsx(l,{value:"medium",children:"Medium"}),e.jsx(l,{value:"high",children:"High"}),e.jsx(l,{value:"urgent",children:"Urgent"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Category"}),e.jsxs(R,{value:i.category,onValueChange:s=>c({...i,category:s}),children:[e.jsx(L,{children:e.jsx(U,{})}),e.jsxs(q,{children:[e.jsx(l,{value:"general",children:"General"}),e.jsx(l,{value:"technical",children:"Technical Issue"}),e.jsx(l,{value:"billing",children:"Billing"}),e.jsx(l,{value:"feature",children:"Feature Request"}),e.jsx(l,{value:"bug",children:"Bug Report"})]})]})]})]})]}),e.jsxs(ne,{children:[e.jsx(n,{variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsx(n,{onClick:K,disabled:S,children:S?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):"Create Ticket"})]})]})]})]}),b.length===0?e.jsxs(N,{className:"p-12 text-center",children:[e.jsx(A,{className:"h-16 w-16 mx-auto mb-4 text-muted-foreground"}),e.jsx("h3",{className:"text-xl font-semibold mb-2",children:"No Support Tickets"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"You haven't created any support tickets yet."}),e.jsxs(n,{onClick:()=>u(!0),className:"gap-2",children:[e.jsx(F,{className:"h-4 w-4"}),"Create Your First Ticket"]})]}):e.jsx("div",{className:"grid gap-4",children:b.map(s=>e.jsx(N,{className:"cursor-pointer hover:border-primary/50 transition-colors",onClick:()=>p(s),children:e.jsx(I,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-medium truncate",children:s.subject}),e.jsx("p",{className:"text-sm text-muted-foreground truncate mt-1",children:s.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:y(new Date(s.created_at),"PPp")})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsxs(x,{variant:"outline",className:O[s.status],children:[Y[s.status],e.jsx("span",{className:"ml-1 capitalize",children:s.status.replace("_"," ")})]}),e.jsx(x,{variant:"outline",className:V[s.priority],children:s.priority})]})]})})},s.id))})]})};export{De 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.