1import{r as a,t as i,j as e,L as T}from"./index-Cf_ajVON.js";import{a as p}from"./index-BZFWozEr.js";import{D,a as R,d as P,b as I,e as Q}from"./dialog-CrMXwKWe.js";import{T as $}from"./textarea-C9pIUsm8.js";import{M as G}from"./message-square-SH8cX_Q0.js";import{S as K}from"./search-CI5-KVok.js";import{E as X}from"./eye-DP9IZTXG.js";import{S as J}from"./square-pen-BVVtgbWS.js";import{C as v}from"./clock-BLUAwf4T.js";import{C as W}from"./circle-x-D6gX1se3.js";import{C as Y}from"./circle-check-big-BK3mOZpE.js";import"./index-BH0fEq1S.js";import"./index-DvNrSChk.js";import"./index-BLHo7-Gi.js";import"./index-Bkla0msJ.js";import"./tslib.es6-CwyXKlH1.js";import"./index-BgkASZz5.js";import"./x-BzwCsDoT.js";function be(){const[N,u]=a.useState([]),[_,w]=a.useState(!0),[h,A]=a.useState(""),[d,E]=a.useState(""),[o,F]=a.useState(""),[t,g]=a.useState(null),[O,n]=a.useState(!1),[U,c]=a.useState(!1),[x,b]=a.useState(""),[k,S]=a.useState(!1),[l,L]=a.useState(null);a.useEffect(()=>{m()},[d,o]),a.useEffect(()=>{j()},[]);const m=async()=>{try{w(!0);const s={};d&&(s.status=d),o&&(s.priority=o),h.trim()&&(s.search=h.trim());const r=await p.getDeliverySupportTickets(s);r?.data?.success&&r?.data?.data?.tickets?u(r.data.data.tickets):u([])}catch{i.error("Failed to load tickets"),u([])}finally{w(!1)}},j=async()=>{try{const s=await p.getDeliverySupportTicketStats();s?.data?.success&&s?.data?.data&&L(s.data.data)}catch{}},M=()=>{m()},V=s=>{g(s),n(!0)},C=s=>{g(s),b(s.adminResponse||""),c(!0)},z=async()=>{if(t)try{S(!0);const s=await p.updateDeliverySupportTicket(t._id,{adminResponse:x.trim(),status:t.status==="open"?"in_progress":t.status});if(s?.data?.success){i.success("Ticket updated successfully!");const r=s?.data?.data?.ticket||s?.data?.ticket||{...t,adminResponse:x.trim(),respondedAt:new Date().toISOString(),status:t.status==="open"?"in_progress":t.status};g(r),c(!1),n(!1),b(""),await m(),await j()}else i.error(s?.data?.message||"Failed to update ticket")}catch(s){i.error(s?.response?.data?.message||"Failed to update ticket")}finally{S(!1)}},y=async(s,r)=>{try{(await p.updateDeliverySupportTicket(s,{status:r}))?.data?.success&&(i.success("Ticket status updated!"),await m(),await j())}catch{i.error("Failed to update status")}},q=s=>{switch(s){case"open":return e.jsx(v,{className:"w-5 h-5 text-orange-500"});case"in_progress":return e.jsx(v,{className:"w-5 h-5 text-blue-500"});case"resolved":return e.jsx(Y,{className:"w-5 h-5 text-green-500"});case"closed":return e.jsx(W,{className:"w-5 h-5 text-gray-500"});default:return e.jsx(v,{className:"w-5 h-5 text-gray-500"})}},B=s=>{switch(s){case"open":return"bg-orange-100 text-orange-700";case"in_progress":return"bg-blue-100 text-blue-700";case"resolved":return"bg-green-100 text-green-700";case"closed":return"bg-gray-100 text-gray-700";default:return"bg-gray-100 text-gray-700"}},f=s=>s?new Date(s).toLocaleString("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"N/A";return e.jsxs("div",{className:"p-4 lg:p-6 bg-slate-50 min-h-screen",children:[e.jsx("div",{className:"max-w-7xl mx-auto",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-slate-200 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx(G,{className:"w-6 h-6 text-slate-600"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:"Delivery Support Tickets"}),e.jsx("p",{className:"text-sm text-slate-600 mt-1",children:"Manage and respond to support tickets from delivery partners"})]})]}),l&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:l.total}),e.jsx("p",{className:"text-xs text-slate-600 mt-1",children:"Total"})]}),e.jsxs("div",{className:"bg-orange-50 rounded-lg p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-orange-700",children:l.open}),e.jsx("p",{className:"text-xs text-orange-600 mt-1",children:"Open"})]}),e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-blue-700",children:l.inProgress}),e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:"In Progress"})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-green-700",children:l.resolved}),e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"Resolved"})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-gray-700",children:l.closed}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Closed"})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 mb-6",children:[e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400"}),e.jsx("input",{type:"text",value:h,onChange:s=>A(s.target.value),onKeyPress:s=>s.key==="Enter"&&M(),placeholder:"Search by subject, description, ticket ID, or delivery partner...",className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]})}),e.jsxs("select",{value:d,onChange:s=>E(s.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"All Status"}),e.jsx("option",{value:"open",children:"Open"}),e.jsx("option",{value:"in_progress",children:"In Progress"}),e.jsx("option",{value:"resolved",children:"Resolved"}),e.jsx("option",{value:"closed",children:"Closed"})]}),e.jsxs("select",{value:o,onChange:s=>F(s.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"All Priority"}),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.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(T,{className:"w-8 h-8 animate-spin text-gray-600"})}):e.jsx("div",{className:"space-y-3",children:N.length===0?e.jsx("div",{className:"bg-slate-50 rounded-lg p-8 text-center",children:e.jsx("p",{className:"text-gray-600",children:"No tickets found"})}):N.map(s=>e.jsx("div",{className:"bg-white rounded-lg p-3 shadow-sm border border-gray-200 hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[q(s.status),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[s.ticketId&&e.jsxs("span",{className:"text-xs font-mono font-semibold bg-gray-100 text-gray-700 px-2 py-0.5 rounded",children:["#",s.ticketId]}),e.jsx("span",{className:"text-sm font-medium text-gray-900 truncate",children:s.subject}),e.jsx("span",{className:"text-xs text-gray-600",children:s.deliveryPartner?.name||"N/A"}),s.deliveryPartner?._id&&e.jsxs("span",{className:"text-xs text-gray-500",children:["ID: DP-",String(s.deliveryPartner._id).slice(-8).toUpperCase()]}),e.jsx("span",{className:"text-xs text-gray-500",children:f(s.createdAt)})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>V(s),className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",title:"View Details",children:e.jsx(X,{className:"w-4 h-4 text-gray-600"})}),e.jsx("button",{onClick:()=>C(s),className:"p-2 hover:bg-blue-50 rounded-lg transition-colors",title:s.adminResponse?"Edit Response":"Send Response",children:e.jsx(J,{className:"w-4 h-4 text-blue-600"})}),s.status!=="closed"&&e.jsxs("select",{value:s.status,onChange:r=>y(s._id,r.target.value),className:"text-xs px-2 py-1 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white",onClick:r=>r.stopPropagation(),children:[e.jsx("option",{value:"open",children:"Open"}),e.jsx("option",{value:"in_progress",children:"In Progress"}),e.jsx("option",{value:"resolved",children:"Resolved"}),e.jsx("option",{value:"closed",children:"Closed"})]})]})]})},s._id))})]})}),e.jsx(D,{open:O,onOpenChange:n,children:e.jsxs(R,{className:"flex w-[calc(100%-2rem)] max-w-[600px] max-h-[85vh] flex-col overflow-hidden border border-slate-200 bg-white p-0 shadow-2xl",children:[e.jsxs(P,{className:"border-b border-slate-200 px-6 py-5 pr-14",children:[e.jsx(I,{className:"text-xl font-semibold text-gray-900",children:"Ticket Details"}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:"Complete information about the support ticket"})]}),t&&e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-1 h-6 bg-blue-500 rounded"}),e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:"Ticket Information"})]}),e.jsxs("div",{className:"pl-4 space-y-4",children:[t.ticketId&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Ticket ID"}),e.jsx("div",{className:"bg-gray-200 text-gray-800 px-4 py-2.5 rounded-lg inline-block",children:e.jsxs("p",{className:"text-base font-mono font-semibold",children:["#",t.ticketId]})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Subject"}),e.jsx("p",{className:"text-base text-gray-900 font-semibold",children:t.subject})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Description / Issue"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-lg border border-gray-200 max-h-64 overflow-y-auto",children:e.jsx("p",{className:"text-sm text-gray-900 whitespace-pre-wrap leading-relaxed",children:t.description})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Status"}),e.jsx("span",{className:`inline-block px-4 py-2 rounded-full text-xs font-semibold ${B(t.status)}`,children:t.status.charAt(0).toUpperCase()+t.status.slice(1).replace("_"," ")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Priority"}),e.jsx("p",{className:"text-sm text-gray-900 capitalize font-semibold",children:t.priority})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-2 uppercase tracking-wide",children:"Category"}),e.jsx("p",{className:"text-sm text-gray-900 capitalize font-semibold",children:t.category})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-1 uppercase tracking-wide",children:"Created"}),e.jsx("p",{className:"text-sm text-gray-900",children:f(t.createdAt)})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-1 h-6 bg-orange-500 rounded"}),e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:"Delivery Partner"})]}),e.jsxs("div",{className:"pl-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-1 uppercase tracking-wide",children:"Name"}),e.jsx("p",{className:"text-sm text-gray-900 font-semibold",children:t.deliveryPartner?.name||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-1 uppercase tracking-wide",children:"Phone Number"}),e.jsx("p",{className:"text-sm text-gray-900",children:t.deliveryPartner?.phone||"N/A"})]}),t.deliveryPartner?._id&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-1 uppercase tracking-wide",children:"ID"}),e.jsxs("p",{className:"text-sm text-gray-900",children:["DP-",String(t.deliveryPartner._id).slice(-8).toUpperCase()]})]})]})]}),t.adminResponse&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-1 h-6 bg-green-500 rounded"}),e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:"Admin Response"})]}),e.jsx("div",{className:"pl-4",children:e.jsxs("div",{className:"bg-blue-50 border border-blue-200 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-900 whitespace-pre-wrap leading-relaxed",children:t.adminResponse}),t.respondedAt&&e.jsxs("p",{className:"text-xs text-gray-500 mt-3 pt-3 border-t border-blue-200",children:["Responded on: ",f(t.respondedAt)]})]})})]}),t.status!=="closed"&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 pt-5 border-t border-gray-200",children:[e.jsx("button",{onClick:()=>C(t),className:"px-5 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 font-medium transition-colors shadow-sm",children:t.adminResponse?"Edit Response":"Send Response"}),t.status==="in_progress"&&e.jsx("button",{onClick:()=>{y(t._id,"resolved"),n(!1)},className:"px-5 py-2.5 bg-green-600 text-white rounded-lg hover:bg-green-700 font-medium transition-colors shadow-sm",children:"Mark Resolved"}),e.jsx("button",{onClick:()=>{y(t._id,"closed"),n(!1)},className:"px-5 py-2.5 bg-gray-600 text-white rounded-lg hover:bg-gray-700 font-medium transition-colors shadow-sm",children:"Close Ticket"})]})]})})]})}),e.jsx(D,{open:U,onOpenChange:c,children:e.jsxs(R,{className:"w-[calc(100%-2rem)] max-w-[560px] overflow-hidden border border-slate-200 bg-white p-0 shadow-2xl",children:[e.jsxs(P,{className:"border-b border-slate-200 px-6 py-5 pr-14",children:[e.jsx(I,{className:"text-xl font-semibold text-slate-900",children:"Respond to Ticket"}),t&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-slate-600",children:t.ticketId?`#${t.ticketId}`:"Support Ticket"}),e.jsx("p",{className:"text-sm text-slate-500 line-clamp-2",children:t.subject||"Send an update that the delivery partner can see."})]})]}),e.jsx("div",{className:"space-y-4 px-6 py-5",children:e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-slate-700",children:"Response"}),e.jsx($,{value:x,onChange:s=>b(s.target.value),placeholder:"Enter your response...",rows:6,className:"min-h-[180px] resize-y rounded-xl border-slate-300 bg-white px-4 py-3 text-sm leading-6 text-slate-800 shadow-sm focus-visible:border-blue-500 focus-visible:ring-4 focus-visible:ring-blue-100"}),e.jsx("p",{className:"mt-2 text-xs text-slate-500",children:"This message will be visible to the delivery partner in their support ticket."})]})}),e.jsxs(Q,{className:"border-t border-slate-200 px-6 py-4",children:[e.jsx("button",{onClick:()=>c(!1),className:"rounded-lg border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50",children:"Cancel"}),e.jsx("button",{onClick:z,disabled:k||!x.trim(),className:"flex min-w-[140px] items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50",children:k?e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"w-4 h-4 animate-spin"}),"Updating..."]}):"Update Ticket"})]})]})})]})}export{be 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.