1import{r as l,j as e,a as n,h as k,H as X,U as Q,X as W,P as J,E as ee,z as o,t as c}from"./index-xCd3gAyT.js";import{A as te}from"./AdminLayout-Bk82X5zR.js";import{B as h}from"./button-w1jMvtq3.js";import{D as se,a as ae,b as le,c as re}from"./dialog-B9rwSXsv.js";import{C as ie}from"./chevron-left-D4DrklTt.js";import{C as H}from"./circle-check-big-MpUBMm7Q.js";import{M as ne}from"./message-square-LZ6IHrm6.js";import"./dropdown-menu-5FITA-Lf.js";import"./index-Bz5TMNHk.js";import"./Combination-BvnS46p4.js";import"./index-DHIduJSO.js";import"./check-BqOSjgYA.js";import"./userService-C1Lr0Fh-.js";import"./target-xnsDqe1y.js";import"./file-text-Cg1Ue2Wk.js";import"./credit-card-THZPnstQ.js";import"./chevron-down-BJkWorBX.js";const j={open:{label:"Má»i",color:"bg-blue-500/10 text-blue-600"},in_progress:{label:"Äang xá» lý",color:"bg-amber-500/10 text-amber-600"},resolved:{label:"Äã Äóng",color:"bg-green-500/10 text-green-600"},closed:{label:"Äã Äóng",color:"bg-green-500/10 text-green-600"}},ce=[{code:"TRIAL",label:"Gói Dùng thá» (3 ngà y)"},{code:"MONTHLY",label:"Gói tháng (30 ngà y)"},{code:"QUARTERLY",label:"Gói quý (90 ngà y)"},{code:"TOPUP_AI_VIDEO",label:"Nạp thêm AI Video Analysis (5 lượt)"},{code:"TOPUP_FORUM_POST",label:"Nạp thêm bà i ÄÄng diá»
n Äà n (10 bà i)"},{code:"TOPUP_AI_ARTICLE",label:"Nạp thêm AI Phân tÃch bà i viết (10 lượt)"}];function Ie(){const[w,u]=l.useState([]),[y,$]=l.useState(0),[z,F]=l.useState(!0),[s,d]=l.useState(null),[K,I]=l.useState(!1),[g,C]=l.useState(""),[N,S]=l.useState(!1),[p,A]=l.useState(null),[T,U]=l.useState(null),[x,V]=l.useState(""),[m,f]=l.useState(null),[L,Y]=l.useState("MONTHLY"),[P,R]=l.useState(!1),_=l.useRef(null),b=l.useRef(null),M=async()=>{F(!0);try{const t=new URLSearchParams({page:"1",pageSize:"50"});x&&t.set("status",x);const a=await o.get(`/api/support/admin/tickets?${t}`);u(a.items??[]),$(a.total??0)}catch{c.error("Không thá» tải danh sách ticket")}finally{F(!1)}};l.useEffect(()=>{d(null),M()},[x]);const D=async t=>{I(!0);try{const a=await o.get(`/api/support/admin/tickets/${t}/messages`);d(a),u(r=>r.map(i=>i.ticketId===t?{...i,unreadByAdmin:0}:i))}catch{c.error("Không thá» tải tin nhắn")}finally{I(!1)}};l.useEffect(()=>{_.current?.scrollIntoView({behavior:"smooth"})},[s?.messages]),l.useEffect(()=>{if(!s||s.ticket.status==="resolved"||s.ticket.status==="closed")return;const a=setInterval(async()=>{try{const r=await o.get(`/api/support/admin/tickets/${s.ticket.ticketId}/messages`);d(i=>i&&(r.messages.length!==i.messages.length?r:i)),u(i=>i.map(v=>v.ticketId===s.ticket.ticketId?{...v,unreadByAdmin:0}:v))}catch{}},5e3);return()=>clearInterval(a)},[s?.ticket.ticketId,s?.ticket.status]);const Z=t=>{const a=t.target.files?.[0];a&&(A(a),U(URL.createObjectURL(a)))},O=()=>{A(null),U(null),b.current&&(b.current.value="")},E=async()=>{if(!(!g.trim()&&!p||N||!s)){S(!0);try{const t=new FormData;t.append("Content",g.trim()),p&&t.append("Image",p);const a=await o.postForm(`/api/support/admin/tickets/${s.ticket.ticketId}/messages`,t);d(r=>r&&{...r,messages:[...r.messages,a],ticket:{...r.ticket,status:"in_progress"}}),C(""),O()}catch{c.error("Gá»i thất bại")}finally{S(!1)}}},B=async t=>{if(s)try{await o.patch(`/api/support/admin/tickets/${s.ticket.ticketId}/status`,{status:t}),d(a=>a&&{...a,ticket:{...a.ticket,status:t}}),u(a=>a.map(r=>r.ticketId===s.ticket.ticketId?{...r,status:t}:r)),c.success("Äã cáºp nháºt trạng thái")}catch{c.error("Lá»i cáºp nháºt")}},q=async()=>{if(m){R(!0);try{await o.post("/api/support/admin/manual-grant-subscription",{userId:m.userId,planCode:L,ticketId:m.ticketId}),c.success("Äã cấp gói thà nh công"),f(null),await D(m.ticketId),M()}catch(t){c.error(t.message||"Lá»i cấp gói")}finally{R(!1)}}},G=t=>new Date(t.endsWith("Z")?t:t+"Z").toLocaleString("vi-VN",{timeZone:"Asia/Ho_Chi_Minh",day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"});return e.jsxs(te,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl font-bold text-foreground",children:"Tin nhắn há» trợ"}),e.jsx("p",{className:"text-slate-500 mt-1 text-sm",children:x?`${y} ticket`:`Tá»ng ${y} ticket`})]}),e.jsx("div",{className:"flex gap-2",children:[{v:"",l:"Tất cả"},{v:"open",l:"Má»i"},{v:"in_progress",l:"Äang xá» lý"},{v:"resolved",l:"Äã Äóng"}].map(t=>e.jsx("button",{onClick:()=>V(t.v),className:n("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",x===t.v?"bg-[#FF4444] text-white":"bg-slate-100 dar
1k:bg-white/5 text-slate-600 dark:text-slate-400 hover:bg-slate-200 dark:hover:bg-white/10"),children:t.l},t.v))})]}),e.jsxs("div",{className:"flex gap-4 h-[calc(100vh-220px)]",children:[e.jsx("div",{className:n("flex flex-col gap-2 overflow-y-auto",s?"hidden lg:flex lg:w-80 flex-shrink-0":"w-full lg:w-80 flex-shrink-0"),children:z?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(k,{className:"w-5 h-5 animate-spin text-[#FF4444]"})}):w.length===0?e.jsx("div",{className:"text-center py-12 text-slate-400 text-sm",children:"Không có ticket nà o"}):w.map(t=>e.jsx("button",{onClick:()=>D(t.ticketId),className:n("text-left p-3 rounded-xl border transition-all",s?.ticket.ticketId===t.ticketId?"border-[#FF4444] bg-[#FF4444]/5":"border-slate-200 dark:border-white/5 hover:border-slate-300 dark:hover:border-white/10 bg-card"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[t.avatarUrl?e.jsx("img",{src:t.avatarUrl,className:"w-8 h-8 rounded-full object-cover flex-shrink-0"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#FF4444] to-[#FF6666] flex items-center justify-center text-white text-xs font-bold flex-shrink-0",children:(t.fullName||t.username||"?").charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:t.fullName||t.username}),t.unreadByAdmin>0&&e.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-[#FF4444] text-white text-[10px] font-bold flex items-center justify-center",children:t.unreadByAdmin})]}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:t.subject}),t.lastMessage&&e.jsx("p",{className:"text-xs text-slate-400 truncate mt-0.5",children:t.lastMessage}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:n("text-[10px] px-1.5 py-0.5 rounded-full font-medium",j[t.status]?.color??"bg-slate-100 text-slate-500"),children:j[t.status]?.label??t.status}),e.jsx("span",{className:"text-[10px] text-slate-400",children:G(t.updatedAt)})]})]})]})},t.ticketId))}),s?e.jsxs("div",{className:"flex-1 flex flex-col bg-card border border-slate-200 dark:border-white/5 rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-slate-200 dark:border-white/5",children:[e.jsx("button",{onClick:()=>d(null),className:"lg:hidden p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-white/5",children:e.jsx(ie,{className:"w-4 h-4"})}),s.ticket.avatarUrl?e.jsx("img",{src:s.ticket.avatarUrl,className:"w-8 h-8 rounded-full object-cover"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#FF4444] to-[#FF6666] flex items-center justify-center text-white text-xs font-bold",children:(s.ticket.fullName||s.ticket.username||"?").charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm text-foreground",children:s.ticket.fullName||s.ticket.username}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:s.ticket.subject})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:n("text-xs px-2 py-0.5 rounded-full font-medium",j[s.ticket.status]?.color),children:j[s.ticket.status]?.label}),s.ticket.status!=="resolved"&&s.ticket.status!=="closed"&&e.jsxs(h,{size:"sm",variant:"outline",onClick:()=>B("resolved"),className:"text-xs gap-1 text-green-600 border-green-200 hover:bg-green-50",children:[e.jsx(H,{className:"w-3 h-3"}),"Äóng ticket"]}),(s.ticket.status==="resolved"||s.ticket.status==="closed")&&e.jsx(h,{size:"sm",variant:"outline",onClick:()=>B("open"),className:"text-xs gap-1 text-blue-600 border-blue-200 hover:bg-blue-50",children:"Má» lại"}),e.jsx(h,{size:"sm",onClick:()=>f({userId:s.ticket.userId,ticketId:s.ticket.ticketId}),className:"text-xs bg-[#FF4444] hover:bg-[#FF5555] text-white gap-1",children:"Cấp gói thá»§ công"})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[K?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(k,{className:"w-5 h-5 animate-spin text-[#FF4444]"})}):s.messages.map(t=>e.jsxs("div",{className:n("flex gap-2",t.senderRole==="admin"?"flex-row-reverse":"flex-row"),children:[e.jsx("div",{className:n("w-7 h-7 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5",t.senderRole==="admin"?"bg-[#FF4444]/20":"bg-slate-200 dark:bg-white/10"),children:t.senderRole==="admin"?e.jsx(X,{className:"w-3.5 h-3.5 text-[#FF4444]"}
1):e.jsx(Q,{className:"w-3.5 h-3.5 text-slate-600 dark:text-slate-300"})}),e.jsxs("div",{className:"max-w-[70%] space-y-1",children:[t.content&&e.jsx("div",{className:n("px-3 py-2 rounded-2xl text-sm leading-relaxed",t.senderRole==="admin"?"bg-[#FF4444]/10 text-slate-900 dark:text-foreground rounded-tr-sm":"bg-slate-100 dark:bg-white/5 text-slate-900 dark:text-foreground rounded-tl-sm"),children:t.content}),t.imageUrl&&e.jsx("a",{href:t.imageUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx("img",{src:t.imageUrl,alt:"attachment",className:"max-w-[240px] rounded-xl border border-slate-200 dark:border-white/10 cursor-pointer hover:opacity-90"})}),e.jsx("p",{className:"text-[10px] text-slate-400 px-1",children:G(t.createdAt)})]})]},t.messageId)),e.jsx("div",{ref:_})]}),T&&e.jsx("div",{className:"px-3 pb-1 flex items-center gap-2",children:e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:T,alt:"preview",className:"h-14 w-14 rounded-lg object-cover border border-slate-200 dark:border-white/10"}),e.jsx("button",{onClick:O,className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-500 text-white flex items-center justify-center",children:e.jsx(W,{className:"w-2.5 h-2.5"})})]})}),e.jsx("div",{className:"p-3 border-t border-slate-200 dark:border-white/5",children:e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx("input",{ref:b,type:"file",accept:"image/*",className:"hidden",onChange:Z}),e.jsx("button",{onClick:()=>b.current?.click(),className:"w-9 h-9 rounded-xl bg-slate-100 dark:bg-white/5 flex items-center justify-center hover:bg-slate-200 dark:hover:bg-white/10 transition-colors flex-shrink-0",children:e.jsx(J,{className:"w-4 h-4 text-slate-500"})}),e.jsx("input",{type:"text",value:g,onChange:t=>C(t.target.value),onKeyDown:t=>t.key==="Enter"&&!t.shiftKey&&E(),placeholder:"Nháºp phản há»i...",className:"flex-1 h-9 px-3 rounded-xl bg-slate-100 dark:bg-white/5 text-sm text-foreground placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-[#FF4444]/30 border border-slate-200 dark:border-white/10"}),e.jsx("button",{onClick:E,disabled:!g.trim()&&!p||N,className:"w-9 h-9 rounded-xl bg-[#FF4444] flex items-center justify-center disabled:opacity-40 hover:bg-[#FF5555] transition-colors flex-shrink-0",children:N?e.jsx(k,{className:"w-4 h-4 text-white animate-spin"}):e.jsx(ee,{className:"w-4 h-4 text-white"})})]})})]}):e.jsx("div",{className:"hidden lg:flex flex-1 items-center justify-center text-slate-400 text-sm",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(ne,{className:"w-10 h-10 mx-auto opacity-30"}),e.jsx("p",{children:"Chá»n má»t ticket Äá» xem tin nhắn"})]})})]})]}),e.jsx(se,{open:!!m,onOpenChange:()=>f(null),children:e.jsxs(ae,{className:"max-w-sm",children:[e.jsx(le,{children:e.jsx(re,{children:"Cấp gói thá»§ công"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-slate-500",children:"Chá»n gói Äá» cấp cho ngưá»i dùng. Há» thá»ng sẽ tá»± Äá»ng gá»i thông báo trong chat."}),e.jsx("div",{className:"space-y-2",children:ce.map(t=>e.jsx("button",{onClick:()=>Y(t.code),className:n("w-full text-left px-3 py-2 rounded-xl text-sm border transition-all",L===t.code?"border-[#FF4444] bg-[#FF4444]/10 text-[#FF4444] font-medium":"border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-400"),children:t.label},t.code))}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(h,{variant:"outline",onClick:()=>f(null),children:"Há»§y"}),e.jsxs(h,{onClick:q,disabled:P,className:"bg-[#FF4444] hover:bg-[#FF5555] text-white gap-1",children:[P?e.jsx(k,{className:"w-4 h-4 animate-spin"}):e.jsx(H,{className:"w-4 h-4"}),"Xác nháºn cấp gói"]})]})]})]})})]})}export{Ie 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.