1import{r as h,w as D,j as e,M as T,C as M,a as F,b as L,p as $,c as A,bl as B,ah as R,v as y,g as b,h as m,a7 as V,k as E,B as H,s as P}from"./index-cOhCav0w.js";import{H as U}from"./Header-BTc3_yFk.js";import{S as z,a as I,b as K,c as Q,d as o}from"./select-CMpsylWz.js";import{T as W,a as X,b as N,c,d as G,e as d}from"./table-BTGfwxKO.js";import{F as S}from"./file-pen-line-BgTQ3W2T.js";import{C as J}from"./circle-check-B4Trbc87.js";import{C as O}from"./circle-x-CLO32wKO.js";import{E as Y}from"./eye-BJMVSpFw.js";import{A as Z}from"./arrow-up-down-by837MwC.js";import"./avatar-z7AtOWUr.js";import"./tabs-P4VDsRm8.js";import"./isPast-CQGIQdjG.js";import"./isTomorrow-DR-ix7Ni.js";import"./isSameDay-DH89sOvn.js";import"./subDays-CF4GyZcL.js";import"./bell-BDvfcA8t.js";import"./clipboard-list-BrFUtPTs.js";import"./calendar-C1rawErJ.js";import"./startOfMonth-SwiHpN_f.js";import"./isSameMonth-BgHynHpu.js";import"./isAfter-DVnZCnOC.js";import"./getDaysInMonth-Cv5opwvR.js";import"./CreateTaskDialog-DMNPP08e.js";import"./plus-CJNf9tmN.js";import"./calendar-days-DzNlh8dE.js";import"./gravatar-DzwRBQfu.js";const q=n=>{const i=(n||"").toLowerCase();return i.includes("signed")||i.includes("completed")?e.jsxs(m,{className:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900 dark:text-emerald-300",children:[e.jsx(J,{className:"h-3 w-3 mr-1"}),"Signed"]}):i.includes("declined")||i.includes("canceled")||i.includes("cancelled")?e.jsxs(m,{variant:"destructive",children:[e.jsx(O,{className:"h-3 w-3 mr-1"}),"Declined"]}):i.includes("sent")||i.includes("awaiting")?e.jsxs(m,{className:"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300",children:[e.jsx(V,{className:"h-3 w-3 mr-1"}),"Awaiting Signature"]}):i.includes("viewed")?e.jsxs(m,{className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",children:[e.jsx(Y,{className:"h-3 w-3 mr-1"}),"Viewed"]}):e.jsxs(m,{variant:"secondary",children:[e.jsx(E,{className:"h-3 w-3 mr-1"}),n||"Pending"]})};function Ce(){const[n,i]=h.useState("created_at"),[g,f]=h.useState("desc"),[l,v]=h.useState("all"),{data:p=[],isLoading:C}=D({queryKey:["signature-requests"],queryFn:async()=>{const{data:s,error:t}=await P.from("signature_requests").select(` 2 *, 3 clients:client_id (first_name, last_name), 4 policies:policy_id (policy_number, display_id) 5 `).order("created_at",{ascending:!1});if(t)throw t;return(s||[]).map(a=>{var r,u,x,w;return{...a,client_first_name:(r=a.clients)==null?void 0:r.first_name,client_last_name:(u=a.clients)==null?void 0:u.last_name,policy_number:(x=a.policies)==null?void 0:x.policy_number,policy_display_id:(w=a.policies)==null?void 0:w.display_id}})}}),_=h.useMemo(()=>{let s=[...p];return l!=="all"&&(s=s.filter(t=>{const a=(t.status||"").toLowerCase();return l==="signed"?a.includes("signed")||a.includes("completed"):l==="awaiting"?a.includes("sent")||a.includes("awaiting"):l==="declined"?a.includes("declined")||a.includes("canceled")||a.includes("cancelled"):l==="viewed"?a.includes("viewed"):!0})),s.sort((t,a)=>{let r=0;if(n==="created_at")r=new Date(t.created_at).getTime()-new Date(a.created_at).getTime();else if(n==="status")r=(t.status||"").localeCompare(a.status||"");else if(n==="signer_name"){const u=t.signer_name||`${t.client_first_name||""} ${t.client_last_name||""}`.trim()||"",x=a.signer_name||`${a.client_first_name||""} ${a.client_last_name||""}`.trim()||"";r=u.localeCompare(x)}return g==="desc"?-r:r}),s},[p,n,g,l]),k=s=>{n===s?f(t=>t==="asc"?"desc":"asc"):(i(s),f("desc"))},j=({field:s,children:t})=>e.jsxs(H,{variant:"ghost",size:"sm",className:"-ml-3 h-8 data-[state=open]:bg-accent",onClick:()=>k(s),children:[t,e.jsx(Z,{className:"ml-2 h-4 w-4"})]});return e.jsxs(T,{children:[e.jsx(U,{title:"ESign Documents",subtitle:"View all documents sent for signature and their status"}),e.jsx("div",{className:"p-6 space-y-6",children:e.jsxs(M,{children:[e.jsx(F,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(L,{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-5 w-5 text-primary"}),"Signature Requests"]}),e.jsxs($,{children:[p.length," total documents sent for signature"]})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(z,{value:l,onValueChange:v,children:[e.jsx(I,{className:"w-[180px]",children:e.jsx(K,{placeholder:"Filter by status"})}),e.jsxs(Q,{children:[e.jsx(o,{value:"all",children:"All Statuses"}),e.jsx(o,{value:"awaiting",children:"Awaiting Signature"}),e.jsx(o,{value:"viewed",children:"Viewed"}),e.jsx(o,{value:"signed",children:"Signed"}),e.jsx(o,{value:"declined",children:"Declined/Canceled"})]})]})})]})}),e.jsx(A,{children:C?e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsx(B,{className:"h-12 w-full"},s))}):_.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(S,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No signature requests found"}),e.jsx("p",{className:"text-sm mt-1",children:"Documents sent for signature will appear here"})]}):e.jsx("div",{className:"rounded-md border",children:e.jsxs(W,{children:[e.jsx(X,{children:e.jsxs(N,{children:[e.jsx(c,{children:e.jsxs(j,{field:"created_at",children:[e.jsx(R,{className:"h-4 w-4 mr-1"}),"Date Sent"]})}),e.jsx(c,{children:e.jsx(j,{field:"signer_name",children:"Customer Name"})}),e.jsx(c,{children:"Policy #"}),e.jsx(c,{children:"Subject"}),e.jsx(c,{children:e.jsx(j,{field:"status",children:"Status"})}),e.jsx(c,{children:"Last Updated"})]})}),e.jsx(G,{children:_.map(s=>{const t=s.signer_name||`${s.client_first_name||""} ${s.client_last_name||""}`.trim()||s.signer_email||"Unknown";return e.jsxs(N,{children:[e.jsx(d,{className:"font-medium",children:y(new Date(s.created_at),"MMM d, yyyy h:mm a")}),e.jsx(d,{children:s.client_id?e.jsx(b,{to:`/dashboard/clients/${s.client_id}`,className:"text-primary hover:underline",children:t}):t}),e.jsx(d,{children:s.policy_id?e.jsx(b,{to:`/dashboard/policies/${s.policy_id}`,className:"text-primary hover:underline font-mono text-sm",children:s.policy_display_id||s.policy_number||"View Policy"}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(d,{className:"max-w-[250px] truncate",children:s.subject||"Signature Request"}),e.jsx(d,{children:q(s.status)}),e.jsx(d,{className:"text-muted-foreground text-sm",children:y(new Date(s.updated_at),"MMM d, yyyy h:mm a")})]},s.id)})})]})})})]})})]})}export{Ce 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.