1import{j as e}from"./ui-C6t_nCSG.js";import{r as a,h as q}from"./vendor-BStmp9eX.js";import{s as x}from"./Dashboard-DTcVF80X.js";import{A as B}from"./index-BL6G0anb.js";import{B as D}from"./Button-CoKN0hb8.js";import{M as k}from"./Modal-CvVAcvuR.js";import{E as A,d as L}from"./icons-Od_4ddEk.js";const I=()=>{const[u,T]=a.useState([]),[s,m]=a.useState(null),[_,M]=a.useState([]),[d,R]=a.useState("all"),[E,h]=a.useState(!0),[g,l]=a.useState(null),[F,c]=a.useState(!1),[y,b]=a.useState(!1),[o,j]=a.useState(""),{setNavbar:f}=q(),[r,n]=a.useState({subject:"",description:"",category:"general",priority:"medium"}),[N,v]=a.useState(!1);a.useEffect(()=>{f({title:"Support Tickets",subtitle:"View and manage your support requests"})},[f]),a.useEffect(()=>{p()},[d]),a.useEffect(()=>{s&&w(s.id)},[s]);const p=async()=>{try{h(!0),l(null);const t=d==="all"?void 0:d,i=await x.getTickets(t);T(i)}catch(t){l(t.message||"Failed to load tickets")}finally{h(!1)}},w=async t=>{try{const i=await x.getMessages(t);M(i)}catch(i){l(i.message||"Failed to load messages")}},P=async()=>{if(!r.subject||!r.description){l("Subject and description are required");return}try{v(!0),l(null);const t=await x.createTicket(r);c(!1),n({subject:"",description:"",category:"general",priority:"medium"}),await p(),m(t)}catch(t){l(t.message||"Failed to create ticket")}finally{v(!1)}},$=async()=>{if(!(!s||!o.trim()))try{b(!0),await x.addMessage(s.id,o),j(""),await w(s.id),await p()}catch(t){l(t.message||"Failed to send reply")}finally{b(!1)}},C=t=>{switch(t){case"open":return"bg-blue-100 text-blue-800";case"in_progress":return"bg-yellow-100 text-yellow-800";case"waiting_customer":return"bg-orange-100 text-orange-800";case"resolved":return"bg-green-100 text-green-800";case"closed":return"bg-gray-100 text-gray-800";default:return"bg-gray-100 text-gray-800"}},S=t=>{switch(t){case"urgent":return"bg-red-100 text-red-800";case"high":return"bg-orange-100 text-orange-800";case"medium":return"bg-yellow-100 text-yellow-800";case"low":return"bg-green-100 text-green-800";default:return"bg-gray-100 text-gray-800"}};return E&&u.length===0?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-1/4"}),e.jsx("div",{className:"h-64 bg-gray-200 rounded"})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("button",{onClick:()=>c(!0),className:"bg-blue-950 hover:bg-blue-800 text-white px-4 py-2 rounded-lg flex items-center",children:[e.jsx(A,{className:"w-4 h-4 mr-2"}),"New Ticket"]})}),g&&e.jsx(B,{variant:"error",title:"Error",onClose:()=>l(null),children:g}),e.jsx("div",{className:"flex gap-2",children:["all","open","in_progress","waiting_customer","resolved","closed"].map(t=>e.jsx("button",{onClick:()=>R(t),className:`px-4 py-2 rounded-md text-sm font-medium ${d===t?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:t==="all"?"All":t.replace("_"," ").replace(/\b\w/g,i=>i.toUpperCase())},t))}),u.length===0?e.jsxs("div",{className:"xui-bg-light rounded-lg p-12 text-center",children:[e.jsx(L,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No tickets found"}),e.jsx("p",{className:"text-gray-600 mb-4",children:"You haven't created any support tickets yet."}),e.jsx("button",{onClick:()=>c(!0),className:"bg-blue-950 hover:bg-blue-800 text-white px-4 py-2 rounded-lg flex items-center mx-auto",children:"Create Your First Ticket"})]}):e.jsx("div",{className:"xui-bg-light rounded-lg overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Ticket #"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Subject"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Category"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Priority"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Status"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Created"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:u.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium xui-text-black-switch",children:t.ticket_number}),e.jsx("td",{className:"px-6 py-4 text-sm xui-text-black-switch",children:t.subject}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:t.category}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${S(t.priority)}`,children:t.priority})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${C(t.status)}`,children:t.status.replace("_"," ")})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm",children:e.jsx("button",{onClick:()=>m(t),className:"text-blue-600 hover:text-blue-800",children:"View"})})]},t.id))})]})})}),e.jsx(k,{isOpen:F,onClose:()=>c(!1),title:"Create Support Ticket",children:e.jsxs("form",{className:"xui-form space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Subject"}),e.jsx("input",{type:"text",value:r.subject,onChange:t=>n({...r,subject:t.target.value}),placeholder:"Brief description of your issue",className:"w-full px-3 py-2 border border-gray-300 rounded-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Category"}),e.jsxs("select",{value:r.category,onChange:t=>n({...r,category:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md",children:[e.jsx("option",{value:"general",children:"General"}),e.jsx("option",{value:"technical",children:"Technical"}),e.jsx("option",{value:"billing",children:"Billing"}),e.jsx("option",{value:"feature_request",children:"Feature Request"}),e.jsx("option",{value:"bug_report",children:"Bug Report"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Priority"}),e.jsxs("select",{value:r.priority,onChange:t=>n({...r,priority:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md",children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"urgent",children:"Urgent"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Description"}),e.jsx("textarea",{value:r.description,onChange:t=>n({...r,description:t.target.value}),placeholder:"Please provide details about your issue...",rows:6,className:"w-full px-3 py-2 border border-gray-300 rounded-md"})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(D,{onClick:()=>c(!1),variant:"secondary",children:"Cancel"}),e.jsx("button",{onClick:P,disabled:N||!r.subject||!r.description,className:"bg-blue-950 hover:bg-blue-800 text-white px-4 py-2 rounded-lg flex items-center",children:N?"Creating...":"Create Ticket"})]})]})}),s&&e.jsx(k,{isOpen:!!s,onClose:()=>m(null),title:`Ticket #${s.ticket_number}`,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Subject"}),e.jsx("p",{className:"text-gray-700",children:s.subject})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Description"}),e.jsx("p",{className:"text-gray-700 whitespace-pre-wrap",children:s.description})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Status:"}),e.jsx("span",{className:`ml-2 px-2 py-1 rounded-full text-xs font-medium ${C(s.status)}`,children:s.status.replace("_"," ")})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Priority:"}),e.jsx("span",{className:`ml-2 px-2 py-1 rounded-full text-xs font-medium ${S(s.priority)}`,children:s.priority})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Category:"}),e.jsx("span",{className:"ml-2 text-sm font-medium",children:s.category})]})]}),s.resolution&&e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-green-800 mb-2",children:"Resolution"}),e.jsx("p",{className:"text-green-700 whitespace-pre-wrap",children:s.resolution})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Conversation"}),e.jsx("div",{className:"space-y-3 max-h-96 overflow-y-auto border rounded-lg p-4",children:_.map(t=>e.jsxs("div",{className:"p-3 rounded-lg bg-gray-50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"You"}),e.jsx("span",{className:"text-xs text-gray-500",children:new Date(t.created_at).toLocaleStr
1ing()})]}),e.jsx("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:t.message})]},t.id))})]}),s.status!=="closed"&&e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Reply"}),e.jsx("textarea",{value:o,onChange:t=>j(t.target.value),placeholder:"Type your reply...",rows:4,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"}),e.jsx("button",{onClick:$,disabled:!o.trim()||y,className:"bg-blue-950 hover:bg-blue-800 text-white px-4 py-2 rounded-lg flex items-center mt-2",children:y?"Sending...":"Send Reply"})]})]})})]})};export{I as SupportTickets};
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.