import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{r}from"./api-Duu96wkE.js";import{E as i,L as a,M as o,N as s,P as c,j as l}from"./index-DyQEyT-0.js";import{t as u}from"./Badge-BGqYAYKM.js";import{t as d}from"./EmptyState-BCP63FMk.js";import{t as f}from"./ErrorState-BkSpMSl3.js";import{t as p}from"./Dialog-BG29laiW.js";import{t as m}from"./Field-o9dlLBxx.js";import{TicketThread as h}from"./SupportPage-DNGUfgwz.js";var g=e(t(),1),_=n(),v=`block w-full rounded-lg border-0 px-3 py-2.5 text-sm ring-1 ring-inset ring-slate-300 focus:ring-2 focus:ring-brand-600`,y={open:`warning`,in_progress:`info`,waiting_applicant:`info`,escalated:`danger`,resolved:`success`,closed:`neutral`};function b(){let{data:e,isPending:t,error:n,refetch:r}=a({per_page:25}),[o,s]=(0,g.useState)(!1),[c,p]=(0,g.useState)(null),[m,v]=(0,g.useState)(null);return t?(0,_.jsx)(i,{label:`Loading your messages`}):n?(0,_.jsx)(f,{error:n,onRetry:()=>r()}):(0,_.jsxs)(`div`,{className:`space-y-6`,children:[m&&(0,_.jsx)(f,{error:Error(m)}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h1`,{className:`text-lg font-semibold text-slate-900`,children:`Help`}),(0,_.jsx)(`p`,{className:`text-sm text-slate-500`,children:`Ask us anything about your application.`})]}),(0,_.jsx)(l,{onClick:()=>s(!0),children:`Ask a question`})]}),e.tickets.length===0?(0,_.jsx)(d,{title:`No messages yet`,description:`If something is unclear or a payment has not appeared, tell us here.`}):(0,_.jsx)(`ul`,{className:`space-y-2`,children:e.tickets.map(e=>(0,_.jsxs)(`li`,{className:`rounded-xl border border-slate-200 bg-white p-4`,children:[(0,_.jsxs)(`button`,{className:`flex w-full flex-wrap items-start justify-between gap-3 text-left`,onClick:()=>p(c===e.id?null:e.id),children:[(0,_.jsxs)(`span`,{children:[(0,_.jsx)(`span`,{className:`block font-medium text-slate-900`,children:e.subject}),(0,_.jsxs)(`span`,{className:`text-xs text-slate-500`,children:[e.ticket_no,` · `,e.category_label,` · opened `,e.opened_at?.slice(0,10)]})]}),(0,_.jsx)(u,{tone:y[e.status]??`neutral`,children:e.status_label})]}),c===e.id&&(0,_.jsx)(h,{ticketId:e.id,onError:v,applicantView:!0})]},e.id))}),(0,_.jsx)(S,{onError:v}),o&&(0,_.jsx)(x,{onClose:()=>s(!1),onError:v})]})}function x({onClose:e,onError:t}){let n=s(),[i,a]=(0,g.useState)(``),[o,c]=(0,g.useState)(`other`),[u,d]=(0,g.useState)(``);return(0,_.jsx)(p,{title:`Ask a question`,description:`We answer sooner on payments and refunds.`,onClose:e,children:(0,_.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[(0,_.jsx)(m,{label:`Subject`,value:i,onChange:e=>a(e.target.value)}),(0,_.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-slate-700`,children:[`What is it about`,(0,_.jsxs)(`select`,{className:v,value:o,onChange:e=>c(e.target.value),children:[(0,_.jsx)(`option`,{value:`payment`,children:`A payment`}),(0,_.jsx)(`option`,{value:`document`,children:`A document`}),(0,_.jsx)(`option`,{value:`process_delay`,children:`A delay`}),(0,_.jsx)(`option`,{value:`agent`,children:`An agent`}),(0,_.jsx)(`option`,{value:`refund`,children:`A refund`}),(0,_.jsx)(`option`,{value:`service`,children:`Service`}),(0,_.jsx)(`option`,{value:`other`,children:`Something else`})]})]}),(0,_.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-slate-700`,children:[`Tell us what happened`,(0,_.jsx)(`textarea`,{rows:5,className:v,value:u,onChange:e=>d(e.target.value)})]}),(0,_.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,_.jsx)(l,{variant:`ghost`,onClick:e,children:`Cancel`}),(0,_.jsx)(l,{disabled:n.isPending||i.trim()===``||u.trim()===``,onClick:async()=>{t(null);try{await n.mutateAsync({subject:i,category:o,body:u}),e()}catch(e){let n=r(e);t(Object.values(n.errors)[0]?.[0]??n.message)}},children:`Send`})]})]})})}function S({onError:e}){let{data:t,isPending:n}=o(),i=c();return n?null:(0,_.jsxs)(`section`,{className:`space-y-3 rounded-xl border border-slate-200 bg-white p-5`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-sm font-semibold text-slate-900`,children:`How we contact you`}),(0,_.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Messages about your money, visa and travel are always sent, whatever you choose here.`})]}),(0,_.jsx)(`ul`,{className:`space-y-2 text-sm`,children:(t??[]).map(t=>(0,_.jsxs)(`li`,{className:`flex items-center justify-between gap-3`,children:[(0,_.jsx)(`span`,{className:`text-slate-700`,children:t.label}),t.can_disable?(0,_.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-slate-500`,children:[(0,_.jsx)(`input`,{type:`checkbox`,checked:t.is_enabled,onChange:async n=>{e(null);try{await i.mutateAsync({[t.channel]:n.target.checked})}catch(t){let n=r(t);e(Object.values(n.errors)[0]?.[0]??n.message)}}}),t.is_enabled?`On`:`Off`]}):(0,_.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Always on`})]},t.channel))})]})}export{b as default};