1import{a as Et}from"./vendor-antd-CjcCcqh_.js";import{a as l,j as t}from"./vendor-react-CIe7BBPp.js";import{a as L,A}from"./index-B3dWxf7F.js";/* empty css */import{a as ue}from"./vendor-react-bootstrap-BWua6sV7.js";import{toast as c,ToastContainer as Ct}from"./vendor-react-toastify-DyH3b-7G.js";import{P as $}from"./vendor-prop-types-DNxwfY3H.js";import{I as at}from"./images-DsoEKV9h.js";import{M as Lt}from"./vendor-react-icons-BjOknaQJ.js";import At from"./Login-CwfFzfYl.js";import{b as Ft}from"./vendor-router-MF_ECADz.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-helpers-Bu0hh0lh.js";import"./vendor-react-dom-t5F7FhZR.js";import"./vendor-resize-observer-polyfill-pFR5zza0.js";import"./vendor-stylis-BmaM3nay.js";import"./vendor-scroll-into-view-if-needed-D5b_oRbX.js";import"./vendor-compute-scroll-into-view-Bl8rNFhg.js";import"./vendor-throttle-debounce-CUWDS_la.js";import"./vendor-json2mq-CN42t7xi.js";import"./vendor-string-convert-Bhuo--sE.js";import"./vendor-copy-to-clipboard-DxQUb0mb.js";import"./vendor-toggle-selection-DGa8lynz.js";import"./vendor-axios-D2K41pGA.js";import"./vendor-js-cookie-Cz0CWeBA.js";import"./vendor-redux-LH1zpDpA.js";import"./vendor-use-sync-external-store-f1cvjnMh.js";import"./vendor-immer-Bp5DpiZ6.js";import"./vendor-redux-thunk-ClJT1hhx.js";import"./vendor-react-helmet-async-CO3viEpT.js";import"./vendor-react-fast-compare-Dxl0Zvcn.js";import"./vendor-invariant-CCbxWKZF.js";import"./vendor-shallowequal-Ck_j7EqP.js";import"./vendor-remix-run-router-D1FRce34.js";import"./vendor-react-lifecycles-compat-BQyd-nVo.js";import"./vendor-restart-ui-CZ6pMDW7.js";import"./vendor-dom-helpers-DY4L_g-8.js";import"./vendor-warning-CQQPl30N.js";import"./vendor-react-aria-ssr-C_EJWdyo.js";import"./vendor-restart-hooks-C7rFwvJj.js";import"./vendor-uncontrollable-B5vvWZVv.js";import"./vendor-prop-types-extra-BShinCMI.js";import"./vendor-react-transition-group-BNHTQ0HL.js";import"./vendor-react-international-phone-0WvDnNd3.js";import"./vendor-libphonenumber-js-D3XxeqIS.js";function It({onClose:oe=null,userData:i=null,onTicketRaised:q=null,setImageUpload:Ae=null}){const[E,rt]=l.useState(!0),[ve,Fe]=l.useState(!1),[je,Me]=l.useState(!1),Y=l.useRef(null),we=l.useRef(null),ke=l.useRef(null),Se=l.useRef(null),[fe,it]=l.useState([]),[p,xe]=l.useState(""),[F,j]=l.useState("category"),[Oe,Re]=l.useState(""),[Q,Ge]=l.useState(""),[He,$e]=l.useState(null),[V,Be]=l.useState(""),[K,Ne]=l.useState(!1),[C,T]=l.useState(!1),[nt,D]=l.useState(1),[qe,z]=l.useState([]),[ge,Ve]=l.useState(""),[R,se]=l.useState(!1),[lt,ot]=l.useState([]),[ct,ze]=l.useState(!1),[M,G]=l.useState(""),[ce,de]=l.useState(""),[We,Ye]=l.useState(!1),[ae,dt]=l.useState(),[Te,Z]=l.useState(),B=l.useRef(null),re=JSON.parse(sessionStorage.getItem("userData")),_e=l.useRef(!1),J=l.useRef(!1),[ie,ee]=l.useState({step1Category:"",step2Description:"",step3Media:"",step4Link:""}),[X,pe]=l.useState(!1);l.useEffect(()=>{(async()=>{if(i!=null&&i.userId){ze(!0);try{const r=await L.get(A.HELP_AND_SUPPORT.PROBLEM_TYPES,{params:{user_id:i.userId}});if(r.data.status&&r.data.data&&r.data.data.length>0){const s=r.data.data;s.length>0&&ot(s)}}catch(r){globalThis.__APP_LOGGER__.log("Error fetching problem types:",r),c.error("Failed to load categories. Using default options.")}finally{ze(!1)}}})()},[i==null?void 0:i.userId]),l.useEffect(()=>{if(p&&(i!=null&&i.userId)){ne();const e=setInterval(()=>{document.hidden},8e3);return()=>clearInterval(e)}},[p,i==null?void 0:i.userId]),l.useEffect(()=>{var e;(e=Se.current)==null||e.scrollIntoView({behavior:"smooth"})},[fe,qe]),l.useEffect(()=>{if(F==="chat"&&M&&p&&(i!=null&&i.userId))if(_e.current===!1){_e.current=!0;const e=setTimeout(()=>{ye(M,p)},2e3);return B.current=setInterval(()=>{!document.hidden&&!J.current&&ye(M,p)},8e3),()=>{clearTimeout(e),B.current&&(clearInterval(B.current),B.current=null)}}else return B.current=setInterval(()=>{!document.hidden&&!J.current&&ye(M,p)},8e3),()=>{B.current&&(clearInterval(B.current),B.current=null)}},[F,M,p,i==null?void 0:i.userId]),l.useEffect(()=>{if(p&&(i!=null&&i.userId)){ne();const e=setInterval(()=>{document.hidden},8e3);return()=>clearInterval(e)}},[p,i==null?void 0:i.userId]);const be=()=>new Date().toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}),Ke=e=>{var s;let r="";for(const n of e)(s=n.text)!=null&&s.content&&(r+=n.text.content);return r},Pe=e=>{var o,d,f;let r=null,s=null,n=null;for(const x of e)(o=x.video)!=null&&o.url&&(s=x.video.url),(d=x.image)!=null&&d.url&&(r=x.image.url),(f=x.file)!=null&&f.name&&(n=x.file.name);return{messageImageUrl:r,messageVideoUrl:s,fileUrl:n}},pt=(e,r,s)=>{var n,o,d,f,x,k,U,g,S,I,w,b;return r||s||e.video_url||e.videoUrl||((n=e.data)==null?void 0:n.video_url)||((o=e.data)==null?void 0:o.videoUrl)||((f=(d=e.data)==null?void 0:d.data)==null?void 0:f.video_url)||((k=(x=e.data)==null?void 0:x.data)==null?void 0:k.videoUrl)||((U=e.video)==null?void 0:U.url)||((S=(g=e.data)==null?void 0:g.video)==null?void 0:S.url)||e.attachment_url||((I=e.data)==null?void 0:I.attachment_url)||e.file_url||e.fileUrl||((w=e.data)==null?void 0:w.file_url)||((b=e.data)==null?void 0:b.fileUrl)||null},mt=(e,r,s)=>{var n,o,d,f,x,k,U,g;return r||s?r:e.image_url||e.imageUrl||e.file_url||e.fileUrl||((n=e.data)==null?void 0:n.file_url)||((o=e.data)==null?void 0:o.fileUrl)||((d=e.data)==null?void 0:d.image_url)||((f=e.data)==null?void 0:f.imageUrl)||((x=e.image)==null?void 0:x.url)||((U=(k=e.data)==null?void 0:k.image)==null?void 0:U.url)||e.attachment_url||((g=e.data)==null?void 0:g.attachment_url)||null},ht=(e,r,s,n)=>{const o=/\.(mp4|webm|mov|avi|mkv|flv|wmv|m4v)(\?|$)/i;return!!(e||r&&o.test(r)||s&&(o.test(s)||s.includes("/video/")||s.includes("video"))||n.toLowerCase().includes("video uploaded")||n.toLowerCase().includes("video sent"))},me=e=>{let r="",s=null,n=null,o=null;if(Array.isArray(e.message_parts)){r=Ke(e.message_parts);const x=Pe(e.message_parts);s=x.messageImageUrl,n=x.messageVideoUrl,o=x.fileUrl}else if(Array.isArray(e.messageParts)){r=Ke(e.messageParts);const x=Pe(e.messageParts);s=x.messageImageUrl,n=x.messageVideoUrl,o=x.fileUrl}else e.message?r=e.message:e.text&&(r=e.text);n=pt(e,n,o),s=mt(e,s,n);const d=ht(n,o,s,r);return{messageText:r,finalFileUrl:n||s,isVideo:d}},Ie=e=>{const r=e.text||e.messageText||"",s=e.created_time||e.createdTime||"";return`${e.actor_type||e.actorType||""}-${s}-${r.substring(0,20)}`},ut=(e,r)=>r.some(s=>s.fingerprint===e.fingerprint||s.text===e.text&&Math.abs(new Date(s.createdTime||0).getTime()-new Date(e.createdTime||0).getTime())<5e3),Ue=e=>{if(e.isTemporary&&!e.serverSynced){const r=new Date(e.createdTime||0).getTime();return Date.now()-r>=3e4}return!1},Ee=(e,r,s,n)=>{if(Array.from(e.values()).some(k=>!k.justSent&&!k.serverSynced?!1:k.fingerprint===s.fingerprint||k.text===s.text&&Math.abs(new Date(k.createdTime||0).getTime()-new Date(s.createdTime||0).getTime())<5e3))return;const d=e.get(s.id),f=r.get(s.fingerprint),x=f?e.get(f):null;d?d.isTemporary&&!s.isTemporary?(e.set(s.id,s),s.fingerprint&&r.set(s.fingerprint,s.id)):d.isUploading&&!s.isUploading&&e.set(s.id,{...s,fileUrl:s.fileUrl||d.fileUrl}):x?(e.delete(f),e.set(s.id,s),r.set(s.fingerprint,s.id)):(e.set(s.id,s),s.fingerprint&&r.set(s.fingerprint,s.id))},ye=async(e,r)=>{var s,n,o,d;if(!e||!r||!(i!=null&&i.userId)||J.current)return[];J.current=!0;try{const f={conversation_id:e,ticket_id:r,user_id:i.userId},x=await L.post(A.HELP_AND_SUPPORT.GET_FRESHCHAT_MSG,f);let k=((s=x.data)==null?void 0:s.messages)||((o=(n=x.data)==null?void 0:n.data)==null?void 0:o.messages);if(k||(d=x.data)!=null&&d.data&&(k=x.data.data),k&&Array.isArray(k)&&k.length>0){const U=k.map(g=>{const S=g.actor_type==="user"||g.actorType==="user",I=g.created_time||g.createdTime?new Date(g.created_time||g.createdTime).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):be(),{messageText:w,finalFileUrl:b,isVideo:N}=me(g),P=g.id||g.message_id,y=Ie({...g,messageText:w});return{id:P||y,fingerprint:y,type:S?"user":"bot",text:w,messageType:N?"video":b?"image":"text",fileUrl:b,isVideo:N,time:I,freshchatId:g.freshchat_conversation_id||g.freshchatConversationId||e,actorType:g.actor_type||g.actorType,createdTime:g.created_time||g.createdTime}});return U.sort((g,S)=>{const I=new Date(g.createdTime||0).getTime(),w=new Date(S.createdTime||0).getTime();return I-w}),z(g=>{const S=new Set(g.map(v=>v.id)),I=new Set(g.filter(v=>
1v.fingerprint).map(v=>v.fingerprint)),w=g.filter(v=>v.justSent||v.isTemporary&&v.serverSynced);if(!U.some(v=>ut(v,w)?!1:!S.has(v.id)&&!I.has(v.fingerprint))&&g.length>0)return g;const N=new Map,P=new Map;for(const v of g)N.set(v.id,v),v.fingerprint&&P.set(v.fingerprint,v.id);for(const v of U)Ee(N,P,v,w);const y=Array.from(N.values()).filter(v=>!Ue(v)).map(v=>v.justSent?{...v,justSent:!1}:v);return y.sort((v,te)=>{const W=new Date(v.createdTime||0).getTime(),le=new Date(te.createdTime||0).getTime();return W-le}),y}),U}else return[]}catch(f){return f.name==="AbortError"||f.code==="ECONNABORTED"?[]:(globalThis.__APP_LOGGER__.log("Error fetching Freshchat messages:",f),[])}finally{J.current=!1}},he=async(e,r,s="",n="skip",o=null)=>{try{const d=new FormData;d.append("sender","user"),d.append("message_type",e),d.append("message",r),d.append("user_id",(i==null?void 0:i.userId)||""),d.append("ticket_id",p),d.append("pass",o===null?nt:o),s&&d.append("file_url",s),n&&d.append("image_skip",n);const f=await L.post(A.HELP_AND_SUPPORT.SUPPORT_SEND,d);return f.data.status&&(f.data.support_ticket_id&&xe(f.data.support_ticket_id),f.data.ticket_id&&xe(f.data.ticket_id)),f.data}catch(d){throw globalThis.__APP_LOGGER__.log("Error sending message:",d),d}},ne=async()=>{var e;if(!(!p||!(i!=null&&i.userId)))try{const r=await L.post(A.HELP_AND_SUPPORT.SUPPORT_RCV,{user_id:i.userId,ticket_id:p});if(!((e=r.data)!=null&&e.status))return;const{messages:s=[],current_step:n}=r.data,o=s.map(d=>({id:`${d.id}-${d.created_at}`,type:d.sender==="user"?"user":"bot",text:d.message,fileUrl:d.file_url==="skip"?null:d.file_url,time:new Date(d.created_at).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}));if(it(d=>{const f=new Map;for(const x of d)f.set(x.id,x);for(const x of o)f.set(x.id,x);return Array.from(f.values())}),n)switch(n){case"1":j("category");break;case"2":j("description");break;case"3":j("media");break;case"4":j("link");break;case"5":j("chat");break;default:globalThis.__APP_LOGGER__.log("Unknown step from backend:",n)}}catch(r){globalThis.__APP_LOGGER__.log("receivemsg API error:",r)}},ft=async e=>{var r,s,n;Re(e.id),T(!0),j("processing");try{D(2);const d=`Hi! I am ${((r=i==null?void 0:i.name)==null?void 0:r.trim())||"User"}. I want help for ${e.problem_type}`;ee(x=>({...x,step1Category:d}));const f=await he("category",e.problem_type,"","skip",2);f.support_ticket_id&&xe(f.support_ticket_id),setTimeout(()=>{j("description"),T(!1)},800)}catch(o){globalThis.__APP_LOGGER__.log("Failed to send category:",o),c.error(((n=(s=o==null?void 0:o.response)==null?void 0:s.data)==null?void 0:n.message)||"Failed to send category"),T(!1),j("category")}},Ze=async()=>{var e,r;if(!Q.trim()){c.error("Please enter a description");return}T(!0),j("processing");try{D(3),ee(s=>({...s,step2Description:Q})),await he("text",Q,"","skip",3),setTimeout(()=>{j("media"),T(!1)},800)}catch(s){globalThis.__APP_LOGGER__.log("Failed to send description:",s),c.error(((r=(e=s==null?void 0:s.response)==null?void 0:e.data)==null?void 0:r.message)||"Failed to send description"),T(!1),j("description")}},Je=e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ze())},Xe=async e=>{const r=e.target.files[0];if(r){if(!r.type.startsWith("image/")){c.error("Only image files are allowed");return}if(r.size>5*1024*1024){c.error("File size must be less than 5MB");return}$e(r),T(!0),j("processing");try{const s=new FormData;s.append("sender","user"),s.append("message_type","image"),s.append("message","Image uploaded"),s.append("user_id",(i==null?void 0:i.userId)||""),s.append("ticket_id",p),s.append("pass","4"),s.append("sender_img1",r),ee(n=>({...n,step3Media:"Image uploaded"})),await L.post(A.HELP_AND_SUPPORT.SUPPORT_SEND,s,{headers:{"Content-Type":"multipart/form-data"}}),c.success("Image uploaded"),await ne(),j("link"),T(!1)}catch(s){globalThis.__APP_LOGGER__.log("Image upload failed:",s),c.error("Failed to upload image"),T(!1),j("media")}}},Qe=async e=>{var s,n;const r=e.target.files[0];if(r){if(!r.type.startsWith("video/")){c.error("Only video files are allowed");return}if(r.size>50*1024*1024){c.error("Video file size must be less than 50MB");return}T(!0),j("processing");try{const o=new FormData;o.append("sender","user"),o.append("message_type","video"),o.append("message","Video uploaded"),o.append("user_id",(i==null?void 0:i.userId)||""),o.append("ticket_id",p),o.append("pass","4"),o.append("image_skip",""),o.append("sender_img1",r,r.n
1ame),D(4),ee(f=>({...f,step3Media:"Video uploaded"}));const d=await L.post(A.HELP_AND_SUPPORT.SUPPORT_SEND,o,{headers:{"Content-Type":"multipart/form-data"}});if(d.data.status)c.success("Video uploaded successfully"),setTimeout(()=>{j("link"),T(!1)},1e3);else throw new Error(d.data.message||"Upload failed")}catch(o){globalThis.__APP_LOGGER__.log("Video upload failed:",o),c.error(((n=(s=o==null?void 0:o.response)==null?void 0:s.data)==null?void 0:n.message)||"Failed to upload video"),T(!1),j("media")}}},xt=async()=>{var e,r;T(!0),j("processing");try{D(4),ee(s=>({...s,step3Media:""})),await he("image","Skip Media","","1",4),await ne(),setTimeout(()=>{j("link"),T(!1)},600)}catch(s){globalThis.__APP_LOGGER__.log("Media skip failed:",s),c.error(((r=(e=s==null?void 0:s.response)==null?void 0:e.data)==null?void 0:r.message)||"Failed to skip media"),T(!1),j("media")}},De=async()=>{let e=V.trim();if(!e){c.error("Please enter a valid link");return}try{/^https?:\/\//i.test(e)||(e=`https://${e}`),new URL(e),Ne(!1),T(!0),j("processing"),D(5);const r=`Link: ${e}`;ee(s=>({...s,step4Link:r})),await he("link",r,"","skip",5),await ne(),await Le(r),Be(e)}catch(r){globalThis.__APP_LOGGER__.log("Link submit error:",r);const s=(r==null?void 0:r.message)||"Please enter a valid URL";c.error(s),T(!1),j("link")}},gt=async()=>{var e,r;T(!0),j("processing");try{D(5),ee(s=>({...s,step4Link:""})),await he("link","Skip Link","","skip",5),await ne(),await Le("")}catch(s){globalThis.__APP_LOGGER__.log("Skip link error:",s);const n=((r=(e=s==null?void 0:s.response)==null?void 0:e.data)==null?void 0:r.message)||(s==null?void 0:s.message)||"Failed to process";c.error(n),T(!1),j("link")}},_t=()=>Ne(!0),Ce=async e=>{var r,s,n,o,d,f,x,k,U,g,S,I,w;dt((r=e==null?void 0:e.data)==null?void 0:r.data.ticketId),pe(!0);try{const b=((s=e==null?void 0:e.data)==null?void 0:s.data)||((n=e==null?void 0:e.data)==null?void 0:n.refId),N=(b==null?void 0:b.freshchat_conversation_id)||((o=e==null?void 0:e.data)==null?void 0:o.freshchat_conversation_id)||"",P=(b==null?void 0:b.support_ticket_id)||(b==null?void 0:b.ticket_id)||((d=e==null?void 0:e.data)==null?void 0:d.support_ticket_id)||((f=e==null?void 0:e.data)==null?void 0:f.ticket_id)||p,y=(b==null?void 0:b.user_id)||((x=e==null?void 0:e.data)==null?void 0:x.user_id)||(i==null?void 0:i.userId)||"",v=(b==null?void 0:b.freshchat_user_id)||((k=e==null?void 0:e.data)==null?void 0:k.freshchat_user_id)||(b==null?void 0:b.freshchatUserId)||((U=e==null?void 0:e.data)==null?void 0:U.freshchatUserId)||"";if(v&&de(v),!N||!P||!y)return globalThis.__APP_LOGGER__.log("Missing required data for fetching messages"),null;G(N);const te={conversation_id:N,ticket_id:P,user_id:y},W=await L.post(A.HELP_AND_SUPPORT.GET_FRESHCHAT_MSG,te);let le=((g=W.data)==null?void 0:g.messages)||((I=(S=W.data)==null?void 0:S.data)==null?void 0:I.messages);if(!le&&((w=W.data)!=null&&w.data)&&(le=W.data.data),le&&Array.isArray(le)&&le.length>0){const kt=le.map(O=>{const vt=O.actor_type==="user"||O.actorType==="user",jt=O.created_time||O.createdTime?new Date(O.created_time||O.createdTime).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):be(),{messageText:st,finalFileUrl:St,isVideo:Nt}=me(O),Ut=()=>{let wt="text";return Nt?wt="video":St&&(wt="image"),wt};return{id:O.id||O.message_id||crypto.randomUUID(),type:vt?"user":"bot",text:st,messageType:Ut(),fileUrl:St,isVideo:Nt,time:jt,freshchatId:O.freshchat_conversation_id||O.freshchatConversationId||N,actorType:O.actor_type||O.actorType,createdTime:O.created_time||O.createdTime,fingerprint:Ie({...O,messageText:st})}});kt.sort((O,vt)=>{const jt=new Date(O.createdTime||0).getTime(),st=new Date(vt.createdTime||0).getTime();return jt-st}),z(kt),_e.current=!0}return W.data}catch(b){return globalThis.__APP_LOGGER__.log("Error in fetchMessagesAfterTicketCreation:",b),c.error("Failed to load initial messages"),null}finally{pe(!1)}},Le=async(e=null)=>{var r,s,n,o,d,f,x,k,U,g,S,I;try{if(T(!0),j("processing"),!p){globalThis.__APP_LOGGER__.log("No ticket ID found"),c.error("Session error. Please try again."),j("link"),T(!1);return}const w=e===null?ie.step4Link:e,b=[ie.step1Category,ie.step2Description,ie.step3Media,w].filter(W=>W==null?void 0:W.trim()).join(` 2`),N=new FormData;N.append("user_id",(i==null?void 0:i.userId)||""),N.append("username",(i==null?void 0:i.username)||(i==null?void 0:i.name)||""),N.append("phone_no",(i==null?void 0:i.phoneNo)||(i==null?void 0:i.phone)||""),N.append("whatsapp_no",(i==null?void 0:i.whatsapp)||(i==null?void 0:i.phoneNo)||(i==null?void 0:i.phone)||""),N.append("email",(i==null?void 0:i.email)||""),N.append("problem_type",Oe),N.append("description",b),N.append("subject","web"),N.append("support_ticket_id",p),He&&N.append("qry_img",He);const P=await L.post(A.HELP_AND_SUPPORT.STUDENT_QUERY,N,{headers:{"Content-Type":"multipart/form-data"}});if(Z(P.data.data.refId),!P.data.status){c.error(P.data.message||"Failed to submit query"),j("link"),T(!1);return}const y=((r=P.data)==null?void 0:r.data)||P.data,v=(y==null?void 0:y.support_ticket_id)||(y==null?void 0:y.ticket_id)||(y==null?void 0:y.ticketId)||(y==null?void 0:y.id)||((s=P.data)==null?void 0:s.support_ticket_id)||((n=P.data)==null?void 0:n.ticket_id)||((o=P.data)==null?void 0:o.ticketId)||p;xe(v);const te={conversation_id:(y==null?void 0:y.freshchat_conversation_id)||((d=P.data)==null?void 0:d.freshchat_conversation_id)||"",ticket_id:v,user_id:(y==null?void 0:y.user_id
2)||(i==null?void 0:i.userId)||"",ref_id:(y==null?void 0:y.refId)||((f=P.data)==null?void 0:f.refId)||"",freshchat_user_id:(y==null?void 0:y.freshchat_user_id)||((x=P.data)==null?void 0:x.freshchat_user_id)||(y==null?void 0:y.freshchatUserId)||((k=P.data)==null?void 0:k.freshchatUserId)||"",status:((U=P.data)==null?void 0:U.status)||!1,message:((g=P.data)==null?void 0:g.message)||""};if(te.freshchat_user_id&&de(te.freshchat_user_id),te.conversation_id&&G(te.conversation_id),!te.ticket_id){globalThis.__APP_LOGGER__.log("Missing ticket_id in response"),c.error("Failed to get ticket ID"),j("link"),T(!1);return}await Ce(P),c.success("Ticket raised successfully!"),q&&q(),j("chat"),T(!1)}catch(w){globalThis.__APP_LOGGER__.log("raiseTicketRequest Error:",w),c.error(((I=(S=w==null?void 0:w.response)==null?void 0:S.data)==null?void 0:I.message)||"Failed to submit query. Please try again."),j("link"),T(!1)}},bt=e=>{const r=e.type.startsWith("video/"),s=e.type.startsWith("image/");return!s&&!r?(c.error("Only image and video files are allowed"),null):s&&e.size>5*1024*1024?(c.error("Image file size must be less than 5MB"),null):r&&e.size>10*1024*1024?(c.error("Video file size must be less than 10MB"),null):{isImage:s,isVideo:r}},yt=(e,r)=>{const s=URL.createObjectURL(e),n=`${r?"temp-video":"temp-image"}-${Date.now()}`;return{tempMessage:{id:n,type:"user",text:r?"":"Image attachment",messageType:r?"video":"image",fileUrl:s,isVideo:r,time:be(),isTemporary:!0,isUploading:!0,createdTime:new Date().toISOString()},tempMessageId:n,localFileUrl:s}},a=(e,r,s)=>{var d;const n=(e==null?void 0:e.data)||{},o=(n==null?void 0:n.data)||{};return r?n.video_url||o.video_url||n.file_url||o.file_url||((d=o==null?void 0:o.data)==null?void 0:d.video_url)||n.url||o.url||s:n.image_url||o.image_url||n.file_url||o.file_url||s},u=(e,r)=>{const s=(e==null?void 0:e.data)||{},n=(s==null?void 0:s.data)||{};return s.message_id||n.message_id||s.id||`${r?"video":"image"}-${Date.now()}`},m=async(e,r)=>{const s=new FormData;return s.append("conversation_id",M),s.append("user_id",(i==null?void 0:i.userId)||""),s.append("message_text",r?"":"Image attachment"),s.append("student_query_id",Te),s.append("ticket_id",ae),s.append("freshchat_user_id",ce),s.append("sender_img1",e,e.name),L.post(A.HELP_AND_SUPPORT.SEND_FRESH_CHAT_MSG,s,{headers:{"Content-Type":"multipart/form-data"}})},h=async e=>{var x,k,U,g;const r=e.target.files[0];if(!r)return;const s=bt(r);if(!s)return;const{isVideo:n}=s;if(!M||!p||!ce){c.error("Missing chat session data");return}se(!0);const{tempMessage:o,tempMessageId:d,localFileUrl:f}=yt(r,n);z(S=>[...S,o]);try{const S=await m(r,n);if(!((x=S.data)!=null&&x.status))throw new Error(((k=S.data)==null?void 0:k.message)||"Upload failed");const I=a(S,n,f),w=u(S,n);z(b=>b.map(N=>N.id===d?{...N,id:w,fileUrl:I,isTemporary:!1,isUploading:!1,serverSynced:!0}:N)),c.success(n?"Video sent successfully":"Image sent"),setTimeout(()=>URL.revokeObjectURL(f),3e3)}catch(S){z(w=>w.filter(b=>b.id!==d)),URL.revokeObjectURL(f);const I=((g=(U=S==null?void 0:S.response)==null?void 0:U.data)==null?void 0:g.message)||S.message||`Failed to send ${n?"video":"image"}`;c.error(I)}finally{se(!1),e.target.value=""}},_=async()=>{var f,x,k,U,g,S;if(!ge.trim())return;const e=ge;Ve(""),se(!0);const r=`temp-text-${Date.now()}`,s=be(),n=new Date().toISOString(),o=Ie({text:e,messageText:e,created_time:n,actor_type:"user"}),d={id:r,type:"user",text:e,time:s,isTemporary:!0,createdTime:n,fingerprint:o,justSent:!0};z(I=>[...I,d]);try{if(!M||!p||!ce)throw c.error("Missing chat session data"),new Error("Missing required data");const I={conversation_id:M,user_id:(i==null?void 0:i.userId)||"",message_text:e,student_query_id:Te,ticket_id:ae,freshchat_user_id:ce,sender_img1:""},w=await L.post(A.HELP_AND_SUPPORT.SEND_FRESH_CHAT_MSG,I);if((f=w.data)!=null&&f.status){const b=((x=w.data)==null?void 0:x.message_id)||((U=(k=w.data)==null?void 0:k.data)==null?void 0:U.message_id)||((g=w.data)==null?void 0:g.id)||`text-${Date.now()}`;z(N=>N.map(P=>P.id===r?{...P,id:b,isTemporary:!1,serverSynced:!0,justSent:!1,fingerprint:o}:P)),J.current=!0,setTimeout(()=>{J.current=!1},3e3),c.success("Message sent")}else throw new Error(((S=w.data)==null?void 0:S.message)||"Send failed")}catch(I){globalThis.__APP_LOGGER__.log("sendChatMessage failed:",I),z(w=>w.filter(b=>b.id!==r)),c.error(I.message||"Failed to send message")}finally{se(!1)}},H=async()=>
2{if(!M||!p){c.error("Cannot refresh: Missing conversation data");return}Ye(!0);try{await ye(M,p),c.success("Messages refreshed successfully")}catch(e){globalThis.__APP_LOGGER__.log("Error refreshing messages:",e),c.error("Failed to refresh messages")}finally{Ye(!1)}},et=()=>{B.current&&(clearInterval(B.current),B.current=null),rt(!1),oe&&oe()},tt=e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),_())};return E?t.jsxs("div",{className:"fixed! top-0! left-0! w-screen! h-screen! bg-white! flex! flex-col! overflow-hidden! z-9999!",children:[t.jsxs("div",{className:"text-black! py-2.5! px-5! flex! justify-between! items-center! bg-[#c8e1ff]! rounded-b-[10px]!",children:[t.jsxs("div",{className:"flex! items-center! gap-3!",children:[t.jsx("div",{className:"w-10! h-10! bg-[rgba(255,255,255,0.2)]! rounded-full! flex! items-center! justify-center!",children:t.jsx("svg",{className:"d-inline-block",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx("div",{})]}),t.jsxs("div",{className:"flex! gap-2! items-center!",children:[F==="chat"&&t.jsx("button",{onClick:H,className:"chatbox-refresh-btn",disabled:We,title:"Refresh messages"}),t.jsx("button",{onClick:et,className:"bg-white! text-black! w-8! h-8! rounded-full! flex! items-center! justify-center!",children:t.jsxs("svg",{className:"d-inline-block",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),t.jsxs("div",{className:"overflow-y-auto! p-5! bg-white! flex! flex-col! gap-3! rounded-[15px]! my-5! max-[767px]:p-3! ",children:[F==="category"&&t.jsxs("div",{className:"flex! items-center! justify-start! gap-5!",children:[t.jsx("div",{className:"userImg1",children:t.jsx("img",{src:`${at}/dams-icon/logo.png`,alt:"logo",className:"max-w-full! w-18.75! h-auto!"})}),t.jsx("div",{children:t.jsxs("h4",{className:"text-base! text-black! bg-[#c8e1ff]! py-3.5! px-5! rounded-lg! leading-6.25! mb-3.75! max-[767px]:text-sm! max-[767px]:py-2! max-[767px]:px-3!",children:["Hi, ",(re==null?void 0:re.name)||"User"," ",t.jsx("br",{}),"Select Your Category"]})})]}),F!=="chat"&&fe.map(e=>{var r;return t.jsxs("div",{className:`message-wrapper ${e.type} ${e.type==="user"?"flex-row-reverse! mb-8.75!":""}`,children:[e.type==="bot"&&t.jsx("div",{className:"message-avatar",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsxs("div",{className:`message-bubble ${e.type}`,children:[t.jsx("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:e.text}),e.fileUrl&&e.fileUrl!=="skip"&&(e.isVideo?t.jsx("video",{src:e.fileUrl,controls:!0,className:"message-attachment",style:{maxWidth:"100%",maxHeight:"200px"},children:t.jsx("track",{kind:"captions",src:"",srcLang:"en",label:"English captions",default:!0})}):t.jsxs(t.Fragment,{children:[e.fileUrl&&((r=e.text)==null?void 0:r.toLowerCase())!=="skip media"&&t.jsx("button",{onClick:()=>Fe(!0),children:t.jsx("img",{src:e.fileUrl,alt:"attachment",className:"message-attachment",style:{cursor:"pointer"}})}),ve&&t.jsx("button",{className:"modal-overlay",onClick:()=>Fe(!1),style:Tt,children:t.jsx("img",{src:e.fileUrl,alt:"zoomed",style:Pt})})]})),t.jsxs("div",{className:"message-time text-[11px]! mt-1! block!",children:[e.time," "]})]})]},e.id)}),X&&t.jsxs("div",{className:"message-wrapper bot flex! flex-row! bg-white! text-[#1e293b]! rounded-bl! mb-6.25! gap-2! items-end! animate-[slideIn_0.3s_ease-out]!",children:[t.jsx("div",{className:"message-avatar w-7.5! h-7.5! bg-[#007aff]! rounded-full! flex! items-center! justify-center! shrink-0! text-white!",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx("div",{className:"message-bubble bot bg-white! text-[#1e293b]! rounded-bl! shadow-[0_1px_2px_rgba(0,0,0,0.05)]! py-2.5! px-3! rounded-2xl! relative! wrap-break-word! max-w-[88%]!",children:t.jsx("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:"Loading messages..."})})]}),F==="chat"&&!X&&qe.map(e=>t.jsxs("div",{className:`message-wrapper ${e.type} ${e.type==="user"?"flex-row-reverse! mb-8.75!":""}`,children:[e.type==="bot"&&t.jsx("div",{className:"message-avatar",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsxs("div",{className:`message-bubble ${e.type}`,children:[t.jsxs("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:[e.text,e.isUploading&&t.jsx("span",{children:" â³"})]}),e.fileUrl&&e.fileUrl!=="skip"&&(e.isVideo||e.messageType==="video"?t.jsxs("video",{src:e.f
2ileUrl,controls:!0,className:"message-attachment",style:{maxWidth:"100%",maxHeight:"200px",borderRadius:"8px",marginTop:"8px",background:"#000"},children:[t.jsx("track",{kind:"captions",src:"",srcLang:"en",label:"English captions",default:!0}),"Your browser does not support the video tag."]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>Me(!0),children:t.jsx("img",{src:e.fileUrl,alt:"attachment",className:"message-attachment",style:{maxWidth:"100%",borderRadius:"8px",marginTop:"8px",cursor:"pointer"}})}),je&&t.jsx("button",{style:Tt,onClick:()=>Me(!1),children:t.jsx("img",{src:e.fileUrl,alt:"zoomed",style:Pt})})]})),t.jsx("div",{className:"message-time text-[11px]! mt-1! block!",children:e.time})]})]},e.id)),R&&F==="chat"&&!X&&t.jsxs("div",{className:"message-wrapper1 bot1 flex! flex-row! bg-white! text-[#1e293b]! rounded-bl! mb-6.25! gap-2! items-end! animate-[slideIn_0.3s_ease-out]!",children:[t.jsx("div",{className:"message-avatar w-7.5! h-7.5! bg-[#007aff]! rounded-full! flex! items-center! justify-center! shrink-0! text-white!",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx("div",{className:"message-bubble1 bot1 bg-white! text-[#1e293b]! rounded-bl! shadow-[0_1px_2px_rgba(0,0,0,0.05)]! py-2.5! px-3! rounded-2xl! relative! wrap-break-word! max-w-[88%]!",children:t.jsx("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:"Sending..."})})]}),F==="category"&&t.jsx("div",{className:"options-container1 flex! flex-col!",children:ct?t.jsx("div",{className:"message-wrapper bot flex! flex-row! bg-white! text-[#1e293b]! rounded-bl! mb-6.25! gap-2! items-end! animate-[slideIn_0.3s_ease-out]!",children:t.jsx("div",{className:"message-bubble1 bot1 bg-white! text-[#1e293b]! rounded-bl! shadow-[0_1px_2px_rgba(0,0,0,0.05)]! py-2.5! px-3! rounded-2xl! relative! wrap-break-word! max-w-[88%]!",children:t.jsx("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:"Loading categories..."})})}):lt.map(e=>t.jsx("button",{onClick:()=>ft(e),className:"option-button1 text-[#3484f2]! font-semibold! text-[15px]! border! border-[#f5f5f5]! mb-1.25! rounded-[10px]! py-3! px-4! transition-all! duration-200! text-left! bg-white! hover:border-[#007aff]! hover:bg-[#f0f9ff]! hover:text-[#0891b2]! hover:translate-x-1! max-[767px]:text-sm! max-[767px]:py-2! max-[767px]:px-3! max-[767px]:mb-2!",disabled:C,children:e.problem_type},e.id))}),F==="media"&&t.jsxs("div",{className:"options-container-inline",children:[t.jsx("button",{onClick:()=>Y.current.click(),className:"option-button-small",disabled:C,children:"ð Upload Image"}),t.jsx("button",{onClick:xt,className:"option-button-small",disabled:C,children:"Skip"}),t.jsx("input",{type:"file",ref:Y,accept:"image/*",className:"file-input-hidden",onChange:Xe}),t.jsx("input",{type:"file",ref:we,accept:"video/*",className:"file-input-hidden",onChange:Qe})]}),F==="link"&&t.jsx(t.Fragment,{children:K?t.jsxs("div",{className:"link-input-container",children:[t.jsx("input",{type:"text",value:V,onChange:e=>Be(e.target.value),placeholder:"Enter link (e.g., https://example.com)",className:"link-input",disabled:C,onKeyDown:e=>{e.key==="Enter"&&!C&&De()}}),t.jsx("button",{onClick:De,className:"link-submit-btn",disabled:C,children:"Add Link"}),t.jsx("button",{onClick:()=>Ne(!1),className:"link-cancel-btn",disabled:C,children:"Cancel"})]}):t.jsxs("div",{className:"options-container-inline",children:[t.jsx("button",{onClick:_t,className:"option-button-small",disabled:C,children:"ð Upload Link"}),t.jsx("button",{onClick:gt,className:"option-button-small",disabled:C,children:"Skip"})]})}),(F==="processing"||C&&F!=="submit"&&F!=="chat")&&!X&&t.jsxs("div",{className:"message-wrapper bot flex! flex-row! bg-white! text-[#1e293b]! rounded-bl! mb-6.25! gap-2! items-end! animate-[slideIn_0.3s_ease-out]!",children:[t.jsx("div",{className:"message-avatar w-7.5! h-7.5! bg-[#007aff]! rounded-full! flex! items-center! justify-center! shrink-0! text-white!",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx("div",{className:"message-bubble bot bg-white! text-[#1e293b]! rounded-bl! shadow-[0_1px_2px_rgba(0,0,0,0.05)]! py-2.5! px-3! rounded-2xl! relative! wrap-break-word! max-w-[88%]!",children:t.jsx("div",{className:"message-text text-sm! leading-normal! m-0! whitespace-pre-line!",children:"Processing..."})})]}),t.jsx("div",{ref:Se})]}),F==="description"&&t.jsxs("div",{className:"chatbox-input-container",children:[t.jsx("textarea",{value:Q,onChange:e=>Ge(e.target.value),onKeyDown:Je,placeholder:"Type your query here... (Press Enter to send)",className:"chatbox-textarea",rows:"2",disabled:C}),t.jsx("button",{onClick:Ze,disabled:!Q.trim()||C,className:"chatbox-send-button",children:t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),t.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),F==="chat"&&!X&&t.jsxs("div",{className:"chatbox-input-container",children:[t.jsx("textarea",{value:ge,onChange:e=>Ve(e.target.value),onKeyDown:tt,placeholder:"Type your message...",className:"chatbox-textarea",rows:"2",disabled:R}),t.jsx("button",{onClick:()=>{var e;return(e=ke.current)==null?void 0:e.click()},className:"chatbox-attachment-button",disabled:R,title:"Upload image or video",children:t.jsx("svg",{width:"24",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),t.jsx("button",{onClick:_,disabled:!ge.trim()||R,className:"chatbox-send-button",children:t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",children:[t.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),t.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}),t.jsx("input",{type:"file",ref:ke,accept:"image/*,video/*",onChange:h,style:{display:"none"}})]})]}):null}It.propTypes={onClose:$.func,onTicketRaised:$.func,userData:$.shape({userId:$.string,username:$.string,name:$.string,phone:$.string,phoneNo:$.string,whatsapp:$.string,email:$.string,deviceToken:$.string,authToken:$.string,freshchatUserId:$.string}),setImageUpload:$.func};const Tt={position:"fixed",top:0,left:0,width:"100%",height:"100%",background:"rgba(0,0,0,0.8)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:9999},Pt={maxWidth:"90%",maxHeight:"90%",borderRadius:"10px",width:"300px"};function Mt(oe){const i=new Date(oe);
2if(Number.isNaN(i.getTime()))return"";const q=i.getHours().toString().padStart(2,"0"),Ae=i.getMinutes().toString().padStart(2,"0");return`${q}:${Ae}`}const Ot=({setIsAuthenticated:oe})=>{const i=Ft(),q=localStorage.getItem("user_id"),Ae=l.useRef(null),[E,rt]=l.useState(null),[ve,Fe]=l.useState(null),[je,Me]=l.useState(null),[Y,we]=l.useState([]),[ke,Se]=l.useState(!1),[fe,it]=l.useState([]),[p,xe]=l.useState(null),[F,j]=l.useState(!1),[Oe,Re]=l.useState(!1),[Q,Ge]=l.useState(!1),[He,$e]=l.useState(!1),[V,Be]=l.useState(null),[K,Ne]=l.useState(null),[C,T]=l.useState(null),[nt,D]=l.useState([]),[qe,z]=l.useState([]),[ge,Ve]=l.useState(null),[R,se]=l.useState(null),[lt,ot]=l.useState(null),[ct,ze]=l.useState(""),M=JSON.parse(sessionStorage.getItem("userData")),[G,ce]=l.useState(null),[de,We]=l.useState(null),[Ye,ae]=l.useState([]),[dt,Te]=l.useState(!1),[Z,B]=l.useState({category:"",query:""}),[re,_e]=l.useState([]),[J,ie]=l.useState(""),[ee,X]=l.useState(!1),pe=l.useRef(null),be=()=>{E?X(!1):c.error("Please login to access this page")},Ke=()=>{X(!1)},Pe=()=>{try{X(!0)}catch(a){globalThis.__APP_LOGGER__.log(a)}};l.useEffect(()=>{(()=>{try{if(!(sessionStorage.getItem("jwt_token")||localStorage.getItem("jwt_token"))){Pe();return}if(!q){Pe();return}rt(q),oe(!0)}catch(u){globalThis.__APP_LOGGER__.log(u),c.error("Authentication failed. Please login again."),i("/login")}})()},[q,i]);const pt=()=>{Ge(!1),ae([]),ce(null),We(null)},mt=()=>$e(!1);l.useEffect(()=>{E&&(me(),Ie(),ut())},[E]);const ht=()=>{j(!0),Re(!1)},me=async()=>{var a,u;if(E)try{const{data:m}=await L.post(A.HELP_AND_SUPPORT.GET_ALL_RAISE_QUERY,{user_id:E});if(Fe(m.data,"sticket"),m.status){const h=((m==null?void 0:m.data)||[]).sort((_,H)=>new Date(H.created_at)-new Date(_.created_at));we(h)}else c.error(m.message||"Failed to fetch query list"),we([])}catch(m){((a=m.response)==null?void 0:a.status)===401||((u=m.response)==null?void 0:u.status)===403?(c.error("Session expired. Please login again."),sessionStorage.clear(),localStorage.clear(),i("/login")):c.error("Failed to load tickets. Please try again."),we([])}},Ie=async()=>{var a,u;if(E)try{const{data:m}=await L.post(A.HELP_AND_SUPPORT.PROBLEM_TYPES);it(m.data||[])}catch(m){(((a=m.response)==null?void 0:a.status)===401||((u=m.response)==null?void 0:u.status)===403)&&c.error("Session expired. Please login again.")}},ut=async()=>{var a,u,m,h;if(E)try{const _=await L.post(A.HELP_AND_SUPPORT.DYNAMIC_USER_FIELDS,{user_id:E});xe((u=(a=_==null?void 0:_.data)==null?void 0:a.data)==null?void 0:u.list)}catch(_){(((m=_.response)==null?void 0:m.status)===401||((h=_.response)==null?void 0:h.status)===403)&&(c.error("Session expired. Please login again."),i("/login"))}},Ue=async a=>{if(a)try{if(Te(!0),response.data.status){const u=response.data.data||[];ae(u)}else ae([])}catch(u){globalThis.__APP_LOGGER__.log(u),ae([])}finally{Te(!1)}},Ee=async(a,u,m,h)=>{var _,H,et,tt;if(!E){c.error("User session invalid. Please login again.");return}try{Be(u),Ne(a),ot(m),h!=null&&h.conversation_id&&ce(h.conversation_id),h!=null&&h.freshchat_user_id&&We(h.freshchat_user_id);const e=ve==null?void 0:ve.find(n=>n.ticket_id===u),r=e==null?void 0:e.support_ticket_id;if(r&&E){const n=await L.post(A.HELP_AND_SUPPORT.SUPPORT_RCV,{user_id:E,ticket_id:r});Me(n.data.messages)}const s=await L.post(A.HELP_AND_SUPPORT.MESSAGE_LIST,{user_id:E,ticket_id:u,student_query_id:a});D(((H=(_=s==null?void 0:s.data)==null?void 0:_.data)==null?void 0:H.adminMsglist)||[]),z(((tt=(et=s==null?void 0:s.data)==null?void 0:et.data)==null?void 0:tt.userMsglist)||[]),h!=null&&h.conversation_id?await Ue(h.conversation_id):ae([]),Ge(!0),me(),suportmsg()}catch(e){globalThis.__APP_LOGGER__.log(e)}},ye=a=>{var u;if((u=a.target.files)!=null&&u[0]){const m=a.target.files[0];if(m.type.startsWith("video/")&&m.size>2*1024*1024){c.error("Video must be less than or equal to 2 MB.");return}se(m)}},he=()=>!C&&!R?(c.error("Please enter a message or attach a file."),!1):!E||!V||!K?(c.error("Session error. Please refresh the page."),!1):!0,ne=async()=>{try{const a=await L.post(A.HELP_AND_SUPPORT.SEND_FRESH_CHAT_MSG,{conversation_id:G,user_id:E,message_text:C||"",student_query_id:K,ticket_id:V,freshchat_user_id:de});a.data.status?(c.success("Message sent successfully"),await Ue(G),Je()):c.error(a.data.message||"Failed to send message")}catch(a){globalThis.__APP_LOGGER__.log(a),c.error("Failed to send message. Please try again.")}},ft=()=>{const a=new FormData;return a.append("user_id",E),a.append("ticket_id",V),a.append("student_query_id",K),a.append("meassage",C||"Image uploaded"),a.append("sender","user"),R&&(R.type.startsWith("video/")?a.append("sender_video",R):R.type.startsWith("image/")&&a.append("sender_img",R)),a},Ze=async()=>{try{const a=ft(),u=await L.post(A.HELP_AND_SUPPORT.SEND_MESSAGE,a,{headers:{"Content-Type":"multipart/form-data"}});if(u.data.status){c.success(u.data.statuscode||"Message sent successfully");const m=Y.find(h=>h.id===K);Ee(K,V,lt,m),Je()}else c.error(u.data.statuscode||"Failed to send message")}catch(a){globalThis.__APP_LOGGER__.log(a),c.error("An error occurred. Please try again.")}},Je=()=>{T(""),se(null)},Xe=async()=>
2{if(he()){if(G&&de){await ne();return}await Ze()}},Qe=a=>{B({...Z,[a.target.name]:a.target.value})},xt=a=>{const u=Array.from(a.target.files);_e(u)},De=a=>{ie(a.target.value)},gt=()=>{ie((p==null?void 0:p.mobile)||"")},_t=async a=>{var u;if(a.preventDefault(),!Z.category||!Z.query){c.error("Please fill all required fields");return}if(!E){c.error("User session invalid. Please login again.");return}try{Se(!0);const m=new FormData;m.append("user_id",E),m.append("username",(p==null?void 0:p.name)||""),m.append("phone_no",(p==null?void 0:p.mobile)||""),m.append("whatsapp_no",J||(p==null?void 0:p.mobile)||""),m.append("email",(p==null?void 0:p.email)||""),m.append("problem_type",Z.category),m.append("description",Z.query),m.append("subject",Z.category),m.append("qry_img",imageFile);const h=await L.post(A.HELP_AND_SUPPORT.STUDENT_QUERY,m,{headers:{"Content-Type":"multipart/form-data"}});if(h.data.status){const _=h.data.ticket_id;c.success(` Ticket #${_} raised successfully!`,{autoClose:1e3,position:"top-center"}),B({category:"",query:""}),_e([]),ie(""),Re(!1),await me()}else c.error(h.data.message||"Failed to raise ticket")}catch(m){if(m.response){const h=m.response.status,_=(u=m.response.data)==null?void 0:u.message;h===404?c.error("API endpoint not found. Please contact support."):h===401||h===403?(c.error("Session expired. Please login again."),sessionStorage.clear(),localStorage.clear(),i("/login")):h===500?c.error("Server error. Please try again later."):c.error(_||"Failed to submit. Please try again.")}else m.request?c.error("Network error. Please check your connection."):c.error("Failed to submit. Please try again.")}finally{Se(!1)}},Ce=[...nt.map(a=>({...a,isAdmin:!0,source:"regular",id:`admin-${a.id}`})),...qe.map(a=>({...a,isAdmin:!1,source:"regular",id:`user-${a.id}`})),...Ye.map((a,u)=>{var m,h,_;return{...a,isAdmin:a.actor_type==="agent",source:"freshchat",meassage:((_=(h=(m=a.message_parts)==null?void 0:m[0])==null?void 0:h.text)==null?void 0:_.content)||a.message||"",created_at:a.created_time||a.created_at,id:`freshchat-${a.id||u}`}})].sort((a,u)=>new Date(a.created_at)-new Date(u.created_at)),Le=a=>{$e(!0),ze(a)},bt=a=>{if(!a)return a;const u=/(https?:\/\/[^\s]+)/g;return a.split(u).map((h,_)=>u.test(h)?t.jsx("a",{href:h,className:"noreferrerPart",target:"_blank",rel:"noopener noreferrer",children:h},h.id):h)},yt=()=>{pe.current&&(pe.current.scrollTop=pe.current.scrollHeight)};return l.useEffect(()=>{if(!Q||!V||!K)return;const a=setInterval(async()=>{var u,m,h,_;try{const H=await L.post(A.HELP_AND_SUPPORT.MESSAGE_LIST,{user_id:E,ticket_id:V,student_query_id:K});D(((m=(u=H==null?void 0:H.data)==null?void 0:u.data)==null?void 0:m.adminMsglist)||[]),z(((_=(h=H==null?void 0:H.data)==null?void 0:h.data)==null?void 0:_.userMsglist)||[]),G&&await Ue(G)}catch(H){globalThis.__APP_LOGGER__.log(H)}},15e3);return()=>clearInterval(a)},[Q,V,K,G]),l.useEffect(()=>{yt()},[Ce]),t.jsxs(t.Fragment,{children:[t.jsx(Ct,{}),t.jsxs("div",{className:"py-10! w-full! float-left! bg-[#fafafa]! max-[767px]:mt-1.25! max-[767px]:py-3!",children:[t.jsxs("div",{className:"tw-container",children:[t.jsx("a",{className:"w-32.5! text-base! py-2.5! px-0! mb-4! inline-block! font-semi-bold! bg-[#007aff]! text-white! rounded-xl! items-center! justify-center! gap-2! text-center! no-underline! max-[767px]:w-25! max-[767px]:text-[13px]! max-[767px]:py-1.75! max-[767px]:mb-3.75! max-[767px]:rounded-[10px]!",href:"/",children:"Home"}),t.jsx("div",{className:"rounded-[10px]! py-12.5! px-7.5! bg-[linear-gradient(0deg,#eeeeee_0%,#fafafa_52%,#ffffff_100%)]! shadow-[0_1px_2px_#0000000d]! max-[767px]:hidden!",children:t.jsx("h1",{className:"font-semibold! text-[22px]! text-[#212121]! m-0! leading-[1.2]! md:text-[18px]!",children:"Technical Support"})})]}),!F&&!Oe&&t.jsx("div",{className:"tw-container",children:t.jsxs("div",{className:"w-full! py-6! max-[767px]:py-3! max-[767px]:px-2.5! max-[767px]:pb-18.75!",children:[t.jsxs("h3",{className:"ticket-title1 flex! items-center! gap-2! text-[17px]! font-semibold! mb-2.5! text-[#212121]! leading-normal! max-[767px]:text-[15px]! max-[767px]:gap-1.5!",children:["ALL Tickets (",Y==null?void 0:Y.length,")"]}),Y==null?void 0:Y.map((a,u)=>{var m;return t.jsxs("button",{type:"button",className:"border-t! border-[#e5e5e5]! py-5.5! px-0! flex! justify-between! items-start! w-full! text-left appearance-button! border-0! shadow-inherit! outline-inherit! max-[767px]:py-3.75! max-[767px]:gap-2.5! max-[767px]:flex-col!",tabIndex:0,onClick:()=>Ee(a==null?void 0:a.id,a==null?void 0:a.ticket_id,a==null?void 0:a.status,a),onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&Ee(a==null?void 0:a.id,a==null?void 0:a.ticket_id,a==null?void 0:a.status,a)},children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-base! font-semibold! mb-1! text-[#333333]!",children:a.problem_type}),t.jsxs("p",{className:"ticket-id text-[#ff4b4b]! text-[13px]! font-medium! mb-0! max-[767px]:text-[12px]!",children:["Ticket ID: ",a.ticket_id]}),t.jsxs("p",{className:"mt-1.5! text-[#999]! text-xs! w-87.5! whitespace-nowrap! overflow-hidden! text-ellipsis! mb-0! normal-case! font-normal! max-[767px]:w-full!",children:[(m=a.description)==null?void 0:m.slice(0,50),"..."]}),a.conversation_id&&t.jsx("span",{className:"bg-[#e3f2fd]! text-[#1976d2]! py-0.5! px-2! rounded-xl! text-xs! mt-1.25! inline-block!",children:"ð¬ Freshchat"})]}),t.jsxs("div",{children:[(()=>{let h="bg-gray-400 text-white",_="Unknown";return a.status==0?(h="bg-[#4caf50]! text-white!",_="Open"):a.status==1?(h="bg-[#f44336]! text-white!",_="Close"):a.status==2?(h="bg-[#ff9800]! text-white!",_="Reopen"):a.status==3?(h="bg-[#2196f3]! text-white!",_="In Progress"):a.status==5&&(h="bg-[#9c27b0]! text-white!",_="Resolved"),t.jsx("span",{className:`${h} py-2! px-3! rounded-[20px]! text-xs! font-semibold! uppercase! inline-block! min-w-22.5! text-center! bg-[#4caf50]! max-[767px]:py-1.75! max-[767px]:px-3! max-[767px]:text-[11px]!`,children:_})})(),(a==null?void 0:a.count_msg)>0&&t.jsx("div",{className:"color1 bg-[#007aff]! w-5! h-5! pl-1.5! rounded-full! pr-1! ml-21.5! mt-0.5! text-[13px]!",children:t.jsx("div",{className:"unread1 text-[wheat]! pr-1! relative!",children:t.jsx("span",{className:"unread-badge1 absolute!",children:a.count_msg})})})]})]},a.id??u)}),t.jsx("div",{className:"raise-wrapper1 flex! justify-center! mt-10! fixed! bottom-5! left-1/2
2! -translate-x-1/2! z-1000!",children:t.jsx("button",{className:"raise-btn1 bg-[#006bff]! text-white! py-3.5! px-15! rounded-[40px]! text-[15px]! font-medium! border-0! cursor-pointer! shadow-[0_8px_20px_rgba(0,102,255,0.2)]! transition-colors! duration-300! ease-in-out! max-[767px]:py-2.5! max-[767px]:px-7.5! max-[767px]:text-xs! max-[767px]:rounded-[30px]! max-[767px]:w-full! max-[767px]:max-w-75!",onClick:ht,children:"Raise New Ticket"})})]})}),t.jsxs("div",{className:"tw-container",children:[F&&t.jsx(It,{userData:{userId:E,name:p==null?void 0:p.name,email:p==null?void 0:p.email,phone:p==null?void 0:p.mobile},imageUpload:ge,setImageUpload:Ve,onClose:()=>j(!1),onTicketRaised:()=>{me()}}),Oe&&t.jsxs("div",{className:"oldFormContainer",children:[t.jsx("div",{className:"formHeader",children:t.jsx("h2",{children:"Raise Your Query"})}),t.jsx("form",{onSubmit:_t,className:"formData",children:t.jsxs("div",{className:"row",children:[t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"category",children:"Choose Your category *"}),t.jsxs("select",{id:"category",name:"category",value:Z.category,onChange:Qe,required:!0,children:[t.jsx("option",{value:"",children:"Select Category"}),fe==null?void 0:fe.map(a=>t.jsx("option",{value:a==null?void 0:a.id,children:a==null?void 0:a.problem_type},a.id))]})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"name",children:"Name *"}),t.jsx("input",{type:"text",name:"firstname",placeholder:"Your name..",value:(p==null?void 0:p.name)||"",disabled:!0})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"email",children:"Email Id *"}),t.jsx("input",{type:"email",name:"email",placeholder:"Your email id..",value:(p==null?void 0:p.email)||"",disabled:!0})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"mobile",children:"Mobile No *"}),t.jsx("input",{type:"number",name:"phone",placeholder:"Your Mobile Number..",value:(p==null?void 0:p.mobile)||"",disabled:!0})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"device",children:"Device info"}),t.jsx("input",{className:"deviceInfo",type:"text",name:"subject",placeholder:"device info..",value:(q==null?void 0:q.split("DT")[1])||"",disabled:!0})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-6 col-lg-4",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"whatsapp",children:"Whatsapp No"}),t.jsxs("div",{className:"sameasMobileno",children:[t.jsx("button",{type:"button",className:"whatsAppData",onClick:gt,children:"Same as Mobile No"}),t.jsx("input",{className:"whatsappNumber",type:"number",name:"subject",placeholder:"whatsapp number...",onChange:De,value:J})]})]})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-12 col-lg-12",children:t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"query",children:"Description of Query *"}),t.jsx("textarea",{name:"query",placeholder:"Enter Details..",value:Z.query,onChange:Qe,required:!0})]})}),t.jsx("div",{className:"col-12 col-sm-4 col-md-4 col-lg-4 col-xl-3",children:t.jsx("div",{className:"form-group uploadGroup",children:t.jsx("input",{type:"file",ref:Ae,name:"file",id:"fileInput",multiple:!0,accept:"image/*,video/*",onChange:xt})})}),re.length>0&&t.jsx("div",{className:"col-12 col-sm-12 col-md-12 col-lg-12",children:t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"preview-files",children:re==null?void 0:re.map(a=>t.jsx("div",{className:"preview-file",children:a.type.startsWith("video/")?t.jsxs("video",{width:"100px",height:"auto",controls:!0,className:"margbordr",children:[t.jsx("source",{src:URL.createObjectURL(a),type:a.type}),t.jsx("track",{kind:"captions",src:"/captions/empty.vtt",srcLang:"en",label:"English captions",default:!0}),"Your browser does not support the video tag."]}):t.jsx("img",{className:"picSet",width:"100px",src:URL.createObjectURL(a),loading:"lazy",alt:"Preview"})},a.id))})})}),t.jsx("div",{className:"col-12 col-sm-12 col-md-12 col-lg-12",children:t.jsx("input",{type:"submit",value:ke?"Submitting...":"Submit",className:"subbtn",disabled:ke})})]})})]}),t.jsxs(ue,{show:Q,onHide:pt,className:"ViewModel",children:[t.jsx(ue.Header,{closeButton:!0,children:t.jsxs(ue.Title,{children:["Ticket: ",V,G&&t.jsx("span",{className:"ml-2.5! text-sm! text-[#1976d2]! bg-[#e3f2fd]! py-0.5! px-2! rounded-xl!",children:"ð¬ Freshchat Active"})]})}),t.jsxs(ue.Body,{children:[dt&&t.jsxs("div",{className:"text-center! p-5!",children:[t.jsx(Et,{}),t.jsx("p",{children:"Loading Freshchat messages..."})]}),t.jsxs("div",{className:"chat-container",ref:pe,children:[t.jsx("div",{className:"chat-area",children:je==null?void 0:je.map(a=>{const u=a.sender==="user";return t.jsxs("div",{className:`chat-row ${u?"right":"left"}`,children:[!u&&t.jsx("span",{children:t.jsx("img",{src:`${at}/dams-icon/logo.png`,alt:"logo"})}),t.jsx("div",{className:"chat-bubble",children:a.message}),u&&t.jsx("span",{children:t.jsx("img",{src:M==null?void 0:M.profile_picture,alt:"User"})})]},a.id)})}),Ce.length===0?t.jsx("div",{className:"text-center! p-5! text-[#999]!",children:"No messages yet. Start the conversation!"}):Ce.map((a,u)=>{var m,h;return t.jsxs("div",{className:`message ${a.isAdmin?"admin":"user"}`,children:[t.jsxs("span",{children:[" ",t.jsx("img",{src:a.isAdmin?`${at}/dams-icon/logo.png`:(M==null?void 0:M.profile_picture)||`${at}/default-user.png`,alt:a.isAdmin?"DAMS":"User",className:"chat-avatar"})]}),t.jsxs("div",{className:"message-content",children:[a.source==="freshchat"&&t.jsx("small",{className:"text-[10px]! text-[#0a3764ff]! bg-[#e78300ff]! py-0.5! px-1.5! rounded-lg! inline-block! mb-1!",children:"ð¬ Freshchat"}),a.meassage&&t.jsx("p",{children:bt(a.meassage)}),a.sender_img&&t.jsx("button",{type:"button",onClick:()=>Le(a.sender_img),className:"chat-image-button",children:t.jsx("img",{src:`https://devmedia.damsdelhi.com/${a.sender_img}`,alt:"attachment",className:"chat-image"})}),a.sender_video&&t.jsxs("video",{width:"200",controls:!0,className:"rounded-lg!",children:[t.jsx("source",{src:a.sender_video,type:"video/mp4"}),t.jsx("track",{kind:"captions",src:"/captions/empty.vtt",srcLang:"en",label:"English",default:!0}),"Your browser does not support the video tag."]}),(m=a.message_parts)==null?void 0:m.some(_=>_.image),((h=a.message_parts)==null?void 0:h.some(_=>_.image))&&a.message_parts.filter(_=>_.image).map(_=>t.jsx("button",{type:"button",onClick:()=>Le(_.image.url),className:"chat-image-button",children:t.jsx("img",{src:_.image.url,alt:"Freshchat attachment",className:"chat-image"})}
2,_.image.url)),t.jsx("small",{className:"timestamp",children:Mt(a.created_at)})]})]},a.id||u)})]}),t.jsxs("div",{className:"message-input-container",children:[t.jsx("input",{type:"text",value:C||"",onChange:a=>T(a.target.value),placeholder:G?"Type your message to Freshchat...":"Type your message...",onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),Xe())}}),!G&&t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"file",accept:"image/*,video/*",onChange:ye,className:"hidden",id:"chat-file-input"}),t.jsx("label",{htmlFor:"chat-file-input",className:"file-attach-btn","aria-label":"Attach file",children:t.jsx("em",{className:"fa fa-paperclip","aria-hidden":"true"})})]}),t.jsx("button",{onClick:Xe,disabled:(!C||C.trim()==="")&&!R,className:`${(!C||C.trim()==="")&&!R?"opacity-50! cursor-not-allowed!":"opacity-100! cursor-pointer!"}`,children:G?"ð¬ Send to Freshchat":t.jsx(Lt,{size:22})})]}),R&&!G&&t.jsxs("div",{className:"attached-preview flex! items-center! justify-between! py-2! px-3! bg-[#f5f5f5]! rounded-lg! mt-2!",children:[t.jsxs("small",{children:[t.jsx("em",{className:"fa fa-paperclip"})," Attached:"," ",R.name]}),t.jsx("button",{onClick:()=>se(null),className:"bg-transparent! border-0! text-lg! cursor-pointer! text-[#999]!",children:"Ã"})]}),G&&t.jsxs("div",{className:"py-2! px-3! bg-[#e3f2fd]! rounded-lg! mt-2! text-xs! text-[#1976d2]!",children:["conversation is connected to Freshchat. Messages are synced in real-time.",de&&t.jsxs("div",{className:"mt-1! text-[11px]!",children:["Freshchat User ID: ",de.slice(0,8),"..."]})]})]})]}),t.jsxs(ue,{show:He,onHide:mt,className:"imageZoombg",children:[t.jsx(ue.Header,{closeButton:!0}),t.jsx(ue.Body,{children:t.jsx("img",{src:`https://devmedia.damsdelhi.com/${ct}`,alt:"Zoomed media",className:"imgWidth"})})]}),ee&&t.jsx(At,{handlerClose:be,setIsAuthenticated:oe,handleSignInSuccess:Ke,setSignInModalOpen:X})]})]})]})};Ot.propTypes={setIsAuthenticated:$.func};export{Ot 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.