import{m as b,s as N,r as i,j as e,i as h}from"./index-D0o5GN6H.js";const v=()=>{const{id:c}=b(),{user:n}=N(),[a,m]=i.useState(null),[l,o]=i.useState([]),[d,x]=i.useState(""),[g,j]=i.useState(!0),[r,p]=i.useState({});i.useEffect(()=>{(async()=>{try{const t=await h.get(`/tickets/${c}`);m(t.data),console.log(t.data),p(t.data.customer||{}),o(t.data.messages||[])}catch(t){console.error("Error loading ticket:",t)}finally{j(!1)}})()},[c]);const f=async()=>{if(d.trim())try{const s=await h.post("/messages",{ticket_id:a.id,user_id:n.id,message:d});o([...l,s.data]),x("")}catch(s){console.error("Error sending message:",s)}};return g?e.jsx("div",{className:"p-4",children:"Loading ticket..."}):a?e.jsxs("div",{className:"max-w-4xl mx-auto py-6 px-4",children:[e.jsxs("h1",{className:"text-2xl font-bold mb-4",children:["Ticket #",a.ticket_no]}),e.jsx("div",{className:"bg-white rounded-lg shadow p-4 mb-6",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Customer:"})," ",r==null?void 0:r.firstName," ",r==null?void 0:r.lastName]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Department:"})," ",a.department]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Subject:"})," ",a.subject]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Status:"})," ",a.status]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Date Created:"})," ",new Date(a.createdAt).toLocaleString()]})]})}),e.jsx("div",{className:"space-y-4 mb-6 shadow-lg",children:l.map(s=>{var t,u;return e.jsx("div",{className:`flex ${s.user_id===n.id?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[70%] p-3 rounded-lg text-sm shadow ${s.user_id===n.id?"bg-blue-100 text-right":"bg-gray-100"}`,children:[e.jsxs("div",{className:"font-semibold mb-1",children:[(t=s.user)==null?void 0:t.first_name," ",(u=s.user)==null?void 0:u.last_name]}),e.jsx("div",{children:s.message}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:new Date(s.createdAt).toLocaleString()})]})},s.id)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{rows:3,className:"flex-1 border border-gray-300 rounded px-3 py-2",placeholder:"Type your reply...",value:d,onChange:s=>x(s.target.value)}),e.jsx("button",{onClick:f,className:"bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded transition",children:"Submit"})]})]}):e.jsx("div",{className:"p-4 text-red-500",children:"Ticket not found."})};export{v as default};
