1import{h as ee,ao as re,r as l,s as o,e as d,j as e,L as E,N as se,B as h,b as O,C as q,a as F,b7 as ae,aj as te,ak as ie,al as le,Q as L,I as u,J as M}from"./index-Btl-MrG-.js";import ce from"./Footer-Dppga8e9.js";import{T as ne}from"./textarea-B7VGLzuY.js";import{S as y,a as f,b,c as N,d as i}from"./select-CrH2Rvqq.js";import{D as I,a as B,b as H,c as R}from"./dialog-D5ICR8yo.js";import{S as oe}from"./send-BVX6a41M.js";import{f as V}from"./format-CxwiUPb9.js";import"./separator-DvxCfcIQ.js";import"./collapsible-BjoJ52T1.js";import"./mail-CWbEyMxb.js";import"./phone-djQLVdm1.js";import"./chevron-down-Bv-G-uR_.js";import"./index-BdQq_4o_.js";import"./index-BfSTLg7g.js";import"./differenceInCalendarDays-CmU0Rc8N.js";const Ce=()=>{const v=ee(),{user:a,loading:g}=re(),[w,A]=l.useState([]),[k,G]=l.useState([]),[Q,J]=l.useState(!0),[K,m]=l.useState(!1),[t,C]=l.useState(null),[U,Y]=l.useState([]),[p,S]=l.useState(""),[j,x]=l.useState(!1),[s,n]=l.useState({subject:"",description:"",category:"general",priority:"medium",order_id:""});l.useEffect(()=>{!g&&!a&&v("/auth")},[a,g,v]),l.useEffect(()=>{a&&(_(),$())},[a]);const _=async()=>{try{const{data:r,error:c}=await o.from("support_tickets").select("*").eq("user_id",a==null?void 0:a.id).order("created_at",{ascending:!1});if(c)throw c;A(r||[])}catch(r){console.error("Error loading tickets:",r),d.error("Failed to load support tickets")}finally{J(!1)}},$=async()=>{try{const{data:r,error:c}=await o.from("orders").select("id, order_number").eq("user_id",a==null?void 0:a.id).order("created_at",{ascending:!1}).limit(20);if(c)throw c;G(r||[])}catch(r){console.error("Error loading orders:",r)}},P=async r=>{try{const{data:c,error:D}=await o.from("ticket_messages").select("*").eq("ticket_id",r).order("created_at",{ascending:!0});if(D)throw D;Y(c||[])}catch(c){console.error("Error loading messages:",c)}},z=async()=>{if(!s.subject.trim()||!s.description.trim()){d.error("Please fill in all required fields");return}x(!0);try{const{error:r}=await o.from("support_tickets").insert({user_id:a==null?void 0:a.id,subject:s.subject,description:s.description,category:s.category,priority:s.priority,order_id:s.order_id||null});if(r)throw r;d.success("Support ticket created successfully"),m(!1),n({subject:"",description:"",category:"general",priority:"medium",order_id:""}),_()}catch(r){console.error("Error creating ticket:",r),d.error("Failed to create support ticket")}finally{x(!1)}},T=async()=>{if(!(!p.trim()||!t)){x(!0);try{const{error:r}=await o.from("ticket_messages").insert({ticket_id:t.id,user_id:a==null?void 0:a.id,message:p,is_admin:!1});if(r)throw r;S(""),P(t.id)}catch(r){console.error("Error sending message:",r),d.error("Failed to send message")}finally{x(!1)}}},W=r=>{C(r),P(r.id)},X=r=>{switch(r){case"open":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400";case"in_progress":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400";case"resolved":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400";case"closed":return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400";default:return"bg-gray-100 text-gray-800"}},Z=r=>{switch(r){case"urgent":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400";case"high":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400";case"medium":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400";case"low":return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400";default:return"bg-gray-100 text-gray-800"}};return g||Q?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(E,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(se,{}),e.jsxs("div",{className:"container max-w-4xl mx-auto py-16 px-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Support"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Get help with your orders and account"})]}),e.jsxs(h,{onClick:()=>m(!0),children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),"New Ticket"]})]}),w.length===0?e.jsx(q,{children:e.jsxs(F,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(ae,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No support tickets"}),e.jsx("p",{className:"text-muted-foreground text-center mb-6",children:"Need help? Create a support ticket and we'll get back to you."}),e.jsxs(h,{onClick:()=>m(!0),children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),"Create Ticket"]})]})}):e.jsx("div",{className:"space-y-4",children:w.map(r=>e.jsxs(q,{className:"cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>W(r),children:[e.jsx(te,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(ie,{className:"text-lg",children:r.subject}),e.jsxs(le,{children:[V(new Date(r.created_at),"PPP")," ⢠",r.category]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{className:Z(r.priority),children:r.priority}),e.jsx(L,{className:X(r.status),children:r.status.replace("_"," ")})]})]})}),e.jsx(F,{children:e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:r.description})})]},r.id))}),e.jsx(I,{open:K,onOpenChange:m,children:e.jsxs(B,{className:"max-w-lg",children:[e.jsx(H,{children:e.jsx(R,{children:"Create Support Ticket"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"subject",children:"Subject *"}),e.jsx(M,{id:"subject",placeholder:"Brief description of your issue",value:s.subject,onChange:r=>n({...s,subject:r.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Category"}),e.jsxs(y,{value:s.category,onValueChange:r=>n({...s,category:r}),children:[e.jsx(f,{children:e.jsx(b,{})}),e.jsxs(N,{children:[e.jsx(i,{value:"general",children:"General"}),e.jsx(i,{value:"order_issue",children:"Order Issue"}),e.jsx(i,{value:"delivery",children:"Delivery Problem"}),e.jsx(i,{value:"refund",children:"Refund Request"}),e.jsx(i,{value:"product",children:"Product Question"}),e.jsx(i,{value:"account",children:"Account Issue"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Priority"}),e.jsxs(y,{value:s.priority,onValueChange:r=>n({...s,priority:r}),children:[e.jsx(f,{children:e.jsx(b,{})}),e.jsxs(N,{children:[e.jsx(i,{value:"low",children:"Low"}),e.jsx(i,{value:"medium",children:"Medium"}),e.jsx(i,{value:"high",children:"High"}),e.jsx(i,{value:"urgent",children:"Urgent"})]})]})]})]}),k.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Related Order (optional)"}),e.jsxs(y,{value:s.order_id,onValueChange:r=>n({...s,order_id:r}),children:[e.jsx(f,{children:e.jsx(b,{placeholder:"Select an order"})}),e.jsxs(N,{children:[e.jsx(i,{value:"",children:"None"}),k.map(r=>
1e.jsx(i,{value:r.id,children:r.order_number},r.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"description",children:"Description *"}),e.jsx(ne,{id:"description",placeholder:"Please describe your issue in detail...",rows:4,value:s.description,onChange:r=>n({...s,description:r.target.value})})]}),e.jsxs(h,{onClick:z,disabled:j,className:"w-full",children:[j?e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Create Ticket"]})]})]})}),e.jsx(I,{open:!!t,onOpenChange:()=>C(null),children:e.jsxs(B,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(H,{children:e.jsx(R,{children:t==null?void 0:t.subject})}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-4 py-4",children:[e.jsxs("div",{className:"p-4 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Original request:"}),e.jsx("p",{children:t==null?void 0:t.description})]}),e.jsx("div",{className:"space-y-3",children:U.map(r=>e.jsxs("div",{className:`p-3 rounded-lg ${r.is_admin?"bg-primary/10 ml-0 mr-8":"bg-muted ml-8 mr-0"}`,children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:r.is_admin?"Support Team":"You"}),e.jsx("p",{className:"text-sm",children:r.message}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:V(new Date(r.created_at),"PPP p")})]},r.id))})]}),(t==null?void 0:t.status)!=="closed"&&(t==null?void 0:t.status)!=="resolved"&&e.jsxs("div",{className:"flex gap-2 pt-4 border-t",children:[e.jsx(M,{placeholder:"Type your message...",value:p,onChange:r=>S(r.target.value),onKeyDown:r=>r.key==="Enter"&&T()}),e.jsx(h,{onClick:T,disabled:j,children:e.jsx(oe,{className:"h-4 w-4"})})]})]})})]}),e.jsx(ce,{})]})};export{Ce 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.